:root {
  --ink: #1B2430;
  --ink-2: #3D4756;
  --muted: #4A5565;
  --line: #DDE2E8;
  --line-2: #E6E9EE;
  --bg: #F6F7F9;
  --card: #FFFFFF;
  --accent: #2457C5;
  --accent-ink: #163A8A;
  --accent-soft: #E8EEFB;
  --accent-line: #AFC3EE;
  --warn: #C2611F;
  --warn-ink: #8A4A12;
  --warn-soft: #FDF0E6;
  --warn-line: #E9A46A;
  --ok-ink: #1E6B3E;
  --ok-soft: #E3F4EA;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'IBM Plex Sans Thai', system-ui, sans-serif; font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
h1, h2 { margin: 0; }

.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-inner, .container { max-width: 1360px; margin: 0 auto; padding-left: 32px; padding-right: 32px; }
.topbar-inner { padding-top: 14px; padding-bottom: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.brand { font-size: 18px; font-weight: 700; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav a { padding: 10px 14px; border-radius: 8px; color: var(--ink-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.spacer { flex: 1; }
.container { padding-top: 28px; padding-bottom: 48px; display: flex; flex-direction: column; gap: 24px; }
.subtitle { color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.row { display: flex; flex-wrap: wrap; gap: 16px; }
.row > .card { flex: 1 1 220px; min-width: 0; }
.stat-label { font-size: 14px; color: var(--muted); }
.stat-value { font-size: 32px; font-weight: 700; }
.stat-value small { font-size: 18px; color: var(--muted); font-weight: 500; }
.step { font-size: 13px; font-weight: 600; color: var(--accent); }
.card-title { font-size: 17px; font-weight: 600; margin-bottom: 10px; }

label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], select {
  height: 44px; width: 100%; border: 1px solid #C4CBD4; border-radius: 8px; padding: 0 10px;
  font: inherit; color: var(--ink); background: #fff;
}
input[type=file] { font: inherit; }
.fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.fields > div { flex: 1 1 140px; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid #C4CBD4; background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); color: #fff; }
.btn-link { background: none; border: none; color: var(--ink-2); cursor: pointer; font: inherit; padding: 10px; }

.alert { border-radius: 10px; padding: 12px 16px; background: var(--ok-soft); color: var(--ok-ink); }
.alert-error { background: var(--warn-soft); color: var(--warn-ink); }

.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 14px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.groups { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.group { flex: 1 1 230px; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.group-head { display: flex; justify-content: space-between; align-items: center; }
.group-head h2 { font-size: 17px; }
.seat { display: flex; align-items: center; gap: 10px; border-radius: 8px; padding: 8px 10px; border: 1px solid var(--line); }
.seat .dot { width: 10px; height: 10px; border-radius: 5px; flex: none; background: #A9B2BE; }
.seat .who { font-size: 14px; font-weight: 600; }
.seat .meta { font-size: 12px; color: var(--muted); }
.seat-active { background: var(--accent-soft); border-color: var(--accent-line); }
.seat-active .dot { background: var(--accent); }
.seat-idle { background: var(--warn-soft); border-color: var(--warn-line); }
.seat-idle .dot { background: var(--warn); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { background: #F1F3F6; text-align: left; font-weight: 600; padding: 12px; white-space: nowrap; }
td { border-top: 1px solid var(--line-2); padding: 10px 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #EEF0F3; color: var(--ink-2); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 640px) {
  .topbar-inner, .container { padding-left: 16px; padding-right: 16px; }
}

/* หน้าจัดการ */
.btn-sm { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn-danger { color: #A33A12; border-color: #E9A46A; }
.btn-danger:hover { background: var(--warn-soft); }
.cell-input { height: 36px !important; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.section-head h2 { font-size: 18px; }
.ok { color: var(--ok-ink); font-weight: 600; }
.token { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ===== Busuu Tracker: sidebar layout + dashboard ===== */
.app-shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 0 6px; }
.side-logo { width: 40px; height: 40px; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.side-name { display: block; font-size: 18px; font-weight: 700; color: var(--accent-ink); line-height: 1.2; }
.side-sub { display: block; font-size: 12px; color: var(--muted); }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; color: var(--ink-2); text-decoration: none; font-weight: 500; }
.side-nav a:hover { background: #F1F3F6; color: var(--ink); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.side-icon { width: 22px; text-align: center; font-size: 17px; flex: none; }
.side-group { margin: 12px 12px 2px; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.side-foot { margin-top: auto; padding: 0 8px; font-size: 12px; color: var(--muted); }
.app-main { min-width: 0; display: flex; flex-direction: column; }
.userbar { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 12px 28px 0; }
.user-chip { display: inline-flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 5px 16px 5px 6px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.user-name { display: block; font-size: 14px; font-weight: 600; line-height: 1.2; }
.user-role { display: block; font-size: 12px; color: var(--muted); line-height: 1.2; }

.page { padding: 8px 28px 48px; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 24px; }
.page-title { font-size: 28px; font-weight: 700; color: var(--accent-ink); line-height: 1.25; }
.scope-filters { margin-left: auto; display: flex; flex-wrap: wrap; gap: 10px; }
.scope-filters > div { width: 150px; }
.scope-filters select, .filter-bar select { height: 40px; }
.btn-excel { color: var(--ok-ink); border-color: #1E8E4E; background: #fff; }
.btn-excel:hover { background: var(--ok-soft); color: var(--ok-ink); }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }
.alert-note { background: var(--accent-soft); color: var(--accent-ink); }
.field-error { color: #B42318; font-weight: 600; font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.kpi { display: flex; gap: 12px; align-items: flex-start; border-radius: 14px; padding: 16px; border: 1px solid transparent; }
.kpi-blue { background: #E8F0FE; border-color: #C9DAFB; }
.kpi-green { background: #E6F5EC; border-color: #BFE3CC; }
.kpi-orange { background: #FDEEE3; border-color: #F4CDB0; }
.kpi-purple { background: #EFEBFB; border-color: #D8CFF3; }
.kpi-teal { background: #E2F4F2; border-color: #B7E0DC; }
.kpi-icon { width: 44px; height: 44px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; flex: none; }
.kpi-blue .kpi-icon { background: #2563EB; }
.kpi-green .kpi-icon { background: #1E8E4E; }
.kpi-orange .kpi-icon { background: #D9622B; }
.kpi-purple .kpi-icon { background: #6D4AD8; }
.kpi-teal .kpi-icon { background: #0E8F86; }
.kpi-body { min-width: 0; flex: 1; }
.kpi-label { font-size: 14px; color: var(--ink-2); }
.kpi-value { font-size: 28px; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.kpi-value small { font-size: 15px; font-weight: 600; }
.kpi-note { font-size: 13px; color: var(--ink-2); }
.kpi-meter { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.kpi-meter b { font-size: 13px; }
.kpi-track { flex: 1; height: 8px; border-radius: 4px; background: rgba(27, 36, 48, .12); overflow: hidden; }
.kpi-track > span { display: block; height: 100%; border-radius: 4px; }
.kpi-green .kpi-track > span { background: #1E8E4E; }
.kpi-orange .kpi-track > span { background: #D9622B; }

.charts { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 14px; }
.chart-card { min-width: 0; }
.chart-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chart-unit { font-size: 13px; font-weight: 400; color: var(--muted); }
.donut-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 24px; }
.donut { width: 180px; height: 180px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
.donut-hole { width: 110px; height: 110px; border-radius: 50%; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.donut-hole strong { font-size: 30px; }
.donut-hole span { font-size: 14px; color: var(--ink-2); }
.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 190px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.donut-legend .swatch { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.lg-label { min-width: 86px; font-weight: 600; }
.lg-val { color: var(--ink-2); margin-left: auto; white-space: nowrap; }

.vbars { display: flex; align-items: flex-end; justify-content: space-around; gap: 8px; height: 200px; }
.vbar { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.vbar-count { font-size: 13px; font-weight: 600; }
.vbar-col { width: 100%; max-width: 54px; flex: 1; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.vbar-fill { display: block; width: 100%; background: #2563EB; border-radius: 4px 4px 0 0; min-height: 2px; }
.vbar:nth-child(4) .vbar-fill { background: #0E8F86; }
.vbar:nth-child(n+5) .vbar-fill { background: #6D4AD8; }
.vbar-label { font-size: 12px; color: var(--ink-2); text-align: center; line-height: 1.3; min-height: 32px; }
.vbar-label b { font-size: 13px; color: var(--ink); }

.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.hbars li { display: grid; grid-template-columns: minmax(90px, 1.2fr) 1.4fr 34px; gap: 10px; align-items: center; font-size: 14px; }
.hbar-name { overflow-wrap: anywhere; }
.hbar-track { height: 12px; border-radius: 6px; background: #EDF0F4; overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 6px; }
.hbar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filter-search { flex: 2 1 280px; }
.filter-search input { height: 40px; }
.filter-field { flex: 1 1 150px; }
.filter-actions { display: flex; gap: 8px; }
.filter-actions .btn { height: 40px; }

.data-table th { background: #EEF3FB; color: var(--ink); font-size: 13px; }
.data-table td { font-size: 14px; }
.data-table tbody tr:hover { background: #F7F9FC; }
.pbar { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.pbar-track { flex: 1; height: 8px; border-radius: 4px; background: #E6E9EE; overflow: hidden; }
.pbar-fill { display: block; height: 100%; border-radius: 4px; }
.pbar-val { font-weight: 700; min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.p-green .pbar-fill { background: #1E8E4E; } .p-green .pbar-val { color: #14693A; }
.p-blue .pbar-fill { background: #2563EB; } .p-blue .pbar-val { color: #1D4ED8; }
.p-yellow .pbar-fill { background: #F2B01E; } .p-yellow .pbar-val { color: #7A4F00; }
.p-red .pbar-fill { background: #E5484D; } .p-red .pbar-val { color: #B42318; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 12px; border-radius: 999px; white-space: nowrap; }
.pill-ok { background: var(--ok-soft); color: var(--ok-ink); }
.pill-wait { background: var(--warn-soft); color: var(--warn-ink); }
.pill-muted { background: #EEF0F3; color: var(--ink-2); }

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line-2); }
.pager-info { font-size: 13px; color: var(--muted); }
.pager-nav { display: flex; gap: 6px; align-items: center; }
.pager-btn { min-width: 34px; height: 34px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink-2); text-decoration: none; font-size: 14px; }
a.pager-btn:hover { background: var(--accent-soft); }
.pager-btn.is-current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pager-btn.is-disabled { opacity: .45; }
.pager-gap { color: var(--muted); }

.form-card { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
.map-list { display: flex; flex-direction: column; gap: 14px; }
.map-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 20px; }
.map-card.has-error { border-color: #E5484D; }
.map-name { font-size: 17px; font-weight: 600; }
.map-courses { margin-top: 8px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.map-choice { display: flex; flex-direction: column; gap: 8px; }
.radio-row { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink); margin: 0; }
.radio-row input { width: 18px; height: 18px; }
.mode-panel { padding-left: 26px; }
.mode-panel[hidden] { display: none; }
.map-actions { display: flex; align-items: center; gap: 14px; position: sticky; bottom: 0; }

.summary-card { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.summary-val { font-size: 20px; font-weight: 600; }

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .charts { grid-template-columns: 1fr 1fr; }
  .charts > :first-child { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 16px; gap: 10px; }
  .side-nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .side-nav a { white-space: nowrap; box-shadow: none !important; }
  .side-group, .side-foot { display: none; }
  .userbar { padding: 10px 16px 0; }
  .page { padding: 8px 16px 40px; }
  .scope-filters { margin-left: 0; width: 100%; }
  .scope-filters > div { flex: 1 1 120px; width: auto; }
  .map-card { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .summary-card { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-title { font-size: 23px; }
}

/* เครดิตผู้พัฒนา */
.credit { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 20px 16px 28px; font-size: 13px; color: var(--muted); text-align: center; flex-wrap: wrap; }
.credit img { border-radius: 4px; flex: none; }
.credit strong { color: var(--ink-2); font-weight: 600; }
.credit a { color: inherit; text-decoration: none; }
.credit a:hover strong, .credit a:focus-visible strong { text-decoration: underline; }
.login { flex-direction: column; }
