/* ===================== ระบบตรวจสอบมาตรฐานสาขา ===================== */
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Sarabun"; src: url("../fonts/Sarabun-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root, [data-bs-theme="light"] {
  --app-font: "Sarabun", system-ui, -apple-system, "Segoe UI", sans-serif;
  --plane: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --ink: #111418;
  --ink-2: #4b5059;
  --ink-muted: #7c818a;
  --hairline: #e3e5e8;
  --sidebar-bg: #10243a;
  --sidebar-ink: #c9d4e1;
  --sidebar-ink-strong: #ffffff;
  --sidebar-hover: rgba(255,255,255,.07);
  --sidebar-active: rgba(77,155,240,.18);
  --accent: #1f63b8;
  --accent-soft: #e6effa;
  /* data viz (validated reference palette) */
  --series-1: #2a78d6;
  --grid: #e1e0d9;
  --axis: #898781;
  /* status (ใช้คู่กับข้อความเสมอ) */
  --good: #0ca30c; --good-ink: #006300; --good-soft: #e5f5e5;
  --warning: #fab219; --warning-ink: #7a5300; --warning-soft: #fff4dc;
  --serious: #ec835a;
  --critical: #d03b3b; --critical-ink: #a32727; --critical-soft: #fbe9e9;
  --bs-primary: #1f63b8; --bs-primary-rgb: 31,99,184;
  --bs-link-color: #1f63b8; --bs-link-color-rgb: 31,99,184;
  --bs-body-font-family: var(--app-font);
  --bs-body-bg: var(--plane);
  --bs-body-color: var(--ink);
  --bs-border-color: var(--hairline);
}
[data-bs-theme="dark"] {
  --plane: #0d0f12;
  --surface: #17191d;
  --surface-2: #1d2025;
  --ink: #eef0f3;
  --ink-2: #b9bec7;
  --ink-muted: #8b9099;
  --hairline: #2b2f36;
  --sidebar-bg: #0a1625;
  --accent: #4d9bf0;
  --accent-soft: #15283f;
  --series-1: #3987e5;
  --grid: #2c2c2a;
  --axis: #898781;
  --good-ink: #3ccf3c; --good-soft: #10291a;
  --warning-ink: #fab219; --warning-soft: #2e2510;
  --critical-ink: #f07a7a; --critical-soft: #331616;
  --bs-primary: #3d8be6; --bs-primary-rgb: 61,139,230;
  --bs-link-color: #6aa8f0; --bs-link-color-rgb: 106,168,240;
  --bs-body-bg: var(--plane);
  --bs-body-color: var(--ink);
  --bs-border-color: var(--hairline);
}

