/* =========================================================================
   Bộ màu & kích thước (theo phong cách trang mẫu: đỏ CCHC, nền xám nhạt)
   ========================================================================= */
:root {
    --primary: #D2232A;
    --primary-hover: #b91c1c;
    --primary-soft: #fef2f2;
    --primary-ring: rgba(210, 35, 42, .16);
    --bg: #f1f5f9;
    --surface: #ffffff;
    --subtle: #f8fafc;
    --muted-bg: #f1f5f9;
    --border: #e2e8f0;
    --border-input: #cbd5e1;
    --text: #0f172a;
    --text-2: #334155;
    --text-muted: #64748b;

    --c-red: #D2232A;    --c-red-soft: #fef2f2;
    --c-blue: #2563eb;   --c-blue-soft: #eff6ff;
    --c-violet: #7c3aed; --c-violet-soft: #f5f3ff;
    --c-green: #15803d;  --c-green-soft: #f0fdf4;
    --c-amber: #b45309;  --c-amber-soft: #fffbeb;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(15,23,42,.05), 0 1px 2px rgba(15,23,42,.03);
    --shadow-lg: 0 24px 48px -12px rgba(15,23,42,.28);
    --font: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', Consolas, monospace;
}
html.dark {
    color-scheme: dark;
    --primary: #f87171;
    --primary-hover: #ef4444;
    --primary-soft: #321f2b;
    --primary-ring: rgba(248,113,113,.24);
    --bg: #0f172a;
    --surface: #1e293b;
    --subtle: #172033;
    --muted-bg: #263449;
    --border: #334155;
    --border-input: #64748b;
    --text: #f1f5f9;
    --text-2: #cbd5e1;
    --text-muted: #a8b3c4;

    --c-red: #f87171;    --c-red-soft: rgba(248,113,113,.12);
    --c-blue: #60a5fa;   --c-blue-soft: rgba(96,165,250,.12);
    --c-violet: #a78bfa; --c-violet-soft: rgba(167,139,250,.12);
    --c-green: #4ade80;  --c-green-soft: rgba(74,222,128,.1);
    --c-amber: #fbbf24;  --c-amber-soft: rgba(251,191,36,.1);
    --shadow: none;
    --shadow-lg: 0 24px 48px -12px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.muted { color: var(--text-muted); font-size: 13px; }

/* ---------------- Thanh trên cùng ---------------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    height: 64px; padding: 0 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 10px;
    display: grid; place-items: center;
    background: var(--primary); color: #fff;
}
html.dark .brand-mark { background: #D2232A; }
.brand-mark svg { width: 20px; height: 20px; }
.brand-title { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.source-badge {
    font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px;
    background: var(--muted-bg); color: var(--text-2); white-space: nowrap;
}
.source-badge.is-sample { background: var(--c-amber-soft); color: var(--c-amber); }
.source-badge.is-live { background: var(--c-green-soft); color: var(--c-green); }
.icon-btn {
    width: 36px; height: 36px; display: grid; place-items: center;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--muted-bg); color: var(--text); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Bố cục chính ---------------- */
.container { max-width: 1240px; margin: 0 auto; padding: 24px; }
.view-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.view-header h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.view-tabs { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.view-tab {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 14px; border: 0; border-radius: 7px;
    background: transparent; color: var(--text-muted); font-weight: 600; cursor: pointer;
}
.view-tab svg { width: 16px; height: 16px; }
.view-tab:hover { color: var(--text); }
.view-tab.active { background: var(--primary-soft); color: var(--primary); }
.panel { display: flex; flex-direction: column; gap: 20px; }
.panel[hidden] { display: none; }

.notice {
    padding: 12px 16px; margin-bottom: 16px; border-radius: var(--radius-sm);
    background: var(--c-amber-soft); color: var(--c-amber); border: 1px solid currentColor; font-size: 13px;
}

.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-bottom: 16px; }
.card-head-split { margin-top: 24px; padding-top: 20px; border-top: 1px dashed var(--border); justify-content: space-between; }
.section-title {
    display: flex; align-items: center; gap: 8px; margin: 0;
    font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2);
}
.section-title svg { color: var(--primary); }

