/* ==========================================================================
   V Club Audit — Strict Flat Minimal Utility
   Nguồn thiết kế: "ux ui/stitch_v_club_audit_ui_kit" (DESIGN.md)
   - Không đổ bóng, không gradient, không glow, không blur: chiều sâu chỉ bằng 3 tầng nền + viền 1px.
   - Số liệu luôn dùng JetBrains Mono; chữ giao tiếp dùng Inter.
   - Mobile (< 768px) 1 cột; tablet 2 cột; desktop (>= 1200px) 3 cột.
   ========================================================================== */

:root {
    /* Nền & bề mặt (Elevation Levels trong DESIGN.md) */
    --bg: #0b0f17;           /* Canvas (Level 0) — cũng là nền ô nhập, tiêu đề bảng */
    --surface: #0b0f17;      /* giếng lồng bên trong thẻ: ô nhập, khung bảng, thanh tiến độ */
    --card: #101622;         /* Level 1: thẻ / khung dữ liệu */
    --l2: #171f2e;           /* Level 2: panel nổi / đang chọn */
    --l3: #1c2536;           /* Level 3: hàng dữ liệu lồng, ô nhập thứ cấp, hover, hộp thoại (Level 4) */
    --row-alt: #131b29;      /* hàng xen kẽ của bảng */
    --border: #2b3a52;       /* viền cấu trúc "cool metallic" */
    --border-modal: #3a4d6b;
    --border-active: rgba(0, 201, 183, 0.4);

    /* Màu nhấn */
    --cyan: #00c9b7;         /* Primary — Desk Teal */
    --cyan-bright: #00e5d4;  /* chữ/viền nhấn, chip "đã xác minh" */
    --cyan-press: #00e5d4;
    --gold: #d4af37;         /* Tertiary — kim loại ấm (VIP / cảnh báo nhẹ) */
    --gold-text: #f2cb51;
    --red: #e5233d;          /* Secondary — Club Red (nút nguy hiểm) */
    --red-text: #ff334b;     /* chữ/viền cảnh báo */

    /* Trạng thái (theo theme: xác minh = teal, thiếu/cảnh báo = vàng, sai = đỏ) */
    --success: #00e5d4;
    --warning: #f2cb51;
    --error: #ff334b;
    --error-deep: #e5233d;

    --text: #ffffff;
    --text-2: #94a3b8;
    --text-3: #64748b;

    --font-display: 'Space Grotesk', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', Consolas, 'SF Mono', monospace;

    --radius: 8px;
    --radius-sm: 4px;
    --header-h: 64px;

    /* Tương thích tên biến cũ còn dùng trong JS/inline */
    --bg-base: var(--bg);
    --bg-surface: var(--card);
    --bg-elevated: var(--l2);
    --accent-cyan: var(--cyan);
    --amber: var(--warning);
    --status-success: var(--success);
    --status-error: var(--error);
    --brand-red: var(--red);
    --text-primary: var(--text);
    --text-secondary: var(--text-2);
    --text-muted: var(--text-3);
    --border-subtle: var(--border);
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

button { font-family: inherit; }
.ic { flex-shrink: 0; vertical-align: -0.15em; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; }

/* ---------------------------------------------------------------- HEADER */

#appHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
    height: var(--header-h);
    padding: 0 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 30;
}

.hdr-left, .hdr-right { display: flex; align-items: center; gap: 16px; min-width: 0; }

.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); flex-shrink: 0; }
.brand-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: 0.01em; }

#tabBar { display: flex; align-items: center; gap: 4px; margin-left: 24px; }

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-2);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--cyan); border-bottom-color: var(--cyan); font-weight: 600; }
.tab-btn .ic { display: none; }

