:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --border: #e1e6ee;
  --text: #191919;
  --text-2: #4b5260;
  --accent: #257de0;
  --accent-ink: #ffffff;
  --series-1: #257de0;
  --seq-0: #eef3fa; --seq-1: #cce3fd; --seq-2: #84b9f3; --seq-3: #338ced; --seq-4: #2370cd; --seq-5: #0f4a96;
  --good: #0aac23; --warning: #fbb315; --serious: #f18a59; --critical: #dc3c3d; --muted: #9aa1ad;
  --good-ink: #08731a; --warning-ink: #8a5a00; --critical-ink: #b42324;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --tap: 40px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111214; --surface: #191919; --surface-2: #232427; --border: #2e3035;
    --text: #f2f2f2; --text-2: #b8bcc3; --accent: #338ced; --series-1: #338ced;
    --seq-0: #1f2124; --seq-1: #0e3d7e; --seq-2: #1757ac; --seq-3: #2370cd; --seq-4: #338ced; --seq-5: #84b9f3;
    --good-ink: #4fd165; --warning-ink: #fbc54a; --critical-ink: #f07373;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214; --surface: #191919; --surface-2: #232427; --border: #2e3035;
  --text: #f2f2f2; --text-2: #b8bcc3; --accent: #338ced; --series-1: #338ced;
  --seq-0: #1f2124; --seq-1: #0e3d7e; --seq-2: #1757ac; --seq-3: #2370cd; --seq-4: #338ced; --seq-5: #84b9f3;
  --good-ink: #4fd165; --warning-ink: #fbc54a; --critical-ink: #f07373;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 600; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Khung */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 12px 16px; }
