/* ================= Tokens ================= */
:root {
  color-scheme: light;
  --bg: #f3f5f4;
  --surface: #fcfcfb;
  --surface-2: #eef2f1;
  --surface-3: #e4eae8;
  --border: #dde3e1;
  --border-strong: #c3ccc9;
  --text: #0f1715;
  --text-2: #4a5552;
  --muted: #7d8783;
  --accent: #0d7a66;
  --accent-hover: #0a6656;
  --accent-weak: #e0f1ec;
  --accent-ink: #ffffff;
  --danger: #c23a3a;
  --danger-weak: #fbe9e9;
  --warn: #9a6200;
  --warn-weak: #fdf1d8;
  --ok: #157a3c;
  --ok-weak: #e3f4e8;
  --info: #2462b3;
  --info-weak: #e5eefb;
  --violet: #5b48c9;
  --violet-weak: #ece9fb;
  --shadow: 0 1px 2px rgba(15, 23, 21, .06), 0 4px 16px rgba(15, 23, 21, .06);
  --shadow-lg: 0 10px 40px rgba(15, 23, 21, .18);
  --radius: 10px;
  --radius-sm: 7px;
  /* biểu đồ */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --sidebar-w: 236px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1110;
    --surface: #1a1a19;
    --surface-2: #222524;
    --surface-3: #2b302e;
    --border: #2e3432;
    --border-strong: #414946;
    --text: #eef2f0;
    --text-2: #bcc5c1;
    --muted: #8a9490;
    --accent: #36b39a;
    --accent-hover: #4cc4ab;
    --accent-weak: #16352f;
    --accent-ink: #06201b;
    --danger: #ec6b6b;
    --danger-weak: #3a1d1d;
    --warn: #f0b440;
    --warn-weak: #3a2d12;
    --ok: #4cc77a;
    --ok-weak: #15301f;
    --info: #6aa5f0;
    --info-weak: #172a44;
    --violet: #a59af0;
    --violet-weak: #262046;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .55);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2c2c2a;
    --baseline: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1110;
  --surface: #1a1a19;
  --surface-2: #222524;
  --surface-3: #2b302e;
  --border: #2e3432;
  --border-strong: #414946;
  --text: #eef2f0;
  --text-2: #bcc5c1;
  --muted: #8a9490;
  --accent: #36b39a;
  --accent-hover: #4cc4ab;
  --accent-weak: #16352f;
  --accent-ink: #06201b;
  --danger: #ec6b6b;
  --danger-weak: #3a1d1d;
  --warn: #f0b440;
  --warn-weak: #3a2d12;
  --ok: #4cc77a;
  --ok-weak: #15301f;
  --info: #6aa5f0;
  --info-weak: #172a44;
  --violet: #a59af0;
  --violet-weak: #262046;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .55);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #2c2c2a;
  --baseline: #383835;
}

/* ================= Base ================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.center { text-align: center; }
.grow { flex: 1 1 auto; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ================= Buttons & inputs ================= */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; font-weight: 550; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .input:focus-visible, .icon-btn:focus-visible, .nav a:focus-visible, .tab:focus-visible, .seg button:focus-visible, .switch input:focus-visible + span {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.btn-danger:hover { background: var(--danger-weak); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn svg, .icon-btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input {
  height: 34px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); min-width: 0;
}
textarea.input { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 28px; }
.input:focus { border-color: var(--accent); }
.input[readonly], .input:disabled { background: var(--surface-2); color: var(--text-2); }
label.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
label.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch > span {
  width: 36px; height: 20px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border-strong);
  position: relative; transition: background .15s; flex: none;
}
.switch > span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s;
}
.switch input:checked + span { background: var(--ok); border-color: var(--ok); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:disabled + span { opacity: .55; }
.switch em { font-style: normal; font-size: 12.5px; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; height: 32px; padding: 0 14px; cursor: pointer; color: var(--text-2); font-weight: 550; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent-weak); color: var(--accent); }

