:root {
  --navy: #10293D;
  --navy-light: #1E415C;
  --teal: #0F6B5C;
  --gold: #C9A227;
  --bg: #F3F5F2;
  --surface: #FFFFFF;
  --ink: #17212B;
  --muted: #64707A;
  --border: #E2E6E1;
  --danger: #B23A2F;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,41,61,0.06), 0 4px 16px rgba(16,41,61,0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Sarabun', 'Noto Sans Thai', sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* ---------- Header ---------- */
.topbar {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: #fff;
  padding: 28px 32px 24px;
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.topbar p {
  margin: 4px 0 0;
  color: rgba(255,255,255,0.72);
  font-size: 13.5px;
}

.eyebrow {
  display: inline-block;
  font-size: 11.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--gold);
  font-weight: 700;
  margin-bottom: 6px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  color: rgba(255,255,255,0.85);
}

.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #4CD07A;
  box-shadow: 0 0 0 3px rgba(76,208,122,0.25);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%,100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Layout ---------- */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 32px 64px;
}

/* ---------- Signature overview bar ---------- */
.overview-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 20px;
  margin-bottom: 20px;
}

.overview-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}

.overview-head h2 {
  font-size: 15px;
  margin: 0;
  font-weight: 700;
  color: var(--navy);
}

.overview-head .total-count {
  font-size: 13px;
  color: var(--muted);
}
.overview-head .total-count b {
  color: var(--ink);
  font-size: 15px;
}

.split-bar {
  display: flex;
  width: 100%;
  height: 40px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
}

.split-seg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  transition: filter 0.15s ease;
  cursor: default;
  position: relative;
}
.split-seg:hover { filter: brightness(1.08); }
.split-seg:not(:last-child) { border-right: 2px solid var(--surface); }

.legend-row {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
}
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item .pct { font-weight: 700; }
.legend-item .cnt { color: var(--muted); }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  border-left: 4px solid var(--dept-color, var(--teal));
}
.stat-card .stat-name {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.stat-card .stat-num {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  font-family: 'JetBrains Mono', monospace;
}
.stat-card .stat-num span {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search-input, .filter-select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ink);
}
.search-input { flex: 1; min-width: 220px; }
.search-input:focus, .filter-select:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: #EEF1EC; }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: rgba(178,58,47,0.08); }
.btn-icon { padding: 6px 8px; }
.btn:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

/* ---------- Table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

table.proj-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 1100px;
  font-size: 13px;
}

.proj-table thead th {
  position: sticky;
  top: 0;
  background: var(--navy);
  color: #fff;
  z-index: 2;
  font-weight: 600;
  font-size: 12px;
  padding: 10px 8px;
  text-align: center;
  border-right: 1px solid rgba(255,255,255,0.08);
}
.proj-table thead th.col-name { text-align: left; padding-left: 14px; }
.proj-table thead th .agenda-num {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
}

.proj-table thead th.agenda-th {
  width: 108px;
  min-width: 108px;
  vertical-align: top;
  padding: 10px 6px;
}
.agenda-th-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.agenda-th-inner .num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
}
.agenda-th-inner .label {
  display: block;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.35;
  color: rgba(255,255,255,0.85);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  text-align: center;
}

.proj-table tbody td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}
.proj-table tbody tr:hover { background: #FAFBF9; }
.proj-table td.col-idx { color: var(--muted); font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.proj-table td.col-name {
  text-align: left;
  padding-left: 14px;
  max-width: 420px;
  line-height: 1.45;
}

.dept-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.agenda-check {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
  padding: 0;
}
.agenda-check:hover { border-color: var(--teal); }
.agenda-check.checked {
  background: var(--teal);
  border-color: var(--teal);
}
.agenda-check.checked::after {
  content: "✓";
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.row-actions { display: flex; gap: 4px; justify-content: center; }

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--muted);
}
.empty-state .big { font-size: 32px; margin-bottom: 8px; }

/* ---------- Agenda overview (accordion by agenda) ---------- */
.agenda-overview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-top: 20px;
}

.agenda-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}
.agenda-panel:last-child { margin-bottom: 0; }

.agenda-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #FAFBF9;
  font-size: 13.5px;
  user-select: none;
}
.agenda-panel summary::-webkit-details-marker { display: none; }
.agenda-panel summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.agenda-panel[open] summary::before { transform: rotate(90deg); }
.agenda-panel[open] summary { border-bottom: 1px solid var(--border); }

.agenda-panel-num {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--navy);
  flex-shrink: 0;
  background: #EEF2EE;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.agenda-panel-title { flex: 1; font-weight: 600; color: var(--ink); }
.agenda-panel-count {
  flex-shrink: 0;
  font-size: 12px;
  color: #fff;
  background: var(--teal);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.agenda-panel-body { padding: 14px 16px 16px; }
.agenda-empty { color: var(--muted); font-size: 13px; margin: 4px 0; }

.agenda-dept-block { margin-bottom: 14px; }
.agenda-dept-block:last-child { margin-bottom: 0; }

.agenda-dept-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.agenda-dept-count { color: var(--muted); font-weight: 400; font-size: 12px; }

.agenda-proj-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 20px;
}
.agenda-proj-list li {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink);
}
@media (max-width: 800px) {
  .agenda-proj-list { grid-template-columns: 1fr; }
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(16,41,61,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal h3 { margin: 0 0 4px; font-size: 17px; color: var(--navy); }
.modal .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 18px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.field input[type=text], .field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--teal); outline-offset: 1px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: #fff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0);
}

@media (prefers-reduced-motion: reduce) {
  .status-dot { animation: none; }
  * { transition: none !important; }
}

/* ---------- Print report ---------- */
#printArea { display: none; }

@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; padding: 6mm 4mm; }

  .print-header { text-align: center; margin-bottom: 10px; }
  .print-header .print-eyebrow {
    font-size: 10.5px; letter-spacing: 1px; color: #555; text-transform: uppercase;
  }
  .print-header h1 { margin: 2px 0 0; font-size: 16px; }
  .print-header h2 { margin: 4px 0 0; font-size: 12.5px; font-weight: 600; }
  .print-meta { font-size: 10.5px; color: #444; margin-top: 6px; }

  .agenda-legend {
    font-size: 9.5px; color: #333; line-height: 1.6;
    border-top: 1px solid #999; border-bottom: 1px solid #999;
    padding: 6px 0; margin: 10px 0 14px;
  }
  .agenda-legend span { display: inline-block; margin-right: 12px; }

  .print-section { page-break-before: always; margin-top: 4px; }
  .print-section:first-of-type { page-break-before: avoid; }

  .print-dept-title {
    font-size: 13px; margin: 0 0 8px; padding-left: 8px;
    border-left: 4px solid #333;
  }
  .print-dept-count { font-weight: 400; color: #555; font-size: 11px; }

  table.print-table {
    width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 8px;
  }
  table.print-table th, table.print-table td {
    border: 1px solid #555; padding: 3px 5px; text-align: center;
  }
  table.print-table thead th { background: #eaeaea; }
  table.print-table td.pname { text-align: left; }
  table.print-table td.ac { font-weight: 700; }

  .print-footer {
    margin-top: 10px; font-size: 9.5px; color: #777; text-align: right;
  }
}
