/* TingPush Camera Cloud — giao diện web. Màu, font khớp app di động (mobile_app/lib/theme.dart). */

@font-face { font-family: "Be Vietnam Pro"; src: url("fonts/BeVietnamPro-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("fonts/BeVietnamPro-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("fonts/BeVietnamPro-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Be Vietnam Pro"; src: url("fonts/BeVietnamPro-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root, [data-theme="dark"] {
    --bg: #0b1120;
    --bg-2: #0f172a;
    --panel: #121a2b;
    --panel-2: #172135;
    --line: #233049;
    --line-2: #2c3a57;
    --text: #e7ecf5;
    --muted: #8b97ad;
    --primary: #3b82f6;
    --primary-2: #2563eb;
    --primary-soft: rgb(59 130 246 / .14);
    --accent: #06b6d4;
    --live: #22c55e;
    --live-soft: rgb(34 197 94 / .14);
    --bad: #ef4444;
    --bad-soft: rgb(239 68 68 / .14);
    --warn: #f59e0b;
    --warn-soft: rgb(245 158 11 / .14);
    --plate: #facc15;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    --radius: 14px;
    color-scheme: dark;
}

[data-theme="light"] {
    --bg: #f3f6fb;
    --bg-2: #eaeef6;
    --panel: #ffffff;
    --panel-2: #f6f8fc;
    --line: #e3e8f1;
    --line-2: #d3dbe8;
    --text: #0f172a;
    --muted: #64748b;
    --primary-soft: rgb(59 130 246 / .10);
    --live-soft: rgb(34 197 94 / .12);
    --bad-soft: rgb(239 68 68 / .10);
    --warn-soft: rgb(245 158 11 / .12);
    --shadow: 0 1px 2px rgb(15 23 42 / .06), 0 8px 24px rgb(15 23 42 / .06);
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--bg); color: var(--text);
    font: 14px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1:focus { outline: none; }
code, .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--text); word-break: break-all; }
.icon { flex: none; vertical-align: -3px; }
.hint { color: var(--muted); font-size: 12.5px; }
.error { color: var(--bad); }
.ok { color: var(--live); }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.only-light { display: none; }
[data-theme="light"] .only-light { display: inline-flex; }
[data-theme="light"] .only-dark { display: none; }
.only-dark, .only-light { align-items: center; gap: 8px; }

/* ---------- nút, ô nhập ---------- */
button, select, input, textarea { font: inherit; color: var(--text); }
button, .btn, a.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2);
    background: var(--panel); color: var(--text); font-weight: 600; font-size: 13.5px;
    cursor: pointer; white-space: nowrap; text-decoration: none; transition: background .15s, border-color .15s, color .15s;
}
button:hover:not(:disabled), .btn:hover { border-color: var(--muted); background: var(--panel-2); text-decoration: none; }
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn-primary, button.on {
    background: var(--primary); border-color: var(--primary); color: #fff;
}
button.primary:hover:not(:disabled), .btn-primary:hover, button.on:hover:not(:disabled) { background: var(--primary-2); border-color: var(--primary-2); }
button.danger, .btn-danger { color: var(--bad); }
button.danger:hover:not(:disabled), .btn-danger:hover { border-color: var(--bad); background: var(--bad-soft); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--panel-2); }
.btn-block { width: 100%; justify-content: flex-start; }
.btn-sm, .table button, .cams button { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
    border-radius: 10px; color: var(--muted); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }

input, select, textarea {
    width: 100%; height: 38px; padding: 0 12px; border-radius: 10px;
    background: var(--bg-2); border: 1px solid var(--line-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
[data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] textarea { background: #fff; }
textarea { height: auto; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); box-shadow: none; }
input[type=file] { height: auto; padding: 7px 10px; }
select { padding-right: 30px; }

/* ---------- khung ứng dụng ---------- */
.shell { display: flex; min-height: 100vh; }
.nav-toggle { display: none; }
.sidebar {
    position: sticky; top: 0; height: 100vh; width: 248px; flex: none;
    display: flex; flex-direction: column; gap: 8px; padding: 16px 12px;
    background: var(--panel); border-right: 1px solid var(--line); z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand span { display: flex; flex-direction: column; font-weight: 700; font-size: 16px; line-height: 1.15; }
.brand small { font-weight: 500; font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side-nav a {
    display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px;
    color: var(--muted); font-weight: 500;
}
.side-nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.side-nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-sep { margin: 14px 12px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.side-foot { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.theme-btn { color: var(--muted); font-weight: 500; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 6px 4px 2px 8px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), var(--accent)); color: #fff; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-meta strong, .user-meta small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--muted); font-size: 11.5px; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page-head {
    display: flex; align-items: center; gap: 14px; padding: 22px 32px 6px; flex-wrap: wrap;
}
.page-title { flex: 1; min-width: 200px; }
.page-title h1 { font-size: 22px; }
.page-title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.menu-btn { display: none; }
.page-body { padding: 16px 32px 40px; display: flex; flex-direction: column; gap: 20px; max-width: 1280px; width: 100%; }

.shell-fluid .page-head { padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.shell-fluid .page-title h1 { font-size: 17px; }
.shell-fluid .page-body { padding: 0; gap: 0; max-width: none; flex: 1; min-height: 0; }
.shell-fluid { height: 100vh; }
.shell-fluid .main { height: 100vh; }

@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
    .nav-toggle:checked ~ .sidebar { transform: none; }
    .nav-toggle:checked ~ .scrim { display: block; position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 20; }
    .menu-btn { display: inline-flex; }
    .page-head { padding: 14px 16px 4px; }
    .page-body { padding: 12px 16px 32px; }
}

/* ---------- thẻ, lưới thống kê ---------- */
.card, .editor {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2, .card-head h3, .editor h3 { font-size: 16px; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.card-head > div { flex: 1; min-width: 200px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 18px 20px 0; }
.editor h3 { margin: 0 0 12px; }
.editor h4 { margin: 18px 0 8px; font-size: 14px; }
.editor > .hint, .card > .hint { margin: -6px 0 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
    display: flex; gap: 14px; align-items: center;
}
.stat .stat-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.stat .stat-icon.green { background: var(--live-soft); color: var(--live); }
.stat .stat-icon.amber { background: var(--warn-soft); color: var(--warn); }
.stat .stat-icon.red { background: var(--bad-soft); color: var(--bad); }
.stat b { display: block; font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat span { color: var(--muted); font-size: 12.5px; }
.meter { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; }
.meter.warn > i { background: var(--warn); }
.meter.bad > i { background: var(--bad); }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; }
.cams, .table { width: 100%; border-collapse: collapse; }
.cams th, .cams td, .table th, .table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cams th, .table th {
    color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
    background: var(--panel-2); white-space: nowrap;
}
.cams tbody tr:hover td, .table tbody tr:hover td { background: var(--panel-2); }
.cams tr:last-child td, .table tr:last-child td { border-bottom: 0; }
.cams .actions, .table .actions { text-align: right; white-space: nowrap; }
.cams .actions button + button, .table .actions button + button { margin-left: 6px; }
.cams tr.off td { opacity: .5; }
.cams.in-card, .card .cams, .card .table { margin: 0; }
.card.flush .cams th:first-child, .card.flush .cams td:first-child { padding-left: 20px; }
.card.flush .cams th:last-child, .card.flush .cams td:last-child { padding-right: 20px; }
.cell-sub { display: block; color: var(--muted); font-size: 12px; }
.total-row td { font-weight: 700; background: var(--panel-2); }

/* ---------- nhãn ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 99px;
    font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.live { background: var(--live-soft); color: var(--live); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--primary-soft); color: var(--primary); }
.tag { font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; margin-left: 4px; }

/* biển số kiểu Việt Nam */
strong.plate, .plate-vn {
    display: inline-block; font: 700 14px/1.2 "Be Vietnam Pro", system-ui, sans-serif; letter-spacing: .04em; font-variant-numeric: tabular-nums;
    background: #fff; color: #111; border: 2px solid #111; border-radius: 6px; padding: 3px 10px; white-space: nowrap;
}

/* ---------- biểu mẫu ---------- */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; margin-bottom: 16px; }
.form.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12.5px; font-weight: 500; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 13.5px; }
.form .full, .form .hint { grid-column: 1 / -1; }
.form label:has(button) { justify-content: flex-end; }
.form .row input { flex: 1; }
.editor .row input, .card .row input { width: auto; flex: 1; min-width: 200px; }
.editor .row select, .card .row select { width: auto; }
.card h4 { margin: 22px 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
@media (max-width: 700px) { .form, .form.cols-3, .form.cols-4 { grid-template-columns: 1fr; } }
.msg { padding: 10px 14px; border-radius: 10px; font-size: 13px; }
.msg.error, p.error.msg { background: var(--bad-soft); }
.msg.ok { background: var(--live-soft); }
.admin > p.error, .page-body > p.error, .page-body > p.ok { padding: 10px 14px; border-radius: 10px; background: var(--bad-soft); margin: 0; }
.page-body > p.ok { background: var(--live-soft); }
.keybox {
    font-family: ui-monospace, monospace; background: var(--bg-2); border: 1px dashed var(--primary);
    padding: 12px 14px; border-radius: 10px; word-break: break-all; margin: 8px 0 14px;
}

/* ---------- trạng thái trống ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state .icon-wrap { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 20px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.empty-state h3 { color: var(--text); font-size: 16px; margin-bottom: 4px; }
.empty-page { margin: auto; padding: 60px 20px; text-align: center; }

/* ---------- lưới camera ---------- */
.grid-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid-tools select { width: auto; height: 34px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 11px; }
.seg button { height: 28px; padding: 0 10px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; font-size: 12.5px; }
.seg button:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.seg button.on { background: var(--primary); color: #fff; }
.pageno { padding: 0 8px; color: var(--muted); font-size: 12.5px; align-self: center; }
.grid-body { flex: 1; display: flex; min-height: 0; background: #05080f; }
.grid {
    flex: 1; display: grid; gap: 6px; padding: 6px;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
}
.grid-empty { margin: auto; }

.tile { position: relative; background: #000; border-radius: 10px; overflow: hidden; min-height: 0; border: 1px solid #1b2436; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; background: #000; }
.tile:fullscreen { border: 0; border-radius: 0; }
.tile-top {
    position: absolute; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 8px 10px 16px; background: linear-gradient(rgb(0 0 0 / .7), transparent); font-size: 13px; pointer-events: none; color: #fff;
}
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; text-shadow: 0 1px 2px #000; }
.tile-state { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; padding: 2px 8px; border-radius: 6px; background: rgb(255 255 255 / .16); white-space: nowrap; }
.tile-live .tile-state { background: var(--bad); color: #fff; }
.tile-offline .tile-state { background: rgb(255 255 255 / .12); color: #cbd5e1; }
.tile-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; color: #94a3b8; font-size: 13px; }
.tile-plate {
    position: absolute; right: 10px; bottom: 10px; padding: 3px 10px; border-radius: 6px;
    font: 700 16px "Be Vietnam Pro", system-ui, sans-serif; letter-spacing: .04em;
    background: #fff; color: #111; border: 2px solid #111;
    animation: plate-in 15s ease-out forwards;
}
.tile-plate small { font: 500 11px "Be Vietnam Pro", system-ui, sans-serif; color: #475569; margin-left: 6px; }
@keyframes plate-in {
    0% { background: var(--plate); transform: scale(1.12); }
    6% { background: var(--plate); transform: scale(1); }
    100% { background: #fff; opacity: .9; }
}

.plates { width: 280px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 14px 14px; }
.plates h3 { font-size: 12px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.plates ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plates li { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.plates li b { font: 700 14px "Be Vietnam Pro", system-ui, sans-serif; background: #fff; color: #111; border: 2px solid #111; border-radius: 5px; padding: 1px 8px; letter-spacing: .04em; }

@media (max-width: 700px) {
    .grid { grid-template-columns: 1fr; grid-auto-rows: auto; overflow-y: auto; }
    .tile { aspect-ratio: 16 / 9; }
    .plates { display: none; }
}

/* ---------- đăng nhập / đăng ký ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
    position: relative; overflow: hidden; padding: 48px 56px; color: #fff; display: flex; flex-direction: column; justify-content: space-between;
    background: radial-gradient(1200px 600px at -10% -10%, #1d4ed8 0%, transparent 60%), radial-gradient(900px 500px at 120% 110%, #0891b2 0%, transparent 55%), #0b1220;
}
.auth-hero .brand { color: #fff; padding: 0; }
.auth-hero .brand small { color: #93c5fd; }
.auth-hero h2 { font-size: 34px; line-height: 1.2; margin: 0 0 14px; max-width: 520px; }
.auth-hero p.lead { color: #cbd5e1; font-size: 15px; max-width: 480px; margin: 0 0 28px; }
.auth-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 14px; }
.auth-features li { display: flex; gap: 12px; align-items: flex-start; color: #e2e8f0; }
.auth-features li .icon-wrap { width: 34px; height: 34px; border-radius: 10px; background: rgb(255 255 255 / .1); display: grid; place-items: center; flex: none; }
.auth-features li small { display: block; color: #94a3b8; }
.auth-hero footer { color: #64748b; font-size: 12px; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 26px; }
.auth-card .sub { color: var(--muted); margin: -8px 0 8px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.auth-card input { height: 44px; }
.auth-card button.primary { height: 44px; font-size: 15px; margin-top: 4px; }
.auth-card .switch { text-align: center; color: var(--muted); margin-top: 6px; }
.auth-mobile-brand { display: none; }
@media (max-width: 900px) {
    .auth { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
    .auth-mobile-brand { display: flex; color: var(--text); padding: 0 0 12px; }
}

/* ---------- phát thử (device-sim) ---------- */
.publish video { width: 100%; max-height: 60vh; background: #000; display: block; }
.publish pre { padding: 8px 12px; color: var(--muted); font-size: 12px; white-space: pre-wrap; }

/* ---------- Blazor ---------- */
.blazor-error-boundary { background: #b32121; padding: 1rem; color: #fff; }
.blazor-error-boundary::after { content: "Đã xảy ra lỗi."; }