/* ================= Badges ================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 11px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.st-moi { background: var(--surface-3); color: var(--text-2); }
.st-dat_lich, .ap-cho { background: var(--info-weak); color: var(--info); }
.st-dang_lam { background: var(--accent-weak); color: var(--accent); }
.st-hoi_lai { background: var(--violet-weak); color: var(--violet); }
.st-hoan_thanh, .ap-da_den { background: var(--ok-weak); color: var(--ok); }
.st-ngung, .ap-khong_den { background: var(--danger-weak); color: var(--danger); }
.ap-huy { background: var(--surface-3); color: var(--muted); text-decoration: line-through; }
.badge.warn { background: var(--warn-weak); color: var(--warn); }
.badge.role-admin { background: var(--violet-weak); color: var(--violet); }
.badge.role-letan { background: var(--info-weak); color: var(--info); }
.badge.role-bacsi { background: var(--accent-weak); color: var(--accent); }
.masked { color: var(--muted); font-style: italic; white-space: nowrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; }

/* ================= Login ================= */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; }
.login-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login-card .brand .logo { width: 40px; height: 40px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .btn { height: 40px; }
.form-error { color: var(--danger); background: var(--danger-weak); padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; }

/* ================= Layout ================= */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.brand .logo svg { width: 20px; height: 20px; }
.brand b { display: block; font-size: 14px; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .sep { margin: 12px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-weak); color: var(--accent); }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a .count { margin-left: auto; font-size: 11.5px; background: var(--danger); color: #fff; border-radius: 9px; padding: 0 6px; line-height: 18px; }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); color: var(--text-2); display: grid; place-items: center; font-weight: 700; font-size: 12.5px; flex: none; }
.me .who { min-width: 0; flex: 1; }
.me .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; 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 .menu-btn { display: none; }
.topbar h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.online { position: relative; }
.online-btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 15px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 12.5px; color: var(--text-2); }
.online-btn i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; }
.dropdown .item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; font-size: 13px; }
.content { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.toolbar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar label.field { min-width: 140px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }
.card-body { padding: 14px 16px 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.tile { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.tile .label { font-size: 12.5px; color: var(--text-2); font-weight: 550; }
.tile .value { font-size: 26px; font-weight: 650; line-height: 1.15; letter-spacing: -.01em; }
.tile .delta { font-size: 12.5px; color: var(--muted); }
.tile .delta.up { color: var(--ok); }
.tile .delta.down { color: var(--danger); }
.tile a.tile-link { font-size: 12.5px; }

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--info-weak); color: var(--text); font-size: 13px; }
.notice svg { width: 18px; height: 18px; color: var(--info); flex: none; margin-top: 1px; }
.notice.warn { background: var(--warn-weak); }
.notice.warn svg { color: var(--warn); }

/* ================= Tables ================= */
.table-wrap { overflow: auto; max-width: 100%; border-radius: 0 0 var(--radius) var(--radius); }
.table-wrap.tall { max-height: calc(100vh - 220px); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.t th, .t td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.t thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--text-2); font-weight: 650; font-size: 12px;
  white-space: nowrap; border-bottom: 1px solid var(--border-strong);
}
.t thead tr:nth-child(2) th { top: 33px; }
.t tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.t tr.clickable { cursor: pointer; }
.t td.sticky, .t th.sticky { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.t thead th.sticky { z-index: 3; background: var(--surface-2); }
.t tbody tr:hover td.sticky { background: var(--surface-2); }
.t tr.group td { background: var(--surface-2); font-weight: 650; color: var(--text-2); font-size: 12.5px; padding-top: 6px; padding-bottom: 6px; }
.t tfoot td { position: sticky; bottom: 0; background: var(--warn-weak); font-weight: 700; border-top: 1px solid var(--border-strong); }
.t td.zero { color: var(--muted); }
.t .wrap { white-space: normal; min-width: 220px; max-width: 360px; }
.t .grp-l { border-left: 1px solid var(--border-strong); }
.t td.weekend, .t th.weekend { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 7px; border-radius: 6px; background: var(--accent-weak); color: var(--accent); font-size: 12px; font-weight: 600; border: 0; cursor: pointer; white-space: nowrap; }
.chip.add { background: transparent; border: 1px dashed var(--border-strong); color: var(--text-2); }
.chip.add:hover { border-color: var(--accent); color: var(--accent); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--border); }

/* ================= Tabs ================= */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: transparent; padding: 10px 12px; cursor: pointer; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab .n { font-size: 11.5px; background: var(--surface-3); border-radius: 9px; padding: 0 6px; margin-left: 4px; color: var(--text-2); }

/* ================= Modal & drawer ================= */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(8, 14, 12, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 24px; overflow-y: auto; animation: fade .12s ease-out; }
.modal { width: 100%; max-width: 640px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; max-height: none; }
.modal.wide { max-width: 860px; }
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--border); }
.modal-foot .spacer { flex: 1; }
.drawer-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(8, 14, 12, .35); animation: fade .12s ease-out; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 91; width: min(720px, 100vw); background: var(--bg); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .18s ease-out; }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 32px; display: flex; flex-direction: column; gap: 14px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.timeline li { display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: start; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13px; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }

.toast-host { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow-lg); font-size: 13.5px; animation: fade .15s; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

.autocomplete { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; }
.ac-item { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.ac-item:hover, .ac-item.active { background: var(--surface-2); }
.picked { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }

/* ================= Thông báo nhắc việc ================= */
.reminder-pop {
  position: fixed; right: 16px; bottom: 16px; z-index: 95; width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--warn);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); animation: slide .2s ease-out;
}
.reminder-pop .rp-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 6px 12px; }
.reminder-pop .rp-head svg { width: 18px; height: 18px; color: var(--warn); }
.reminder-pop .rp-item { padding: 8px 12px 10px; border-top: 1px solid var(--border); }

/* ================= Charts ================= */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .chart text.lbl { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart text.val { fill: var(--text-2); font-size: 11.5px; font-weight: 600; font-family: var(--font); }
.chart text.cat { fill: var(--text-2); font-size: 12px; font-family: var(--font); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hover-band { fill: var(--surface-2); opacity: 0; }
.chart .hover-band.on { opacity: 1; }
.chart .crosshair { stroke: var(--baseline); stroke-width: 1; }
.chart-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; min-width: 120px; white-space: nowrap; }
.chart-tip b { display: block; margin-bottom: 3px; }
.chart-tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.chart-tip .r span:last-child { font-weight: 650; font-variant-numeric: tabular-nums; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key.line { height: 3px; width: 14px; border-radius: 2px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.segbar { display: flex; height: 28px; gap: 2px; border-radius: 4px; overflow: hidden; }
.segbar > div { display: flex; align-items: center; padding: 0 8px; color: #fff; font-size: 12px; font-weight: 650; border-radius: 4px; min-width: 0; white-space: nowrap; overflow: hidden; }

/* ================= Responsive ================= */
@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 80; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px 16px 32px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid-3 { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .toolbar label.field { min-width: 0; flex: 1 1 140px; }
  .online-btn .lbl { display: none; }
  .overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
}
@media (max-width: 520px) {
  .tile .value { font-size: 22px; }
  .timeline li { grid-template-columns: 80px minmax(0, 1fr); }
  .timeline li > :nth-child(3) { grid-column: 2; }
}
@media print {
  .sidebar, .topbar, .toolbar, .btn, .icon-btn { display: none !important; }
  .app { display: block; }
  .card { box-shadow: none; }
  .table-wrap { overflow: visible; max-height: none !important; }
}
