
:root {
    --navy: #082f49;
    --primary: #075985;
    --primary-2: #0284c7;
    --sky: #0ea5e9;
    --soft: #f0f9ff;
    --surface: #ffffff;
    --border: #dbeafe;
    --text: #172033;
    --muted: #64748b;
    --success: #047857;
    --success-bg: #ecfdf5;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --warning: #9a6700;
    --warning-bg: #fff8db;
    --shadow: 0 18px 45px rgba(7, 89, 133, .10);
    --radius: 20px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
    margin: 0;
    font-family: "Noto Sans Thai", Tahoma, Arial, sans-serif;
    color: var(--text);
    background: #f5fbff;
}

a { color: inherit; }

code {
    padding: .12rem .35rem;
    border-radius: 6px;
    background: #eef6fb;
    font-family: Consolas, monospace;
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        radial-gradient(circle at 10% 10%, rgba(14,165,233,.20), transparent 30rem),
        radial-gradient(circle at 90% 90%, rgba(2,132,199,.13), transparent 32rem),
        linear-gradient(145deg, #eaf8ff, #f8fbfd 56%, #edf7ff);
}

.auth-shell { width: min(460px, 100%); }

.auth-card,
.panel-card,
.danger-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: rgba(255,255,255,.97);
    box-shadow: var(--shadow);
}

.auth-card { padding: 34px; }

.auth-brand,
.brand-circle {
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, var(--navy), var(--primary-2));
    font-weight: 800;
    letter-spacing: .06em;
}

.auth-brand {
    width: 64px;
    height: 64px;
    margin-bottom: 22px;
    box-shadow: 0 12px 30px rgba(7,89,133,.22);
}

.auth-card h1,
.panel-card h1,
.danger-card h1 {
    margin: 4px 0 10px;
    line-height: 1.25;
}

.auth-card form,
.panel-card form {
    display: grid;
    gap: 10px;
    margin-top: 22px;
}

label {
    margin-top: 7px;
    color: #334155;
    font-size: .88rem;
    font-weight: 700;
}

input {
    width: 100%;
    min-height: 46px;
    padding: 10px 13px;
    border: 1px solid #cbd5e1;
    border-radius: 11px;
    outline: none;
    background: #fff;
    color: var(--text);
    font: inherit;
}

input:focus {
    border-color: var(--sky);
    box-shadow: 0 0 0 4px rgba(14,165,233,.12);
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--sky);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
}

.muted { color: var(--muted); }

.auth-footnote {
    margin-top: 22px;
    color: var(--muted);
    font-size: .8rem;
    text-align: center;
}

.btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    white-space: nowrap;
}

.btn-block { width: 100%; }

.btn-primary {
    color: #fff;
    background: linear-gradient(115deg, var(--primary), var(--primary-2));
    box-shadow: 0 8px 20px rgba(2,132,199,.18);
}

.btn-secondary {
    color: #334155;
    border-color: #cbd5e1;
    background: #fff;
}

.btn-soft {
    color: #e0f2fe;
    border-color: rgba(255,255,255,.18);
    background: rgba(255,255,255,.10);
}

.btn-outline {
    color: #fff;
    border-color: rgba(255,255,255,.38);
    background: transparent;
}

.btn-danger {
    color: #fff;
    background: var(--danger);
}

.btn-danger-outline {
    min-height: 34px;
    color: var(--danger);
    border-color: #fecaca;
    background: #fff;
}

.alert {
    margin: 18px 0;
    padding: 13px 15px;
    border: 1px solid;
    border-radius: 11px;
    font-size: .9rem;
}