.week-nav {
    display: flex;
    align-items: center;
    height: 38px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.week-nav button {
    width: 40px;
    height: 100%;
    background: none;
    border: none;
    color: var(--text-2);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.week-nav button:hover:not(:disabled) { color: var(--cyan); }
.week-nav button:disabled { opacity: 0.35; cursor: default; }
#weekNavLabel {
    min-width: 230px;
    padding: 0 6px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

/* Trạng thái Firebase (JS đổi textContent + class cloud-ok / cloud-error) */
#tvCloudStatus {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
#tvCloudStatus.cloud-ok { color: var(--success); border-color: rgba(0, 201, 183, 0.45); background: rgba(0, 201, 183, 0.08); }
#tvCloudStatus.cloud-error { color: var(--error); border-color: rgba(229, 35, 61, 0.5); background: rgba(229, 35, 61, 0.08); }

/* ---------------------------------------------------------------- BUTTONS */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-primary { background: var(--cyan); color: var(--bg); font-weight: 700; }
.btn-primary:hover:not(:disabled), .btn-primary:active:not(:disabled) { background: var(--cyan-press); }

.btn-secondary { background: var(--l3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--cyan); }

.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--l2); border-color: var(--text-3); }

.btn-danger { background: transparent; color: var(--red-text); border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: rgba(229, 35, 61, 0.12); }
.btn-danger-solid { background: var(--red); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { background: var(--red-text); }

.btn-warn { background: var(--warning); color: var(--bg); font-weight: 700; }
.btn-warn:hover:not(:disabled) { background: #b89326; }

.kbd {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
}

/* ---------------------------------------------------------------- CARD / CHIP / FORM */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.card-surface { background: var(--l2); }
.card-accent { background: var(--l2); border-color: var(--border-active); }       /* Level 2: máy đang kiểm tra */
.card-alert { background: var(--l2); border-color: rgba(229, 35, 61, 0.5); }       /* Level 3: cảnh báo */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-title { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.card-title.strong { position: relative; padding-left: 12px; font-family: var(--font-display); color: var(--text); font-size: 16px; letter-spacing: 0.02em; }
.card-title.strong::before { content: ''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 2px; background: var(--cyan); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 9999px;
    background: transparent;
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}
.chip-cyan { color: var(--cyan-bright); border-color: rgba(0, 201, 183, 0.3); background: rgba(0, 201, 183, 0.12); }
.chip-gold { color: var(--gold); border-color: rgba(212, 175, 55, 0.35); background: rgba(212, 175, 55, 0.12); }
.chip-error { color: var(--red-text); border-color: rgba(229, 35, 61, 0.4); background: rgba(229, 35, 61, 0.15); }
.chip-success { color: var(--cyan-bright); border-color: rgba(0, 201, 183, 0.3); background: rgba(0, 201, 183, 0.12); }
.chip-warn { color: var(--gold); border-color: rgba(212, 175, 55, 0.35); background: rgba(212, 175, 55, 0.12); }
.chip-lg { height: 28px; font-size: 12px; text-transform: none; }

.field-label {
    display: block;
    margin: 0 0 6px;
    color: var(--text-2);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.field-row .field-label { margin: 0; }

.input, select.input,
#dataPanel input[type="text"], .row3 input, .row3 select {
    width: 100%;
    height: 36px;
    padding: 0 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums lining-nums;
    outline: none;
}
.input:focus, #dataPanel input[type="text"]:focus, .row3 input:focus, .row3 select:focus { border-color: var(--cyan); }
.input::placeholder, #dataPanel input::placeholder { color: var(--text-3); font-weight: 500; }
.input[readonly] { color: var(--text-2); }
select.input { font-family: var(--font-sans); font-size: 13px; font-weight: 500; }
.input-wrap { position: relative; }
.input-wrap .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-family: var(--font-mono); pointer-events: none; }
.input-wrap .input { padding-right: 32px; }
.input-search { padding-left: 38px; font-family: var(--font-sans); font-size: 14px; font-weight: 500; }
.input-wrap .lead { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); display: inline-flex; pointer-events: none; }

.progress { height: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--cyan); }
.progress.ok > i { background: var(--success); }

.hint { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-2); font-size: 12px; }
.hint .mono { color: var(--text); }
.empty { padding: 32px 16px; text-align: center; color: var(--text-3); font-family: var(--font-mono); }

