:root {
  --primary: #C8102E;
  --primary-dark: #9E0C24;
  --primary-soft: #FDF1F3;
  --accent: #D4AF37;
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;
  --text: #1F2937;
  --muted: #6B7280;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05);
  --shadow-md: 0 8px 24px -12px rgba(17, 24, 39, .18);
  --font-head: "Bai Jamjuree", "Sarabun", "Noto Sans Thai", sans-serif;
  --font-body: "Sarabun", "Noto Sans Thai", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 88px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-head); line-height: 1.25; margin: 0; }
a { color: inherit; }
ul, ol { list-style: none; margin: 0; padding: 0; }
dl, dd { margin: 0; }
svg { flex-shrink: 0; }
::selection { background: var(--primary); color: #fff; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.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;
}
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--primary); color: #fff; padding: .75rem 1rem; text-decoration: none;
}
.skip-link:focus { left: 0; }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-top: 3px solid var(--primary);
  border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 64px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }
.brand img { height: 44px; width: auto; display: block; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: .9rem; font-weight: 500; text-decoration: none; color: var(--text);
  transition: border-color .2s, color .2s, background-color .2s;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ---------- Hero ---------- */
.hero { background: var(--surface); border-bottom: 1px solid var(--border); padding: 36px 0 28px; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; color: var(--muted); margin-bottom: 14px; }
.breadcrumb a { text-decoration: none; }
.breadcrumb a:hover { color: var(--primary); text-decoration: underline; }
.breadcrumb li + li::before { content: "/"; margin-right: 6px; color: var(--border-strong); }
.hero-grid { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end; }
.eyebrow {
  display: inline-block; font-family: var(--font-head); font-size: .8rem; font-weight: 600;
  letter-spacing: .04em; color: var(--primary); margin-bottom: 8px;
}
.hero h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); font-weight: 700; }
.hero-lead { color: var(--muted); margin: 10px 0 0; max-width: 60ch; }
.stats { display: flex; gap: 28px; }
.stat { display: flex; flex-direction: column; }
.stat-value { font-family: var(--font-head); font-size: 1.75rem; font-weight: 700; line-height: 1; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-label { font-size: .8rem; color: var(--muted); margin-top: 6px; }

.toolbar { display: flex; gap: 12px; margin-top: 24px; align-items: center; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 320px; max-width: 520px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 46px; padding: 0 44px 0 42px;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 999px;
  transition: border-color .2s, background-color .2s, box-shadow .2s;
}
.search input::placeholder { color: #9CA3AF; }
.search input:focus { outline: none; background: var(--surface); border-color: var(--primary); box-shadow: 0 0 0 4px rgba(200, 16, 46, .12); }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.search-clear:hover { background: var(--border); color: var(--text); }
.kbd {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .75rem;
  padding: 2px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; color: var(--muted);
}
.hint, .search-status { font-size: .85rem; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; padding: 32px 20px 56px; }
.year-nav { position: sticky; top: 88px; align-self: start; }
.year-nav-title { font-family: var(--font-head); font-size: .75rem; font-weight: 600; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px 12px; }
.year-nav ul { display: flex; flex-direction: column; gap: 2px; border-left: 2px solid var(--border); }
.year-nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; margin-left: -2px; border-left: 2px solid transparent;
  text-decoration: none; color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums;
  transition: color .2s, border-color .2s, background-color .2s;
}
.year-nav a:hover { color: var(--text); background: var(--surface); }
.year-nav a.is-active { color: var(--primary); border-left-color: var(--primary); background: var(--surface); }
.year-nav a[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.nav-count { font-size: .75rem; color: var(--muted); }

.content { display: flex; flex-direction: column; gap: 24px; }

/* ---------- Year card ---------- */
.year {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 24px;
}
.year-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.year-head h2 { font-size: 1.35rem; font-weight: 700; }
.year-period { font-size: .875rem; color: var(--muted); margin-top: 4px; }
.year-count {
  flex-shrink: 0; font-size: .8rem; font-weight: 600; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
  font-variant-numeric: tabular-nums;
}
.year.is-latest .year-head h2::after {
  content: "ล่าสุด"; margin-left: 10px; vertical-align: middle;
  font-family: var(--font-body); font-size: .7rem; font-weight: 600;
  color: var(--primary); background: var(--primary-soft); border-radius: 999px; padding: 3px 9px;
}
.group-label { font-size: .8rem; font-weight: 600; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.group + .group { margin-top: 22px; }

/* Supporting documents */
.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  text-decoration: none; transition: border-color .2s, background-color .2s, transform .2s;
}
a.doc:hover { border-color: var(--primary); background: var(--primary-soft); }
a.doc:hover .doc-arrow { transform: translateX(3px); color: var(--primary); }
.doc-icon {
  width: 36px; height: 36px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary); flex-shrink: 0;
}
.doc-title { flex: 1; font-size: .95rem; }
.doc-arrow { color: var(--border-strong); transition: transform .2s, color .2s; }
.doc.is-pending { border-style: dashed; color: var(--muted); }
.doc.is-pending .doc-icon { background: var(--bg); color: var(--muted); }
.badge { font-size: .7rem; font-weight: 600; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.badge-new { color: #fff; background: var(--primary); }
.badge-pending { color: var(--muted); background: var(--bg); border: 1px solid var(--border); }

/* Monthly grid */
.month-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.month {
  position: relative; display: flex; flex-direction: column; justify-content: center;
  min-height: 76px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  text-decoration: none; transition: border-color .2s, box-shadow .2s, transform .2s;
}
a.month::after {
  content: ""; position: absolute; top: 10px; right: 10px; width: 14px; height: 14px;
  background: currentColor; color: var(--border-strong);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 17 17 7M8 7h9v9'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 17 17 7M8 7h9v9'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: color .2s;
}
a.month:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
a.month:hover::after { color: var(--primary); }
a.month:hover .month-abbr { color: var(--primary); }
.month-abbr { font-family: var(--font-head); font-size: 1.1rem; font-weight: 600; transition: color .2s; }
.month-year { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.month-tag { font-size: .7rem; color: var(--muted); }
.month.is-empty { border-style: dashed; background: var(--bg); color: var(--muted); }
.month.is-empty .month-abbr { color: var(--muted); }

/* Search state */
.is-hidden { display: none !important; }
.empty-state {
  text-align: center; padding: 48px 24px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty-state strong { display: block; font-family: var(--font-head); color: var(--text); font-size: 1.1rem; margin-bottom: 4px; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 24px 0; font-size: .85rem; color: var(--muted); }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 12px 24px; justify-content: space-between; align-items: center; }
.trust { display: inline-flex; align-items: center; gap: 8px; }
.trust svg { color: #15803D; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-top: 0; }
  .year-nav {
    position: sticky; top: 64px; z-index: 30; margin: 0 -20px;
    background: var(--bg); border-bottom: 1px solid var(--border); padding: 10px 20px;
  }
  .year-nav-title { display: none; }
  .year-nav ul { flex-direction: row; overflow-x: auto; border-left: 0; gap: 6px; scrollbar-width: none; }
  .year-nav ul::-webkit-scrollbar { display: none; }
  .year-nav a { margin-left: 0; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; background: var(--surface); white-space: nowrap; }
  .year-nav a.is-active { border-color: var(--primary); background: var(--primary-soft); }
  .nav-count { display: none; }
  .month-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  html { scroll-padding-top: 130px; }
}
@media (max-width: 640px) {
  .hero-grid { grid-template-columns: 1fr; }
  .stats { gap: 20px; }
  .hint { display: none; }
  .brand img { height: 36px; }
  .btn-ghost span { display: none; }
  .year { padding: 18px; }
  .month-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .month { min-height: 66px; padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media print {
  .site-header, .year-nav, .toolbar, .skip-link { display: none !important; }
  .layout { display: block; padding: 0; }
  .year { break-inside: avoid; box-shadow: none; margin-bottom: 16px; }
  a.month::after { display: none; }
}
