/* base.css — สี ฟอนต์ โครงหน้า เมนูล่าง และชิ้นส่วนที่ทุกหน้าใช้ร่วม (การ์ด ปุ่ม ป้าย ช่องกรอก แผ่นล่าง) */

@font-face {
  font-family: 'Phetsarath OT';
  src: local('Phetsarath OT'), local('PhetsarathOT'), url('../../fonts/PhetsarathOT.ttf') format('truetype');
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #e6eef8;
  --card: #ffffff;
  --text: #0f2a4a;
  --muted: #5b6b80;
  --line: #d3e0ef;
  --hdr: #0b3f7a;
  --primary: #1a6fc4;
  --primary-ink: #0b4a96;
  --soft: #e4eefb;
  --series-1: #2a78d6;
  --grid: #e3ebf4;
  --ok-bg: #dcf3e6;  --ok-ink: #166534;
  --warn-bg: #fdeccb; --warn-ink: #7a4a06;
  --bad-bg: #fde2e2; --bad-ink: #a32a1f;
  --info-bg: #dbe9fb; --info-ink: #0b3f7a;
  --mute-bg: #e9eef4; --mute-ink: #5b6b80;
  --red: #e24b4a;
  --field: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1620; --card: #17212c; --text: #eaf1f8; --muted: #9fb0c3; --line: #2b3b4e;
    --hdr: #0d3b73; --primary: #3987e5; --primary-ink: #9cc5f7; --soft: #1b2c42;
    --series-1: #3987e5; --grid: #263444; --field: #111a24;
    --ok-bg: #12351f; --ok-ink: #86efac; --warn-bg: #3d2c0a; --warn-ink: #fcd34d;
    --bad-bg: #3a1613; --bad-ink: #fca5a5; --info-bg: #14305a; --info-ink: #9cc5f7;
    --mute-bg: #243242; --mute-ink: #9fb0c3; --red: #e66767;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Phetsarath OT', 'Noto Sans Lao', 'Noto Sans Lao UI', system-ui, sans-serif;
  font-size: 15px; line-height: 1.5;
  padding-bottom: 84px;
}

.ico { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.22em; }

/* ---------- หัว ---------- */
.app-header {
  position: sticky; top: 0; z-index: 5;
  background: var(--hdr); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px;
}
.hdr-text h1 { margin: 0; font-size: 19px; line-height: 1.3; }
.hdr-text p { margin: 0; font-size: 12px; opacity: .85; }
.hdr-side { display: flex; align-items: center; gap: 8px; }
.mode-tag { white-space: nowrap; font-size: 11px; background: rgba(255,255,255,.18); padding: 2px 8px; border-radius: 999px; }
.role-btn { white-space: nowrap; font: inherit; font-size: 12px; color: #fff; background: rgba(255,255,255,.18); border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; }

/* ---------- โครงหน้า ---------- */
.page { max-width: 640px; margin: 0 auto; padding: 12px; }

/* ---------- เมนูล่าง ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; background: var(--hdr);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
}
.nv-b {
  flex: 1; position: relative; border: 0; background: none; cursor: pointer;
  color: #a9c4e4; font: inherit; font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0;
}
.nv-b .ico { width: 24px; height: 24px; }
.nv-b.on { color: #fff; font-weight: 700; }
.nb { display: inline-block; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-style: normal; line-height: 17px; text-align: center; }
.nv-b .nb { position: absolute; top: 0; left: 55%; }

/* ---------- การ์ดและตัวอักษร ---------- */
.cd { background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.tt { font-size: 14px; font-weight: 700; margin: 0 0 8px; }
.sec { font-size: 14px; color: var(--primary-ink); margin: 14px 2px 8px; }
.m { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.count { font-size: 12px; color: var(--muted); margin: 4px 2px 8px; }
.note { background: var(--info-bg); color: var(--info-ink); border-radius: 10px; padding: 8px 12px; font-size: 13px; margin: 0 0 10px; }
.note.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- ปุ่ม ---------- */
.btn, .btn-ghost, .link-btn, .chip, .subtab {
  font: inherit; cursor: pointer;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 700;
}
.btn.big { width: 100%; min-height: 48px; font-size: 16px; margin-top: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost {
  min-height: 40px; padding: 0 14px; border-radius: 10px; font-size: 14px;
  background: transparent; color: var(--primary-ink); border: 1.5px solid var(--primary);
}
.btn-ghost.danger { color: var(--bad-ink); border-color: var(--bad-ink); }
.link-btn { background: none; border: 0; color: var(--primary-ink); font-size: 13px; padding: 6px 2px; text-decoration: underline; }
.icon-sq { width: 36px; height: 36px; border: 0; border-radius: 9px; background: var(--soft); color: var(--primary-ink); font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- ป้ายและชิป ---------- */
.tag { display: inline-block; font-size: 11px; padding: 1px 9px; border-radius: 999px; margin-left: 6px; white-space: nowrap; }
.tag-ok { background: var(--ok-bg); color: var(--ok-ink); }
.tag-warn { background: var(--warn-bg); color: var(--warn-ink); }
.tag-bad { background: var(--bad-bg); color: var(--bad-ink); }
.tag-info { background: var(--info-bg); color: var(--info-ink); }
.tag-mute { background: var(--mute-bg); color: var(--mute-ink); }

.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.chip { font-size: 13px; padding: 5px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--primary-ink); }
.chip.on { background: var(--hdr); border-color: var(--hdr); color: #fff; }
.chip.on.warn { background: var(--warn-bg); border-color: #e8c27a; color: var(--warn-ink); }

.subtabs { display: flex; gap: 4px; background: var(--card); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.subtab { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 4px; font-size: 14px; color: var(--muted); }
.subtab.on { background: var(--hdr); color: #fff; font-weight: 700; }

/* ---------- ช่องกรอก ---------- */
select, input[type="text"], input[type="search"] {
  width: 100%; min-height: 42px; padding: 0 12px; font: inherit; font-size: 15px;
  color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
select:focus, input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.lbl { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- ไอคอนวงกลมและแถวทั่วไป ---------- */
.sc-ic { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex: none; }
.tone-red { background: var(--bad-bg); color: var(--bad-ink); }
.tone-blue { background: var(--info-bg); color: var(--info-ink); }
.tone-green { background: var(--ok-bg); color: var(--ok-ink); }
.tone-amber { background: var(--warn-bg); color: var(--warn-ink); }
.tone-violet { background: #e6e1f7; color: #4a3aa7; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tone-violet { background: #2a2650; color: #b9b0f5; } }

.al-row { display: flex; gap: 10px; align-items: flex-start; }
.al-main { flex: 1; min-width: 0; }
.al-act { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }

/* ---------- แผ่นล่าง (รายละเอียด) ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: rgba(8, 20, 36, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 86vh; overflow: auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-h { display: flex; justify-content: space-between; align-items: center; font-size: 18px; margin-bottom: 6px; }
.dl-r { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.dl-r:last-child { border-bottom: 0; }
.dl-k { color: var(--muted); font-size: 13px; }
.dl-v { text-align: right; font-weight: 700; overflow-wrap: anywhere; }
.dl-warn { margin-top: 10px; background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 8px 12px; }
.dl-warn ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- แจ้งสั้นๆ ---------- */
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 30; background: #0f2a4a; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; max-width: 90vw; }

@media (prefers-reduced-motion: no-preference) { .sheet { animation: up .18s ease-out; } @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } } }
