:root {
  --bg: #EEF2EC;          /* sage white — พื้นหลัง */
  --surface: #FFFFFF;
  --ink: #173326;         /* deep leaf — ตัวอักษร */
  --muted: #5B6F63;
  --line: #CFDACF;
  --leaf: #2E7A4E;        /* สีหลัก ปุ่ม/ลิงก์ */
  --leaf-soft: #DDEBDF;
  --grow: #B0357A;        /* แสงไฟ LED ปลูกพืช — ใช้กับแถบนำเข้าเท่านั้น */
  --grow-glow: rgba(176, 53, 122, .35);
  --warn: #A4510E;
  --warn-soft: #F7E7D6;
  --danger: #A12A2A;
  --danger-soft: #F6DEDC;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101A14; --surface: #17241C; --ink: #E3ECE5; --muted: #9AAEA1; --line: #2A3B30;
    --leaf: #6CC08D; --leaf-soft: #1F3527; --grow: #E46BB0; --grow-glow: rgba(228, 107, 176, .4);
    --warn: #E7A45F; --warn-soft: #3A2A18; --danger: #EE8A84; --danger-soft: #3B1F1D;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif; line-height: 1.65;
  font-variant-numeric: tabular-nums;
}
a { color: var(--leaf); }
:focus-visible { outline: 3px solid var(--leaf); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 .25rem; font-weight: 600; }
h2 { font-size: 1.2rem; line-height: 1.35; margin: 0 0 .75rem; font-weight: 600; }
h3 { font-size: 1rem; margin: 0 0 .4rem; font-weight: 600; }
p { margin: 0 0 .75rem; max-width: 72ch; }
.lead { color: var(--muted); margin-bottom: 1.75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* โครงหน้า: เมนูซ้าย + เนื้อหา */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 1.5rem;
}
.brand { display: flex; gap: .65rem; align-items: center; text-decoration: none; color: var(--ink); }
.brand svg { flex: none; }
.brand b { display: block; font-weight: 600; line-height: 1.2; }
.brand span { font-size: .8rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  text-decoration: none; color: var(--ink); padding: .5rem .75rem; border-radius: 8px;
}
.nav a:hover { background: var(--leaf-soft); }
.nav a[aria-current="page"] { background: var(--leaf-soft); color: var(--leaf); font-weight: 600; }
.side-foot { margin-top: auto; font-size: .85rem; color: var(--muted); }
.side-foot form { margin-top: .4rem; }
main { padding: 2.25rem 2.5rem 4rem; max-width: 1040px; width: 100%; }

/* กล่องเนื้อหา */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem 1.5rem; margin-bottom: 1.5rem;
}
.panel > h2:first-child { margin-top: 0; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.row.top { align-items: flex-start; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* ตัวเลขสรุป: แถวเดียว คั่นเส้น ไม่ใช่การ์ดแยก */
.figures { display: flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); margin-bottom: 1.5rem; }
.figures div { flex: 1 1 140px; padding: 1rem 1.25rem; border-right: 1px solid var(--line); }
.figures div:last-child { border-right: 0; }
.figures b { display: block; font-size: 1.6rem; font-weight: 600; line-height: 1.2; }
.figures span { color: var(--muted); font-size: .875rem; }

/* ขั้นตอนเริ่มใช้งาน (เป็นลำดับจริง จึงมีหมายเลข) */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li { display: grid; grid-template-columns: 2rem 1fr auto; gap: .75rem; align-items: center;
  padding: .7rem 0; border-top: 1px solid var(--line); counter-increment: s; }
.steps li:first-child { border-top: 0; }
.steps li::before { content: counter(s); width: 1.75rem; height: 1.75rem; border-radius: 50%;
  display: grid; place-items: center; font-size: .85rem; border: 1.5px solid var(--line); color: var(--muted); }
.steps li.done::before { content: "✓"; background: var(--leaf); border-color: var(--leaf); color: #fff; }
.steps li.done .t { color: var(--muted); }

/* ฟอร์ม */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .75rem;
}
textarea { min-height: 14rem; line-height: 1.6; }
input:focus, select:focus, textarea:focus { border-color: var(--leaf); outline: 2px solid var(--leaf-soft); }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: .55rem 1.1rem;
  border: 1px solid var(--leaf); background: var(--leaf); color: #fff; text-decoration: none; display: inline-block;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn.quiet { background: transparent; color: var(--leaf); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.link { background: none; border: 0; color: var(--muted); padding: 0; font-weight: 400; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ตาราง */
table { width: 100%; border-collapse: collapse; font-size: .925rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .85rem; padding: .5rem .6rem;
  border-bottom: 1px solid var(--line); }
td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.num { text-align: right; }

.tag { display: inline-block; font-size: .8rem; padding: .05rem .55rem; border-radius: 999px;
  background: var(--leaf-soft); color: var(--leaf); white-space: nowrap; }
.tag.new, .tag.changed, .tag.expired { background: var(--warn-soft); color: var(--warn); }
.tag.missing, .tag.revoked, .tag.err { background: var(--danger-soft); color: var(--danger); }

.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--leaf-soft); }
.flash.error { background: var(--danger-soft); color: var(--danger); }

/* URL ของ key ที่เพิ่งออก — แสดงครั้งเดียว */
.once { border: 2px solid var(--leaf); }
.copy { display: flex; gap: .5rem; }
.copy input { font-size: .9rem; }

/* แถบนำเข้า: ชั้นวางถาดปลูกที่ไฟ LED ติดทีละช่อง — จุดเด่นเดียวของหน้า */
.shelf { display: grid; grid-template-columns: repeat(var(--cells, 40), 1fr); gap: 3px; margin: .75rem 0 .5rem;
  padding: 6px; border-radius: 8px; background: var(--ink); }
.shelf i { height: 14px; border-radius: 2px; background: color-mix(in srgb, var(--surface) 14%, transparent); }
.shelf i.on { background: var(--grow); box-shadow: 0 0 8px var(--grow-glow); }
@media (prefers-reduced-motion: no-preference) {
  .shelf i.on { transition: background .4s, box-shadow .4s; }
}
.joblog { background: var(--bg); border-radius: 8px; padding: .75rem 1rem; max-height: 16rem; overflow: auto;
  font: inherit; font-size: .85rem; white-space: pre-wrap; margin: 0; }

/* ผลค้นหา */
.result { padding: .9rem 0; border-top: 1px solid var(--line); }
.result:first-child { border-top: 0; padding-top: 0; }
.result h3 { margin-bottom: .2rem; }
.fact { padding: .35rem 0; }
.topic { padding: .75rem 0; border-top: 1px solid var(--line); }
.topic:first-of-type { border-top: 0; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .panel { width: 100%; max-width: 400px; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); padding: 1rem; gap: .75rem; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin-top: 0; }
  main { padding: 1.5rem 1rem 3rem; }
  .split { grid-template-columns: 1fr; }
  .figures { display: grid; grid-template-columns: 1fr 1fr; }
  .figures div { border-right: 0; border-bottom: 1px solid var(--line); }
  .figures div:nth-child(odd) { border-right: 1px solid var(--line); }
  .figures div:last-child { border-bottom: 0; border-right: 0; grid-column: 1 / -1; }
  .steps li { grid-template-columns: 2rem 1fr; }
  .steps li .go { grid-column: 2; }
}
