:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #fffdf9;
  --ink: #181714;
  --muted: #706d67;
  --line: #e4dfd6;
  --gold: #aa771c;
  --gold-deep: #8c5f12;
  --gold-soft: #f4ead3;
  --done: #15974b;
  --done-dark: #0b7a39;
  --pending: #e92b24;
  --draft: #f2ab00;
  --inactive: #818181;
  --shadow: 0 14px 42px rgba(60, 44, 18, 0.08), 0 2px 8px rgba(60, 44, 18, 0.05);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 82% 12%, rgba(187, 134, 38, 0.09), transparent 26rem),
    radial-gradient(circle at 10% 85%, rgba(84, 116, 90, 0.05), transparent 30rem),
    var(--bg);
  font-family: "Noto Sans Thai", system-ui, -apple-system, sans-serif;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }

.app-shell { min-height: 100vh; padding: 14px; }

.topbar {
  min-height: 96px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 14px 22px;
  border: 1px solid rgba(229, 222, 211, 0.8);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 10px;
  z-index: 20;
}

.brand {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  width: fit-content;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(145deg, #bd8b2d, #8a5a0a);
  border-radius: 15px;
  box-shadow: 0 8px 18px rgba(162, 109, 19, 0.22);
  font-size: 27px;
  transform: rotate(180deg);
}

.brand strong { display: block; font-size: 19px; letter-spacing: -0.02em; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.tabs {
  display: flex;
  align-items: center;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.66);
  box-shadow: 0 4px 12px rgba(55, 39, 12, 0.05);
}

.tab {
  min-width: 154px;
  padding: 13px 18px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #4e4a44;
  font-weight: 600;
}

.tab + .tab { border-left: 1px solid var(--line); border-radius: 0 12px 12px 0; }
.tab.is-active { color: white; background: linear-gradient(135deg, #b78125, #946410); box-shadow: 0 8px 18px rgba(156, 103, 18, 0.25); border-radius: 12px; }
.tab.is-active + .tab { border-left-color: transparent; }

.topbar-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.source-badge { padding: 7px 10px; color: #8b5b07; background: #fff3ce; border: 1px solid #efd58c; border-radius: 999px; font-size: 12px; font-weight: 700; }
.icon-button { width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 14px; background: white; box-shadow: 0 5px 14px rgba(56, 42, 17, 0.06); font-size: 25px; transition: transform .2s ease, box-shadow .2s ease; }
.icon-button:hover { transform: translateY(-2px) rotate(8deg); box-shadow: 0 9px 18px rgba(56, 42, 17, 0.1); }
.icon-button.is-loading { animation: spin 0.8s linear infinite; }

main { max-width: 1720px; margin: 0 auto; padding: 22px 22px 0; }

.filter-bar {
  width: fit-content;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 8px 14px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 7px 20px rgba(62, 45, 17, 0.06);
  overflow-x: auto;
}

.field { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 600; }
.field input, .field select { border: 0; outline: 0; color: var(--ink); background: transparent; min-height: 32px; font-weight: 600; }
.field select { padding: 0 26px 0 2px; }
.date-field input { min-width: 135px; }
.divider { width: 1px; height: 25px; flex: 0 0 auto; background: var(--line); }

.message { min-height: 22px; margin: 8px 4px 0; color: var(--muted); font-size: 13px; }
.message.is-error { color: #a51f1a; }

.view { display: none; animation: fade-in .25s ease; }
.view.is-active { display: block; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 26px; margin-top: 8px; }
.zone-board { display: grid; grid-template-columns: repeat(3, minmax(250px, 1fr)); gap: 24px 32px; align-content: start; padding: 12px 0 24px; }

.zone-card { min-width: 0; padding: 10px; border-radius: 17px; transition: background .2s ease; }
.zone-card:hover { background: rgba(255,255,255,.45); }
.zone-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 17px; }
.zone-icon { width: 39px; height: 39px; display: grid; place-items: center; flex: 0 0 auto; color: var(--gold-deep); background: var(--gold-soft); border-radius: 50%; font-size: 18px; }
.zone-title span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }

.line-tile {
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 1px;
  padding: 9px 11px;
  color: white;
  border: 0;
  border-radius: 11px;
  text-align: left;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.09), 0 5px 9px rgba(43, 38, 26, .12);
  transition: transform .18s ease, filter .18s ease;
}
.line-tile:hover { transform: translateY(-2px); filter: brightness(1.04); }
.line-tile strong { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.line-tile small { width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .84; font-size: 10px; }
.line-tile.done { background: linear-gradient(150deg, #21aa5a, #0d8741); }
.line-tile.pending { background: linear-gradient(150deg, #fb4038, #d81d17); }
.line-tile.draft { background: linear-gradient(150deg, #fbc42f, #e99a00); }
.line-tile.inactive { background: linear-gradient(150deg, #9e9e9e, #747474); }

.summary-column { display: flex; flex-direction: column; gap: 18px; }
.summary-card, .legend-card, .table-card, .zone-summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.summary-card { padding: 23px 24px; }
.summary-card h2, .legend-card h2 { margin: 0 0 18px; font-size: 17px; }
.summary-card h2 span { color: var(--gold); margin-right: 6px; }
.status-summary { margin: 0; }
.status-summary > div { display: flex; justify-content: space-between; align-items: center; min-height: 42px; }
.status-summary dt { display: flex; align-items: center; gap: 10px; color: #4e4a44; font-size: 13px; }
.status-summary dd { margin: 0; font-size: 21px; font-weight: 700; }
.swatch { width: 21px; height: 21px; flex: 0 0 auto; display: inline-block; border-radius: 6px; box-shadow: inset 0 -2px 0 rgba(0,0,0,.12); }
.swatch.done { background: var(--done); }
.swatch.pending { background: var(--pending); }
.swatch.draft { background: var(--draft); }
.swatch.inactive { background: var(--inactive); }

.completion { margin-top: 15px; padding-top: 19px; border-top: 1px solid var(--line); }
.completion > div:first-child { display: flex; flex-direction: column; }
.completion > div:first-child span { color: var(--muted); font-size: 12px; }
.completion-row { display: flex; align-items: center; justify-content: center; gap: 19px; margin: 14px 0 9px; }
.completion-row > strong { font-size: 42px; letter-spacing: -0.04em; }
.completion-ring { --rate: 0deg; width: 82px; height: 82px; padding: 13px; border-radius: 50%; background: conic-gradient(var(--gold) var(--rate), #d9d8d5 0); }
.completion-ring span { display: block; width: 100%; height: 100%; background: var(--surface-solid); border-radius: 50%; }
.completion small { display: block; color: var(--muted); font-size: 11px; text-align: center; }

.legend-card { padding: 20px 22px; }
.legend-card ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 13px; }
.legend-card li { display: grid; grid-template-columns: 22px 80px 1fr; align-items: center; gap: 8px; font-size: 12px; }
.legend-card li .swatch { width: 19px; height: 19px; }
.legend-card li > span:last-child { color: var(--muted); }

.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin: 28px 2px 18px; }
.section-heading h1 { margin: 1px 0 0; font-size: 28px; }
.section-heading p { max-width: 540px; margin: 0; color: var(--muted); font-size: 13px; text-align: right; }
.eyebrow { color: var(--gold-deep); font-size: 10px; font-weight: 700; letter-spacing: .15em; }
.zone-summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.zone-summary-card { padding: 20px; }
.zone-summary-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.zone-summary-top h2 { margin: 0; font-size: 16px; }
.zone-summary-top strong { font-size: 24px; }
.progress-track { height: 9px; margin: 18px 0 12px; background: #dedbd5; border-radius: 999px; overflow: hidden; }
.progress-track span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #d49b36); border-radius: inherit; }
.zone-summary-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }

.report-heading { align-items: center; }
.search-field input { width: min(310px, 70vw); padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; background: white; }
.search-field input:focus { border-color: #c4943d; box-shadow: 0 0 0 3px rgba(180, 129, 35, .12); }
.table-card { overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 14px 16px; border-bottom: 1px solid #ece8e1; text-align: left; vertical-align: middle; }
th { color: #666159; background: #f6f3ee; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: rgba(248, 243, 233, .72); }
.status-pill { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-pill.good { color: #0d7137; background: #dbf4e5; }
.status-pill.warn { color: #925400; background: #fff0c4; }
.status-pill.bad { color: #a51f1a; background: #fde3e1; }
.empty-state { padding: 48px 20px; color: var(--muted); text-align: center; }

.page-footer { display: flex; justify-content: space-between; gap: 20px; padding: 20px 4px 6px; color: var(--muted); font-size: 11px; }

.line-dialog { width: min(480px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 20px; color: var(--ink); background: var(--surface-solid); box-shadow: 0 28px 80px rgba(27, 22, 12, .24); }
.line-dialog::backdrop { background: rgba(34, 29, 20, .32); backdrop-filter: blur(4px); }
.dialog-close { position: absolute; right: 13px; top: 11px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #eee9e1; font-size: 23px; }
.dialog-content { padding: 28px; }
.dialog-kicker { color: var(--gold-deep); font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.dialog-content h2 { margin: 5px 40px 3px 0; font-size: 24px; }
.dialog-content > p { margin: 0 0 18px; color: var(--muted); }
.dialog-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-facts div { padding: 12px; background: #f5f1ea; border-radius: 12px; }
.dialog-facts span { display: block; color: var(--muted); font-size: 10px; }
.dialog-facts strong { display: block; margin-top: 2px; font-size: 13px; }

.skeleton { position: relative; overflow: hidden; background: #e8e3db; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent); animation: shimmer 1.2s infinite; }
.skeleton-card { height: 168px; border-radius: 18px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (max-width: 1250px) {
  .topbar { grid-template-columns: 1fr auto; }
  .tabs { grid-row: 2; grid-column: 1 / -1; justify-self: center; }
  .topbar-actions { grid-column: 2; grid-row: 1; }
  .zone-board { grid-template-columns: repeat(2, minmax(240px, 1fr)); }
  .zone-summary-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 860px) {
  .app-shell { padding: 8px; }
  .topbar { position: static; min-height: 0; padding: 14px; gap: 12px; }
  .brand strong { font-size: 16px; }
  .brand-mark { width: 42px; height: 42px; }
  .tabs { width: 100%; overflow-x: auto; justify-self: stretch; }
  .tab { min-width: 130px; padding: 11px 13px; }
  main { padding: 16px 8px 0; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .summary-column { grid-row: 1; display: grid; grid-template-columns: 1fr 1fr; }
  .zone-board { grid-row: 2; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading p { text-align: left; }
  .table-card { overflow-x: auto; }
  table { min-width: 820px; }
}

@media (max-width: 600px) {
  .topbar { display: flex; flex-wrap: wrap; }
  .brand { flex: 1; }
  .source-badge { display: none; }
  .topbar-actions { margin-left: auto; }
  .tabs { order: 3; }
  .filter-bar { width: 100%; }
  .dashboard-grid { gap: 16px; }
  .summary-column { grid-template-columns: 1fr; }
  .zone-board, .zone-summary-grid { grid-template-columns: 1fr; gap: 14px; }
  .zone-card { padding: 8px 2px; }
  .line-grid { grid-template-columns: repeat(3, 1fr); }
  .line-tile { min-height: 56px; }
  .page-footer { flex-direction: column; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
