/* BatteryBox Cloud – giao diện quản trị. Màu biểu đồ theo bảng màu đã kiểm định (sáng/tối). */
:root {
  color-scheme: light;
  /* Tông xanh lá chuối – cùng bảng màu với giao diện web của Air Print Server */
  --bg: #eef4e2;
  --surface-1: #fafcf4;
  --surface-2: #f4f9e8;
  --border: #d5e3bf;
  --line2: #e4eed2;
  --text-primary: #1e2b16;
  --text-secondary: #3f5230;
  --text-muted: #5a6b4c;
  --accent: #4e7a2e;
  --accent-d: #2f5a12;
  --accent-soft: #cfe3ae;
  --accent-ink: #1e3a0f;
  --field: #a9be8c;
  --grid: #e4eed2;
  --series-1: #2a78d6; /* blue  – PV / sản lượng PV */
  --series-2: #eb6834; /* orange – tải */
  --series-3: #1baf7a; /* aqua  – lưới */
  --series-4: #eda100; /* yellow – pin */
  --good: #2f8a12;
  --warning: #e0a800;
  --critical: #a13a25;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12190d;
    --surface-1: #1a2314;
    --surface-2: #232e1b;
    --border: #35452a;
    --line2: #2a3820;
    --text-primary: #eaf2dd;
    --text-secondary: #c5d4b0;
    --text-muted: #94a881;
    --accent: #8dbf5f;
    --accent-d: #a6d479;
    --accent-soft: #34492a;
    --accent-ink: #e2f0cc;
    --field: #506640;
    --grid: #2a3820;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --good: #6fc24a;
    --warning: #e0a800;
    --critical: #e0705a;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary); line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }

/* --- khung: thanh bên (máy tính bảng, máy tính) / thanh tab dưới đáy (điện thoại) ---
 * ≥ 1024 px: thanh bên đầy đủ · 768–1023 px: thanh bên chỉ biểu tượng · < 768 px: thanh tab dưới đáy */
.shell { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; }
.side { position: sticky; top: 0; align-self: flex-start; height: 100vh; width: 232px; flex: none; display: flex; flex-direction: column;
  gap: 14px; padding: 16px 12px; background: var(--surface-1); border-right: 1px solid var(--border); z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-weight: 700; color: var(--text-primary); font-size: 1.05rem; }
.brand .bname span { color: var(--accent); font-weight: 600; }
.brand .mark { display: none; width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; align-items: center;
  justify-content: center; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
#nav { flex: 1; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; color: var(--text-muted); font-size: .92rem; }
.side-foot { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px solid var(--border); }
main { max-width: 1240px; margin: 0 auto; padding: 20px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

/* --- nút & form --- */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; background: transparent; color: var(--text-secondary); }
button.danger { color: var(--critical); }
button:disabled { opacity: .5; cursor: default; }
input, select { font: inherit; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--surface-2); font-weight: 600; }

/* --- đăng nhập --- */
.login { max-width: 380px; margin: 12vh auto; }
.login input { width: 100%; margin: 8px 0 12px; }
.error { color: var(--critical); font-size: .9rem; min-height: 1.2em; }

/* --- thẻ số liệu --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-secondary); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 1.6rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: .9rem; font-weight: 500; color: var(--text-secondary); margin-left: 3px; }
.tile .sub { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* --- bảng --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: .82rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0 24px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

/* --- trạng thái (màu + chữ, không chỉ màu) --- */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--text-secondary); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status.online::before { background: var(--good); }
.status.offline::before { background: var(--critical); }
.status.pending::before { background: var(--warning); }
.status.unknown::before { background: var(--text-muted); }

/* --- tab --- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { white-space: nowrap; border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px;
  color: var(--text-secondary); }
.tabs button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }

/* --- biểu đồ --- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .zero { stroke: var(--text-muted); stroke-width: 1; }
.chart .cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .empty { fill: var(--text-muted); font-size: 13px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--text-secondary); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: .82rem; box-shadow: 0 4px 16px rgb(0 0 0 / .12); min-width: 150px; }
.tooltip .t { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .r b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip .r span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary);
  color: var(--surface-1); padding: 8px 16px; border-radius: 8px; font-size: .9rem; z-index: 30; }
.banner { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; font-size: .9rem; }

@media (max-width: 640px) {
  .tile .value { font-size: 1.35rem; }
  .card { padding: 12px; }
}

/* --- chờ duyệt & hộp thoại --- */
.approve { border-color: var(--warning); }
.count { display: inline-block; min-width: 22px; padding: 0 7px; margin-left: 6px; border-radius: 999px; background: var(--warning);
  color: #0b0b0b; font-size: .8rem; text-align: center; vertical-align: middle; }
.approve input[type="checkbox"], th input[type="checkbox"] { width: 16px; height: 16px; }
.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .35); display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px; z-index: 40; }
.modal { width: 100%; max-width: 480px; box-shadow: 0 10px 40px rgb(0 0 0 / .25); }
.modal h2 { margin-bottom: 8px; }

.banner.warn { border-color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface-1)); }

/* --- menu, vai trò --- */
#nav a, #nav .more { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--text-secondary);
  position: relative; background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
#nav a:hover, #nav .more:hover { background: var(--surface-2); text-decoration: none; }
#nav a.active, #nav .more.active { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
#nav a.active .ico { color: var(--accent); }
#nav .more { display: none; }
#nav .ls { display: none; }
#nav .sheet { display: contents; }
#nav .count { margin-left: auto; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.who { font-size: .88rem; display: flex; align-items: center; gap: 8px; min-width: 0; }
.who > a { display: flex; align-items: center; gap: 8px; color: var(--text-primary); min-width: 0; }
.who .wname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); display: inline-flex;
  align-items: center; justify-content: center; font-weight: 600; font-size: .8rem; flex: none; }
#logout { display: flex; align-items: center; gap: 12px; justify-content: flex-start; padding: 9px 10px; }
#logout[hidden] { display: none; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; border: 1px solid var(--border);
  color: var(--text-secondary); background: var(--surface-2); white-space: nowrap; }
.login input { width: 100%; }
fieldset { margin: 0; }

/* Máy tính bảng cỡ vừa: thanh bên thu gọn, chỉ biểu tượng (rê chuột / giữ để xem nhãn) */
@media (min-width: 768px) and (max-width: 1023.98px) {
  .side { width: 68px; padding: 12px 8px; align-items: center; }
  .brand { padding: 0; }
  .brand .bname { display: none; }
  .brand .mark { display: inline-flex; }
  #nav { width: 100%; align-items: center; }
  #nav a { justify-content: center; padding: 10px; width: 44px; height: 44px; }
  #nav .lbl, #logout .lbl, .who .wname, .who .chip { display: none; }
  #nav .count { position: absolute; top: 2px; right: 0; min-width: 18px; margin: 0; padding: 0 5px; font-size: .7rem; }
  .side-foot { align-items: center; width: 100%; }
  #logout { padding: 8px; }
}

/* Điện thoại: thanh trên chỉ có thương hiệu + tài khoản; menu thành thanh tab dưới đáy */
@media (max-width: 767.98px) {
  .shell { flex-direction: column; }
  .side { position: sticky; top: 0; width: auto; height: auto; flex-direction: row; align-items: center; gap: 10px;
    padding: 8px 14px; border-right: 0; border-bottom: 1px solid var(--border); align-self: stretch; }
  .brand { padding: 0; }
  .side-foot { margin-left: auto; flex-direction: row; align-items: center; padding: 0; border: 0; gap: 8px; min-width: 0; }
  .who .wname { max-width: 110px; }
  #logout .lbl { display: none; }
  #logout { padding: 6px 8px; }
  main { padding: 14px 14px calc(76px + env(safe-area-inset-bottom)); }
  #nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 12; flex-direction: row; justify-content: space-around; gap: 0; overflow: visible;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--surface-1); border-top: 1px solid var(--border); }
  #nav a, #nav .more { flex: 1; min-width: 0; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 2px; text-align: center; font-size: .7rem; }
  #nav .lf { display: none; }
  #nav .ls { display: inline; }
  #nav .lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #nav .more { display: flex; }
  #nav .count { position: absolute; top: 0; left: 50%; margin: 0 0 0 6px; min-width: 18px; padding: 0 5px; font-size: .68rem; }
  /* mục phụ: bảng nổi phía trên thanh tab, chỉ hiện khi bấm "Thêm" */
  #nav .sheet { display: none; position: absolute; right: 8px; bottom: calc(100% + 8px); width: 220px; flex-direction: column; padding: 6px;
    background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 28px rgb(0 0 0 / .22); }
  #nav.open .sheet { display: flex; }
  #nav .sheet a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px; font-size: .92rem; text-align: left; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* khu thiết bị chưa có chủ */
