/* ============================================================
   PI3 Project Tracker — Style (แนวเดียวกับต้นแบบ SiteFlow)
   ============================================================ */
* { box-sizing: border-box; }
:root {
  --teal-dark: #0f4c4c;
  --teal: #136767;
  --teal-bright: #17b3a3;
  --pink: #e94f7c;
  --green: #28b16d;
  --gray: #c7cdd0;
  --bg: #f4f6f7;
  --card: #ffffff;
  --text: #17303a;
  --text-mute: #6b7c82;
  --border: #e7ecec;
}
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
}
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, var(--teal-dark), var(--teal));
  color: #fff;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--pink), #ff8a5c);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
.brand div b { display: block; font-size: 15px; }
.brand div span { display: block; font-size: 11px; opacity: .7; }

.nav-label { font-size: 11px; opacity: .6; margin: 14px 4px 6px; text-transform: uppercase; letter-spacing: .04em; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; margin-bottom: 4px;
  font-size: 14px; cursor: pointer; opacity: .85;
  transition: background .15s, opacity .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); opacity: 1; }
.nav-item.active { background: var(--pink); opacity: 1; font-weight: 600; }
.sidebar-footer { margin-top: auto; font-size: 12px; opacity: .7; }

/* Main content */
.content { padding: 24px 28px; overflow-x: auto; }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; }
.page-header p { margin: 0; color: var(--text-mute); font-size: 13px; }

.project-select {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-size: 13px; min-width: 240px;
}

.btn {
  border: none; border-radius: 8px; padding: 9px 16px; font-size: 13px;
  font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: linear-gradient(135deg, var(--pink), #ff6b6b); color: #fff; }
.btn-secondary { background: #eef2f2; color: var(--text); }
.btn-danger { background: #fdeef0; color: var(--pink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.card { background: var(--card); border-radius: 12px; padding: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card .icon { font-size: 20px; margin-bottom: 8px; }
.card .value { font-size: 28px; font-weight: 700; }
.card .label { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.card.warn .value { color: var(--pink); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .sidebar { display: none; } }

.progress-row { margin-bottom: 14px; }
.progress-row .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.progress-track { height: 8px; border-radius: 6px; background: #eef2f2; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 6px; }

/* Status colors */
.status-ongoing { color: var(--teal-bright); }
.status-late { color: var(--pink); }
.status-done { color: var(--green); }
.status-planned { color: #8f9ea3; }
.fill-ongoing { background: var(--teal-bright); }
.fill-late { background: var(--pink); }
.fill-done { background: var(--green); }
.fill-planned { background: var(--gray); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.badge.ongoing { background: #e6f9f6; color: #0f9285; }
.badge.ongoing::before { background: var(--teal-bright); }
.badge.late { background: #fdeef0; color: var(--pink); }
.badge.late::before { background: var(--pink); }
.badge.done { background: #e9f8ef; color: var(--green); }
.badge.done::before { background: var(--green); }
.badge.planned { background: #f1f3f4; color: #6b7c82; }
.badge.planned::before { background: var(--gray); }

/* Task table */
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
thead th { text-align: left; font-size: 12px; color: var(--text-mute); padding: 12px 14px; border-bottom: 1px solid var(--border); }
tbody td { padding: 12px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafcfc; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 15px; padding: 4px 6px; color: var(--text-mute); }
.icon-btn:hover { color: var(--text); }

/* Gantt container */
.gantt-card { background: var(--card); border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); overflow-x: auto; }
.legend { display: flex; gap: 16px; font-size: 12px; margin-bottom: 12px; color: var(--text-mute); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.view-mode-switch { display: flex; gap: 4px; background: #eef2f2; border-radius: 8px; padding: 3px; }
.view-mode-btn {
  border: none; background: transparent; padding: 7px 14px; border-radius: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-mute); cursor: pointer;
}
.view-mode-btn.active { background: #fff; color: var(--teal-dark); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.bar-wrapper.ongoing .bar-progress { fill: var(--teal-bright); }
.bar-wrapper.ongoing .bar { fill: #d6f2ee; }
.bar-wrapper.late .bar-progress { fill: var(--pink); }
.bar-wrapper.late .bar { fill: #fbdbe3; }
.bar-wrapper.done .bar-progress { fill: var(--green); }
.bar-wrapper.done .bar { fill: #d9f2e3; }
.bar-wrapper.planned .bar-progress { fill: var(--gray); }
.bar-wrapper.planned .bar { fill: #ecefef; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,30,30,.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 480px; max-width: 92vw; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 18px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-mute); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] { flex: 1; }
.slider-value { font-weight: 700; color: var(--pink); font-size: 13px; min-width: 40px; text-align: right; }

.checklist { max-height: 160px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.checklist-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 13px; cursor: pointer; }
.checklist-item:hover { background: #fafcfc; }
.checklist-item input { margin: 0; }
.checklist-item small { color: var(--text-mute); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-mute); }
.loading { text-align: center; padding: 40px 20px; color: var(--text-mute); font-size: 13px; }
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--teal-dark); color: #fff;
  padding: 12px 18px; border-radius: 10px; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.2);
  z-index: 100;
}
.toast.error { background: var(--pink); }

/* Login screen */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
}
.login-card { background: #fff; border-radius: 16px; padding: 32px; width: 340px; max-width: 90vw; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-error { background: #fdeef0; color: var(--pink); font-size: 12px; padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; }

/* Report view */
.report-card { background: var(--card); border-radius: 12px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.report-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 18px 0; }
.report-stats .stat { text-align: center; }
.report-stats .stat .n { font-size: 26px; font-weight: 700; }
.report-stats .stat .l { font-size: 12px; color: var(--text-mute); }

@media print {
  .sidebar, .page-header, #btn-add-task, .project-select, .ai-fab, .ai-panel { display: none !important; }
  .app { display: block !important; }
  .content { padding: 0; }
  body { background: #fff; }
  .report-card { box-shadow: none; }
}

/* AI Assistant */
.ai-fab {
  position: fixed; bottom: 24px; right: 24px; width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--teal-bright));
  color: #fff; border: none; font-size: 22px; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 40;
}
.ai-panel {
  position: fixed; top: 0; right: -420px; width: 400px; max-width: 92vw; height: 100vh;
  background: #f4f6f7; box-shadow: -4px 0 24px rgba(0,0,0,.15);
  display: flex; flex-direction: column; z-index: 60; transition: right .25s ease;
}
.ai-panel.open { right: 0; }
.ai-panel-header {
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff; padding: 16px 18px; display: flex; justify-content: space-between; align-items: center;
}
.ai-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.6; max-width: 88%; white-space: pre-wrap; }
.ai-msg-bot { background: #fff; align-self: flex-start; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.ai-msg-user { background: var(--pink); color: #fff; align-self: flex-end; }
.ai-msg-loading { color: var(--text-mute); font-size: 12px; }
.ai-suggestions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.ai-chip {
  background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  font-size: 12px; cursor: pointer; color: var(--teal-dark);
}
.ai-chip:hover { background: #eef8f7; }
.ai-input-row { display: flex; gap: 8px; padding: 12px 16px; background: #fff; border-top: 1px solid var(--border); }
.ai-input-row input { flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; }
.ai-input-row .btn { padding: 10px 16px; }
