@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@400;500;600;700&family=Sarabun:wght@400;600&display=swap");

:root {
  --font-ui: "IBM Plex Sans Thai", "Sarabun", system-ui, sans-serif;
  --font-document: "Sarabun", "TH Sarabun New", serif;

  --paper: hsl(40 30% 97%);
  --surface: hsl(0 0% 100%);
  --surface-sunken: hsl(40 20% 94%);
  --line: hsl(35 14% 86%);
  --line-strong: hsl(35 12% 74%);
  --ink: hsl(222 28% 16%);
  --ink-soft: hsl(222 12% 42%);
  --ink-faint: hsl(222 8% 60%);

  --navy-900: hsl(222 48% 13%);
  --navy-800: hsl(222 44% 19%);
  --navy-700: hsl(222 38% 27%);
  --gold: hsl(41 58% 50%);
  --gold-soft: hsl(41 70% 92%);
  --gold-deep: hsl(36 60% 34%);

  --danger: hsl(4 58% 44%);
  --danger-soft: hsl(4 70% 96%);
  --success: hsl(152 42% 32%);
  --success-soft: hsl(150 40% 94%);
  --warn-soft: hsl(41 80% 94%);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 2px hsl(222 30% 20% / 0.06), 0 8px 24px hsl(222 30% 20% / 0.06);
  --shadow-pop: 0 16px 48px hsl(222 40% 10% / 0.22);
  --ease: 0.16s ease;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.3; margin: 0; font-weight: 600; }
a { color: var(--navy-700); text-decoration: none; transition: color var(--ease); }
a:hover { color: var(--gold-deep); }
[hidden] { display: none !important; }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  font: inherit; font-weight: 500; font-size: 14px;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease), box-shadow var(--ease);
}
.btn:focus-visible, .field input:focus-visible, .field select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--navy-800); color: hsl(40 40% 96%); }
.btn-primary:hover:not(:disabled) { background: var(--navy-700); box-shadow: inset 0 -2px 0 var(--gold); }
.btn-quiet { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover:not(:disabled) { border-color: var(--navy-700); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: hsl(4 50% 80%); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-soft); }
.field input, .field select {
  height: 42px; padding: 0 12px;
  font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.field input:hover, .field select:hover { border-color: var(--ink-faint); }
.field input:focus, .field select:focus { border-color: var(--navy-700); box-shadow: 0 0 0 3px hsl(222 40% 40% / 0.12); outline: none; }
.field-hint { font-size: 12px; color: var(--ink-faint); }

.notice {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px;
  border-left: 3px solid var(--line-strong); background: var(--surface-sunken);
}
.notice-error { border-color: var(--danger); background: var(--danger-soft); color: hsl(4 60% 30%); }
.notice-success { border-color: var(--success); background: var(--success-soft); color: hsl(152 45% 22%); }
.notice-gold { border-color: var(--gold); background: var(--warn-soft); color: hsl(36 55% 26%); }

/* ---------- Sign-in layout ---------- */
.auth-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 44%) 1fr; }
.auth-brand {
  position: relative; overflow: hidden;
  padding: 48px; color: hsl(40 30% 92%);
  background:
    radial-gradient(120% 80% at 0% 0%, hsl(222 40% 24%) 0%, transparent 60%),
    linear-gradient(160deg, var(--navy-800), var(--navy-900));
  display: flex; flex-direction: column; justify-content: space-between;
}
.auth-brand::after {
  content: ""; position: absolute; inset: auto -12% -18% auto; width: 420px; height: 420px;
  border: 1px solid hsl(41 58% 50% / 0.25); border-radius: 50%;
  box-shadow: 0 0 0 32px hsl(41 58% 50% / 0.05), 0 0 0 64px hsl(41 58% 50% / 0.035);
}
.brand-mark { display: flex; align-items: center; gap: 12px; font-weight: 600; letter-spacing: 0.01em; }
.brand-mark svg { width: 40px; height: 40px; flex: none; }
.auth-brand h1 { font-size: 32px; margin-bottom: 16px; color: hsl(40 40% 97%); }
.auth-brand p { max-width: 380px; color: hsl(222 20% 78%); margin: 0; }
.auth-brand .rule { width: 56px; height: 2px; background: var(--gold); margin: 24px 0; }
.auth-foot { font-size: 12px; color: hsl(222 16% 62%); position: relative; z-index: 1; }