.unowned { border-color: var(--accent); }
.unowned > summary { cursor: pointer; list-style: none; gap: 12px; }
.unowned > summary::-webkit-details-marker { display: none; }
.unowned > summary::before { content: '▸'; color: var(--text-muted); }
.unowned[open] > summary::before { content: '▾'; }
.unowned[open] > summary { margin-bottom: 4px; }
.unowned input[type="checkbox"] { width: 16px; height: 16px; }
.owner-picker { gap: 8px; }

/* mã license + QR */
.qr-box svg { display: block; border-radius: 6px; }
.key-big { font-weight: 700; font-size: 1.05rem; letter-spacing: .02em; word-break: break-all; margin-bottom: 4px; }

/* Lịch sử phát triển */
.cl-rel { display: flex; flex-direction: column; gap: 10px; }
.cl-head { align-items: center; gap: 10px; }
.cl-head h2 { margin: 0; }
.cl-title { font-weight: 600; }
.cl-sec h3 { font-size: .9rem; margin: 6px 0 4px; }
.cl-sec ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 3px; font-size: .9rem; }
.cl-added h3 { color: var(--good); }
.cl-fixed h3 { color: var(--critical); }
.cl-notes { border-left: 3px solid var(--warning); padding-left: 10px; }

/* sản phẩm dùng chung cloud */
.chip.prod-printserver { border-color: #7a5af8; color: #5b3fd0; }
.chip.prod-atc-hass { border-color: var(--border); }

/* ---------- tông xanh lá chuối: các thành phần theo kiểu Air Print Server ---------- */
a:hover { color: var(--accent-d); }
.brand .mark { background: var(--accent-soft); color: var(--accent-d); border-radius: 12px; width: 38px; height: 38px; }
.card, .tile { border-radius: 16px; }
.card { padding: 20px; }
.banner { border-radius: 12px; }
#nav a, #nav .more { height: 44px; border-radius: 10px; font-weight: 500; color: var(--text-secondary); }
#nav a:hover, #nav .more:hover { background: var(--line2); }
#nav a.active, #nav .more.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
#nav a.active .ico { color: var(--accent-ink); }
.side-foot { border-top-color: var(--border); }
button, .btn { border-color: var(--field); border-radius: 10px; }
button:hover { background: var(--line2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-d); border-color: var(--accent-d); filter: none; }
@media (prefers-color-scheme: dark) { button.primary { color: #10180a; } button.primary:hover { color: #10180a; } }
button.ghost { border-color: transparent; }
button.ghost:hover { background: var(--line2); }
button.danger { color: var(--critical); border-color: var(--border); }
input, select { border-color: var(--field); border-radius: 10px; background: #fff; }
@media (prefers-color-scheme: dark) { input, select { background: var(--surface-2); } }
.seg { border: 0; background: var(--line2); padding: 4px; gap: 4px; border-radius: 12px; }
.seg button { border: 0 !important; border-radius: 9px; background: transparent; color: var(--text-secondary); font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--accent-ink); box-shadow: 0 1px 2px rgb(30 43 22 / .12); }
.tabs button[aria-selected="true"] { color: var(--accent-ink); border-bottom-color: var(--accent); }
tbody tr.link:hover { background: var(--line2); }
th { color: var(--text-muted); }
.chip { background: var(--line2); }
.count { background: var(--warning); color: #2b2100; }
.modal { border-radius: 16px; }
.banner.warn { border-color: var(--warning); }
.unowned { border-color: var(--accent); }
@media (max-width: 767.98px) {
  #nav a, #nav .more { height: auto; border-radius: 12px; }
  #nav a.active, #nav .more.active { background: var(--accent-soft); }
  #nav .sheet a { height: auto; }
}
