/* Website giám sát đếm hàng OB1/OB2 – responsive (iPhone, Android, tablet, PC), sáng/tối theo hệ thống */
:root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --text: #191919;
  --text-2: #666666;
  --border: rgba(11, 11, 11, 0.1);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --accent: #257de0;
  --accent-ink: #ffffff;
  --series-1: #257de0;
  --series-2: #f47230;
  --good: #0aac23;
  --good-text: #006c10;
  --warning: #fbb315;
  --critical: #dc3c3d;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --surface-2: #222222;
    --text: #efefef;
    --text-2: #9c9c9c;
    --border: rgba(255, 255, 255, 0.1);
    --grid: #303030;
    --axis: #474747;
    --accent: #338ced;
    --series-1: #338ced;
    --series-2: #e76624;
    --good-text: #53c556;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- khung trang ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px calc(10px) 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--text-2); font-weight: 500; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.tabs {
  position: sticky; top: 53px; z-index: 19;
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; text-decoration: none;
  color: var(--text-2); font-weight: 600; font-size: 14px;
}
.tabs a.active { background: var(--accent); color: var(--accent-ink); }
main { max-width: 1200px; margin: 0 auto; padding: 16px 12px 48px; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head .muted { font-size: 13px; }

/* ---------- thẻ ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; min-width: 0;
}
.card > h3 { display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 12px; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .label { color: var(--text-2); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 30px; font-weight: 700; margin-top: 4px; letter-spacing: -0.01em; }
.kpi .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }

/* ---------- 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; padding: 2px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-2); }
.badge.good::before { background: var(--good); }
.badge.warn::before { background: var(--warning); }
.badge.bad::before { background: var(--critical); }
.badge.info::before { background: var(--accent); }
.dev-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.rssi { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; vertical-align: -2px; margin-right: 4px; }
.rssi i { width: 4px; background: var(--grid); border-radius: 1px; }
.rssi i.on { background: var(--text); }
.rssi i:nth-child(1) { height: 25%; } .rssi i:nth-child(2) { height: 50%; }
.rssi i:nth-child(3) { height: 75%; } .rssi i:nth-child(4) { height: 100%; }
.alert { border-left: 4px solid var(--warning); background: var(--surface-2); padding: 8px 12px; border-radius: 8px; margin: 8px 0; font-size: 14px; }
.alert.bad { border-left-color: var(--critical); }
.alert.good { border-left-color: var(--good); }

/* ---------- form ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field.grow { flex: 1 1 220px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  min-height: 38px; max-width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input[type="checkbox"] { min-height: auto; width: 18px; height: 18px; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--critical); color: #fff; }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.form-grid .field { min-width: 0; }
.hint { font-size: 12px; color: var(--text-2); }

/* ---------- bảng ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--surface); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; color: var(--text-2); font-weight: 700; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }

/* ---------- biểu đồ ---------- */
.chart-box { position: relative; height: 260px; }
.chart-title { font-weight: 700; margin-bottom: 2px; }
.chart-sub { color: var(--text-2); font-size: 13px; margin-bottom: 8px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

/* ---------- đăng nhập ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ---------- thông báo ---------- */
#toasts { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100;
  display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--page); box-shadow: 0 4px 16px rgba(0,0,0,0.2); font-size: 14px; }
.toast.error { background: var(--critical); color: #fff; }
.toast.ok { background: var(--good-text); color: #fff; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(560px, 94vw); padding: 18px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.secret { padding: 10px; background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; user-select: all; }
details > summary { cursor: pointer; color: var(--text-2); font-size: 13px; }

@media (max-width: 640px) {
  body { font-size: 14px; }
  .kpi .value { font-size: 26px; }
  .tabs { top: 0; position: relative; }
  .topbar { position: relative; }
  .chart-box { height: 220px; }
  .field { min-width: 46%; flex: 1 1 46%; }
}
@media print {
  .topbar, .tabs, .toolbar, .btn, #toasts { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
