/* LKT CRM demo — giao diện chung.
   Lớp dùng lại cho các màn:
   bố cục: .grid-2 .grid-3 .kpi-grid .stack .row .row-between .wrap .gap-sm .mb
   khối:   .card .section .section-head .note .stat(.stat-label .stat-value .stat-sub) .stat-box .list .list-row
   bảng:   .table-wrap > table.table (td.num căn phải, tr.is-click bấm được, tfoot tổng) .group-head
   nút:    .btn .btn-primary .btn-secondary .btn-danger .btn-ghost .btn-sm .icon-btn .link
   form:   .form-grid .field (label + input/select/textarea) .field-full .form-actions .form-error .search .toolbar .checkbox
   nhãn:   .badge-{tone} .pill-{tone} .chip  (tone: amber blue green red gray slate orange violet)
   biểu đồ: .chart .chart-legend .chart-tip   thanh: .bar > .bar-fill.bar-{accent|ink|amber|red|blue|gray}
   chữ:    .muted .small .strong .num .up .down .ellipsis */

:root {
  --bg: #f4f1ea;
  --bg-pattern: #ece7dc;
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --ink: #1b1a17;
  --ink-2: #57534e;
  --muted: #8a847a;
  --line: #e6e0d4;
  --line-strong: #d6cfc0;
  --sidebar: #13201a;
  --sidebar-2: #1c2d25;
  --sidebar-ink: #c9d6cf;
  --accent: #b9e27c;
  --accent-strong: #3f8f3a;
  --accent-ink: #14240f;
  --good: #1f8a4c;
  --good-bg: #e3f4e8;
  --bad: #c2410c;
  --bad-bg: #fde9df;
  --danger: #c62828;
  --danger-bg: #fdeaea;
  --warn: #b7791f;
  --warn-bg: #fdf3dc;
  --info: #2563eb;
  --info-bg: #e6eeff;
  --violet: #6d28d9;
  --violet-bg: #efe8fd;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(27, 26, 23, 0.05), 0 4px 14px rgba(27, 26, 23, 0.04);
  --sidebar-w: 236px;
  --bar-h: 42px;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, var(--bg-pattern) 1px, transparent 0);
  background-size: 22px 22px;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