.auth-panel { display: grid; place-items: center; padding: 48px 24px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 24px; margin-bottom: 8px; }
.auth-card .lead { color: var(--ink-soft); margin: 0 0 32px; }

@media (max-width: 820px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-brand { padding: 32px 24px; min-height: 200px; }
  .auth-brand h1 { font-size: 24px; }
}

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  height: 64px; padding: 0 32px;
  background: var(--navy-900); color: hsl(40 30% 92%);
  box-shadow: inset 0 -2px 0 var(--gold);
}
.topbar .brand-mark { font-size: 16px; color: hsl(40 40% 97%); }
.topbar .brand-mark svg { width: 32px; height: 32px; }
.topbar nav { display: flex; gap: 4px; margin-left: 16px; }
.topbar nav a {
  color: hsl(222 18% 76%); padding: 8px 12px; border-radius: var(--radius-sm); font-size: 14px;
  transition: background var(--ease), color var(--ease);
}
.topbar nav a:hover { color: hsl(40 40% 97%); background: hsl(222 40% 22%); }
.topbar nav a[aria-current="page"] { color: hsl(40 40% 97%); background: hsl(222 40% 22%); box-shadow: inset 0 -2px 0 var(--gold); }
.topbar .who { margin-left: auto; display: flex; align-items: center; gap: 16px; font-size: 14px; }
.who-name { text-align: right; line-height: 1.3; }
.who-name small { display: block; color: hsl(222 18% 66%); font-size: 12px; }
.topbar .btn-quiet { background: transparent; color: hsl(40 30% 92%); border-color: hsl(222 30% 34%); }
.topbar .btn-quiet:hover:not(:disabled) { border-color: var(--gold); }