.switches { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px 18px; }
.switches .switch { margin-left: 0; }
.switch[hidden], .field[hidden] { display: none; }
.fluct-note { margin-top: 4px; font-size: 12px; }
.change-line { font-size: 12px; font-weight: 400; color: var(--text-muted); margin-top: 3px; }
a.icon-btn { text-decoration: none; }
.kiosk-link { display: inline-flex; align-items: center; height: 36px; padding: 0 12px; border-radius: var(--radius-sm); background: var(--primary); color: #fff; font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
html.dark .kiosk-link { background: #D2232A; }
.kiosk-link[hidden] { display: none; }
@media (max-width: 720px) { .kiosk-link { display: none; } }

/* Công tắc */
.switch { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-2); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: relative; width: 34px; height: 20px; border-radius: 999px; background: var(--border-input); transition: background .2s; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--primary-ring); }

/* ---------------- Thẻ số liệu ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-card {
    --tone: var(--c-red); --tone-soft: var(--c-red-soft);
    position: relative; overflow: hidden; text-align: left;
    display: flex; flex-direction: column; gap: 10px;
    padding: 18px 20px; border-radius: var(--radius);
    border: 1px solid var(--border); background: var(--surface);
    cursor: pointer; transition: border-color .15s, transform .15s, box-shadow .15s;
}
.stat-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--tone); }
.stat-card:hover { border-color: var(--tone); transform: translateY(-1px); box-shadow: 0 6px 16px -8px rgba(15,23,42,.2); }
.stat-card:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: 1px; }
.tone-blue   { --tone: var(--c-blue);   --tone-soft: var(--c-blue-soft); }
.tone-violet { --tone: var(--c-violet); --tone-soft: var(--c-violet-soft); }
.tone-green  { --tone: var(--c-green);  --tone-soft: var(--c-green-soft); }
.tone-amber  { --tone: var(--c-amber);  --tone-soft: var(--c-amber-soft); }
.stat-label { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.stat-label .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tone); }
.stat-value { font-size: 34px; font-weight: 800; line-height: 1; color: var(--tone); font-variant-numeric: tabular-nums; }
.stat-icon { position: absolute; right: 16px; bottom: 14px; width: 46px; height: 46px; color: var(--tone); opacity: .14; stroke-width: 1.6; }

/* ---------------- Dịch vụ công ---------------- */
.dvc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.dvc-card { --tone: var(--c-red); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--subtle); }
.dvc-tinh { --tone: var(--c-blue); }
.dvc-xa { --tone: var(--c-violet); }
.dvc-card button { border: 0; background: transparent; cursor: pointer; text-align: left; }
.dvc-head { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; background: var(--surface) !important; border-bottom: 1px solid var(--border) !important; border-top: 3px solid var(--tone) !important; }
.dvc-head span { font-weight: 700; color: var(--text-2); }
.dvc-head strong { font-size: 26px; font-weight: 800; color: var(--tone); font-variant-numeric: tabular-nums; }
.dvc-break { display: grid; grid-template-columns: 1fr 1fr; }
.dvc-break button { display: flex; flex-direction: column; gap: 2px; padding: 12px 18px; }
.dvc-break button + button { border-left: 1px solid var(--border); }
.dvc-break span { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.dvc-break strong { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dvc-card button:hover { background: var(--muted-bg) !important; }

/* ---------------- Biểu đồ ---------------- */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.chart-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.chart-copy h3 { margin: 4px 0 14px; font-size: 17px; font-weight: 700; }
.kicker { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); }
.legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--text-2); }
.chart-copy .legend:has(.sw-new) { flex-direction: row; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; }
.legend span { display: flex; align-items: center; gap: 8px; }
.legend strong { font-variant-numeric: tabular-nums; color: var(--text); }
.legend em { font-style: normal; color: var(--text-muted); font-size: 12px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-blue { background: var(--c-blue); } .sw-violet { background: var(--c-violet); }
.sw-green { background: var(--c-green); } .sw-amber { background: var(--c-amber); }
.sw-new { background: var(--c-green); } .sw-amd { background: var(--c-amber); } .sw-abo { background: var(--c-red); }

.radial { position: relative; width: 170px; height: 170px; flex-shrink: 0; }
.radial svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--muted-bg); stroke-width: 12; }
.ring { fill: none; stroke-width: 12; stroke-linecap: round; stroke-dasharray: 0 100; transition: stroke-dasharray .8s ease; }
.ring-blue { stroke: var(--c-blue); } .ring-violet { stroke: var(--c-violet); }
.ring-green { stroke: var(--c-green); } .ring-amber { stroke: var(--c-amber); }
.radial-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.radial-center strong { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.radial-center span { font-size: 11px; color: var(--text-muted); font-weight: 600; }

.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(0, 190px) 1fr 40px; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; border: 0; background: none; padding: 0; text-align: left; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar-track, .hbar-fill { display: block; }
.hbar-track { height: 10px; border-radius: 999px; background: var(--muted-bg); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; background: var(--primary); width: 0; transition: width .8s ease; }
.hbar-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.hbar:hover .hbar-label { color: var(--primary); }

.trend { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 200px; padding-top: 18px; }
.trend-col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.trend-stack { flex: 1; width: 100%; max-width: 30px; display: flex; flex-direction: column-reverse; justify-content: flex-start; position: relative; }
.trend-stack i { display: block; width: 100%; transition: height .8s ease; }
.trend-stack i:last-child { border-radius: 4px 4px 0 0; }
.trend-stack .seg-new { background: var(--c-green); }
.trend-stack .seg-amd { background: var(--c-amber); }
.trend-stack .seg-abo { background: var(--c-red); }
.trend-total { position: absolute; left: 50%; transform: translate(-50%, -100%); font-size: 11px; font-weight: 700; color: var(--text-2); padding-bottom: 2px; }
.trend-label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ---------------- Danh mục ---------------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.search { flex: 1; min-width: 240px; position: relative; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 16px; height: 16px; }
.search input { width: 100%; height: 38px; padding: 0 12px 0 36px; border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: var(--surface); }
.search input:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 14px; border-radius: 6px; font-weight: 600; cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
html.dark .btn-primary { background: #D2232A; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-input); color: var(--text-2); }
.btn-secondary:hover { background: var(--muted-bg); }

.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 14px; margin-bottom: 14px; background: var(--subtle); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field span { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.select { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.select-sm { width: auto; height: 34px; font-weight: 600; }

.table-meta { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.pagination { display: flex; gap: 4px; flex-wrap: wrap; }
.pagination button { min-width: 34px; height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
html.dark .pagination button.active { background: #D2232A; border-color: #D2232A; }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination .gap { padding: 0 4px; align-self: center; color: var(--text-muted); }

.table-scroll { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { position: sticky; top: 0; z-index: 1; background: var(--subtle); text-align: left; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--subtle); }
.data-table td.name { color: var(--text); font-weight: 600; min-width: 260px; }
.col-stt { width: 56px; text-align: center !important; }
.data-table td:first-child { text-align: center; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.col-ma { width: 110px; }
.code { font-family: var(--mono); font-size: 12px; color: var(--primary); font-weight: 600; white-space: nowrap; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag-full { background: var(--c-green-soft); color: var(--c-green); }
.tag-part { background: var(--c-amber-soft); color: var(--c-amber); }
.tag-none { background: var(--muted-bg); color: var(--text-muted); }
.tag-abo { background: var(--c-red-soft); color: var(--c-red); margin-left: 6px; }
.empty { text-align: center; padding: 40px 12px !important; color: var(--text-muted) !important; }

/* ---------------- Hộp thoại ---------------- */
.modal { width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 64px); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(15,23,42,.5); backdrop-filter: blur(2px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { margin: 16px 20px; flex: 1; min-height: 0; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--subtle); }

/* ---------------- Màn hình nhỏ ---------------- */
@media (max-width: 960px) {
    .chart-grid { grid-template-columns: 1fr; }
    .filters { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
    .container { padding: 16px; }
    .topbar { padding: 0 16px; }
    .brand-sub, .source-badge { display: none; }
    .stat-grid, .dvc-grid { grid-template-columns: 1fr; }
    .switch, .switches { margin-left: 0; }
    .chart-card { flex-direction: column; align-items: flex-start; }
    .radial { align-self: center; }
    .hbar { grid-template-columns: minmax(0, 120px) 1fr 36px; }
    .trend-label { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}
