:root {
  --navy: #000D36;
  --navy-2: #0B1E5B;
  --blue: #0B3F94;
  --gold: #C9A46A;
  --gold-2: #E8D3A8;
  --ivory: #F7F3EA;
  --bg: #F4F5F8;
  --card: #FFFFFF;
  --text: #121826;
  --muted: #5B6476;
  --line: #E2E5EC;
  --ok: #1F8A5B;
  --warn: #B7791F;
  --danger: #C0392B;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,13,54,.06), 0 6px 20px rgba(0,13,54,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.55; font-size: 16px;
}
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--navy); color: #fff; border-bottom: 2px solid var(--gold);
}
[hidden] { display: none !important; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; letter-spacing: .08em; }
.brand img { height: 34px; background: #fff; border-radius: 6px; padding: 2px 4px; }
.brand b { color: var(--gold); }
.nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: #D6DBEA; text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; font-size: .95rem;
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: rgba(201,164,106,.18); color: var(--gold-2); }

.app { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }

/* ---------- cards & layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 860px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 560px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0,1fr); } }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.row.nowrap { flex-wrap: nowrap; }
@media (max-width: 560px) {
  .seg { display: flex; width: 100%; }
  .seg button { flex: 1; padding: 8px 4px; white-space: nowrap; font-size: .85rem; }
  .row.nowrap input { min-width: 0; flex: 1; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand span { display: none; }
}
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 0; }

/* ---------- forms ---------- */
label.field { display: block; }
label.field > span { display: block; font-size: .9rem; font-weight: 500; margin-bottom: 4px; }
label.field > span em { color: var(--danger); font-style: normal; }
input, select, textarea {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid #CBD1DC; border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(11,63,148,.25); border-color: var(--blue); }
textarea { min-height: 84px; resize: vertical; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 4px; }
.input-unit { position: relative; }
.input-unit input { padding-right: 64px; }
.input-unit i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: .85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: #B8925A; }
.btn-ghost { background: #fff; border-color: #CBD1DC; color: var(--text); }
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

.check { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #FBFCFE; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; accent-color: var(--blue); }
.check + .check { margin-top: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid #CBD1DC; background: #fff; border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: .9rem;
}
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }

.seg { display: inline-flex; border: 1px solid #CBD1DC; border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { font: inherit; border: 0; background: transparent; padding: 8px 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid #CBD1DC; }
.seg button.on { background: var(--navy); color: #fff; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-side {
  background: radial-gradient(ellipse at 110% 110%, rgba(201,164,106,.35), transparent 55%), var(--navy);
  color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.auth-side::after {
  content: ""; position: absolute; right: -180px; bottom: -220px; width: 560px; height: 560px; border-radius: 50%;
  border: 3px solid var(--gold); opacity: .6;
}
@media (min-width: 901px) { .auth-side { position: sticky; top: 0; height: 100vh; } }
.auth-side .logo { background: #fff; border-radius: 12px; padding: 8px 12px; width: 150px; }
.auth-side h1 { font-size: 2.6rem; letter-spacing: .06em; margin-top: 40px; }
.auth-side h1 b { color: var(--gold); }
.auth-side ul { padding-left: 1.1em; color: #D6DBEA; }
.auth-side li { margin: 6px 0; }
.auth-main { padding: 48px 32px; display: flex; align-items: center; justify-content: center; background: var(--ivory); }
.auth-box { width: 100%; max-width: 420px; }
.auth-box.wide { max-width: 640px; }
@media (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { padding: 28px 20px; }
  .auth-side h1 { font-size: 2rem; margin-top: 16px; }
  .auth-side ul, .auth-side .foot { display: none; }
  .auth-main { padding: 28px 16px; }
}

.steps { display: flex; gap: 6px; margin-bottom: 18px; }
.steps div { flex: 1; height: 5px; border-radius: 3px; background: #DCD5C4; }
.steps div.on { background: var(--gold); }

#map { height: 300px; border-radius: 12px; border: 1px solid var(--line); margin-top: 10px; z-index: 0; }

.animal-row { display: grid; grid-template-columns: 1fr 150px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.animal-row label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.animal-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--blue); }

/* ---------- dashboard / stats ---------- */
.hero {
  background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 70%, #2A3570 100%);
  color: #fff; border-radius: var(--radius); padding: 24px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  border-bottom: 3px solid var(--gold);
}
.hero h1 { margin: 0; }
.hero p { margin: 4px 0 0; color: #C9D0E4; }

.stat { padding: 16px; }
.stat .label { font-size: .85rem; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.stat .value { font-size: 1.7rem; font-weight: 600; margin-top: 2px; }
.stat .value small { font-size: .85rem; font-weight: 400; color: var(--muted); margin-left: 4px; }
.stat .sub { font-size: .82rem; color: var(--muted); }
.delta { white-space: nowrap; flex: none; font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #EEF1F6; color: var(--muted); }
.delta.up { background: #FBEAE8; color: var(--danger); }
.delta.down { background: #E6F4EC; color: var(--ok); }

.param-card { padding: 16px; }
.param-card canvas { margin-top: 10px; width: 100% !important; height: 150px !important; }
.mm { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.mm div { background: #F6F7FA; border-radius: 8px; padding: 6px 8px; }
.mm span { display: block; font-size: .72rem; color: var(--muted); }
.mm b { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #F6F7FA; font-weight: 600; color: var(--muted); font-size: .8rem; position: sticky; top: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #FAFBFD; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: #EEF1F6; color: var(--muted); }
.badge.ok { background: #E6F4EC; color: var(--ok); }
.badge.no { background: #FBEAE8; color: var(--danger); }
.lock { display: inline-flex; gap: 6px; align-items: center; font-size: .8rem; color: var(--muted); }

.notice { border-left: 4px solid var(--gold); background: #FFF9EE; padding: 12px 14px; border-radius: 8px; font-size: .92rem; }
.notice.danger { border-color: var(--danger); background: #FDF1EF; }
.notice ul { margin: 6px 0 0; padding-left: 1.2em; }
.notice li { margin: 3px 0; }

/* ---------- marketing banners & links ---------- */
.promo-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 28px; }
.promo {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 170px; padding: 20px;
  border-radius: var(--radius); overflow: hidden; color: #fff; text-decoration: none; border-bottom: 3px solid var(--gold);
  background: radial-gradient(ellipse at 100% 0%, rgba(201,164,106,.45), transparent 60%), linear-gradient(135deg, var(--navy), var(--blue));
  background-size: cover; background-position: center; box-shadow: var(--shadow); transition: transform .15s;
}
.promo:hover { transform: translateY(-2px); }
.promo > * { position: relative; }
.promo > img.bg, .promo > .shade { position: absolute; inset: 0; width: 100%; height: 100%; }
.promo > img.bg { object-fit: cover; }
.promo > .shade { background: linear-gradient(0deg, rgba(0,13,54,.88) 0%, rgba(0,13,54,.2) 75%); }
.promo .tag { font-size: .72rem; letter-spacing: .1em; color: var(--gold-2); text-transform: uppercase; }
.promo h3 { margin: 4px 0; font-size: 1.15rem; }
.promo p { margin: 0 0 10px; color: #D6DBEA; font-size: .9rem; }
.promo .btn { align-self: flex-start; padding: 6px 14px; font-size: .9rem; }
.site-foot { max-width: 1120px; margin: 0 auto; padding: 20px 16px 40px; border-top: 1px solid var(--line); display: flex; gap: 8px 20px; flex-wrap: wrap; align-items: center; font-size: .88rem; color: var(--muted); }
.site-foot a { color: var(--blue); text-decoration: none; font-weight: 500; }
.site-foot a:hover { text-decoration: underline; }
.ext-links { display: flex; gap: 8px; flex-wrap: wrap; }
.ext-links a { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.auth-side .ext-links a { background: rgba(255,255,255,.08); border-color: rgba(201,164,106,.5); color: var(--gold-2); }
.promo-thumb { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; background: #EEF1F6; display: block; }

/* ---------- dialog / toast ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; max-width: 560px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,13,54,.3); }
dialog::backdrop { background: rgba(0,13,54,.5); }
.dlg-body { padding: 22px; }
.dlg-foot { padding: 14px 22px; background: #F6F7FA; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.review dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0; }
.review dt { color: var(--muted); }
.review dd { margin: 0; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 10px; transition: .25s; z-index: 3000; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); }

.print-only { display: none; }

@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .topbar, .no-print, .toast { display: none !important; }
  .print-only { display: block; }
  .print-only.print-head { display: flex; }
  .app { max-width: none; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .param-card canvas { height: 120px !important; }
}
.print-head { align-items: center; gap: 16px; border-bottom: 2px solid var(--gold); padding-bottom: 10px; margin-bottom: 14px; }
.print-head img { height: 48px; }
