:root {
  --navy-900: #141a5c;
  --navy-800: #1d2479;
  --navy-700: #26308f;
  --navy-600: #3340b0;
  --gold: #f2b33a;
  --gold-soft: #ffe7a8;
  --ink: #1b1f3b;
  --muted: #5b607e;
  --line: #dfe2f0;
  --bg: #f4f5fb;
  --card: #ffffff;
  --green: #1f9d55;
  --green-bg: #e3f6ea;
  --yellow: #b7791f;
  --yellow-bg: #fff4d6;
  --red: #c53030;
  --red-bg: #fde8e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 26, 92, .06), 0 6px 20px rgba(20, 26, 92, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Sarabun", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3, .brand-title, .btn, .tab { font-family: "Kanit", "Sarabun", sans-serif; }
a { color: var(--navy-600); }

/* ---------- ส่วนหัว (ตามป้ายศูนย์) ---------- */
.hero {
  background: radial-gradient(120% 140% at 50% 0%, var(--navy-600) 0%, var(--navy-800) 55%, var(--navy-900) 100%);
  color: #fff;
  padding: 18px 16px 22px;
}
.hero-inner {
  max-width: 760px;
  margin: 0 auto;
  border: 2px solid var(--gold);
  border-radius: 6px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.hero img { width: 64px; height: 64px; flex: none; }
.brand-title { font-weight: 700; font-size: clamp(18px, 4.6vw, 28px); line-height: 1.25; margin: 0; }
.brand-sub { color: var(--gold); font-weight: 500; font-size: clamp(14px, 3.4vw, 18px); margin: 2px 0 0; font-family: "Kanit", sans-serif; }

nav.tabs {
  max-width: 760px;
  margin: 14px auto 0;
  display: flex;
  gap: 8px;
}
.tab {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: #fff;
  padding: 9px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .18);
  font-size: 15px;
}
.tab[aria-current="page"] { background: var(--gold); color: var(--navy-900); border-color: var(--gold); font-weight: 600; }

main { max-width: 760px; margin: 0 auto; padding: 18px 16px 48px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 6px; font-size: 21px; color: var(--navy-800); }
.lead { color: var(--muted); margin: 0 0 4px; }

.safe-note {
  display: flex; gap: 12px; align-items: flex-start;
  background: #eef0ff; border-left: 4px solid var(--navy-600);
  padding: 12px 14px; border-radius: 10px; font-size: 15.5px;
}

.hotlines { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-top: 10px; }
.hotline {
  display: block; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fff;
}
.hotline b { font-family: "Kanit", sans-serif; font-size: 22px; color: var(--navy-700); display: block; line-height: 1.2; }
.hotline span { font-size: 13.5px; color: var(--muted); }

.alert {
  border-radius: 10px; padding: 12px 14px; margin: 12px 0; font-size: 15.5px;
}
.alert-red { background: var(--red-bg); color: #7f1d1d; border: 1px solid #f5b5b5; }
.alert-gold { background: var(--yellow-bg); color: #6b4300; border: 1px solid #f3d58a; }
.hidden { display: none !important; }

/* ---------- ฟอร์ม ---------- */
.field { margin-top: 16px; }
.field > label, .legend { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 14px; }
input[type=text], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 11px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy-600); box-shadow: 0 0 0 3px rgba(51, 64, 176, .15); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; }
.chip span {
  display: inline-block; padding: 8px 14px; border-radius: 999px;
  border: 1.5px solid var(--line); background: #fff; font-size: 15px; cursor: pointer;
}
.chip input:checked + span { border-color: var(--navy-700); background: var(--navy-700); color: #fff; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(51, 64, 176, .3); }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.cat {
  position: relative; display: block; cursor: pointer;
}
.cat input { position: absolute; opacity: 0; }
.cat span {
  display: block; padding: 11px 14px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-size: 15.5px;
}
.cat input:checked + span { border-color: var(--navy-700); background: #eef0ff; box-shadow: inset 4px 0 0 var(--navy-700); font-weight: 600; }
.cat input:focus-visible + span { box-shadow: 0 0 0 3px rgba(51, 64, 176, .3); }

.toggle {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; background: #fff;
}
.toggle input { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--navy-700); flex: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid-2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px; font-weight: 600; border: 0; border-radius: 12px; cursor: pointer;
  padding: 13px 20px; text-decoration: none;
}
.btn-primary { background: var(--navy-700); color: #fff; }
.btn-primary:hover { background: var(--navy-800); }
.btn-gold { background: var(--gold); color: var(--navy-900); }
.btn-ghost { background: #eef0ff; color: var(--navy-700); }
.btn-sm { font-size: 14.5px; padding: 8px 12px; border-radius: 9px; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-block { width: 100%; }

.error { color: var(--red); font-weight: 600; margin-top: 10px; }

/* ---------- หน้าส่งสำเร็จ ---------- */
.success { text-align: center; }
.code-box {
  font-family: "Kanit", monospace; font-size: clamp(28px, 8vw, 40px); letter-spacing: 2px; font-weight: 700;
  color: var(--navy-800); background: var(--gold-soft); border: 2px dashed var(--gold);
  border-radius: 12px; padding: 12px; margin: 12px 0; user-select: all;
}

/* ---------- สถานะ ---------- */
.steps { list-style: none; padding: 0; margin: 16px 0 0; }
.steps li { display: flex; gap: 12px; align-items: flex-start; padding-bottom: 14px; position: relative; color: var(--muted); }
.steps li::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--line); background: #fff; flex: none; margin-top: 4px; z-index: 1;
}
.steps li:not(:last-child)::after { content: ""; position: absolute; left: 7px; top: 20px; bottom: 0; width: 2px; background: var(--line); }
.steps li.done { color: var(--ink); }
.steps li.done::before { background: var(--navy-700); border-color: var(--navy-700); }
.steps li.current { color: var(--ink); font-weight: 600; }
.steps li.current::before { border-color: var(--gold); background: var(--gold); }
.note-box { background: #f7f8fd; border-radius: 10px; padding: 12px 14px; margin-top: 8px; }

footer { text-align: center; color: var(--muted); font-size: 14px; padding: 8px 16px 32px; }

/* ---------- หลังบ้าน ---------- */
body.admin main { max-width: 1180px; }
body.admin .hero-inner, body.admin nav.tabs { max-width: 1180px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); border-top: 4px solid var(--navy-700); }
.stat b { display: block; font-family: "Kanit", sans-serif; font-size: 28px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 14px; }
.stat.red { border-color: var(--red); } .stat.red b { color: var(--red); }
.stat.yellow { border-color: #e2a32b; } .stat.yellow b { color: var(--yellow); }
.stat.green { border-color: var(--green); } .stat.green b { color: var(--green); }
.stat.over { border-color: #7f1d1d; } .stat.over b { color: #7f1d1d; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 150px; padding: 8px 10px; font-size: 15px; }
.filters input[type=search] { flex: 1; min-width: 180px; }

.layout { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } }

.list { display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 120px); overflow: auto; padding: 2px; }
.item {
  text-align: left; font: inherit; background: #fff; border: 1.5px solid transparent; border-radius: 12px;
  padding: 10px 12px 10px 14px; cursor: pointer; box-shadow: var(--shadow); border-left: 6px solid var(--line); width: 100%;
}
.item.lv-red { border-left-color: var(--red); }
.item.lv-yellow { border-left-color: #e2a32b; }
.item.lv-green { border-left-color: var(--green); }
.item.active { border-color: var(--navy-600); }
.item.closed { opacity: .6; }
.item-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; color: var(--muted); }
.item-code { font-family: "Kanit", sans-serif; font-weight: 600; color: var(--navy-800); }
.item-cat { font-weight: 600; margin: 2px 0; font-size: 15.5px; }
.item-prev { font-size: 14px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.badge { display: inline-block; font-size: 12.5px; padding: 2px 9px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.b-red { background: var(--red-bg); color: var(--red); }
.b-yellow { background: var(--yellow-bg); color: var(--yellow); }
.b-green { background: var(--green-bg); color: var(--green); }
.b-gray { background: #eceef6; color: var(--muted); }
.b-over { background: #7f1d1d; color: #fff; }

.detail h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 15.5px; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }
.desc { white-space: pre-wrap; background: #f7f8fd; border-radius: 10px; padding: 12px 14px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.files a { font-size: 14px; }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; font-size: 15px; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--navy-600); }
.timeline .meta { color: var(--muted); font-size: 13px; }
.timeline .k-note { white-space: pre-wrap; }
.empty { color: var(--muted); text-align: center; padding: 40px 10px; }

.login-wrap { max-width: 420px; margin: 24px auto; }

dialog { border: 0; border-radius: 16px; padding: 0; max-width: 640px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 26, 92, .45); }
dialog .card { margin: 0; box-shadow: none; }

@media print {
  .hero, nav, .filters, .list, .actions-form, .topbar .btn { display: none !important; }
}
