/* Giao diện kiểu TailAdmin: sidebar trắng, nhấn xanh dương, card viền mảnh. */
:root, [data-theme="light"] {
  color-scheme: light;
  --bg: #f1f5f9; --card: #ffffff; --line: #e2e8f0; --text: #0f172a; --muted: #64748b;
  --primary: #2563eb; --primary-ink: #ffffff; --primary-soft: #eff6ff; --primary-text: #1d4ed8;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2;
  --input: #ffffff; --shadow: 0 1px 2px rgba(15,23,42,.06);
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120; --card: #111827; --line: #1f2937; --text: #e5e7eb; --muted: #94a3b8;
  --primary: #2563eb; --primary-ink: #ffffff; --primary-soft: #172554; --primary-text: #93c5fd;
  --ok: #4ade80; --ok-soft: #052e16; --warn: #fbbf24; --warn-soft: #422006; --bad: #f87171; --bad-soft: #450a0a;
  --input: #0b1120; --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--primary-text); text-decoration: none; }
button, select, input, label[for], .clickable, [role="button"] { font: inherit; }
button, select, .clickable, [role="button"], label.switch, a { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
svg.i { width: 18px; height: 18px; flex: 0 0 auto; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- khung ---- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--card); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand-logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.nav a:hover { background: var(--bg); }
.nav a.on { background: var(--primary-soft); color: var(--primary-text); }
.side-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: var(--card); border-bottom: 1px solid var(--line); height: 60px; padding: 0 24px; padding-top: env(safe-area-inset-top); display: flex; align-items: center; gap: 12px; }
.top h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); display: grid; place-items: center; }
.icon-btn:hover { background: var(--bg); }
.content { padding: 24px; width: 100%; max-width: 1400px; }
.bottom { display: none; }

/* ---- thẻ ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.card-h .ic { width: 36px; height: 36px; border-radius: 10px; background: var(--primary-soft); color: var(--primary-text); display: grid; place-items: center; }
.card-h h2 { margin: 0; font-size: 15px; }
.card-h p { margin: 0; font-size: 13px; color: var(--muted); }
.card-b { padding: 18px; }
.grid { display: grid; gap: 16px; align-items: start; }
@media (min-width: 1024px) { .g2 { grid-template-columns: 1fr 1fr; } }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { padding: 16px 18px; display: flex; align-items: center; gap: 14px; }
.kpi .ic { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); }
.kpi b { display: block; font-size: 24px; line-height: 1.1; }
.kpi span { font-size: 13px; color: var(--muted); }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { margin: 0; font-size: 16px; }

/* ---- danh sách đồng hồ ---- */
.clocks { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.clock { padding: 18px; display: flex; flex-direction: column; gap: 12px; transition: border-color .15s; }
.clock:hover { border-color: var(--primary); }
.clock-top { display: flex; align-items: center; gap: 10px; }
.clock-top h3 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.led { background: #0b0b0b; color: #ff3b30; border-radius: 10px; padding: 10px 14px; font: 700 26px/1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 3px; text-align: center; text-shadow: 0 0 8px rgba(255,59,48,.6); }
.meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.meta span { display: inline-flex; align-items: center; gap: 5px; }
.meta svg.i { width: 15px; height: 15px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--bg); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ic { width: 56px; height: 56px; border-radius: 16px; background: var(--primary-soft); color: var(--primary-text); display: inline-grid; place-items: center; margin-bottom: 12px; }
.empty .ic svg.i { width: 26px; height: 26px; }
.empty h3 { color: var(--text); margin: 0 0 6px; }

/* ---- form ---- */
.field { position: relative; display: block; }
.field > svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input, select.input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--input); color: var(--text); padding: 0 12px 0 40px; outline: none; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input::placeholder { color: var(--muted); }
.stack { display: grid; gap: 12px; }
.row2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-weight: 600; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--bg); }
.btn.pri { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.pri:hover:not(:disabled) { background: #1d4ed8; }
.btn.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn.danger:hover:not(:disabled) { background: #991b1b; }
.btn.ghost-danger { color: var(--bad); }
.btn.block { width: 100%; }
.slider { display: grid; grid-template-columns: 1fr 44px; gap: 12px; align-items: center; }
.slider input { width: 100%; accent-color: var(--primary); }
.slider output { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.lbl { font-size: 13px; font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }

/* công tắc gạt: ô thật là checkbox role=switch, phần nhìn do span phía sau vẽ */
label.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
label.switch + label.switch { border-top: 1px solid var(--line); }
label.switch .t { display: flex; align-items: center; gap: 10px; font-weight: 500; }
label.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
label.switch .sw { width: 44px; height: 24px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .15s; flex: 0 0 auto; }
[data-theme="dark"] label.switch .sw { background: #334155; }
label.switch .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
label.switch input:checked + .sw { background: var(--primary); }
label.switch input:checked + .sw::after { transform: translateX(20px); }
label.switch input:focus-visible + .sw { box-shadow: 0 0 0 3px var(--primary-soft); }

/* ô chọn có tìm kiếm */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line); border-radius: 10px; max-height: 280px; overflow-y: auto; overflow-x: hidden; box-shadow: 0 10px 30px rgba(15,23,42,.15); padding: 4px; }
.combo-list div { padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.combo-list div.act, .combo-list div:hover { background: var(--primary-soft); color: var(--primary-text); }
.combo-list .none { color: var(--muted); cursor: default; }

/* thông tin dạng bảng 2 cột */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.notes { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.notes li + li { margin-top: 4px; }
.fw-item { padding: 16px 18px; }
.fw-item + .fw-item { border-top: 1px solid var(--line); }
.fw-item h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.savebar { position: sticky; bottom: 0; z-index: 15; display: flex; justify-content: flex-end; gap: 10px; padding: 14px 0; margin-top: 16px; background: linear-gradient(transparent, var(--bg) 35%); }

/* ---- đăng nhập ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 400px; padding: 28px; }
.login h1 { margin: 12px 0 4px; font-size: 22px; }
.login .brand-logo { width: 48px; height: 48px; border-radius: 14px; }

/* ---- modal ---- */
.ov { position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.5); display: grid; place-items: center; padding: 16px; }
.dlg { background: var(--card); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 480px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dlg-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dlg-h h2 { margin: 0; font-size: 16px; flex: 1; }
.dlg-b { padding: 18px; }
.dlg-f { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }

/* ---- thông báo ---- */
#toasts { position: fixed; z-index: 80; right: 16px; bottom: 16px; display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(15,23,42,.18); font-size: 14px; }
.toast.ok svg.i { color: var(--ok); }
.toast.err { border-color: var(--bad); }
.toast.err svg.i { color: var(--bad); }
.toast span { flex: 1; }
.toast button { background: none; border: 0; color: var(--muted); padding: 0; }

.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ---- điện thoại: thanh trên gọn + thanh dưới kiểu app ---- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .top { padding: 0 16px; padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); }
  .content { padding: 16px; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .kpis { gap: 10px; }
  .kpi { flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px; }
  .kpi .ic { width: 36px; height: 36px; }
  .kpi b { font-size: 20px; }
  .bottom { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom a, .bottom button { height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); background: none; border: 0; }
  .bottom .on { color: var(--primary-text); }
  .bottom svg.i { width: 22px; height: 22px; }
  .savebar { bottom: calc(64px + env(safe-area-inset-bottom)); }
  #toasts { bottom: calc(80px + env(safe-area-inset-bottom)); }
  .row2 { grid-template-columns: 1fr; }
}