.page { max-width: 1200px; margin: 0 auto; padding: 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 4px 0 0; color: var(--ink-soft); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-card); }
.card-pad { padding: 24px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.tab {
  font: inherit; font-weight: 500; font-size: 15px; color: var(--ink-soft);
  background: none; border: 0; padding: 12px 8px; margin-bottom: -1px; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color var(--ease), border-color var(--ease);
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--navy-800); border-bottom-color: var(--gold); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
table.grid th {
  text-align: left; font-weight: 600; font-size: 12px; letter-spacing: 0.02em; color: var(--ink-soft);
  padding: 12px 16px; background: var(--surface-sunken); border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.grid td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tbody tr { transition: background var(--ease); }
table.grid tbody tr:hover { background: hsl(40 30% 98%); }
table.grid .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.empty-row td { text-align: center; color: var(--ink-faint); padding: 40px 16px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  font-size: 12px; font-weight: 500; border-radius: 999px; white-space: nowrap;
  background: var(--surface-sunken); color: var(--ink-soft);
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-admin { background: var(--gold-soft); color: var(--gold-deep); }
.chip-ok { background: var(--success-soft); color: var(--success); }
.chip-off { background: var(--danger-soft); color: var(--danger); }
.chip-wait { background: var(--warn-soft); color: hsl(36 60% 34%); }

.filters { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.filters .field { margin: 0; min-width: 160px; }
.filters .spacer { flex: 1; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; font-size: 14px; color: var(--ink-soft); }

table.grid tbody tr.issue-row, table.grid tbody tr.issue-row:hover { background: var(--surface-sunken); }
.issue-list { padding: 4px 0 4px 24px; border-left: 2px solid var(--gold); font-size: 14px; }
.issue-list > div { display: grid; grid-template-columns: minmax(160px, 1fr) 1.2fr 1.2fr 140px; gap: 16px; padding: 6px 0; }
.issue-list > div + div { border-top: 1px solid var(--line); }
.issue-head { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.issue-list s { color: var(--danger); text-decoration-color: hsl(4 60% 60%); }

/* ---------- Dialog ---------- */
dialog {
  border: 0; padding: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  width: min(460px, calc(100vw - 32px)); color: var(--ink);
}
dialog::backdrop { background: hsl(222 48% 10% / 0.5); backdrop-filter: blur(2px); }
.dialog-body { padding: 24px; }
.dialog-body h3 { font-size: 18px; margin-bottom: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; background: var(--surface-sunken); border-top: 1px solid var(--line); }
.secret-box {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 22px; letter-spacing: 0.08em;
  text-align: center; padding: 16px; margin: 16px 0; border-radius: var(--radius-sm);
  background: var(--navy-900); color: var(--gold-soft); user-select: all;
}

/* ---------- Check page ---------- */
.check-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.check-toolbar .field { margin: 0; min-width: 200px; }
.check-toolbar .spacer { flex: 1; }
.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-sunken); border-radius: var(--radius); }
.segmented button {
  font: inherit; font-size: 14px; font-weight: 500; height: 34px; padding: 0 16px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-soft); cursor: pointer; transition: background var(--ease), color var(--ease), box-shadow var(--ease);
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--navy-800); box-shadow: 0 1px 3px hsl(222 30% 20% / 0.12); }
.input-body { padding: 24px; }
.paste-box {
  width: 100%; min-height: 360px; padding: 16px 24px; resize: vertical;
  font-family: var(--font-document); font-size: 17px; line-height: 1.7; color: var(--ink); tab-size: 4;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.paste-box:focus { outline: none; border-color: var(--navy-700); box-shadow: 0 0 0 3px hsl(222 40% 40% / 0.12); }
.dropzone {
  display: grid; place-items: center; text-align: center; min-height: 280px; padding: 32px; cursor: pointer;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-sunken); color: var(--ink-soft);
  transition: border-color var(--ease), background var(--ease);
}
.dropzone:hover, .dropzone.is-over { border-color: var(--gold); background: var(--warn-soft); }
.dropzone svg { width: 48px; height: 48px; color: var(--ink-faint); margin-bottom: 8px; }
.dropzone strong { color: var(--ink); }
.privacy-note { margin: 16px 0 0; font-size: 13px; color: var(--ink-faint); }

.result-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start; }
.result-head { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-bottom: 16px; }
.result-head h2 { font-size: 18px; }
.result-head .field { margin: 0; min-width: 200px; }
.result-head .result-field-first { margin-left: auto; }
.paper {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-card);
  padding: 48px 56px; font-family: var(--font-document); font-size: 17px; line-height: 1.75; color: hsl(222 20% 12%);
  white-space: pre-wrap; tab-size: 4; overflow-wrap: anywhere;
}
.paper p { margin: 0; min-height: 1.75em; }
.paper mark {
  background: transparent; color: inherit; cursor: pointer; border-radius: 2px; padding: 1px 0;
  border-bottom: 2px solid; transition: background var(--ease), box-shadow var(--ease);
}
.paper mark.sev-error { border-color: var(--danger); background: hsl(4 70% 95%); }
.paper mark.sev-warning { border-color: var(--gold); background: hsl(41 80% 92%); }
.paper mark.sev-info { border-color: hsl(212 40% 55%); background: hsl(212 50% 95%); }
.paper mark.is-active { box-shadow: 0 0 0 2px var(--navy-700); }
.paper mark.is-space { min-width: 8px; display: inline-block; }
.paper .fixed { background: var(--success-soft); border-bottom: 2px solid var(--success); }

