[hidden] { display: none !important; }
/* IoT Home Hub - giao dien */
:root {
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #f8f9fc; --ink: #141a26; --ink-2: #4a5468; --muted: #7b8498;
  --line: #e4e8f0; --line-2: #d5dbe6;
  --brand: #2f6bff; --brand-ink: #ffffff; --brand-soft: #e9f0ff;
  --good: #12a150; --good-soft: #e6f6ed; --warn: #d97706; --warn-soft: #fdf3e2; --bad: #e0342f; --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --radius: 14px; --side: 236px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --panel: #151b24; --panel-2: #1a212c; --ink: #e8ecf3; --ink-2: #b4bccb; --muted: #8a93a6;
    --line: #242c38; --line-2: #2f3846; --brand: #5b8cff; --brand-soft: #1b2944;
    --good-soft: #10291c; --warn-soft: #2f2210; --bad-soft: #321616; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #151b24; --panel-2: #1a212c; --ink: #e8ecf3; --ink-2: #b4bccb; --muted: #8a93a6;
  --line: #242c38; --line-2: #2f3846; --brand: #5b8cff; --brand-soft: #1b2944;
  --good-soft: #10291c; --warn-soft: #2f2210; --bad-soft: #321616; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14.5px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--brand); }

/* ---- khung ---- */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 15.5px; }
.brand .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.brand .logo svg { width: 18px; height: 18px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--ink-2); cursor: pointer; border: 0; background: none; width: 100%; text-align: left; font-weight: 500; }
.nav-item:hover { background: var(--panel-2); color: var(--ink); }
.nav-item.on { background: var(--brand-soft); color: var(--brand); }
.nav-item .count { margin-left: auto; background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 0 7px; line-height: 19px; }
.side .spacer { flex: 1; }
.side .user { display: flex; align-items: center; gap: 10px; padding: 10px; border-top: 1px solid var(--line); margin-top: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; flex: none; }
.user .who { flex: 1; min-width: 0; line-height: 1.25; }
.user .who b { display: block; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .who span { font-size: 12px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: -.01em; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.content { padding: 24px 28px 48px; max-width: 1360px; width: 100%; }
.alertbar { display: none; align-items: center; gap: 12px; margin: 16px 28px 0; padding: 12px 16px; border-radius: 12px; background: var(--bad); color: #fff; font-weight: 500; }
.alertbar.show { display: flex; }
.alertbar span { flex: 1; }
.alertbar button { background: rgba(255,255,255,.18); color: #fff; border: 0; }

/* ---- thanh phan ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13.5px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); color: var(--ink); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { margin: 0; font-size: 15px; flex: 1; }
.card-b { padding: 14px 18px 18px; }
.section-h { display: flex; align-items: center; gap: 10px; margin: 28px 0 12px; }
.section-h:first-child { margin-top: 0; }
.section-h h2 { margin: 0; font-size: 15px; flex: 1; }
.section-h .sub { color: var(--muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; display: flex; gap: 14px; align-items: flex-start; }
.kpi .ic { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.kpi .ic.good { background: var(--good-soft); color: var(--good); } .kpi .ic.warn { background: var(--warn-soft); color: var(--warn); } .kpi .ic.bad { background: var(--bad-soft); color: var(--bad); }
.kpi .lbl { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .val { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi .val small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.kpi .hint { font-size: 12px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.two { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }

.dev { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.dev-h { display: flex; align-items: flex-start; gap: 12px; }
.dev-ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--panel-2); color: var(--ink-2); flex: none; }
.dev-ic.on { background: var(--brand-soft); color: var(--brand); }
.dev-ic.alarm { background: var(--bad-soft); color: var(--bad); }
.dev-t { flex: 1; min-width: 0; }
.dev-t b { display: block; font-size: 14.5px; line-height: 1.3; }
.dev-t span { font-size: 12px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); } .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); } .badge.brand { background: var(--brand-soft); color: var(--brand); }
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px dashed var(--line); font-size: 13.5px; }
.row:first-child { border-top: 0; }
.row .k { color: var(--ink-2); }
.row .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.v.alarm { color: var(--bad); }

/* cong tac */
.switch { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line-2); border: 0; cursor: pointer; transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(18px); }
.switch:disabled { opacity: .5; cursor: default; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip { border: 1px solid var(--line-2); background: var(--panel); padding: 6px 13px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--panel); }

/* camera */
.cams { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.cam { position: relative; border-radius: var(--radius); overflow: hidden; background: #0b0e13; aspect-ratio: 16/9; cursor: pointer; border: 1px solid var(--line); }
.cam img, .cam iframe { width: 100%; height: 100%; object-fit: cover; border: 0; display: block; }
.cam .ov { position: absolute; inset: auto 0 0 0; padding: 26px 12px 10px; background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.cam .ov span { flex: 1; }
.cam .tag { position: absolute; top: 10px; left: 10px; background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; }
.cam .empty-cam { position: absolute; inset: 0; display: grid; place-items: center; color: #8a93a6; font-size: 13px; }

/* bang */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.t td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t td.actions { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }

/* tab quan tri */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tab { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 7px; align-items: center; }
.tab.on { color: var(--brand); border-color: var(--brand); }

/* form */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.in, select.in, textarea.in { width: 100%; border: 1px solid var(--line-2); background: var(--panel); border-radius: 10px; padding: 9px 12px; outline: none; }
.in:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.in { min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.in.sm { padding: 6px 9px; border-radius: 8px; font-size: 13px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.note { padding: 12px 14px; border-radius: 10px; background: var(--brand-soft); color: var(--ink-2); font-size: 13px; }
.note.warn { background: var(--warn-soft); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10,14,20,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 16px; width: min(760px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.wide { width: min(1100px, 100%); }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-h h3 { margin: 0; flex: 1; font-size: 16px; }
.modal-b { padding: 20px; overflow: auto; }
.modal-f { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal .live-view { aspect-ratio: 16/9; background: #000; border-radius: 10px; overflow: hidden; }
.modal .live-view iframe { width: 100%; height: 100%; border: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 18px; border-radius: 10px; font-weight: 500; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty svg { width: 34px; height: 34px; margin-bottom: 8px; opacity: .6; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.list-item .t { flex: 1; min-width: 0; }
.list-item .t b { font-size: 13.5px; font-weight: 600; display: block; }
.list-item .t span { font-size: 12.5px; color: var(--muted); }
.sev { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--brand); }
.sev.critical { background: var(--bad); } .sev.warning { background: var(--warn); }
.subgrid { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }

/* dang nhap */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 10% -10%, var(--brand-soft), transparent), var(--bg); }
.login { width: min(400px, 100%); padding: 32px 28px; }
.login .brand { padding: 0 0 22px; font-size: 18px; }
.login .field { margin-bottom: 14px; }
.login .btn { width: 100%; padding: 11px; }

/* di dong */
.mnav { display: none; }
.mobile-only { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .top { padding: 12px 16px; }
  .content { padding: 16px 16px 96px; }
  .alertbar { margin: 12px 16px 0; }
  .two { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .mnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .mnav button { flex: 1; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; padding: 4px 0; cursor: pointer; position: relative; }
  .mnav button.on { color: var(--brand); }
  .mnav .count { position: absolute; top: 0; right: 22%; background: var(--bad); color: #fff; font-size: 10px; border-radius: 999px; padding: 0 5px; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi { padding: 12px; gap: 10px; }
  .kpi .ic { width: 34px; height: 34px; }
  .kpi .val { font-size: 19px; }
  .grid, .cams { grid-template-columns: 1fr; }
  .modal-bg { padding: 0; align-items: end; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
}