.logo { width: 22px; height: 28px; border-radius: 5px; background: var(--accent); position: relative; }
.logo::after { content: ""; position: absolute; inset: 4px 4px 10px; background: var(--surface); border-radius: 2px; }
.nav a { color: var(--text); text-decoration: none; padding: 9px 12px; border-radius: 8px; font-size: 16px; display: flex; align-items: center; gap: 8px; min-height: var(--tap); }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--surface-2); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.nav-foot { margin-top: auto; padding: 12px; font-size: 14px; color: var(--text-2); display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); }
main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 16px 24px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top h1 { font-size: 24px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .menu.btn { display: none; }
.tenant-pick { max-width: 240px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); }
.live i { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.live.on i { background: var(--good); }
.page { padding: 0 24px 48px; display: flex; flex-direction: column; gap: 20px; }

/* Thành phần */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: 20px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.two { grid-template-columns: 2fr 1fr; }
.half { grid-template-columns: 1fr 1fr; }
.kpi .label { font-size: 15px; color: var(--text-2); font-weight: 500; }
.kpi .value { font-size: 30px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { font-size: 14px; color: var(--text-2); margin-top: 4px; }
.kpi.alert .value { color: var(--critical-ink); }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 16px; min-height: var(--tap); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn.danger { color: var(--critical-ink); }
.btn.icon { padding: 6px 10px; min-width: var(--tap); }
.btn.icon svg { width: 18px; height: 18px; }
.btn.sm { padding: 4px 12px; font-size: 14px; min-height: 34px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid color-mix(in srgb, var(--text-2) 35%, var(--border)); border-radius: 8px; padding: 8px 12px; min-width: 0; min-height: var(--tap); }
textarea { min-height: 80px; line-height: 1.5; }
input[type=checkbox], input[type=radio] { min-height: 0; width: 20px; height: 20px; padding: 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; color: var(--text-2); }
label.check { flex-direction: row; align-items: center; gap: 10px; font-size: 16px; font-weight: 400; color: var(--text); min-height: var(--tap); }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label { min-width: 150px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { font: inherit; background: var(--surface); color: var(--text); border: 0; border-right: 1px solid var(--border); padding: 8px 14px; min-height: var(--tap); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.err { color: var(--critical-ink); min-height: 1em; margin: 0; font-size: 15px; }

/* Bảng */
.table-wrap { overflow-x: auto; margin: 0 -20px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 14px; font-weight: 600; color: var(--text-2); white-space: nowrap; background: var(--surface-2); }
tbody tr:nth-child(even) > td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.empty { color: var(--text-2); text-align: center; padding: 28px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 8px; flex-wrap: wrap; }

/* Trạng thái: luôn có biểu tượng + chữ, không chỉ màu */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; font-weight: 500; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.good::before { background: var(--good); }
.badge.warning::before { background: var(--warning); }
.badge.serious::before { background: var(--serious); }
.badge.critical::before { background: var(--critical); }
.badge.info::before { background: var(--series-1); }
.chip { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); margin: 2px 4px 2px 0; }
.chip.warn { color: var(--warning-ink); }
.chip.bad { color: var(--critical-ink); }

/* Thẻ máy */
.machines { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.mcard { cursor: pointer; display: flex; flex-direction: column; gap: 10px; }
.mcard:hover { border-color: var(--accent); }
.mcard .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mcard .name { font-weight: 600; font-size: 17px; }
.mstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mstats div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.mstats b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.mstats span { font-size: 13px; color: var(--text-2); }

/* Khe hàng */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.slot { border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 14px; }
.slot .no { color: var(--text-2); }
.slot .nm { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .bar { height: 6px; background: var(--surface-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.slot .bar i { display: block; height: 100%; background: var(--series-1); border-radius: 2px; }
.slot.low { border-color: var(--warning); border-width: 2px; }
.slot.empty, .slot.fault { border-color: var(--critical); border-width: 2px; }
.slot.off { opacity: .55; }

/* Biểu đồ */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { fill: var(--text-2); font-size: 13px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--border); stroke-dasharray: 2 3; }
.chart .axis { stroke: var(--border); }
.chart .bar { fill: var(--series-1); }
.chart .bar.dim { opacity: .45; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; }
.chart .band { fill: var(--good); opacity: .08; }
.chart .limit { stroke: var(--critical); stroke-width: 1; stroke-dasharray: 4 3; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.heat { display: grid; grid-template-columns: 52px repeat(24, minmax(14px, 1fr)); gap: 2px; font-size: 12px; color: var(--text-2); min-width: 520px; }
.heat .c { aspect-ratio: 1.4; border-radius: 3px; background: var(--seq-0); }
.heat .h { text-align: center; }
.legend { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-2); }
.legend i { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.15); max-width: 280px; }
.tip b { font-variant-numeric: tabular-nums; }

/* Danh sách sự kiện */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.feed li:last-child { border-bottom: 0; }
.feed time { color: var(--text-2); font-size: 14px; white-space: nowrap; min-width: 96px; font-variant-numeric: tabular-nums; }
.ai p { margin: 0 0 8px; }
.ai-list { margin: 0 0 8px; padding-left: 20px; }
.ai-list li { margin-bottom: 6px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
details.gw { border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; }
details.gw summary { cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
details.gw[open] summary { margin-bottom: 6px; }
code.sel { user-select: all; word-break: break-all; }
.warn-card { border-color: var(--warning); }
.keybox { font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 10px; border-radius: 8px; word-break: break-all; user-select: all; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; z-index: 60; font-size: 15px; max-width: calc(100% - 32px); }

/* Đăng nhập */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; padding: 32px; }
.login-card .btn { min-height: 48px; font-size: 17px; }
.login-card h1 { font-size: 24px; }

/* Phông Be Vietnam Pro (giấy phép SIL OFL, xem fonts/OFL.txt) */
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 400; font-display: swap; src: url(/fonts/be-vietnam-pro-vietnamese-400-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 400; font-display: swap; src: url(/fonts/be-vietnam-pro-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 500; font-display: swap; src: url(/fonts/be-vietnam-pro-vietnamese-500-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 500; font-display: swap; src: url(/fonts/be-vietnam-pro-latin-500-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 600; font-display: swap; src: url(/fonts/be-vietnam-pro-vietnamese-600-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 600; font-display: swap; src: url(/fonts/be-vietnam-pro-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 700; font-display: swap; src: url(/fonts/be-vietnam-pro-vietnamese-700-normal.woff2) format('woff2'); unicode-range: U+0102-0103,U+0110-0111,U+0128-0129,U+0168-0169,U+01A0-01A1,U+01AF-01B0,U+0300-0301,U+0303-0304,U+0308-0309,U+0323,U+0329,U+1EA0-1EF9,U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 700; font-display: swap; src: url(/fonts/be-vietnam-pro-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }

/* Biểu tượng menu (vẽ bằng CSS, không cần sửa HTML) */
.nav a[data-page="tenants"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 21V5a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v16'/%3E%3Cpath d='M16 9h3a1 1 0 0 1 1 1v11'/%3E%3Cpath d='M2 21h20M8 7h4M8 11h4M8 15h4'/%3E%3C/svg%3E"); --ic: #2563eb; }
.nav a[data-page="system"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='6' rx='2'/%3E%3Crect x='3' y='14' width='18' height='6' rx='2'/%3E%3Cpath d='M7 7h.01M7 17h.01'/%3E%3C/svg%3E"); --ic: #0891b2; }
.nav a[data-page="overview"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='3' width='7' height='7' rx='1.5'/%3E%3Crect x='3' y='14' width='7' height='7' rx='1.5'/%3E%3Crect x='14' y='14' width='7' height='7' rx='1.5'/%3E%3C/svg%3E"); --ic: #2563eb; }
.nav a[data-page="machines"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='2' width='14' height='20' rx='2'/%3E%3Cpath d='M8 6h8v7H8zM8 17h4M15.5 17h.5'/%3E%3C/svg%3E"); --ic: #ea580c; }
.nav a[data-page="restock"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 8 12 3 3 8v8l9 5 9-5z'/%3E%3Cpath d='M3 8l9 5 9-5M12 13v8'/%3E%3C/svg%3E"); --ic: #d97706; }
.nav a[data-page="staff"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='4'/%3E%3Cpath d='M2 21a7 7 0 0 1 14 0M16 4a4 4 0 0 1 0 8M22 21a7 7 0 0 0-4-6.3'/%3E%3C/svg%3E"); --ic: #4f46e5; }
.nav a[data-page="products"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20.6 13.4 13.4 20.6a2 2 0 0 1-2.8 0L3 13V3h10l7.6 7.6a2 2 0 0 1 0 2.8z'/%3E%3Cpath d='M7.5 7.5h.01'/%3E%3C/svg%3E"); --ic: #db2777; }
.nav a[data-page="orders"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 3h14v18l-3-2-2 2-2-2-2 2-2-2-3 2z'/%3E%3Cpath d='M9 8h6M9 12h6'/%3E%3C/svg%3E"); --ic: #059669; }
.nav a[data-page="collections"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='20' height='13' rx='2'/%3E%3Ccircle cx='12' cy='12.5' r='2.5'/%3E%3Cpath d='M6 10v.01M18 15v.01'/%3E%3C/svg%3E"); --ic: #16a34a; }
.nav a[data-page="payments"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='5' width='20' height='14' rx='2'/%3E%3Cpath d='M2 10h20M6 15h4'/%3E%3C/svg%3E"); --ic: #7c3aed; }
.nav a[data-page="recon"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v18M5 7h14M5 7l-3 7a3 3 0 0 0 6 0zM19 7l-3 7a3 3 0 0 0 6 0zM8 21h8'/%3E%3C/svg%3E"); --ic: #0d9488; }
.nav a[data-page="invoices"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6M8 13h8M8 17h5'/%3E%3C/svg%3E"); --ic: #0284c7; }
.nav a[data-page="reports"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3v18h18'/%3E%3Cpath d='M8 17v-5M13 17V8M18 17v-9'/%3E%3C/svg%3E"); --ic: #2563eb; }
.nav a[data-page="alerts"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E"); --ic: #dc2626; }
.nav a[data-page="settings"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z'/%3E%3C/svg%3E"); --ic: #64748b; }
.nav a[data-page="security"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E"); --ic: #059669; }
.nav a[data-page="audit"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2'/%3E%3Crect x='9' y='3' width='6' height='4' rx='1'/%3E%3Cpath d='M9 12h6M9 16h4'/%3E%3C/svg%3E"); --ic: #9333ea; }

/* Giao diện: bảng màu, thẻ số liệu có màu, menu có biểu tượng */
:root {
  --bg: #f3f6fb; --surface: #ffffff; --surface-2: #eef2f8; --border: #e2e8f0;
  --text: #0f172a; --text-2: #475569; --accent: #2563eb; --accent-2: #3b82f6; --series-1: #2563eb;
  --head-bg: #2563eb; --head-ink: #ffffff;
  --c-blue: #2563eb; --c-green: #059669; --c-purple: #7c3aed; --c-amber: #d97706; --c-rose: #e11d48;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f19; --surface: #111827; --surface-2: #1a2337; --border: #243049;
    --text: #f1f5f9; --text-2: #a5b1c4; --accent: #3b82f6; --accent-2: #60a5fa; --series-1: #3b82f6;
    --head-bg: #1d3a7a; --head-ink: #e8efff;
    --c-blue: #60a5fa; --c-green: #34d399; --c-purple: #a78bfa; --c-amber: #fbbf24; --c-rose: #fb7185;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f19; --surface: #111827; --surface-2: #1a2337; --border: #243049;
  --text: #f1f5f9; --text-2: #a5b1c4; --accent: #3b82f6; --accent-2: #60a5fa; --series-1: #3b82f6;
  --head-bg: #1d3a7a; --head-ink: #e8efff;
  --c-blue: #60a5fa; --c-green: #34d399; --c-purple: #a78bfa; --c-amber: #fbbf24; --c-rose: #fb7185;
  --shadow: none;
}
body { font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
h2 { font-weight: 700; letter-spacing: -.005em; }

/* Menu trái */
.nav { padding: 18px 14px; gap: 4px; }
.brand { font-size: 18px; letter-spacing: -.01em; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--accent-2), var(--accent)); box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent); }
.logo::after { inset: 8px 10px 12px; border-radius: 2px; background: #fff; }
.nav a { font-weight: 500; color: var(--text-2); gap: 12px; }
.nav a::before { content: ""; flex: none; width: 20px; height: 20px; background: var(--ic, currentColor); -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.nav a:hover { color: var(--text); }
.nav a.on { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.nav a .badge { margin-left: auto; }

/* Thanh tiêu đề trang */
.top h1 { font-size: 26px; font-weight: 700; letter-spacing: -.015em; }
.top h1::before { content: ""; display: inline-block; width: 6px; height: .9em; margin-right: 12px; border-radius: 3px; background: linear-gradient(var(--accent-2), var(--accent)); vertical-align: -.08em; }

/* Thẻ, nút */
.card { border-color: var(--border); }
.btn { border-radius: 10px; }
.btn.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border-color: transparent; box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn.primary:hover { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
input, select, textarea { border-radius: 10px; }
.seg { border-radius: 10px; }

/* Thẻ số liệu: mỗi ô một màu, ô đầu nền xanh đậm */
.kpi { position: relative; overflow: hidden; border-top: 3px solid var(--k); background: linear-gradient(135deg, color-mix(in srgb, var(--k) 9%, var(--surface)), var(--surface) 70%); }
.kpis > .kpi:nth-child(5n+1) { --k: var(--c-blue); }
.kpis > .kpi:nth-child(5n+2) { --k: var(--c-green); }
.kpis > .kpi:nth-child(5n+3) { --k: var(--c-purple); }
.kpis > .kpi:nth-child(5n+4) { --k: var(--c-amber); }
.kpis > .kpi:nth-child(5n+5) { --k: var(--c-rose); }
.kpi .label { color: var(--text); font-weight: 600; }
.kpi .value { color: var(--k); font-weight: 700; }
.kpis > .kpi:first-child { border: 0; background: linear-gradient(135deg, #1e40af, #3b82f6); color: #fff; box-shadow: 0 8px 24px rgba(37, 99, 235, .28); }
.kpis > .kpi:first-child::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; border: 26px solid rgba(255, 255, 255, .08); pointer-events: none; }
.kpis > .kpi:first-child .label, .kpis > .kpi:first-child .value { color: #fff; }
.kpis > .kpi:first-child .sub { color: rgba(255, 255, 255, .85); }
.kpis > .kpi:first-child .badge { background: rgba(255, 255, 255, .92); color: #0f172a; }
.kpi.alert .value { color: var(--critical-ink); }
.kpis > .kpi.alert:first-child .value { color: #fff; }

/* Bảng: dòng tiêu đề nền xanh */
th { background: var(--head-bg); color: var(--head-ink); font-weight: 600; border-bottom: 0; }
.table-wrap > table, .card > table { border-radius: 0; }
tr.click:hover td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }

/* Huy hiệu trạng thái có nền màu nhạt */
.badge.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); }
.badge.warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning-ink); }
.badge.serious { background: color-mix(in srgb, var(--serious) 18%, transparent); color: var(--warning-ink); }
.badge.critical { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical-ink); }
.badge.info { background: color-mix(in srgb, var(--series-1) 14%, transparent); color: var(--accent); }

/* Thẻ máy */
.mcard { border-top: 3px solid var(--accent); }
.mcard:hover { box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 15%, transparent); }

/* Đăng nhập */
.login { background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent), var(--bg); }
.login-card h1::before { content: ""; display: block; width: 44px; height: 44px; margin-bottom: 14px; border-radius: 12px; background: linear-gradient(135deg, var(--accent-2), var(--accent)); }

@media (max-width: 900px) {
  .two, .half { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  :root { --tap: 44px; }
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; z-index: 20; left: 0; top: 0; width: min(300px, 85vw); transform: translateX(-100%); transition: transform .2s; }
  .nav.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .nav a { padding: 11px 14px; font-size: 17px; }
  .top .menu.btn { display: inline-flex; font-size: 20px; }
  .top { padding: 10px 16px; gap: 10px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
  .top h1 { font-size: 20px; }
  .page { padding: 0 12px 32px; gap: 14px; }
  .card { padding: 16px; }
  .table-wrap { margin: 0 -16px; }
  .table-wrap td:first-child { min-width: 8em; }
  th:first-child, td:first-child { padding-left: 16px; }
  th:last-child, td:last-child { padding-right: 16px; }
  .grid { gap: 12px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .label { font-size: 14px; }
  .kpi .value { font-size: 24px; }
  .hide-sm { display: none; }
  .tenant-pick { max-width: 140px; }
  .live span { display: none; }
  /* Ô nhập 16px để iPhone không tự phóng to; bộ lọc 2 cột đều nhau */
  input, select, textarea { font-size: 16px; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .filters > *, .filters label { min-width: 0; }
  .filters input, .filters select, .filters .btn { width: 100%; }
  .filters .seg { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid input, .form-grid select { width: 100%; }
  .filters { align-items: end; }
  .seg { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .seg button { flex: 0 0 auto; }
  .slots { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .actions .btn { flex: 1 1 auto; }
}

/* In danh sách "Cần bổ sung" */
@media print {
  .nav, .top, .btn, select, #route { display: none !important; }
  .shell, main { display: block; }
  .card { break-inside: avoid; box-shadow: none; }
}

/* Giá trên máy khác giá web (trang cài khe) */
.price-diff { color: var(--critical-ink); font-weight: 600; }
.bad-text { color: var(--bad, #c0392b); }
pre.log { max-height: 480px; overflow: auto; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; margin: 0; }