/* Chip máy còn thiếu + ma trận */
.cov-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cov-chip {
    display: inline-flex; align-items: center; height: 28px; padding: 0 8px;
    border: 1px solid var(--warning); border-radius: var(--radius-sm); background: rgba(212, 175, 55, 0.1);
    color: var(--warning); font-family: var(--font-mono); font-size: 13px; font-weight: 700;
}
.cov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; }
.cov-cell {
    display: flex; align-items: center; justify-content: center; height: 30px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: var(--font-mono); font-size: 12px; font-weight: 600;
}
.cov-cell.have { color: var(--success); background: rgba(0, 201, 183, 0.08); border-color: rgba(0, 201, 183, 0.45); }
.cov-cell.miss { color: var(--warning); background: rgba(212, 175, 55, 0.1); border-color: var(--warning); }
.cov-cell.sel { background: var(--cyan); border-color: var(--cyan); color: var(--bg); }
.cov-cell.clickable { cursor: pointer; }
.legend { display: flex; gap: 12px; font-size: 11px; color: var(--text-2); font-family: var(--font-mono); }
.legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; }
.cov-extra { margin-top: 10px; padding: 8px 10px; border: 1px solid var(--warning); border-radius: var(--radius); background: rgba(212, 175, 55, 0.08); color: var(--warning); font-size: 12px; }

/* ---------------------------------------------------------------- MAIN / VIEWS */

#appMain { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#dataTabView, #verifyTabView { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; }
#scanTabView { flex: 1; min-height: 0; display: flex; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-family: var(--font-display); display: flex; align-items: center; gap: 12px; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.page-title::before { content: ''; width: 12px; height: 12px; background: var(--cyan); }
.page-sub { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }

.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.stat-tile .lbl { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.stat-tile .val { margin-top: 4px; font-family: var(--font-mono); font-size: 24px; font-weight: 700; line-height: 1.2; }

/* ---------------------------------------------------------------- TAB DỮ LIỆU */

.data-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.data-left, .data-center, .data-right { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.data-right { display: none; }

.cov-big { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 2px; }
.cov-big strong { font-family: var(--font-mono); font-size: 30px; font-weight: 700; color: var(--warning); }
.cov-big.ok strong { color: var(--success); }
.cov-big span { color: var(--text-2); font-size: 13px; }
.cov-meta { display: flex; justify-content: space-between; margin: 6px 0 8px; font-size: 12px; font-family: var(--font-mono); }
.cov-meta .pct { color: var(--cyan); font-weight: 600; }
.cov-meta .goal { color: var(--text-3); }
.cov-sub { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 8px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--warning); font-size: 13px; }
.cov-sub.ok { color: var(--success); }

.week-list { display: flex; flex-direction: column; gap: 8px; }
.week-item {
    display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
    padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); text-align: left; cursor: pointer;
}
.week-item:hover { border-color: var(--text-3); }
.week-item.active { border-color: var(--cyan); }
.week-item .w-title { font-size: 14px; font-weight: 600; }
.week-item .w-range { margin-top: 2px; color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }

.list-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.list-tools { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-bottom: 12px; }
.list-tools .only-mobile { display: none; }

.week-group-head {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 8px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.week-group-head .wg-title { font-size: 15px; font-weight: 700; }
.week-group-head .wg-total { color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }
.week-group-head .grow { flex: 1; }
.week-group-head .chev { color: var(--text-2); display: inline-flex; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; margin-bottom: 14px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    padding: 10px 10px; text-align: left; background: var(--bg); border-bottom: 1px solid var(--border);
    color: var(--text-3); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap;
}
.data-table td { height: 48px; padding: 6px 10px; border-bottom: 1px solid rgba(43, 58, 82, 0.5); white-space: nowrap; vertical-align: middle; }
.data-table tbody tr:nth-child(even) { background: var(--row-alt); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--l3); }
.data-table tbody tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--cyan); }
.data-table tbody tr.sel { background: var(--l3); }
.data-table tbody tr.sel td:first-child { border-left: 3px solid var(--cyan); padding-left: 9px; }
.data-table td.num, .data-table th.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; font-size: 14px; font-weight: 600; }
.m-id { color: var(--cyan); font-weight: 700; }
.auto-corrected { color: var(--warning); }
.row-actions { display: flex; align-items: center; gap: 10px; }
.link-act { background: none; border: none; padding: 4px 2px; font-size: 13px; font-weight: 600; cursor: pointer; }
.link-act.edit { color: var(--cyan); }
.link-act.del { color: var(--error); }
.row-sep { width: 1px; height: 14px; background: var(--border); }