/* ---------- Thanh demo ---------- */
.demo-bar {
  position: fixed; inset: 0 0 auto 0; height: var(--bar-h); z-index: 40;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 13px;
}
.demo-tag { letter-spacing: 0.04em; white-space: nowrap; }
.demo-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demo-spacer { flex: 1; }
.demo-role { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.demo-role select { border: 1px solid rgba(20, 36, 15, 0.25); background: rgba(255, 255, 255, 0.6); border-radius: 8px; padding: 3px 8px; width: auto; }
.nav-toggle { display: none; }

/* ---------- Bố cục ---------- */
.layout { padding-top: var(--bar-h); }
.sidebar {
  position: fixed; top: var(--bar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 30;
  background: var(--sidebar); color: var(--sidebar-ink); overflow-y: auto; padding: 14px 10px 18px;
  display: flex; flex-direction: column;
}
.main { margin-left: var(--sidebar-w); min-height: calc(100vh - var(--bar-h)); }
.view { max-width: 1240px; margin: 0 auto; padding: 22px 26px 80px; }
.sidebar-scrim { display: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); margin-bottom: 10px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 20px; }
.brand strong { display: block; color: #fff; font-size: 16px; }
.brand small { color: var(--accent); letter-spacing: 0.12em; font-size: 10px; font-weight: 700; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; font-weight: 500; }
.nav-item:hover { background: var(--sidebar-2); color: #fff; }
.nav-item.is-active { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.nav-icon { width: 18px; text-align: center; opacity: 0.9; }
.nav-label { flex: 1; }
.nav-group { margin: 16px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: #6f8478; }
.nav-soon .nav-item { opacity: 0.55; }
.nav-soon .nav-item.is-active { opacity: 1; }
.soon { font-size: 10px; border: 1px solid currentColor; border-radius: 6px; padding: 0 5px; opacity: 0.8; }
.sidebar-foot { margin-top: auto; padding: 14px 10px 0; font-size: 12px; color: #6f8478; }

.bottom-nav { display: none; }

/* ---------- Tiêu đề màn ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-sub { color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Khối & lưới ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.section { padding: 18px; margin-bottom: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.note { margin-top: 12px; font-size: 12px; color: var(--muted); line-height: 1.55; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-2 > .section, .grid-3 > .section { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }
.gap-sm { gap: 6px; }
.mb { margin-bottom: 16px; }

.kpi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 4px; transition: border-color .15s, transform .15s; }
a.kpi:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.kpi-head { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 500; }
.kpi-go { margin-left: auto; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.kpi-delta { font-size: 12px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.kpi-sub { font-size: 12px; color: var(--muted); }
.spark { width: 100%; height: 34px; margin: 2px 0; }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { color: var(--ink-2); font-size: 12px; }
.stat-value { font-size: 20px; font-weight: 800; }
.stat-sub { font-size: 12px; color: var(--muted); }
.stat-box { padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }

.delta { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 6px; font-weight: 700; font-size: 12px; }
.delta.is-good { color: var(--good); background: var(--good-bg); }
.delta.is-bad { color: var(--bad); background: var(--bad-bg); }

.info-tip { display: inline-grid; place-items: center; width: 15px; height: 15px; border: 1px solid var(--line-strong); border-radius: 50%; font-size: 10px; color: var(--muted); cursor: help; font-style: italic; }

/* ---------- Danh sách ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { background: var(--surface-2); }

.attention { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 22px; }
.attention-item { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px dashed var(--line); }
.attention-icon { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-weight: 800; font-size: 12px; flex: none; }
.attention-icon.danger { background: var(--danger-bg); color: var(--danger); }
.attention-icon.warn { background: var(--warn-bg); color: var(--warn); }
.attention-text { flex: 1; }
.attention-go { font-weight: 700; white-space: nowrap; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-click { cursor: pointer; }
.table tr.is-click:hover td { background: var(--surface-2); }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.group-head { padding: 14px 4px 8px; font-weight: 700; display: flex; gap: 8px; align-items: baseline; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  padding: 9px 15px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-2); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #33312c; border-color: #33312c; }
.btn-secondary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-secondary:hover { background: #a7d566; border-color: #a7d566; }
.btn-danger { color: var(--danger); border-color: #f1c0c0; }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: rgba(0, 0, 0, 0.05); border-color: transparent; }
.btn-ghost-dark { background: rgba(20, 36, 15, 0.08); border-color: rgba(20, 36, 15, 0.2); color: var(--accent-ink); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; font-size: 16px; }
.icon-btn:hover { background: rgba(0, 0, 0, 0.06); }
.link { color: var(--accent-strong); font-weight: 600; cursor: pointer; background: none; border: 0; padding: 0; }
.link:hover { text-decoration: underline; }

/* ---------- Chip, badge, pill ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 6px 13px; font-weight: 500; cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { border-color: var(--ink-2); }
.chip.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip-count { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: rgba(0, 0, 0, 0.07); }
.chip.is-active .chip-count { background: rgba(255, 255, 255, 0.2); }
.chip-red:not(.is-active) { border-color: #f1c0c0; color: var(--danger); }
.chip-amber:not(.is-active) { border-color: #ecd49a; background: var(--warn-bg); }
.chip-blue:not(.is-active) { border-color: #c4d4fb; color: var(--info); }
.chip-green:not(.is-active) { border-color: #bfe3cb; color: var(--good); }
.chip-violet:not(.is-active) { border-color: #d9c9f7; color: var(--violet); }
.chip-orange:not(.is-active) { border-color: #f6cfa8; color: #c2410c; }
.chip-gray:not(.is-active) { color: var(--ink-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.pill { display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-amber, .pill-amber { background: var(--warn-bg); color: var(--warn); }
.badge-blue, .pill-blue { background: var(--info-bg); color: var(--info); }
.badge-green, .pill-green { background: var(--good-bg); color: var(--good); }
.badge-red, .pill-red { background: var(--danger-bg); color: var(--danger); }
.badge-gray, .pill-gray { background: #efede8; color: var(--ink-2); }
.badge-slate, .pill-slate { background: #e8edf2; color: #475569; }
.badge-orange, .pill-orange { background: #ffedd5; color: #c2410c; }
.badge-violet, .pill-violet { background: var(--violet-bg); color: var(--violet); }
.sidebar .pill-amber { background: #f3c64d; color: #3d2c00; }
.sidebar .pill-red { background: #e5484d; color: #fff; }
.sidebar .pill-blue { background: #3b82f6; color: #fff; }
.nav-item.is-active .pill { background: var(--accent-ink); color: var(--accent); }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; flex: none; }

.bar { display: block; height: 8px; border-radius: 99px; background: #eeeae1; overflow: hidden; min-width: 60px; }
.bar-fill { display: block; height: 100%; border-radius: 99px; }
.bar-accent { background: var(--accent-strong); }
.bar-ink { background: var(--ink); }
.bar-amber { background: #e3a82b; }
.bar-red { background: #e5484d; }
.bar-blue { background: #3b82f6; }
.bar-gray { background: #b8b1a3; }

/* ---------- Form ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-full { grid-column: 1 / -1; }
.field > label, .field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; padding: 9px 11px; background: var(--surface);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(63, 143, 58, 0.15); }
.search { flex: 1; min-width: 200px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.form-error { margin-top: 12px; padding: 9px 12px; border-radius: 9px; background: var(--danger-bg); color: var(--danger); font-weight: 600; font-size: 13px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar select, .toolbar input[type=date] { width: auto; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------- Modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(19, 32, 26, 0.45); display: grid; place-items: center; padding: 18px; animation: fade .15s ease; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 36px); overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.modal.modal-lg { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 18px; }
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 80; }
.toast { padding: 11px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2); animation: rise .2s ease; }
.toast-error { background: var(--danger); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Trạng thái trống ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { width: 44px; height: 44px; border-radius: 50%; border: 1px dashed var(--line-strong); display: grid; place-items: center; font-size: 18px; }

/* ---------- Chữ ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.up { color: var(--good); }
.down { color: var(--bad); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Biểu đồ ---------- */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 8px 10px; border-radius: 9px; font-size: 12px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, -100%); z-index: 5; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .nav-toggle { display: inline-grid; }
  .demo-text, .demo-role > span { display: none; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-scrim { display: block; position: fixed; inset: var(--bar-h) 0 0 0; background: rgba(0, 0, 0, 0.35); z-index: 25; }
  .main { margin-left: 0; }
  .view { padding: 16px 16px 96px; }
  .grid-2, .grid-3, .attention { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  h1 { font-size: 21px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 35;
    background: var(--sidebar); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bn-item { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--sidebar-ink); padding: 4px 0; border-radius: 10px; position: relative; }
  .bn-item.is-active { color: var(--accent); }
  #toast-root { bottom: calc(76px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100vw - 32px); }
  .bn-dot { position: absolute; top: 0; right: 18%; background: #e5484d; color: #fff; font-size: 10px; border-radius: 99px; padding: 0 5px; font-weight: 700; }
}

@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .kpi-value { font-size: 23px; }
}

/* Dải báo dữ liệu mẫu đã cũ (js/shell.js renderStaleBanner) */
.stale-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 12px; padding: 8px 12px;
  border: 1px solid #ecd49a; border-radius: 8px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.stale-banner > span { flex: 1 1 260px; }
