/* Pann Count — ชุดตัวแปรและชิ้นส่วนกลาง (ตามแบบ docs/design/Stock Audit App.dc.html) */

:root {
  --bg: #F5F6F4;
  --surface: #FFFFFF;
  --surface-2: #FAFBFA;
  --soft: #F1F3F1;
  --ink: #15201B;
  --muted: #5E6A64;
  --faint: #9AA59F;
  --line: #E9ECEA;
  --line-2: #E3E7E4;
  --line-3: #F0F2F0;
  --track: #EEF1EF;
  --seg: #E9ECEA;
  --green: #0F8A5F;
  --green-dark: #0B6B4A;
  --green-soft: #E7F3EE;
  --red: #C23B2B;
  --red-soft: #FBE8E5;
  --amber: #A86A12;
  --amber-ink: #7A4D0C;
  --amber-soft: #FBF0DC;
  --blue: #2B5CB8;
  --blue-soft: #E6EEFB;
  --radius-card: 20px;
  --radius-field: 16px;
  --radius-btn: 14px;
  --font: Anuphan, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --shadow: 0 4px 12px rgba(15, 138, 95, .3);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
a { color: var(--green); text-decoration: none; }
a:hover { color: var(--green-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.mono, code { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- โครงหน้า ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1080px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; border: 0; background: transparent; padding: 4px 8px 4px 4px; border-radius: 14px; min-width: 0; text-align: left; }
.brand:hover { background: var(--soft); }
.brand-logo { width: 38px; height: 38px; border-radius: 12px; background: var(--green-soft); color: var(--green); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; overflow: hidden; }
.brand-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { padding: 8px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a.on, .nav a:hover { background: var(--green-soft); color: var(--green); }
.page { max-width: 1080px; margin: 0 auto; padding: 18px 16px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 27px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.page-head .sub { font-size: 13px; color: var(--muted); }
@media (max-width: 720px) {
  .nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); margin: 0; z-index: 30; }
  .nav a { font-size: 12px; padding: 8px 6px; }
  .page-head h1 { font-size: 24px; }
}

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border-radius: var(--radius-card); padding: 16px; border: 1px solid var(--line); }
.card + .card, .stack > * + * { margin-top: 14px; }
.card h2, .card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.card-list { background: var(--surface); border-radius: var(--radius-card); overflow: hidden; border: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-3); }
.row:last-child { border-bottom: 0; }
.row.click { cursor: pointer; }
.row.click:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 720px) { .grid4 { grid-template-columns: 1fr 1fr; } }
.stat { background: var(--surface); border-radius: 18px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 24px; font-weight: 700; line-height: 1.2; }
.hero { background: var(--green); color: #fff; border-radius: 24px; padding: 20px 20px 18px; }
.hero .big { font-size: 44px; font-weight: 700; letter-spacing: -.02em; line-height: 1; margin: 6px 0 12px; }
.hero .bar { background: rgba(255,255,255,.25); }
.hero .bar > i { background: #fff; }

/* ---------- ปุ่ม ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 18px; border-radius: var(--radius-btn); border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap; transition: background .12s, transform .06s; }
.btn:active { transform: scale(.98); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--green); }
.btn.sm { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn[disabled], .btn.busy { opacity: .55; pointer-events: none; }
.btn .spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.fab { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--green); color: #fff; box-shadow: var(--shadow); cursor: pointer; font-size: 22px; }

/* ---------- ฟอร์ม ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 13px; font-weight: 600; color: var(--ink); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, .select, .textarea { width: 100%; height: 50px; padding: 0 16px; background: var(--surface); border-radius: var(--radius-field); border: 1px solid var(--line-2); font-size: 15px; }
.textarea { height: auto; min-height: 90px; padding: 12px 16px; resize: vertical; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 22px, calc(100% - 15px) 22px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.search { display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 16px; background: var(--surface); border-radius: var(--radius-field); border: 1px solid var(--line-2); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 15px; padding: 0; outline: none; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }

/* ---------- ชิป แถบ ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber-ink); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.dark { background: var(--ink); color: #fff; }
.bar { height: 8px; border-radius: 8px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 8px; background: var(--green); width: 0; transition: width .4s; }
.bar.thin { height: 6px; }
.seg { display: flex; gap: 6px; background: var(--seg); border-radius: 14px; padding: 4px; overflow-x: auto; }
.seg > * { flex: 1; text-align: center; padding: 9px 8px; border-radius: 11px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; color: var(--muted); border: 0; background: transparent; }
.seg > .on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.steps { display: flex; gap: 6px; }
.steps > i { flex: 1; height: 4px; border-radius: 4px; background: #DDE2DF; }
.steps > i.on { background: var(--green); }
.notice { display: flex; align-items: center; gap: 10px; border-radius: 14px; padding: 11px 14px; font-size: 13px; line-height: 1.4; background: var(--soft); color: var(--muted); }
.notice.amber { background: var(--amber-soft); color: var(--amber-ink); }
.notice.red { background: var(--red-soft); color: var(--red); }
.notice.green { background: var(--green-soft); color: var(--green-dark); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex: none; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- ตาราง ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius-card); border: 1px solid var(--line); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-3); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.warn td { background: #FFF8EC; }
.tbl tr.bad td { background: #FDF1EF; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 4px; font-size: 13px; color: var(--muted); }

/* ---------- แผ่นล่าง / modal / toast ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(16,22,20,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 721px) { .sheet-bg { align-items: center; } .sheet { border-radius: 24px; } }
.sheet h2 { margin: 0 0 14px; font-size: 20px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; z-index: 80; max-width: 92vw; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.toast.err { background: var(--red); }
.skeleton { background: linear-gradient(90deg, var(--soft), #fafbfa, var(--soft)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 10px; height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- หน้าเข้าใช้ ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 28px; padding: 32px 24px; text-align: center; border: 1px solid var(--line); }
.login-card h1 { font-size: 27px; margin: 14px 0 6px; }
.google-btn { width: 100%; height: 56px; font-size: 16px; }

/* ---------- ปฏิทินไทย ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid i { font-style: normal; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-d { height: 42px; border-radius: 12px; border: 0; background: var(--surface); cursor: pointer; font-weight: 600; }
.cal-d:hover { background: var(--green-soft); }
.cal-d.today { box-shadow: inset 0 0 0 1.5px var(--green); }
.cal-d.on { background: var(--green); color: #fff; }

/* ---------- แท็บ ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 0 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--green); border-bottom-color: var(--green); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .search { flex: 1 1 220px; height: 44px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; z-index: 5; }
@media (max-width: 720px) { .sticky-actions { bottom: 58px; } }
