/* ============================================================
   AAG Panel Monitor — ธีมหลัก
   ออกแบบให้ใช้งานง่ายบนมือถือและแท็บเล็ตหน้างาน
   ปุ่มใหญ่พอสำหรับนิ้ว (อย่างน้อย 44px) ตัวหนังสืออ่านง่ายกลางแดด
   ============================================================ */

:root {
    --ink: #101b26;
    --ink-2: #41546a;
    --muted: #6b7f95;
    --line: #dce4ed;
    --line-soft: #eef2f7;

    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-2: #f7fafc;

    --brand: #0f6aa8;
    --brand-dark: #0a4d7c;
    --brand-soft: #e7f2fa;
    --on-brand: #ffffff;

    --ok-bg: #e4f5ea;   --ok-ink: #14663a;
    --err-bg: #fdeaea;  --err-ink: #97231f;
    --warn-bg: #fff6e0; --warn-ink: #8a5b00;

    --r-sm: 10px;
    --r: 16px;
    --r-lg: 22px;

    --shadow-1: 0 1px 2px rgba(16, 27, 38, .06), 0 2px 8px rgba(16, 27, 38, .05);
    --shadow-2: 0 10px 34px rgba(16, 27, 38, .16);

    --tap: 46px;                 /* ขนาดต่ำสุดที่นิ้วกดได้สบาย */
    --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: "Noto Sans Thai", "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.65;
}

/* พื้นหลังภาพอาคาร — ใช้บนหน้าล็อกอินและหน้าสแกน */
body.has-bg {
    background:
        linear-gradient(180deg, rgba(8, 26, 41, .72), rgba(8, 26, 41, .84)),
        url('/assets/bg-facade.svg') center / cover no-repeat fixed;
}

a { color: var(--brand); }

/* ---------- แถบบน ---------- */
.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 14px; flex-wrap: nowrap;
    padding: 10px 18px;
    background: linear-gradient(120deg, var(--brand-dark), var(--brand));
    color: #fff;
    box-shadow: 0 2px 14px rgba(10, 46, 74, .28);
}
.brand {
    display: inline-flex; align-items: center; gap: 9px; min-width: 0;
    font-weight: 700; font-size: 17px; color: #fff; text-decoration: none; letter-spacing: .2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand span { overflow: hidden; text-overflow: ellipsis; }
.brand-mark {
    width: 30px; height: 30px; border-radius: 9px; flex: none;
    background: rgba(255, 255, 255, .16);
    display: grid; place-items: center; font-size: 15px;
}
.topbar nav { display: flex; gap: 4px; flex: 1; margin-left: 10px; }
.topbar nav a {
    color: rgba(255, 255, 255, .86); text-decoration: none;
    padding: 9px 14px; border-radius: 999px; font-size: 15px; font-weight: 500;
}
.topbar nav a:hover, .topbar nav a.on { background: rgba(255, 255, 255, .18); color: #fff; }
.logout { display: flex; align-items: center; gap: 10px; margin: 0; }
.who { color: rgba(255, 255, 255, .85); font-size: 14px; }
.logout button {
    background: rgba(255, 255, 255, .14); color: #fff; border-color: rgba(255, 255, 255, .3);
    min-height: 38px; padding: 6px 14px; white-space: nowrap; flex: none;
}
.logout button:hover { background: rgba(255, 255, 255, .26); }

/* ---------- เมนูล่างสำหรับมือถือ ---------- */
.tabbar { display: none; }

/* ---------- โครงหน้า ---------- */
.container { max-width: 1040px; margin: 0 auto; padding: 22px 16px 40px; }
.container.wide { max-width: 1480px; }
main.bare { padding: 0; }

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 14px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.2px; }
.page-head p { margin: 3px 0 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 20px;
    box-shadow: var(--shadow-1);
}
.card + .card { margin-top: 16px; }
.card-narrow { max-width: 430px; margin: 8vh auto 24px; }

h1 { font-size: 23px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -.1px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.center { text-align: center; }
.err { color: var(--err-ink); }
code {
    background: var(--surface-2); border: 1px solid var(--line-soft);
    padding: 1px 6px; border-radius: 6px; font-size: 90%;
}

/* ---------- ฟอร์ม ---------- */
label { display: block; margin: 14px 0 5px; font-size: 13.5px; color: var(--ink-2); font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], input[type="file"], select {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 13px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    font-size: 16px;                      /* 16px กัน iOS ซูมอัตโนมัติ */
    font-family: inherit;
    background: var(--surface);
    color: var(--ink);
}
input:focus, select:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(15, 106, 168, .16);
}
input[type="range"] { width: 100%; accent-color: var(--brand); }
input[type="color"] { min-height: 44px; padding: 3px; }

button {
    min-height: var(--tap);
    padding: 10px 18px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--ink);
    font-size: 15px; font-weight: 600; font-family: inherit;
    cursor: pointer;
    transition: background .15s, transform .05s;
}
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
    margin-top: 18px; width: 100%;
    background: var(--brand); border-color: var(--brand); color: var(--on-brand);
    box-shadow: 0 2px 10px rgba(15, 106, 168, .28);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-inline { margin-top: 0; width: auto; align-self: flex-end; }