html, body { font-family: var(--app-font); }
body { background: var(--plane); color: var(--ink); font-size: .95rem; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }
.btn:hover, .nav-link:hover, .list-group-item:hover, .dropdown-item:hover, .page-link:hover { text-decoration: none; }
.btn-primary { --bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary); --bs-btn-hover-bg: #1a559e; --bs-btn-hover-border-color: #1a559e; --bs-btn-active-bg: #164a8a; }
.btn-outline-primary { --bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary); --bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary); }
.text-primary { color: var(--bs-primary) !important; }
.form-label { font-weight: 500; font-size: .875rem; color: var(--ink-2); margin-bottom: .25rem; }
.form-control, .form-select { border-color: var(--hairline); background-color: var(--surface); }
.form-control:disabled { background-color: var(--surface-2); }
.form-check-input:not(:checked) { background-color: var(--surface); }
.input-group-text { background-color: var(--surface-2); }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 .2rem rgba(31,99,184,.15); }
.skip-link { position: absolute; z-index: 2000; top: 8px; left: 8px; background: var(--surface); padding: 6px 12px; border-radius: 6px; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-ink); width: 256px; flex-shrink: 0; display: flex; flex-direction: column; }
@media (min-width: 992px) {
  .sidebar { position: sticky; top: 0; height: 100vh; }
}
.sidebar.offcanvas-lg { --bs-offcanvas-bg: var(--sidebar-bg); --bs-offcanvas-width: 270px; background-color: var(--sidebar-bg) !important; }
.sidebar-brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1rem .9rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, #2a78d6, #1baf7a); display: grid; place-items: center; color: #fff; font-size: 1.15rem; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text b { color: var(--sidebar-ink-strong); font-weight: 600; font-size: .95rem; }
.brand-text small { color: var(--sidebar-ink); font-size: .75rem; opacity: .8; }
.sidebar-nav { padding: .75rem .6rem; flex: 1; overflow-y: auto; }
.sidebar-nav .nav-link { display: flex; align-items: center; gap: .7rem; color: var(--sidebar-ink); padding: .55rem .75rem; border-radius: 8px; font-size: .92rem; margin-bottom: 2px; }
.sidebar-nav .nav-link i { font-size: 1.05rem; opacity: .9; width: 1.2rem; text-align: center; }
.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-strong); }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: var(--sidebar-ink-strong); font-weight: 500; box-shadow: inset 3px 0 0 #4d9bf0; }
.nav-group { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-ink); opacity: .55; padding: 1rem .75rem .35rem; }
.sidebar-user { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user .who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-user .who b { color: var(--sidebar-ink-strong); font-weight: 500; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who small { font-size: .75rem; opacity: .75; }
.sidebar-user .btn-link { color: var(--sidebar-ink) !important; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #2a78d6; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 1010; display: flex; align-items: center; gap: .75rem; padding: .7rem 1.5rem; background: color-mix(in srgb, var(--plane) 96%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--hairline); }
.page-title { font-size: 1.2rem; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.btn-icon { border: 1px solid var(--hairline); background: var(--surface); color: var(--ink-2); width: 38px; height: 38px; padding: 0; display: inline-grid; place-items: center; border-radius: 9px; }
.btn-icon:hover { color: var(--ink); border-color: var(--ink-muted); }
.content { padding: 1.5rem; flex: 1; max-width: 1480px; width: 100%; }
.app-footer { padding: 1rem 1.5rem; font-size: .78rem; color: var(--ink-muted); }
@media (max-width: 575.98px) {
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .page-title { font-size: 1.05rem; }
}

/* ---------- cards & tiles ---------- */
.card { --bs-card-bg: var(--surface); --bs-card-border-color: var(--hairline); --bs-card-cap-bg: transparent; border-radius: 12px; }
.card-header { border-bottom: 1px solid var(--hairline); padding: .85rem 1.1rem; }
.card-title-sm { font-size: .98rem; font-weight: 600; margin: 0; }
.card-sub { font-size: .8rem; color: var(--ink-muted); }
.card-body { padding: 1.1rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.stat-tile { background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; padding: 1rem 1.1rem; position: relative; }
.stat-tile .label { font-size: .82rem; color: var(--ink-2); display: flex; align-items: center; gap: .4rem; }
.stat-tile .label i { color: var(--ink-muted); }
.stat-tile .value { font-size: 1.9rem; font-weight: 600; line-height: 1.15; margin-top: .25rem; letter-spacing: -.01em; }
.stat-tile .value small { font-size: .9rem; font-weight: 400; color: var(--ink-muted); margin-left: .15rem; }
.stat-tile .hint { font-size: .78rem; color: var(--ink-muted); margin-top: .15rem; }
.stat-tile .hint.bad { color: var(--critical-ink); }
.stat-tile .hint.good { color: var(--good-ink); }

/* ---------- tables ---------- */
.table { --bs-table-bg: transparent; --bs-table-border-color: var(--hairline); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .78rem; font-weight: 600; color: var(--ink-2); background: var(--surface-2); white-space: nowrap; }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: var(--accent-soft); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-card { overflow-x: auto; }
.table-card .table thead th:first-child { border-top-left-radius: 0; }

/* ---------- status / score ---------- */
.status-badge { font-weight: 500; font-size: .76rem; padding: .35em .7em; }
.text-bg-warning { color: #3d2a00 !important; }
.score-pill { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .55rem .15rem .45rem; border-radius: 999px; font-size: .82rem; border: 1px solid var(--hairline); background: var(--surface); white-space: nowrap; }
.score-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); }
.score-pill b { font-weight: 600; font-variant-numeric: tabular-nums; }
.score-pill span { color: var(--ink-2); font-size: .76rem; }
.score-pill.lvl-good::before { background: var(--good); }
.score-pill.lvl-ok::before { background: #6cc56c; }
.score-pill.lvl-warning::before { background: var(--warning); }
.score-pill.lvl-critical::before { background: var(--critical); }
.score-big { font-size: 2.6rem; font-weight: 700; line-height: 1; letter-spacing: -.02em; }

.meter { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--hairline); }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 4px; }
.meter.lvl-good > span { background: var(--good); }
.meter.lvl-warning > span { background: var(--warning); }
.meter.lvl-critical > span { background: var(--critical); }

/* ---------- filters ---------- */
.filter-bar { background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; padding: .8rem 1rem; margin-bottom: 1rem; }
.filter-bar .form-label { font-size: .78rem; margin-bottom: .15rem; }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.login-hero { background: radial-gradient(1200px 600px at 10% 10%, #1d4b7a 0%, #10243a 55%, #0a1625 100%); color: #dfe8f3; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-hero h1 { font-size: 2.1rem; font-weight: 700; color: #fff; line-height: 1.3; }
.login-hero p { color: #b8c7d8; max-width: 30rem; }
.login-hero .biz-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
.login-hero .biz-list span { border: 1px solid rgba(255,255,255,.18); border-radius: 999px; padding: .3rem .8rem; font-size: .82rem; color: #dfe8f3; }
.login-hero .grid-deco { position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px); background-size: 40px 40px; pointer-events: none; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 2rem; background: var(--plane); }
.login-card { width: 100%; max-width: 400px; }
.login-card .form-control { padding: .65rem .85rem; }
@media (max-width: 991.98px) { .login-page { grid-template-columns: 1fr; } .login-hero { padding: 2rem; min-height: auto; } .login-hero h1 { font-size: 1.5rem; } }

/* ---------- audit form ---------- */
.audit-layout { display: grid; grid-template-columns: 230px 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1199.98px) { .audit-layout { grid-template-columns: 1fr; } .section-nav { display: none; } }
.section-nav { position: sticky; top: 80px; background: var(--surface); border: 1px solid var(--hairline); border-radius: 12px; padding: .75rem; font-size: .85rem; }
.section-nav a { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem .55rem; border-radius: 7px; color: var(--ink-2); text-decoration: none; }
.section-nav a:hover { background: var(--surface-2); color: var(--ink); }
.section-nav a .cnt { font-variant-numeric: tabular-nums; color: var(--ink-muted); font-size: .78rem; white-space: nowrap; }
.section-nav a.done .cnt { color: var(--good-ink); }
.progress-wrap { padding: .4rem .55rem .7rem; border-bottom: 1px solid var(--hairline); margin-bottom: .5rem; }
.form-section { scroll-margin-top: 80px; }
.section-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.section-head .sec-no { font-weight: 700; color: var(--accent); }
.section-head .sec-weight { margin-left: auto; font-size: .78rem; color: var(--ink-muted); }

.check-item { border-top: 1px solid var(--hairline); padding: .9rem 1.1rem; display: grid; grid-template-columns: 3.2rem 1fr auto; gap: .25rem 1rem; align-items: start; }
.check-item:first-child { border-top: 0; }
.check-item .no { font-weight: 600; color: var(--ink-2); font-variant-numeric: tabular-nums; padding-top: .2rem; }
.check-item .txt { padding-top: .2rem; }
.check-item .detail { margin: .35rem 0 0; padding-left: 1.1rem; color: var(--ink-2); font-size: .86rem; }
.check-item .pts { font-size: .75rem; color: var(--ink-muted); }
.check-item .extra { grid-column: 2 / -1; }
.check-item.is-fail { background: color-mix(in srgb, var(--critical-soft) 55%, transparent); }
.check-item.is-missing { box-shadow: inset 3px 0 0 var(--warning); }
@media (max-width: 767.98px) {
  .check-item { grid-template-columns: 2.6rem 1fr; }
  .check-item .result-group { grid-column: 1 / -1; }
  .check-item .extra { grid-column: 1 / -1; }
}
.result-group .btn { min-width: 76px; font-size: .85rem; padding: .4rem .7rem; }
.result-group .btn-check:checked + .btn-res-pass { background: var(--good); border-color: var(--good); color: #fff; }
.result-group .btn-check:checked + .btn-res-fail { background: var(--critical); border-color: var(--critical); color: #fff; }
.result-group .btn-check:checked + .btn-res-na { background: #6b7280; border-color: #6b7280; color: #fff; }
.btn-res-pass, .btn-res-fail, .btn-res-na { border-color: var(--hairline); color: var(--ink-2); background: var(--surface); }
.btn-res-pass:hover { border-color: var(--good); color: var(--good-ink); }
.btn-res-fail:hover { border-color: var(--critical); color: var(--critical-ink); }
.btn-res-na:hover { border-color: #6b7280; }
.item-tools { display: flex; gap: .75rem; margin-top: .5rem; font-size: .82rem; flex-wrap: wrap; }
.item-tools button { background: none; border: 0; padding: 0; color: var(--accent); }
.item-tools .has { color: var(--good-ink); }
.photo-strip { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.photo-thumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; border: 1px solid var(--hairline); background: var(--surface-2); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb label { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px; font-size: .7rem; padding: 1px 5px; cursor: pointer; }
.photo-thumb.marked img { opacity: .3; }
.photo-thumb.pending { display: grid; place-items: center; font-size: .7rem; color: var(--ink-muted); text-align: center; padding: 4px; }

.sticky-actions { position: sticky; bottom: 0; z-index: 1000; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--hairline); padding: .75rem 1rem; margin: 1.25rem -1.5rem -1.5rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
@media (max-width: 575.98px) { .sticky-actions { margin: 1rem -1rem -1rem; } }
.sticky-actions .live-score { margin-right: auto; font-size: .88rem; color: var(--ink-2); }
.sticky-actions .live-score b { color: var(--ink); font-size: 1.05rem; }

.cash-table td, .cash-table th { vertical-align: middle; }
.cash-table input { text-align: right; font-variant-numeric: tabular-nums; min-width: 110px; }
.cash-table .diff-cell { text-align: right; font-variant-numeric: tabular-nums; min-width: 110px; }
.cash-block-title { font-weight: 600; font-size: .9rem; color: var(--ink-2); }

.sig-box { border: 1px dashed var(--ink-muted); border-radius: 10px; background: #fff; position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.sig-box canvas { width: 100%; height: 160px; display: block; border-radius: 10px; cursor: crosshair; }
.sig-box .sig-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-muted); pointer-events: none; font-size: .85rem; }
.sig-existing { max-height: 120px; background: #fff; border-radius: 8px; border: 1px solid var(--hairline); padding: 4px; }

/* ---------- report view ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .9rem; }
.kv dt { color: var(--ink-muted); font-weight: 400; }
.kv dd { margin: 0; }
.kv-4 { grid-template-columns: max-content 1fr max-content 1fr; }
@media (max-width: 767.98px) { .kv-4 { grid-template-columns: max-content 1fr; } }
.res-tag { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; font-weight: 500; white-space: nowrap; }
.res-tag.pass { color: var(--good-ink); }
.res-tag.fail { color: var(--critical-ink); }
.res-tag.na { color: var(--ink-muted); }
.timeline { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.timeline li { padding: .45rem 0 .45rem 1.1rem; border-left: 2px solid var(--hairline); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: .8rem; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline time { color: var(--ink-muted); font-size: .78rem; display: block; }

/* ---------- dashboard ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.viz-table { display: none; }
.show-table .viz-table { display: block; }
.show-table .chart-box { display: none; }
.rank-bar { display: flex; align-items: center; gap: .5rem; }
.rank-bar .meter { flex: 1; min-width: 40px; max-width: 110px; }
.legend-inline { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--ink-2); }
.legend-inline span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; background: var(--c, var(--series-1)); }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--ink-2); }
.empty-state i { font-size: 2.6rem; color: var(--ink-muted); display: block; margin-bottom: .5rem; }
.empty-state h2 { font-size: 1.2rem; font-weight: 600; color: var(--ink); }

.tpl-item-row textarea { min-height: 38px; }
.small-muted { font-size: .8rem; color: var(--ink-muted); }
.d-contents { display: contents; }
.min-w-0 { min-width: 0; }
.w-num { width: 90px; }
.w-num-sm { width: 70px; }
.cursor-pointer { cursor: pointer; }
.collapse-row:not(.show) { display: none; }

@media print {
  .sidebar, .topbar, .app-footer, .sticky-actions, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}