.roi-thumb { display: block; width: 48px; height: 32px; object-fit: cover; border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: zoom-in; background: var(--bg); }
.roi-thumb:hover { border-color: var(--cyan); }
.no-img { color: var(--text-3); }

.detail-img { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.detail-img img { display: block; width: 100%; max-height: 260px; object-fit: contain; }
.detail-img .noimg { padding: 40px 0; text-align: center; color: var(--text-3); font-family: var(--font-mono); }
.metrics { display: grid; grid-template-columns: 0.8fr 1fr 1fr; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; }
.metrics > div { background: var(--surface); padding: 10px 12px; }
.metrics .m-lbl { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); }
.metrics .m-val { margin-top: 2px; font-family: var(--font-mono); font-size: 20px; font-weight: 700; }
.metrics .m-val.c { color: var(--cyan); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; font-family: var(--font-mono); }
.sec-title { margin: 16px 0 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.grid3 { display: grid; grid-template-columns: 0.8fr 1fr 1fr; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------------------------------------------------------------- TAB QUÉT */

#scanCamCol { flex: 1.65; min-width: 0; display: flex; flex-direction: column; gap: 12px; padding: 16px; }
#scanSideCol { flex: 1; min-width: 360px; max-width: 520px; display: flex; flex-direction: column; gap: 12px; padding: 16px 16px 16px 0; overflow-y: auto; }

#cameraContainer {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #030407;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
#video { width: 100%; height: 100%; object-fit: cover; display: block; }
#guideOverlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#guideOverlay rect { stroke: var(--cyan); stroke-width: 2; fill: none; vector-effect: non-scaling-stroke; }
#guideBottomLine { stroke: var(--cyan); stroke-width: 2; stroke-dasharray: 4, 2.5; vector-effect: non-scaling-stroke; }
#frozenFrameImage { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #030407; }
#frozenBorder { position: absolute; inset: 0; border: 3px solid var(--success); pointer-events: none; }

.cam-label {
    position: absolute; left: 12px; top: 12px; z-index: 6; display: inline-flex; align-items: center; gap: 8px;
    height: 28px; padding: 0 10px; background: var(--bg); border: 1px solid var(--cyan); border-radius: var(--radius-sm);
    color: var(--cyan); font-family: var(--font-mono); font-size: 12px; font-weight: 600; letter-spacing: 0.06em;
}
.cam-label::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); }
#scanChips { position: absolute; right: 12px; top: 12px; z-index: 6; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#scanChips .chip { height: 30px; padding: 0 10px; background: var(--bg); font-size: 13px; text-transform: none; font-family: var(--font-sans); font-weight: 600; }
#camMeta { position: absolute; left: 12px; bottom: 44px; z-index: 6; padding: 4px 8px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-2); font-family: var(--font-mono); font-size: 11px; }

#badgeMachineNumber {
    position: absolute; top: 56px; left: 50%; transform: translateX(-50%); z-index: 7;
    padding: 6px 14px; background: var(--error-deep); color: #fff; border-radius: var(--radius);
    font-family: var(--font-mono); font-weight: 700; font-size: 15px; white-space: nowrap;
}
#tvScanStatus {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 6; padding: 8px 12px; text-align: center;
    background: var(--bg); border-top: 1px solid var(--border); color: var(--cyan);
    font-family: var(--font-mono); font-size: 12px; font-weight: 600;
}
#btnSavePhoto {
    position: absolute; bottom: 44px; right: 12px; z-index: 6; height: 30px; padding: 0 10px;
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-2); font-size: 11px; cursor: pointer;
}

#permissionOverlay {
    position: absolute; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; padding: 24px; background: var(--bg); text-align: center; color: var(--text-2);
}
#loadingOverlay {
    position: absolute; top: 52px; left: 12px; right: 12px; z-index: 30; display: flex; align-items: center; justify-content: center; gap: 10px;
    padding: 8px 14px; background: var(--surface); border: 1px solid var(--cyan); border-radius: var(--radius);
    font-family: var(--font-mono); font-size: 12px; color: var(--text);
}
#loadingText.error { color: var(--warning); }
#btnGrantPermission, #btnRetryLoad { height: 38px; padding: 0 20px; background: var(--cyan); color: var(--bg); border: none; border-radius: var(--radius); font-size: 14px; font-weight: 700; cursor: pointer; }

