:root {
    --bg: #0d0f12;
    --panel: #171a1f;
    --line: #2a2f37;
    --text: #e6e8eb;
    --muted: #8a919c;
    --accent: #3b82f6;
    --live: #22c55e;
    --bad: #ef4444;
    --plate: #facc15;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: #c4cad3; word-break: break-all; }
h1:focus { outline: none; }

button, select, input {
    font: inherit; color: var(--text); background: var(--panel);
    border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button.on, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger:hover { border-color: var(--bad); color: var(--bad); }
input { width: 100%; }
input[type=checkbox] { width: auto; }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar .brand { font-size: 15px; margin-right: 6px; }
.spacer { flex: 1; }
.seg { display: inline-flex; gap: 2px; align-items: center; }
.pageno { padding: 0 6px; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.error { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; }
.tag { font-size: 11px; background: var(--line); border-radius: 4px; padding: 0 5px; margin-left: 4px; }

/* ---------- lưới ---------- */
.grid-page { display: flex; flex-direction: column; height: 100vh; }
.grid-body { flex: 1; display: flex; min-height: 0; }
.grid {
    flex: 1; display: grid; gap: 4px; padding: 4px;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-auto-rows: minmax(0, 1fr);
}
.empty { margin: auto; color: var(--muted); }

.tile { position: relative; background: #000; border-radius: 4px; overflow: hidden; min-height: 0; border: 1px solid var(--line); }
.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; gap: 8px;
    padding: 4px 8px; background: linear-gradient(#000a, #0000); font-size: 13px; pointer-events: none;
}
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 1px 2px #000; }
.tile-state { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tile-live .tile-state { color: var(--live); }
.tile-offline .tile-state { color: var(--bad); }
.tile-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; color: var(--muted); }
.tile-plate {
    position: absolute; right: 8px; bottom: 8px; padding: 2px 8px; border-radius: 4px;
    font: 600 16px ui-monospace, Consolas, monospace; letter-spacing: .5px;
    background: #000b; color: var(--plate); border: 1px solid #0000;
    animation: plate-in 15s ease-out forwards;
}
.tile-plate small { font: 11px system-ui, sans-serif; color: var(--muted); margin-left: 4px; }
@keyframes plate-in {
    0% { background: var(--plate); color: #000; transform: scale(1.15); }
    6% { background: var(--plate); color: #000; transform: scale(1); }
    100% { background: #000b; color: var(--plate); opacity: .75; }
}

.plates { width: 260px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 8px 12px; }
.plates h3 { font-size: 13px; margin: 4px 0 8px; color: var(--muted); font-weight: 600; }
.plates ul { list-style: none; margin: 0; padding: 0; }
.plates li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.plates li b { font-family: ui-monospace, Consolas, monospace; color: var(--plate); }

@media (max-width: 700px) {
    .grid { grid-template-columns: 1fr; grid-auto-rows: auto; overflow-y: auto; }
    .tile { aspect-ratio: 16 / 9; }
    .plates { display: none; }
}

/* ---------- quản lý ---------- */
.admin { max-width: 1100px; margin: 0 auto; padding-bottom: 40px; }
.cams { width: 100%; border-collapse: collapse; margin: 12px 0; }
.cams th, .cams td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.cams th { color: var(--muted); font-weight: 500; font-size: 12px; }
.cams tr.off td { opacity: .5; }
.cams .actions { text-align: right; white-space: nowrap; }
.editor { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin: 0 12px; }
.editor h3 { margin-top: 4px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-bottom: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.form label.check { flex-direction: row; align-items: center; color: var(--text); font-size: 14px; }
.form .hint, .form label:has(select) { grid-column: 1 / -1; }
.form .row input { flex: 1; }

/* ---------- đăng nhập / phát thử ---------- */
.login { display: flex; height: 100vh; align-items: center; justify-content: center; }
.login form { display: flex; flex-direction: column; gap: 10px; width: 280px; background: var(--panel); padding: 24px; border-radius: 10px; border: 1px solid var(--line); }
.login h2 { margin: 0 0 8px; font-size: 18px; }
.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-ui { display: none; }
.blazor-error-boundary { background: #b32121; padding: 1rem; color: #fff; }
.blazor-error-boundary::after { content: "Đã xảy ra lỗi."; }
.empty-page { padding: 40px; text-align: center; }
.ok { color: var(--live); }
.nav { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.editor h4 { margin: 16px 0 6px; }
.admin h3 { margin: 18px 12px 6px; }
.admin > .hint, .admin > .error { margin: 0 12px; }
.editor .row input { width: auto; flex: 1; }
.form label:has(button) button { align-self: flex-start; }
