/* HMMart — hệ thiết kế. Token màu ở :root (nền trắng); nền đen ở :root[data-theme="dark"], chọn bằng nút trên thanh trên. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ee;
  --text: #1b2733;
  --muted: #637083;
  --brand: #0f766e;
  --brand-600: #0b5e58;
  --brand-50: #e6f4f2;
  --pos: #15803d;
  --neg: #b91c1c;
  --warn-bg: #fff4d6;
  --chart-1: #0f766e;
  --chart-2: #d97706;
  --chart-3: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar-w: 248px;
  color-scheme: light;
}
/* Nền đen: theme.js đặt data-theme="dark" (theo lựa chọn của người dùng hoặc theo hệ thống). */
:root[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #171d24;
  --surface-2: #1c232b;
  --border: #2a333d;
  --text: #e6ebf0;
  --muted: #93a1b1;
  --brand: #2dd4bf;
  --brand-600: #5eead4;
  --brand-50: #12302d;
  --pos: #4ade80;
  --neg: #f87171;
  --warn-bg: #3a2f10;
  --chart-1: #2dd4bf;
  --chart-2: #fbbf24;
  --chart-3: #60a5fa;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }

.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Khung ---------- */
.app { display: flex; min-height: 100%; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 40; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; font-weight: 700; font-size: 18px; color: var(--text); }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 14px; }
.nav { padding: 4px 12px 24px; }
.nav-title { margin: 18px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-50); color: var(--brand-600); }
.nav .tag { margin-left: auto; font-size: 10px; padding: 1px 6px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.nav a.disabled { color: var(--muted); cursor: default; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 30; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar .spacer { flex: 1; }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.user strong { color: var(--text); font-weight: 600; }
.burger { display: none; }
.content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------- Thành phần ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h h2 { font-size: 15px; font-weight: 700; }
.card-b { padding: 18px; }
.stack > * + * { margin-top: 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; min-height: 40px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
:root[data-theme="dark"] .btn-primary { color: #04201d; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.theme-float { position: fixed; top: 14px; right: 14px; z-index: 50; }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; align-items: end; }
.field label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .tools input, .tools select {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
.field input:focus, .field select:focus, .tools input:focus, .tools select:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.filters .actions { display: flex; gap: 10px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value { margin-top: 4px; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .sub { margin-top: 2px; color: var(--muted); font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

.alert { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.alert-danger { border-color: var(--neg); color: var(--neg); }
.alert-warning { background: var(--warn-bg); }
.alert-success { border-color: var(--pos); }
.alert-info { background: var(--brand-50); }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- Bảng ---------- */
.tools { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.tools input { max-width: 280px; }
.tools select { width: auto; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl td.wrap { white-space: normal; min-width: 220px; }
.tbl thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.tbl th[data-sort] { cursor: pointer; user-select: none; }
.tbl th[data-sort]::after { content: " ↕"; opacity: .35; }
.tbl th[aria-sort="ascending"]::after { content: " ↑"; opacity: 1; }
.tbl th[aria-sort="descending"]::after { content: " ↓"; opacity: 1; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl tfoot td { font-weight: 700; background: var(--surface-2); }
.tbl tr.low td { color: var(--neg); }
.tbl td.flag { background: var(--warn-bg); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 18px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.pager .btns { display: flex; gap: 6px; }

.tbl tbody tr[data-detail] { cursor: pointer; }
.tbl tbody tr.open > td { border-bottom-color: transparent; }
.tbl tr.detail > td { background: var(--surface-2); padding: 12px 18px; white-space: normal; }
.tbl tr.up td { background: color-mix(in srgb, var(--neg) 9%, transparent); }
.tbl tr.down td { background: color-mix(in srgb, var(--pos) 9%, transparent); }
.tbl tr.up td.trend { color: var(--neg); font-weight: 700; }
.tbl tr.down td.trend { color: var(--pos); font-weight: 700; }
.detail-tbl { background: var(--surface); }
.legend { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-left: 8px; }
.dot.up { background: var(--neg); } .dot.down { background: var(--pos); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.tbl tr.warn td { background: var(--warn-bg); }
.dot.warn { background: #d99a00; }
.cell-input { min-height: 34px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.cell-input.num { width: 150px; text-align: right; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2::after { content: " ▾"; color: var(--muted); }
.chart-box { position: relative; height: 320px; }
.chart-box.short { height: 220px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 26px 0 10px; }
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.login-card .brand { padding: 0 0 18px; }
.flashes { display: grid; gap: 10px; margin-bottom: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Điện thoại / máy tính bảng ---------- */
@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .overlay { display: block; }
  .main { margin-left: 0; }
  .burger { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .user span.name { display: none; }
}
@media (max-width: 575px) {
  .kpi .value { font-size: 20px; }
  .chart-box { height: 260px; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
@media print { .sidebar, .topbar, .filters, .tools, .pager, .no-print { display: none !important; } .main { margin: 0; } }