/* Thanh trong camera (chỉ dùng trên mobile): tóm tắt độ phủ */
#headerBar { display: none; position: absolute; top: 0; left: 0; right: 0; z-index: 10; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--border); }
#headerInfo { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#tvCsvFileName { display: none; }
#tvCoverage { font-family: var(--font-mono); font-size: 13px; font-weight: 700; cursor: pointer; user-select: none; }
#tvCoverage.cov-missing { color: var(--cyan); }
#tvCoverage.cov-done { color: var(--success); }
#coveragePanel { display: none; }

#camToolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
#camToolbar .btn { height: 38px; }
#camToolbar .spacer { flex: 1; }
#btnManualCapture:not([hidden]) { display: inline-flex; }
#btnManualCapture { background: var(--surface); color: var(--cyan); border-color: var(--cyan); }
#btnFlash { margin-left: auto; }
.info-bar { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-2); font-size: 13px; }
.info-bar b { color: var(--text); }

#scanProgressCard .sp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
#scanProgressCard .sp-title { font-family: var(--font-mono); font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--cyan); }
#scanProgressCard .sp-count { font-family: var(--font-mono); font-size: 13px; font-weight: 700; }
#scanProgressCard .sp-line { display: flex; justify-content: space-between; margin: 10px 0; font-size: 13px; }
#scanProgressCard .sp-line .miss { color: var(--warning); font-family: var(--font-mono); font-weight: 700; }
#scanProgressCard .sp-line .miss.ok { color: var(--success); }
#scanProgressCard .sp-sub { margin: 10px 0 8px; padding-top: 10px; border-top: 1px solid var(--border); color: var(--text-3); font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }

#lastRoiCard .roi-box { position: relative; height: 96px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; }
#lastRoiCard img { width: 100%; height: 100%; object-fit: contain; }
#lastRoiCard .roi-empty { color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }

#dataPanel { display: flex; flex-direction: column; gap: 12px; }
#dataPanel .form-row { display: grid; grid-template-columns: 1fr; gap: 12px; }
#etMachineId { font-size: 22px !important; font-weight: 700 !important; color: var(--cyan) !important; height: 44px !important; border-color: var(--cyan) !important; }
#etParamX, #etParamY { font-size: 17px !important; font-weight: 700 !important; height: 40px !important; }
.btn-row { display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1.6fr; gap: 8px; }
.row3 { display: flex; gap: 8px; }
.conf-note { color: var(--text-3); font-family: var(--font-mono); font-size: 11px; }
.kbd-hint { padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-3); font-family: var(--font-mono); font-size: 11px; }

.recent-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.recent-row:first-of-type { border-top: none; }
.recent-row .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.recent-row .dot.new { background: var(--success); }
.recent-row .rid { font-family: var(--font-mono); font-weight: 700; }
.recent-row .rval { flex: 1; font-family: var(--font-mono); color: var(--text-2); }
.recent-row .rtime { color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }

/* ---------------------------------------------------------------- TAB KIỂM TRA */

