/* ===== CMAP Dashboard — hệ thống giao diện sáng, hiện đại ===== */
:root {
  --bg: #f4f6fd;
  --surface: #ffffff;
  --surface-2: #f8faff;
  --line: #e6e9f4;
  --line-strong: #d5dbee;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #8391a7;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --sky: #0ea5e9;
  --cyan: #06b6d4;
  --teal: #14b8a6;
  --green: #16a34a;
  --orange: #f97316;
  --pink: #ec4899;
  --amber: #f59e0b;
  --red: #e11d48;
  --flag-red: #da251d;
  --flag-gold: #ffcd00;
  --up-bg: #dcfce7; --up-fg: #15803d;
  --down-bg: #ffe4e6; --down-fg: #be123c;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(79, 70, 229, .18);
  --shadow-lg: 0 20px 50px -20px rgba(79, 70, 229, .35);
  --font: 'Be Vietnam Pro', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 500px at 0% -10%, rgba(99, 102, 241, .10), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(14, 165, 233, .10), transparent 60%);
  background-attachment: fixed;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.container { max-width: 1360px; margin: 0 auto; padding: 0 20px; }
@media (max-width: 640px) { .container { padding: 0 16px; } }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40; color: #fff;
  background: linear-gradient(110deg, #4338ca 0%, #4f46e5 35%, #0ea5e9 100%);
  box-shadow: 0 10px 30px -15px rgba(67, 56, 202, .7);
}
.topbar::before { content: ''; display: block; height: 4px; background: linear-gradient(90deg, var(--flag-red), var(--flag-gold) 50%, var(--flag-red)); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 14px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--flag-red), #ff7a45); box-shadow: 0 0 0 3px rgba(255, 205, 0, .45), 0 6px 14px rgba(0,0,0,.2);
}
.brand-logo svg { width: 24px; height: 24px; fill: var(--flag-gold); }
.brand-org { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; opacity: .85; }
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: -.01em; line-height: 1.25; }
.brand-title small { font-weight: 500; opacity: .8; font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .25); }
.seg button { border: 0; background: transparent; color: #fff; padding: 6px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; opacity: .85; }
.seg button.active { background: #fff; color: var(--primary); opacity: 1; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.seg button:hover:not(.active) { opacity: 1; background: rgba(255,255,255,.12); }
.sel-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.sel-wrap label { opacity: .9; }
.top-select {
  appearance: none; border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .15) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: #fff; padding: 6px 30px 6px 10px; border-radius: 10px; font-weight: 600; font-size: 13px; cursor: pointer;
}
.top-select option { color: var(--text); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text); transition: .15s;
}
.btn:hover { border-color: var(--primary-2); color: var(--primary); text-decoration: none; }
.btn svg { width: 16px; height: 16px; }
.btn-ghost { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .3); color: #fff; }
.btn-ghost:hover { background: rgba(255, 255, 255, .28); color: #fff; border-color: #fff; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--sky)); color: #fff; border: 0; box-shadow: 0 8px 18px -8px rgba(79, 70, 229, .7); }
.btn-primary:hover { color: #fff; filter: brightness(1.06); }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: #fff1f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Context bar ---------- */
.context {
  margin: 18px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow);
}
.live { display: inline-flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .2); flex: none; }
.context-title { font-weight: 700; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); }
.chip.c-a { background: #eef2ff; border-color: #c7d2fe; color: #4338ca; }
.chip.c-b { background: #fff7ed; border-color: #fed7aa; color: #c2410c; }
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 420px) { .kpis { grid-template-columns: 1fr; } }
.kpi {
  position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.kpi::after { content: ''; position: absolute; inset: auto -30px -40px auto; width: 120px; height: 120px; border-radius: 50%; background: var(--accent); opacity: .09; }
.kpi-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.kpi-icon { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: #fff; background: var(--accent); flex: none; box-shadow: 0 6px 14px -6px var(--accent); }
.kpi-icon svg { width: 18px; height: 18px; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 8px; line-height: 1.15; }
.kpi-value .unit { font-size: 14px; font-weight: 600; color: var(--text-3); margin-left: 2px; }
.kpi-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--text-3); flex-wrap: wrap; }
.delta { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-size: 12px; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.delta.up { background: var(--up-bg); color: var(--up-fg); }
.delta.down { background: var(--down-bg); color: var(--down-fg); }
.delta.flat { background: #f1f5f9; color: #475569; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; margin-top: 16px; }
.g-3-2 { grid-template-columns: 3fr 2fr; }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-5-7 { grid-template-columns: 5fr 7fr; }
@media (max-width: 1024px) { .g-3-2, .g-2, .g-5-7 { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.card-title .ic { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--ic-bg, #eef2ff); color: var(--ic-fg, var(--primary)); flex: none; }
.card-title .ic svg { width: 16px; height: 16px; }
.card-sub { font-size: 12px; color: var(--text-3); margin: 4px 0 0; }
.tag { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }
.chart-box { position: relative; height: 320px; }
.chart-box.sm { height: 220px; }
.chart-box.md { height: 260px; }
.note { margin-top: 12px; font-size: 12.5px; color: var(--text-2); background: linear-gradient(135deg, #eef2ff, #ecfeff); border: 1px solid #dbe4ff; border-radius: var(--radius-sm); padding: 10px 12px; }
.note strong { color: var(--text); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat b { display: block; font-size: 18px; font-weight: 800; }
.stat span { font-size: 11.5px; color: var(--text-3); font-weight: 600; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 0; flex-wrap: wrap; }
.section-head h2 { font-size: 18px; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.section-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-3); }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); }

/* ---------- Tables ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.input, .select {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 10px; padding: 8px 12px; font-size: 13px; min-width: 0;
}
.input:focus, .select:focus { outline: 2px solid #c7d2fe; border-color: var(--primary-2); }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--text-3); }
.search .input { padding-left: 32px; width: 240px; max-width: 100%; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 560px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; z-index: 1; background: #f3f5fc; color: var(--text-2); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--primary); }
thead th .arrow { opacity: .5; margin-left: 2px; }
th.r, td.r { text-align: right; }
tbody td { padding: 10px 12px; border-bottom: 1px solid #eef1f8; vertical-align: middle; }
tbody tr:hover td { background: #f8f9ff; }
tbody tr:last-child td { border-bottom: 0; }
.rank { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; font-weight: 800; font-size: 12px; background: #f1f5f9; color: var(--text-2); }
.rank.r1 { background: linear-gradient(135deg, #fde68a, #f59e0b); color: #78350f; }
.rank.r2 { background: linear-gradient(135deg, #e2e8f0, #94a3b8); color: #1e293b; }
.rank.r3 { background: linear-gradient(135deg, #fed7aa, #fb923c); color: #7c2d12; }
.cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.cat i { width: 7px; height: 7px; border-radius: 50%; }
.path { font-family: var(--mono); font-size: 12px; color: var(--text-2); word-break: break-all; }
.ev-name { font-weight: 600; color: var(--text); }
.bar { height: 6px; border-radius: 4px; background: #eef1f8; overflow: hidden; min-width: 60px; margin-top: 4px; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--primary), var(--sky)); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--text-3); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; align-items: center; }
.pager button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; min-width: 30px; height: 30px; cursor: pointer; font-weight: 600; font-size: 12px; }
.pager button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager button[disabled] { opacity: .4; cursor: default; }
.badge-auto { white-space: nowrap; display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: #ecfeff; color: #0e7490; border: 1px solid #a5f3fc; margin-left: 4px; }
.empty { padding: 36px 16px; text-align: center; color: var(--text-3); }

/* ---------- Insights ---------- */
.insights { margin-top: 16px; border-radius: var(--radius); padding: 22px; color: #fff; background: linear-gradient(125deg, #312e81 0%, #4f46e5 45%, #0891b2 100%); box-shadow: var(--shadow-lg); }
.insights h2 { margin: 0; font-size: 18px; font-weight: 800; }
.insights .sub { margin: 4px 0 0; opacity: .8; font-size: 12.5px; }
.ins-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 18px; }
@media (max-width: 1024px) { .ins-grid { grid-template-columns: 1fr; } }
.ins { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2); border-radius: var(--radius-sm); padding: 16px; display: flex; flex-direction: column; justify-content: space-between; gap: 12px; backdrop-filter: blur(4px); }
.ins h3 { margin: 0 0 6px; font-size: 13px; letter-spacing: .03em; text-transform: uppercase; color: var(--flag-gold); }
.ins p { margin: 0; font-size: 13.5px; line-height: 1.6; opacity: .95; }
.ins .rec { font-size: 12.5px; background: rgba(255, 255, 255, .12); border-radius: 10px; padding: 8px 10px; }
.ins-foot { margin-top: 16px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; opacity: .9; }

/* ---------- Footer / misc ---------- */
footer { margin: 32px 0 0; padding: 20px 0 28px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 12px; }
footer .container { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13px; box-shadow: 0 12px 30px rgba(0,0,0,.25); opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 90; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid #e0e7ff; border-top-color: var(--primary); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

@media print {
  body { background: #fff; }
  .topbar { position: static; box-shadow: none; }
  .no-print, .toolbar { display: none !important; }
  .card, .kpi, .context { box-shadow: none; break-inside: avoid; }
  .table-wrap { max-height: none; overflow: visible; }
  .insights { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
@media (max-width: 720px) {
  .topbar { position: static; }
  .brand-title small { display: none; }
}