.alert-danger { color: #991b1b; border-color: #fecaca; background: var(--danger-bg); }
.alert-success { color: #065f46; border-color: #a7f3d0; background: var(--success-bg); }
.alert-warning { color: var(--warning); border-color: #fde68a; background: var(--warning-bg); }

.page-body { min-height: 100vh; background: #f5fbff; }

.topbar {
    color: #fff;
    background: linear-gradient(115deg, var(--navy), var(--primary) 55%, var(--primary-2));
    box-shadow: 0 8px 26px rgba(8,47,73,.16);
}

.topbar-inner {
    width: min(1480px, calc(100% - 36px));
    min-height: 94px;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand-group,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-circle {
    width: 58px;
    height: 58px;
    border: 2px solid rgba(255,255,255,.65);
    background: rgba(255,255,255,.12);
}

.brand-title { font-size: 1.25rem; font-weight: 800; }
.brand-subtitle { margin-top: 4px; color: #bae6fd; font-size: .85rem; }

.admin-name {
    display: grid;
    gap: 2px;
    margin-right: 4px;
    text-align: right;
}

.admin-name span { color: #bae6fd; font-size: .72rem; }

.topbar-actions form { margin: 0; }

.dashboard-shell {
    width: min(1480px, calc(100% - 36px));
    margin: 26px auto 40px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.stat-card {
    padding: 21px;
    border: 1px solid var(--border);
    border-radius: 17px;
    background: var(--surface);
    box-shadow: 0 10px 28px rgba(7,89,133,.07);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: .84rem;
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin: 7px 0 2px;
    color: var(--primary);
    font-size: 2rem;
}

.stat-card small { color: #94a3b8; }

.dashboard-grid {
    margin: 18px 0;
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(310px, .7fr);
    gap: 18px;
}

.panel-card { padding: 22px; }

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.panel-head h2,
.quick-card h2 {
    margin: 3px 0 5px;
    color: #0f3f5d;
    font-size: 1.05rem;
}

.mini-chart {
    height: 190px;
    margin-top: 22px;
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    align-items: end;
    gap: 12px;
}

.bar-item {
    height: 100%;
    display: grid;
    grid-template-rows: 25px 1fr 24px;
    align-items: end;
    text-align: center;
}

.bar-count { color: var(--primary); font-size: .82rem; font-weight: 800; }
.bar-track {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: end;
    justify-content: center;
    border-radius: 9px;
    background: #f0f9ff;
    overflow: hidden;
}
.bar-fill {
    width: 66%;
    min-height: 3px;
    border-radius: 8px 8px 3px 3px;
    background: linear-gradient(to top, var(--primary), var(--sky));
}
.bar-label { padding-top: 5px; color: var(--muted); font-size: .75rem; }

.h-0 { height: 0%; }
.h-1 { height: 1%; }
.h-2 { height: 2%; }
.h-3 { height: 3%; }
.h-4 { height: 4%; }
.h-5 { height: 5%; }
.h-6 { height: 6%; }
.h-7 { height: 7%; }
.h-8 { height: 8%; }
.h-9 { height: 9%; }
.h-10 { height: 10%; }
.h-11 { height: 11%; }
.h-12 { height: 12%; }
.h-13 { height: 13%; }
.h-14 { height: 14%; }
.h-15 { height: 15%; }
.h-16 { height: 16%; }
.h-17 { height: 17%; }
.h-18 { height: 18%; }
.h-19 { height: 19%; }
.h-20 { height: 20%; }
.h-21 { height: 21%; }
.h-22 { height: 22%; }
.h-23 { height: 23%; }
.h-24 { height: 24%; }
.h-25 { height: 25%; }
.h-26 { height: 26%; }
.h-27 { height: 27%; }
.h-28 { height: 28%; }
.h-29 { height: 29%; }
.h-30 { height: 30%; }
.h-31 { height: 31%; }
.h-32 { height: 32%; }
.h-33 { height: 33%; }
.h-34 { height: 34%; }
.h-35 { height: 35%; }
.h-36 { height: 36%; }
.h-37 { height: 37%; }
.h-38 { height: 38%; }
.h-39 { height: 39%; }
.h-40 { height: 40%; }
.h-41 { height: 41%; }
.h-42 { height: 42%; }
.h-43 { height: 43%; }
.h-44 { height: 44%; }
.h-45 { height: 45%; }
.h-46 { height: 46%; }
.h-47 { height: 47%; }
.h-48 { height: 48%; }
.h-49 { height: 49%; }
.h-50 { height: 50%; }
.h-51 { height: 51%; }
.h-52 { height: 52%; }
.h-53 { height: 53%; }
.h-54 { height: 54%; }
.h-55 { height: 55%; }
.h-56 { height: 56%; }
.h-57 { height: 57%; }
.h-58 { height: 58%; }
.h-59 { height: 59%; }
.h-60 { height: 60%; }
.h-61 { height: 61%; }
.h-62 { height: 62%; }
.h-63 { height: 63%; }
.h-64 { height: 64%; }
.h-65 { height: 65%; }
.h-66 { height: 66%; }
.h-67 { height: 67%; }
.h-68 { height: 68%; }
.h-69 { height: 69%; }
.h-70 { height: 70%; }
.h-71 { height: 71%; }
.h-72 { height: 72%; }
.h-73 { height: 73%; }
.h-74 { height: 74%; }
.h-75 { height: 75%; }
.h-76 { height: 76%; }
.h-77 { height: 77%; }
.h-78 { height: 78%; }
.h-79 { height: 79%; }
.h-80 { height: 80%; }
.h-81 { height: 81%; }
.h-82 { height: 82%; }
.h-83 { height: 83%; }
.h-84 { height: 84%; }
.h-85 { height: 85%; }
.h-86 { height: 86%; }
.h-87 { height: 87%; }
.h-88 { height: 88%; }
.h-89 { height: 89%; }
.h-90 { height: 90%; }
.h-91 { height: 91%; }
.h-92 { height: 92%; }
.h-93 { height: 93%; }
.h-94 { height: 94%; }
.h-95 { height: 95%; }
.h-96 { height: 96%; }
.h-97 { height: 97%; }
.h-98 { height: 98%; }
.h-99 { height: 99%; }
.h-100 { height: 100%; }

.quick-links {
    margin-top: 17px;
    display: grid;
    gap: 10px;
}

.quick-links a {
    padding: 13px 14px;
    display: grid;
    gap: 3px;
    border: 1px solid var(--border);
    border-radius: 12px;
    text-decoration: none;
    background: #f8fcff;
}

.quick-links a:hover { border-color: #7dd3fc; background: #f0f9ff; }
.quick-links strong { color: var(--primary); }
.quick-links span { color: var(--muted); font-size: .8rem; }

.records-head { margin-bottom: 16px; }

.filter-form {
    display: grid !important;
    grid-template-columns: minmax(220px, 1fr) 170px 170px auto;
    align-items: end;
    gap: 10px !important;
    margin: 0 0 18px !important;
    padding: 14px;
    border-radius: 13px;
    background: #f8fcff;
}

.filter-field { display: grid; gap: 6px; }
.filter-field label { margin: 0; }
.filter-buttons { display: flex; gap: 8px; }

.bulk-delete-form { display: block !important; margin: 0 !important; }
.bulk-actions {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
    color: var(--muted);
    font-size: .9rem;
}
.bulk-actions strong { color: var(--danger); }
.btn:disabled { cursor: not-allowed; opacity: .5; }
.select-column { width: 48px; text-align: center !important; }
.record-checkbox { width: 18px; min-height: 18px; margin: 0; cursor: pointer; }
.data-table tbody tr:has(.row-checkbox:checked) { background: #fff7f7; }

.table-wrap {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

.data-table th,
.data-table td {
    padding: 12px 13px;
    border-bottom: 1px solid #eaf0f5;
    vertical-align: middle;
    text-align: left;
}

.data-table th {
    color: #475569;
    background: #f8fafc;
    font-size: .78rem;
    letter-spacing: .02em;
}

.data-table tbody tr:hover { background: #fbfdff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.right { text-align: right !important; }

.thumb-link { display: inline-block; cursor: zoom-in; }
.thumb-link .thumb { transition: transform .18s ease, box-shadow .18s ease; }
.thumb-link:hover .thumb, .thumb-link:focus-visible .thumb { transform: scale(1.08); box-shadow: 0 8px 22px rgba(15, 23, 42, .22); }
.image-hover-preview { position: fixed; z-index: 1200; display: none; width: min(360px, calc(100vw - 32px)); padding: 7px; pointer-events: none; border: 1px solid #cbd5e1; border-radius: 14px; background: #fff; box-shadow: 0 18px 50px rgba(15, 23, 42, .3); }
.image-hover-preview.is-visible { display: block; }
.image-hover-preview img { display: block; width: 100%; max-height: 360px; object-fit: contain; border-radius: 9px; }
.image-preview-modal { position: fixed; inset: 0; z-index: 1300; display: none; align-items: center; justify-content: center; padding: 24px; }
.image-preview-modal.is-open { display: flex; }
.image-preview-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(15, 23, 42, .78); cursor: zoom-out; }
.image-preview-dialog { position: relative; width: min(1000px, 96vw); max-height: 94vh; overflow: hidden; border-radius: 18px; background: #fff; box-shadow: 0 24px 80px rgba(0, 0, 0, .45); }
.image-preview-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 18px; border-bottom: 1px solid #e2e8f0; }
.image-preview-header h2 { margin: 0; font-size: 1.05rem; }
.image-preview-actions { display: flex; align-items: center; gap: 10px; }
.image-preview-close { width: 40px; height: 40px; border: 0; border-radius: 50%; color: #334155; background: #f1f5f9; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.image-preview-close:hover { background: #e2e8f0; }
.image-preview-body { display: grid; place-items: center; min-height: 240px; padding: 16px; background: #0f172a; }
.image-preview-body img { display: block; max-width: 100%; max-height: calc(94vh - 100px); object-fit: contain; }
body.preview-open { overflow: hidden; }
.realtime-status { position: fixed; right: 16px; bottom: 16px; z-index: 1100; display: flex; align-items: center; gap: 7px; padding: 8px 12px; border: 1px solid #a7f3d0; border-radius: 999px; color: #047857; background: rgba(236, 253, 245, .94); box-shadow: 0 6px 20px rgba(15, 23, 42, .12); font-size: .78rem; font-weight: 700; backdrop-filter: blur(6px); }
.realtime-status span { width: 8px; height: 8px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgba(16, 185, 129, .15); }
.realtime-status.is-paused { color: #92400e; border-color: #fde68a; background: rgba(255, 251, 235, .95); }
.realtime-status.is-paused span { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, .15); }

.thumb {
    width: 92px;
    height: 68px;
    display: block;
    object-fit: cover;
    border: 1px solid #dbeafe;
    border-radius: 10px;
    background: #e2e8f0;
}

.thumb-link { display: inline-block; }

.record-id { margin-bottom: 5px; color: #334155; font-weight: 800; }
.status-pass {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    color: var(--success);
    background: var(--success-bg);
    font-size: .72rem;
    font-weight: 800;
}

.confidence-cell { min-width: 110px; }
.confidence-line {
    width: 100%;
    height: 6px;
    margin-top: 7px;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: #e2e8f0;
    appearance: none;
}
.confidence-line::-webkit-progress-bar {
    border-radius: 999px;
    background: #e2e8f0;
}
.confidence-line::-webkit-progress-value {
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--sky));
}
.confidence-line::-moz-progress-bar {
    border-radius: 999px;
    background: var(--primary-2);
}

.empty-state {
    padding: 50px 20px;
    color: var(--muted);
    text-align: center;
}

.pagination {
    margin-top: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.pagination a,
.pagination span {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    text-decoration: none;
    background: #fff;
}

.simple-page {
    width: min(900px, calc(100% - 32px));
    margin: 35px auto;
}

.simple-page.narrow { width: min(560px, calc(100% - 32px)); }

.back-link {
    margin-bottom: 14px;
    display: inline-block;
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
}

.danger-card { padding: 26px; border-color: #fecaca; }
.danger-text { color: var(--danger); }

.delete-preview {
    margin: 22px 0;
    display: grid;
    grid-template-columns: minmax(220px, 360px) 1fr;
    gap: 22px;
    align-items: start;
}

.delete-preview img {
    width: 100%;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
}

.delete-preview > div {
    display: grid;
    gap: 9px;
    padding: 8px 0;
}

.delete-actions {
    display: flex !important;
    grid-template-columns: none !important;
    justify-content: flex-end;
    gap: 10px !important;
}

.security-list {
    margin: 20px 0;
    display: grid;
    gap: 10px;
}

.security-row {
    padding: 13px 14px;
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 12px;
    align-items: center;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}

.security-badge {
    padding: 5px 8px;
    border-radius: 999px;
    text-align: center;
    font-size: .72rem;
    font-weight: 800;
}

.security-badge.ok { color: #065f46; background: #d1fae5; }
.security-badge.warn { color: #92400e; background: #fef3c7; }

@media (max-width: 1050px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .filter-form { grid-template-columns: 1fr 1fr; }
    .filter-field.grow { grid-column: 1 / -1; }
    .filter-buttons { grid-column: 1 / -1; }
    .topbar-inner { align-items: flex-start; padding: 18px 0; }
    .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 720px) {
    .topbar-inner { flex-direction: column; }
    .topbar-actions { width: 100%; justify-content: flex-start; }
    .admin-name { width: 100%; text-align: left; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filter-form { grid-template-columns: 1fr; }
    .filter-field.grow, .filter-buttons { grid-column: auto; }
    .filter-buttons { flex-wrap: wrap; }
    .mini-chart { gap: 6px; }
    .delete-preview { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .auth-card { padding: 25px 20px; }
    .dashboard-shell, .topbar-inner { width: min(100% - 22px, 1480px); }
}