.vf-top { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 14px; margin-bottom: 16px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.seg button { height: 30px; padding: 0 12px; background: none; border: none; border-radius: var(--radius-sm); color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--cyan); color: var(--bg); font-weight: 700; }
.vf-scope-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.vf-range { font-family: var(--font-mono); font-size: 13px; color: var(--text-2); }
.vf-range b { color: var(--text); }
.vf-run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.vf-progress { display: none; align-items: center; gap: 10px; padding: 8px 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); min-width: 280px; flex: 1; max-width: 460px; }
.vf-progress.on { display: flex; }
.vf-progress .txt { font-family: var(--font-mono); font-size: 12px; white-space: nowrap; }
.vf-progress .progress { flex: 1; min-width: 80px; }
.vf-tiles { display: grid; grid-template-columns: repeat(4, 1fr) 1.4fr; gap: 12px; }
.vf-tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.vf-tile .lbl { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-2); text-transform: uppercase; }
.vf-tile .val { margin-top: 6px; font-family: var(--font-mono); font-size: 28px; font-weight: 700; }
.vf-tile.ok .val { color: var(--success); }
.vf-tile.bad .val { color: var(--error); }
.vf-tile.unread .val { color: var(--warning); }
.vf-tile.noimg .val { color: var(--text-3); }
.vf-replace { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; text-align: center; background: rgba(229, 35, 61, 0.08); border: 1px solid var(--error); border-radius: var(--radius); color: var(--error); font-weight: 700; cursor: pointer; font-size: 14px; }
.vf-replace:hover:not(:disabled) { background: rgba(229, 35, 61, 0.16); }
.vf-replace:disabled { opacity: 0.35; cursor: not-allowed; }