.issue-panel { position: sticky; top: 88px; max-height: calc(100vh - 112px); display: flex; flex-direction: column; }
.issue-summary { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.issue-summary h3 { font-size: 16px; margin-bottom: 8px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-chip {
  font: inherit; font-size: 13px; height: 28px; padding: 0 12px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); transition: all var(--ease);
}
.filter-chip:hover { border-color: var(--navy-700); color: var(--ink); }
.filter-chip[aria-pressed="true"] { background: var(--navy-800); border-color: var(--navy-800); color: hsl(40 40% 96%); }
.issue-scroll { overflow-y: auto; padding: 12px 16px 16px; display: grid; gap: 12px; }
.issue-group-title { font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink-soft); margin: 8px 0 -4px; }
.issue-card {
  border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 12px 16px; background: var(--surface); cursor: pointer; transition: border-color var(--ease), box-shadow var(--ease);
}
.issue-card:hover { box-shadow: var(--shadow-card); }
.issue-card.sev-error { border-left-color: var(--danger); }
.issue-card.sev-warning { border-left-color: var(--gold); }
.issue-card.sev-info { border-left-color: hsl(212 40% 55%); }
.issue-card.is-active { border-color: var(--navy-700); box-shadow: 0 0 0 1px var(--navy-700); }
.issue-card.is-done { opacity: 0.55; }
.issue-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.issue-message { margin: 4px 0 8px; font-size: 14px; color: var(--ink-soft); }
.issue-change { font-family: var(--font-document); font-size: 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.issue-change s { color: var(--danger); text-decoration-color: hsl(4 60% 60%); background: var(--danger-soft); padding: 0 4px; border-radius: 3px; white-space: pre; }
.issue-change ins { color: var(--success); text-decoration: none; background: var(--success-soft); padding: 0 4px; border-radius: 3px; white-space: pre; }
.issue-change .arrow { color: var(--ink-faint); }
.issue-reference { font-size: 12px; color: var(--ink-faint); margin-bottom: 8px; }
.issue-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.issue-status { font-size: 12px; font-weight: 600; }
.issue-status.done-fixed { color: var(--success); }
.issue-status.done-skipped { color: var(--ink-faint); }
.chip-error { background: var(--danger-soft); color: var(--danger); }
.chip-warning { background: var(--warn-soft); color: hsl(36 60% 34%); }
.chip-info { background: hsl(212 50% 95%); color: hsl(212 40% 40%); }
.all-clear { text-align: center; padding: 32px 16px; color: var(--success); }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

@media (max-width: 1100px) {
  .result-layout { grid-template-columns: 1fr; }
  .issue-panel { position: static; max-height: none; }
  .paper { padding: 32px 24px; }
}

@media (max-width: 900px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .topbar nav { margin-left: 0; }
  .who-name { display: none; }
  .page { padding: 24px 16px; }
}
.form-foot { text-align: center; margin: 16px 0 0; font-size: 14px; }

/* ---------- Admin: words, settings, stats ---------- */
.tab-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; font-size: 12px; background: var(--danger); color: hsl(0 0% 100%); }
.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.card-head { padding: 16px 24px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 16px; }
.card-head p { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.inline-form .field { margin: 0; flex: 1; min-width: 140px; }
.settings-form h3 { font-size: 16px; margin: 24px 0 12px; }
.settings-form h3:first-of-type { margin-top: 0; }
.margin-grid input { width: 80px; height: 36px; padding: 0 8px; font: inherit; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.margin-grid input:focus { outline: none; border-color: var(--navy-700); box-shadow: 0 0 0 3px hsl(222 40% 40% / 0.12); }
.margin-grid .not-used { color: var(--ink-faint); font-size: 13px; }
.settings-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-tile { padding: 24px; border-right: 1px solid var(--line); }
.stat-tile:last-child { border-right: 0; }
.stat-tile .stat-value { font-size: 32px; font-weight: 600; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-tile .stat-label { font-size: 13px; color: var(--ink-soft); margin-top: 4px; }
.stats-columns, .stats-block { margin-top: 24px; }
.bar-list { display: grid; gap: 2px; margin-top: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 38%) 1fr 48px; gap: 12px; align-items: center; padding: 6px 4px; border-radius: var(--radius-sm); transition: background var(--ease); }
.bar-row:hover { background: var(--surface-sunken); }
.bar-row .bar-name { font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-name small { color: var(--ink-faint); }
.bar-track { height: 12px; }
.bar-fill { height: 100%; min-width: 2px; background: var(--navy-700); border-radius: 0 4px 4px 0; }
.bar-row:hover .bar-fill { background: var(--navy-800); }
.bar-row .bar-value { font-size: 13px; color: var(--ink-soft); text-align: right; font-variant-numeric: tabular-nums; }
.month-chart { display: flex; align-items: flex-end; gap: 8px; height: 180px; margin-top: 16px; padding-bottom: 28px; border-bottom: 1px solid var(--line); position: relative; }
.month-bar { flex: 1; max-width: 56px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; position: relative; }
.month-bar .bar-fill { width: 100%; border-radius: 4px 4px 0 0; }
.month-bar .month-value { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.month-bar .month-name { position: absolute; bottom: -24px; font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.muted-empty { color: var(--ink-faint); font-size: 14px; padding: 16px 0; }
@media (max-width: 1000px) {
  .two-column, .settings-row { grid-template-columns: 1fr; }
  .stat-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
