:root {
    --primary: #183a59;
    --primary-light: #2b5884;
    --accent: #2563eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --radius: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--surface);
    color: #ffffff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    z-index: 20;
}

.app-title {
    font-size: 1.05rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    background: #0284c7;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
}

/* Main Container */
.main-container {
    flex: 1;
    position: relative;
    overflow-y: auto;
}

/* Views */
.view {
    display: none;
    padding: 16px;
    height: 100%;
    overflow-y: auto;
}

.view.active {
    display: block;
}

/* Card */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #38bdf8;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group {
    margin-bottom: 14px;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input[type="text"], select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    background: #0f172a;
    color: #fff;
}

input[type="file"] {
    display: none;
}

.file-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #0f172a;
    border: 2px dashed #475569;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    font-size: 0.95rem;
    color: #38bdf8;
    font-weight: 600;
    text-align: center;
}

.file-btn.loaded {
    border-color: var(--success);
    background: rgba(22, 163, 74, 0.15);
    color: #4ade80;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 18px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary { background: #0284c7; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-accent  { background: #7c3aed; color: #fff; }
.btn-secondary { background: #334155; color: #fff; }

/* SCANNER VIEW */
#view-scanner {
    padding: 0;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #000;
    display: none;
    flex-direction: column;
}

#view-scanner.active {
    display: flex;
}

.scanner-video-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* KHUNG NGẮM KHÓA CHẶT TỶ LỆ A4 CHUẨN 210 x 297 */
.viewfinder {
    position: absolute;
    /* Khóa tỷ lệ 1 : 1.414 chuẩn khổ A4 */
    width: 82vw;
    max-width: 380px;
    aspect-ratio: 210 / 297;
    max-height: 72vh;
    border: 2px dashed rgba(255, 255, 255, 0.45);
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.65);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 4 Ô VUÔNG ĐỊNH VỊ NẰM LÙI VÀO TRONG 5% (ĐÚNG TỌA ĐỘ IN TRÊN PHIẾU A4) */
.target-box {
    position: absolute;
    width: 50px;
    height: 50px;
    border: 3px solid #facc15; /* Màu vàng mặc định */
    background: rgba(250, 204, 21, 0.2);
    border-radius: 6px;
    transition: all 0.2s ease;
}

/* Tọa độ lùi 5% từ mép mép giấy A4 */
.target-tl { top: 4.8%; left: 5.1%; }
.target-tr { top: 4.8%; right: 5.1%; }
.target-br { bottom: 4.8%; right: 5.1%; }
.target-bl { bottom: 4.8%; left: 5.1%; }

/* Khi đã khớp cả 4 góc */
.viewfinder.matched {
    border-color: #22c55e;
}

.viewfinder.matched .target-box {
    border-color: #22c55e !important;
    background: rgba(34, 197, 94, 0.4) !important;
    box-shadow: 0 0 16px #22c55e;
}

/* Thanh hướng dẫn căn góc */
.viewfinder-guide {
    position: absolute;
    top: 14px;
    left: 12px;
    right: 12px;
    text-align: center;
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(15, 23, 42, 0.85);
    padding: 8px 14px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    pointer-events: none;
}

.guide-status {
    color: #facc15;
}

.viewfinder.matched + .viewfinder-guide .guide-status {
    color: #4ade80;
}

/* Controls */
.scanner-controls {
    background: #0f172a;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 16px;
    border-top: 1px solid var(--border);
}

.round-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: #1e293b;
    color: #fff;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.round-btn.snap-btn {
    width: 66px;
    height: 66px;
    background: #38bdf8;
    color: #0f172a;
    font-size: 1.8rem;
    border: 4px solid #fff;
}

/* MÀN HÌNH XEM LẠI KẾT QUẢ VỪA CHẤM (REVIEW OVERLAY) */
.scan-preview-modal {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 50;
    display: none;
    flex-direction: column;
    padding: 12px;
    overflow-y: auto;
}

.scan-preview-modal.show {
    display: flex;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e293b;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 10px;
}

.preview-score {
    font-size: 1.8rem;
    font-weight: 800;
    color: #ef4444;
}

.preview-canvas-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin-bottom: 12px;
    background: #000;
    border-radius: 8px;
    border: 1px solid #334155;
}

.preview-canvas-wrap canvas {
    max-width: 100%;
    max-height: 55vh;
    object-fit: contain;
    border-radius: 6px;
}

.preview-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Toast Thông Báo Lưu */
.toast-msg {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: #16a34a;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    display: none;
}

/* Bottom Navigation */
.bottom-nav {
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    height: 58px;
    z-index: 20;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    gap: 3px;
    cursor: pointer;
}

.nav-item.active {
    color: #38bdf8;
    font-weight: 700;
}

.nav-icon {
    font-size: 1.25rem;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: #1e293b;
}

th, td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

th {
    background: #334155;
    color: #f8fafc;
    font-weight: 600;
}