.vf-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.vf-listcol { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.vf-filter { display: flex; border-bottom: 1px solid var(--border); }
.vf-filter button { flex: 1; height: 38px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--text-2); font-size: 14px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.vf-filter button.active { color: var(--cyan); border-bottom-color: var(--cyan); font-weight: 700; }
.vf-filter button.active.bad { color: var(--error); border-bottom-color: var(--error); }
.vf-filter .n { font-family: var(--font-mono); font-size: 12px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--card); color: var(--text-2); }
.vf-filter button.bad .n { background: rgba(229, 35, 61, 0.18); color: var(--error); }
.vf-list { max-height: 640px; overflow-y: auto; }
.vf-item { display: flex; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; cursor: pointer; }
.vf-item:hover { background: rgba(255, 255, 255, 0.025); }
.vf-item.sel { background: rgba(0, 201, 183, 0.06); }
.vf-item.s-MATCH { border-left-color: var(--success); }
.vf-item.s-MISMATCH { border-left-color: var(--error); }
.vf-item.s-UNREADABLE { border-left-color: var(--warning); }
.vf-item.s-NO_IMAGE { border-left-color: var(--text-3); }
.vf-item .thumb { width: 64px; height: 44px; flex-shrink: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); object-fit: cover; }
.vf-item .main { flex: 1; min-width: 0; }
.vf-item .l1 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.vf-item .mid { font-family: var(--font-mono); font-size: 15px; font-weight: 700; color: var(--cyan); }
.vf-item .l2 { margin-top: 3px; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.vf-item .l2 .diff { color: var(--error); font-family: var(--font-mono); font-weight: 600; }
.vf-item .l2 .diff s { color: var(--text-3); }

.vf-detailcol { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.vf-detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.vf-detail-head h2 { margin: 0; font-size: 18px; font-weight: 700; color: var(--cyan); font-family: var(--font-mono); letter-spacing: 0.02em; }
.vf-stage { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; touch-action: none; user-select: none; }
.vf-stage canvas { display: block; width: 100%; height: auto; }
.vf-stage .stage-tools { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; z-index: 3; }
.vf-stage .stage-tools .btn { height: 36px; background: var(--bg); }
.vf-stage .stage-tools .btn.on { background: var(--cyan); color: var(--bg); border-color: var(--cyan); }
.vf-stage .stage-note { position: absolute; right: 10px; bottom: 10px; z-index: 3; padding: 4px 8px; background: var(--bg); border: 1px dashed var(--cyan); border-radius: var(--radius-sm); color: var(--cyan); font-family: var(--font-mono); font-size: 11px; }
.cmp-table { width: 100%; border-collapse: collapse; }
.cmp-table th { padding: 10px 14px; text-align: left; color: var(--text-2); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; border-bottom: 1px solid var(--border); }
.cmp-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.cmp-table tr:last-child td { border-bottom: none; }
.cmp-table td.v { font-family: var(--font-mono); font-weight: 700; }
.cmp-table td.rd { font-family: var(--font-mono); font-weight: 700; }
.cmp-table td.rd.ok { color: var(--success); }
.cmp-table td.rd.bad { color: var(--error); }
.cmp-table td.rd.na { color: var(--text-3); }
.region-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.region-result { padding: 6px 10px; border: 1px solid var(--cyan); border-radius: var(--radius-sm); color: var(--cyan); font-family: var(--font-mono); font-size: 13px; }
.vf-actions { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 10px; }

/* ---------------------------------------------------------------- MODAL / TOAST */

.modal-overlay { position: fixed; inset: 0; z-index: 999; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(11, 15, 23, 0.8); }
.modal-card { width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; padding: 20px; background: var(--l3); border: 1px solid var(--border-modal); border-radius: var(--radius); }
.modal-card.wide { max-width: 860px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-family: var(--font-display); margin: 0; font-size: 17px; font-weight: 700; color: var(--cyan); letter-spacing: 0.02em; text-transform: uppercase; }
.modal-close-btn { display: inline-flex; background: none; border: none; color: var(--text-2); cursor: pointer; padding: 4px; }
.modal-close-btn:hover { color: var(--text); }
.modal-body { display: flex; flex-direction: column; gap: 14px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-footer .btn { flex: 1; }
.modal-note { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-2); font-size: 12px; }
.roi-image-container { position: relative; display: flex; align-items: center; justify-content: center; min-height: 240px; max-height: 64vh; overflow: hidden; background: #030407; border: 1px solid var(--border); border-radius: var(--radius); user-select: none; touch-action: pan-y; }
.roi-lightbox-image { max-width: 100%; max-height: 64vh; object-fit: contain; display: block; pointer-events: none; }
.roi-nav-btn { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); font-size: 22px; cursor: pointer; z-index: 2; }
.roi-nav-btn:hover { border-color: var(--cyan); color: var(--cyan); }
.roi-nav-btn:disabled { opacity: 0.2; pointer-events: none; }
.roi-nav-prev { left: 8px; }
.roi-nav-next { right: 8px; }

#toastHost { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 10px 16px; background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--cyan); border-radius: var(--radius); font-size: 13px; max-width: 90vw; }
.toast.err { border-left-color: var(--error); }
.toast.ok { border-left-color: var(--success); }

/* ---------------------------------------------------------------- FOOTER */

#appFooter { display: none; flex-shrink: 0; justify-content: space-between; gap: 16px; padding: 10px 24px; background: var(--bg); border-top: 1px solid var(--border); color: var(--text-3); font-family: var(--font-mono); font-size: 12px; }

/* ================================================================ RESPONSIVE */

/* Desktop rộng: 3 cột */
@media (min-width: 1200px) {
    #appFooter { display: flex; }
    .data-layout { grid-template-columns: 300px minmax(0, 1fr) 340px; }
    .data-right { display: flex; }
    .vf-body { grid-template-columns: 420px minmax(0, 1fr); }
    .stat-tiles { display: none; }
    .list-tools .only-mobile { display: none; }
}

/* Tablet / màn hình ngang nhỏ: 2 cột */
@media (min-width: 768px) and (max-width: 1199px) {
    .data-layout { grid-template-columns: 300px minmax(0, 1fr); }
    .data-left { grid-column: 1; }
    .data-center { grid-column: 2; }
    .stat-tiles { display: none; }
    .vf-body { grid-template-columns: 340px minmax(0, 1fr); }
    .vf-tiles { grid-template-columns: repeat(2, 1fr); }
    .vf-replace { grid-column: 1 / -1; }
    #scanSideCol { min-width: 320px; }
}

/* Mobile */
@media (max-width: 767px) {
    :root { --header-h: auto; }
    #appHeader { flex-wrap: wrap; height: auto; padding: 8px 16px 0; gap: 0; }
    .hdr-left { width: 100%; flex-direction: column; align-items: stretch; gap: 0; }
    .hdr-right { position: absolute; right: 16px; top: 10px; }
    .brand { height: 34px; }
    .brand-name { font-size: 16px; }
    #tabBar { margin-left: 0; width: 100%; }
    .tab-btn { flex: 1; justify-content: center; padding: 0 4px; height: 44px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
    .tab-btn .ic { display: inline-block; }
    .week-nav, #btnHeaderCsv { display: none; }
    #tvCloudStatus { height: 28px; padding: 0 8px; font-size: 11px; }
    #dataTabView, #verifyTabView { padding: 12px; }
    .page-head { margin-bottom: 12px; }
    .page-title { font-size: 18px; }
    .stat-tiles { display: grid; }

    .data-layout { gap: 12px; }
    .data-center { order: 3; }
    .data-left { order: 2; }
    .list-tools { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .list-tools .only-mobile { display: inline-flex; }
    .list-tools .search-wrap { grid-column: 1 / -1; order: 1; }
    #dvSort { order: 2; width: 100% !important; }
    #dvWeekSel { order: 3; width: 100%; }
    #btnDvAdd { order: 4; grid-column: 1 / -1; }
    #btnDvCsv { order: 5; grid-column: 1 / -1; }
    .week-group-head .wg-total { display: none; }

    /* Quét: 1 cột, vừa khít màn hình */
    #scanTabView { flex-direction: column; overflow-y: auto; }
    #scanCamCol { flex: none; padding: 0; gap: 0; }
    #cameraContainer { flex: none; height: 52vh; min-height: 320px; border-radius: 0; border-left: none; border-right: none; }
    #headerBar { display: block; }
    #coveragePanel { display: block; position: absolute; top: 40px; left: 0; right: 0; z-index: 12; max-height: 48%; overflow-y: auto; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--warning); }
    #coveragePanel[hidden] { display: none !important; }
    #coveragePanel .cov-panel-title { font-family: var(--font-mono); font-size: 11px; font-weight: 700; color: var(--warning); margin-bottom: 8px; }
    .cam-label { top: 48px; }
    #scanChips { top: 48px; }
    #camMeta { display: none; }
    #camToolbar { border-radius: 0; border-left: none; border-right: none; padding: 8px 12px; }
    #camToolbar .btn { height: 34px; font-size: 12px; padding: 0 10px; }
    #camToolbar .btn .lbl-long { display: none; }
    #camToolbar .kbd { display: none; }
    .info-bar { display: none; }
    #scanSideCol { max-width: none; min-width: 0; padding: 12px; gap: 10px; overflow: visible; }
    #scanProgressCard, #lastRoiCard, #recentCard, .kbd-hint { display: none; }
    #dataPanel { padding: 10px; gap: 8px; }
    #dataPanel .form-row { grid-template-columns: 0.85fr 1fr 1fr; gap: 6px; }
    #etMachineId { font-size: 17px !important; height: 36px !important; padding: 0 8px; }
    #etParamX, #etParamY { font-size: 14px !important; height: 36px !important; padding: 0 8px; }
    #dataPanel .card-title { display: none; }
    .field-label { font-size: 10px; margin-bottom: 4px; }

    /* Kiểm tra: 1 cột */
    .vf-tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .vf-replace { grid-column: 1 / -1; }
    .vf-actions { grid-template-columns: 1fr; }
    .vf-detailcol { gap: 12px; }
    .modal-overlay { padding: 8px; }
}

/* Màn hình thấp (laptop 768px cao): giảm đệm */
@media (min-width: 1200px) and (max-height: 820px) {
    #dataTabView, #verifyTabView { padding: 16px 24px; }
    #cameraContainer { min-height: 360px; }
}

/* Cột chỉ hiện trên desktop/tablet (ẩn trên mobile cho bảng gọn như thiết kế) */
@media (max-width: 767px) {
    .hide-m { display: none !important; }
}

/* Theme: thẻ đệm rộng hơn trên desktop, nút/ô nhập 40px */
@media (min-width: 1200px) {
    .card { padding: 24px; }
    .btn { height: 34px; }
    .btn-sm { height: 28px; }
    .input, select.input { height: 34px; }
    #camToolbar .btn { height: 34px; }
}

/* Cột phải tab Quét gọn hơn để nút Xác nhận luôn trong tầm nhìn trên laptop */
#scanProgressCard .cov-chips { max-height: 78px; overflow-y: auto; }
#lastRoiCard .roi-box { height: 72px; }
#scanSideCol { gap: 10px; }
#scanProgressCard.card, #lastRoiCard.card, #recentCard.card { padding: 14px; }

@media (max-width: 767px) {
    .weeks-card { display: none; }
}