.btn-link {
    display: inline-flex; align-items: center; min-height: 38px;
    color: var(--brand); text-decoration: none; font-size: 14.5px; font-weight: 600;
    padding: 4px 10px; border-radius: 999px; background: var(--brand-soft);
}
.btn-link:hover { background: #d7e9f6; }
.btn-icon { border: 0; background: none; font-size: 20px; padding: 6px 10px; min-height: 40px; }

.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row.tight label { margin-top: 0; }
.form-row .grow { flex: 1; min-width: 190px; }

/* ---------- ตาราง → การ์ดบนมือถือ ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line-soft); }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: none; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table a { color: var(--brand); text-decoration: none; font-weight: 600; }

/* ---------- ความคืบหน้า ---------- */
.progress-bar {
    display: flex; height: 22px; border-radius: 999px; overflow: hidden;
    background: var(--line-soft); box-shadow: inset 0 1px 2px rgba(0,0,0,.05);
}
.progress-bar .seg { display: block; height: 100%; }
.legend { list-style: none; padding: 0; margin: 16px 0 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 16px; }
.legend li { display: flex; align-items: center; gap: 9px; font-size: 14.5px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.legend-item {
    display: inline-flex; align-items: center; gap: 7px; font-size: 14px;
    background: var(--surface-2); border: 1px solid var(--line-soft);
    padding: 5px 12px; border-radius: 999px;
}
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- ตัวแสดงแบบ ---------- */
.viewer-wrap {
    overflow: auto; -webkit-overflow-scrolling: touch;
    background: #223140; border-radius: var(--r-sm); padding: 10px; max-height: 76vh;
}
.stage { position: relative; display: inline-block; background: #fff; border-radius: 4px; }
.stage canvas { display: block; }
.overlay { position: absolute; inset: 0; pointer-events: none; }

.marker {
    position: absolute; width: 15px; height: 15px; margin: -7.5px 0 0 -7.5px;
    border-radius: 50%; border: 2px solid rgba(255, 255, 255, .92); padding: 0; min-height: 0;
    cursor: pointer; pointer-events: auto; box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
    transition: transform .12s;
}
.marker:hover, .marker:focus { transform: scale(1.6); z-index: 5; }
.marker.preview { background: #e0218a; pointer-events: none; }

/* ---------- แผงรายละเอียดแผง ---------- */
.sheet {
    position: fixed; right: 18px; bottom: 18px; width: 360px; max-height: 72vh; overflow: auto;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    box-shadow: var(--shadow-2); padding: 18px; z-index: 40;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.sheet-head strong { font-size: 18px; }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.status-btn { display: flex; align-items: center; gap: 8px; justify-content: flex-start; font-size: 14px; padding: 10px 12px; }
.history { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 12px; line-height: 1.85; }

/* ---------- หน้าสแกน QR ---------- */
.scan { text-align: center; }
.scan-code { font-size: 27px; margin: 6px 0 2px; letter-spacing: -.5px; word-break: break-all; line-height: 1.2; }
.scan-item { margin: 0 0 8px; }
.scan-floor { font-size: 17px; margin: 0 0 14px; color: var(--ink-2); }
.scan-status {
    font-size: 16px; background: var(--surface-2); border: 1px solid var(--line-soft);
    border-radius: var(--r-sm); padding: 12px; margin: 0 0 6px;
}
.scan-buttons { display: grid; gap: 11px; margin-top: 12px; }
.scan-btn {
    display: flex; align-items: center; justify-content: center; gap: 11px;
    padding: 17px; font-size: 17px; border-width: 2px; border-radius: 14px; min-height: 58px;
}
.scan-btn:hover { background: var(--surface-2); }
.history-list { list-style: none; padding: 0; margin: 0; }
.history-list li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.history-list li:last-child { border-bottom: 0; }
.history-list .dot { margin-right: 7px; }

/* ---------- แจ้งเตือน ---------- */
.alert { padding: 13px 16px; border-radius: var(--r-sm); margin-bottom: 16px; font-size: 15px; }
.alert-success { background: var(--ok-bg); color: var(--ok-ink); }
.alert-error { background: var(--err-bg); color: var(--err-ink); }

/* ---------- แอดมิน ---------- */
.status-row {
    display: flex; gap: 9px; align-items: center; flex-wrap: wrap;
    padding: 12px 0; border-bottom: 1px solid var(--line-soft); margin: 0;
}
.status-row:last-child { border-bottom: 0; }
.status-row input[type="color"] { width: 50px; }
.status-row .grow { flex: 1; min-width: 160px; }
.status-row label { margin: 0; }
.teams { display: flex; gap: 8px; flex-wrap: wrap; }
.chk {
    display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink);
    background: var(--surface-2); border: 1px solid var(--line-soft);
    padding: 7px 12px; border-radius: 999px; min-height: 40px; cursor: pointer;
}
.chk input { width: auto; min-height: 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { background: var(--brand-soft); color: var(--brand-dark); border-radius: 999px; padding: 6px 14px; font-size: 14px; font-weight: 600; }

.sticky-actions {
    position: sticky; bottom: calc(12px + var(--safe-b)); z-index: 20;
    display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
    box-shadow: var(--shadow-2);
}
.sticky-actions .btn-primary { width: auto; margin: 0; }

.token-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; max-height: 180px; overflow: auto; }
.token {
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
    padding: 6px 11px; font-size: 13.5px; font-family: ui-monospace, "Cascadia Code", monospace; cursor: pointer;
}
.token:hover { border-color: var(--brand); background: var(--brand-soft); }
.token small { color: var(--muted); font-family: inherit; }

.floor-rows { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 9px; margin-top: 14px; max-height: 280px; overflow: auto; }
.floor-row {
    display: flex; align-items: center; gap: 10px; justify-content: space-between;
    border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 12px; background: var(--surface-2);
}
.floor-row input { width: 90px; min-height: 40px; }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 16px 0 0; }
.kv dt { color: var(--muted); font-size: 14px; }
.kv dd { margin: 0; }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 28px 16px calc(32px + var(--safe-b)); }

/* ---------- สติกเกอร์ QR ---------- */
.sticker-toolbar {
    display: flex; flex-direction: column; gap: 10px;
    padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 10;
}
.sticker-toolbar p { width: 100%; margin: 0; }
.sticker-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.sticker-head .btn-link { margin-left: auto; }
.sticker-controls { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.sticker-controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.sticker-controls label.grow { flex: 1; min-width: 200px; }
.sticker-controls input, .sticker-controls select { min-height: 40px; }

/* เลือกชั้นที่จะพิมพ์ */
.floor-picker { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.fp-label { font-size: 13px; color: var(--ink-2); padding-top: 7px; white-space: nowrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; max-height: 104px; overflow-y: auto; }
.chip {
    border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
    border-radius: 999px; padding: 6px 13px; font: inherit; font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

.sticker-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn-soft {
    border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
    border-radius: var(--r-sm); padding: 0 14px; min-height: 40px; font: inherit; cursor: pointer;
}
.btn-soft:hover { border-color: var(--brand); }
.count-pill {
    margin-left: auto; padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 13px;
    background: var(--brand-soft); color: var(--brand-dark);
}
.count-pill.zero { background: rgba(204, 43, 43, .12); color: #cc2b2b; }
.sticker-sheet { display: grid; gap: 4mm; padding: 8mm; }
.sticker-sheet.cols-4 { grid-template-columns: repeat(4, 1fr); }
.sticker-sheet.cols-5 { grid-template-columns: repeat(5, 1fr); }
.sticker-sheet.cols-6 { grid-template-columns: repeat(6, 1fr); }
.sticker {
    display: flex; align-items: center; gap: 3mm; padding: 2mm;
    border: 1px dashed #b9c0c9; border-radius: 2mm; background: #fff; break-inside: avoid;
    position: relative; cursor: pointer;
}
.sticker.hidden { display: none; }
.sticker .pick {
    position: absolute; top: 1.5mm; right: 1.5mm; width: 17px; height: 17px;
    accent-color: var(--brand); cursor: pointer; margin: 0;
}
/* ดวงที่ไม่ได้ติ๊ก จางลงบนจอ และไม่ถูกพิมพ์ */
.sticker:has(.pick:not(:checked)),
.sticker.unpicked { opacity: .35; border-style: dotted; }
.sticker .qr img, .sticker .qr canvas { width: 16mm !important; height: 16mm !important; display: block; }
.sticker-text { min-width: 0; }
.sticker-text .code { font-weight: 700; font-size: 10pt; line-height: 1.15; word-break: break-all; color: #000; }
/* Item code เต็ม (เช่น FG.2408.P-AW-8A-02) ยาวกว่าเบอร์แผงเปล่า จึงย่อลงตามจำนวนคอลัมน์ */
.sticker-sheet.cols-5 .sticker-text .code { font-size: 9pt; }
.sticker-sheet.cols-6 .sticker-text .code { font-size: 8pt; }
.sticker-text .seq { font-size: 8.5pt; color: #222; font-weight: 600; }
.sticker-text .uid { font-family: ui-monospace, monospace; font-size: 8pt; color: #333; letter-spacing: .5px; }
.sticker-text .proj { font-size: 7pt; color: #666; }

/* ---------- มือถือ / แท็บเล็ต ---------- */
@media (max-width: 860px) {
    .container { padding: 16px 14px calc(96px + var(--safe-b)); }
    .page-head h1 { font-size: 21px; }
    .card { padding: 16px; border-radius: 14px; }

    /* แถบบนเหลือแค่ชื่อระบบ + ผู้ใช้ เมนูย้ายไปข้างล่าง */
    .topbar nav { display: none; }
    .topbar { padding: 9px 14px; }
    .who { display: none; }
    .logout { margin-left: auto; flex: none; }
    .logout button { font-size: 14px; padding: 6px 12px; }
    .brand { font-size: 15.5px; }

    .tabbar {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
        display: flex; justify-content: space-around;
        background: var(--surface); border-top: 1px solid var(--line);
        padding: 6px 4px calc(6px + var(--safe-b));
        box-shadow: 0 -4px 18px rgba(16, 27, 38, .10);
    }
    .tabbar a {
        flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
        padding: 7px 4px; text-decoration: none; color: var(--muted);
        font-size: 11.5px; font-weight: 600; border-radius: 12px; min-height: var(--tap);
    }
    .tabbar a .ic { font-size: 20px; line-height: 1; }
    .tabbar a.on { color: var(--brand); background: var(--brand-soft); }

    /* ตารางแปลงเป็นการ์ด อ่านง่ายบนจอแคบ */
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table thead { display: none; }
    .table tr {
        border: 1px solid var(--line); border-radius: 12px;
        padding: 10px 12px; margin-bottom: 10px; background: var(--surface-2);
    }
    .table td { border: 0; padding: 4px 0; text-align: left !important; }
    .table td::before {
        content: attr(data-label) " ";
        color: var(--muted); font-size: 12.5px; display: inline-block; min-width: 82px;
    }

    .sheet {
        right: 0; left: 0; bottom: 0; width: auto; max-height: 78vh;
        border-radius: var(--r-lg) var(--r-lg) 0 0; padding-bottom: calc(18px + var(--safe-b));
    }
    .status-grid { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; }
    .kv dd { margin-bottom: 10px; }
    .viewer-wrap { max-height: 62vh; padding: 6px; }
    .card-narrow { margin: 4vh auto 20px; }
    .sticky-actions { bottom: calc(80px + var(--safe-b)); }

    /* แถวตัวกรองในหน้าแสดงแบบ: จัดเป็น 2 ช่องต่อแถว กดง่าย */
    .form-row.tight { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
    .form-row.tight .grow, .form-row.tight > div:has(input[type="search"]) { grid-column: 1 / -1; }
    .form-row.tight button { grid-column: 1 / -1; width: 100%; }
    .head-actions .btn-link { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 420px) {
    .scan-code { font-size: 23px; }
    .brand { font-size: 14.5px; }
    .legend { grid-template-columns: 1fr 1fr; gap: 6px 10px; }
    .legend li { font-size: 13px; }
}

/* ---------- พิมพ์ ---------- */
@media print {
    .no-print, .topbar, .tabbar, .footer { display: none !important; }
    body, body.has-bg { background: #fff !important; }
    .sticker-sheet { padding: 5mm; gap: 3mm; }
    .sticker { border-color: #ddd; opacity: 1 !important; border-style: dashed !important; }
    /* พิมพ์เฉพาะดวงที่ติ๊กไว้ */
    .sticker:has(.pick:not(:checked)),
    .sticker.unpicked { display: none !important; }
}

/* ---------- โหมดมืด (ตามเครื่องผู้ใช้) ---------- */
@media (prefers-color-scheme: dark) {
    :root {
        --ink: #e8eef5; --ink-2: #b4c3d4; --muted: #8fa3b8;
        --line: #2a3a4c; --line-soft: #223041;
        --bg: #101922; --surface: #17222e; --surface-2: #1c2937;
        --brand: #3d9ad4; --brand-dark: #2a7bb0; --brand-soft: #1b3345;
        --ok-bg: #16351f; --ok-ink: #8fe0ab;
        --err-bg: #3a1c1c; --err-ink: #f4a9a5;
    }
    .sticker, .sticker-text .code { background: #fff; color: #000; }
    .sticker-sheet { background: #fff; }
}

/* ---------- การ์ดแบบพับเก็บได้ (ตั้งค่าโครงการ) ---------- */
.settings-card > summary {
    cursor: pointer; list-style: none; display: flex; flex-wrap: wrap;
    align-items: baseline; gap: 10px; min-height: 28px;
}
.settings-card > summary::-webkit-details-marker { display: none; }
.settings-card > summary::before { content: '▸'; color: var(--muted); font-size: 13px; }
.settings-card[open] > summary::before { content: '▾'; }

/* ---------- หน้าสแกน QR ---------- */
.scan-setup .mode-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 10px 0 4px; }
.scan-setup .mode {
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px;
    background: var(--surface-2); font-size: 14.5px;
}
.scan-setup .mode:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.scan-btn.picked { background: var(--brand-soft); font-weight: 700; box-shadow: inset 0 0 0 2px currentColor; }

.cam-wrap {
    position: relative; background: #0b1117; border-radius: var(--r-sm); overflow: hidden;
    aspect-ratio: 4 / 3; max-height: 62vh; display: flex; align-items: center; justify-content: center;
}
.cam-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* กรอบเล็งกลางจอ ช่วยให้เล็งง่ายตอนแดดจ้า */
.cam-frame {
    position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%);
    width: min(62%, 260px); aspect-ratio: 1; border: 3px solid rgba(255,255,255,.85);
    border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0,0,0,.28); pointer-events: none;
}
.cam-msg { position: absolute; color: #d8e3ee; font-size: 14px; text-align: center; padding: 0 24px; }

.scan-log { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scan-log li {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 9px 12px; border-radius: var(--r-sm); font-size: 14px;
    border-left: 4px solid var(--line);
}
.scan-log li strong { font-family: ui-monospace, monospace; word-break: break-all; }
.scan-log li.good { background: var(--ok-bg); border-left-color: #1f9d4d; }
.scan-log li.dup  { background: var(--surface-2); border-left-color: #e0a800; }
.scan-log li.bad  { background: rgba(204,43,43,.10); border-left-color: #cc2b2b; }

/* ปุ่มสแกนในแถบล่าง ให้เด่นกว่าปุ่มอื่นเพราะใช้บ่อยสุดหน้างาน */
.tabbar a.scan-tab { color: var(--brand); font-weight: 700; }
.tabbar a.scan-tab .ic { font-size: 20px; }

/* ---------- โซนอันตราย (ลบข้อมูล) ---------- */
.danger-zone {
    margin-top: 18px; padding: 14px; border-radius: var(--r-sm);
    border: 1px solid rgba(204, 43, 43, .35); background: rgba(204, 43, 43, .05);
}
.danger-zone h3 { margin: 0 0 6px; font-size: 15px; color: #cc2b2b; }
.danger-zone code { word-break: break-all; }
.btn-danger {
    background: #cc2b2b; color: #fff; border: 1px solid #cc2b2b;
    border-radius: var(--r-sm); padding: 0 16px; min-height: 46px;
    font: inherit; font-weight: 600; cursor: pointer;
}
.btn-danger:hover { background: #b02020; border-color: #b02020; }

/* ---------- การ์ดรายการ (โครงการ / แบบ) ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tile {
    display: flex; flex-direction: column; gap: 4px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
    padding: 16px 18px; text-decoration: none; color: var(--ink);
    box-shadow: var(--shadow-1); transition: transform .12s, box-shadow .12s, border-color .12s;
}
a.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--brand); }
.tile-code {
    align-self: flex-start; background: var(--brand-soft); color: var(--brand-dark);
    font-size: 12.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; letter-spacing: .3px;
}
.tile-name { font-size: 17px; font-weight: 700; line-height: 1.35; color: var(--ink); text-decoration: none; }
a.tile-name:hover { color: var(--brand); }
.tile-stats { display: flex; gap: 16px; margin-top: 8px; font-size: 14px; color: var(--muted); }
.tile-stats strong { color: var(--ink); font-size: 16px; }
.tile-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.login-card { backdrop-filter: blur(3px); }
.login-brand { text-align: center; margin-bottom: 6px; }
.login-brand h1 { font-size: 21px; margin: 10px 0 2px; }
.brand-mark.big {
    width: 54px; height: 54px; border-radius: 16px; font-size: 26px; color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: inline-grid; place-items: center; box-shadow: 0 6px 18px rgba(15, 106, 168, .35);
}
