@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;650;700&display=swap");

:root {
    color-scheme: dark;
    --bg: #0B101B;
    --sidebar: #101827;
    --card: #151F30;
    --card-2: #1B283C;
    --line: #263247;
    --accent: #6387FF;
    --teal: #2DD4BF;
    --violet: #A78BFA;
    --text: #F3F6FC;
    --muted: #B6C3D8;
    --ok: #34D399;
    --warn: #FBBF24;
    --bad: #F07178;
    --shadow: 0 16px 40px rgba(2, 6, 16, .35);
    --radius: 16px;
    font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14.5px;
    line-height: 1.45;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", system-ui, sans-serif; }
a { color: #B9C8FF; text-decoration: none; }
button, input, select { font: inherit; color: inherit; font-family: inherit; }
h1, h2, h3, p { margin: 0; font-family: inherit; }
h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.03em; font-weight: 650; }
h2 { font-size: 17px; letter-spacing: -.02em; font-weight: 600; }
img { max-width: 100%; }

.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
body.is-collapsed .shell { grid-template-columns: 84px minmax(0, 1fr); }

.sidebar {
    background: var(--sidebar);
    border-right: 1px solid var(--line);
    padding: 22px 14px 16px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    transition: width .2s ease, transform .2s ease, padding .2s ease;
}
body.is-collapsed .nav-label,
body.is-collapsed .nav-group { display: none; }
body.is-collapsed .nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
body.is-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
body.is-collapsed .side-user { justify-content: center; padding-left: 0; padding-right: 0; }
body.is-collapsed .collapse svg { transform: rotate(180deg); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 18px; }
.mark, .brand img { width: 40px; height: 40px; border-radius: 12px; object-fit: cover; flex: 0 0 auto; }
.mark { display: grid; place-items: center; background: linear-gradient(160deg, #6387FF, #3E63E6); color: white; }
.brand strong { display: block; font-size: 15px; font-weight: 650; }
.brand small { color: var(--muted); }
.nav-group { margin: 16px 10px 6px; color: var(--muted); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    color: var(--muted); border-radius: 12px; padding: 11px 12px; margin-bottom: 2px;
    font-size: 14px; font-weight: 500;
    transition: background .18s ease, color .18s ease;
}
.nav-link:hover { background: rgba(99, 135, 255, .08); color: var(--text); text-decoration: none; }
.nav-link.active { background: rgba(99, 135, 255, .16); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.side-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--card-2); border: 1px solid var(--line); font-weight: 650; flex: 0 0 auto; }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }
.who { display: flex; flex-direction: column; min-width: 0; }
.who strong, .who small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); }
.collapse, .menu, .icon-btn {
    background: transparent; border: 1px solid var(--line); color: var(--text);
    border-radius: 10px; padding: 8px 10px; cursor: pointer;
    transition: background .18s ease, border-color .18s ease;
}
.collapse:hover, .menu:hover, .icon-btn:hover, .btn:hover { background: var(--card-2); }
.collapse { margin-left: auto; width: 32px; height: 32px; display: grid; place-items: center; padding: 0; flex: 0 0 auto; }
.collapse svg { transition: transform .2s ease; }
.menu, .backdrop { display: none; }

.main { min-width: 0; }
.header { padding: 28px 32px 0; display: flex; flex-direction: column; gap: 18px; }
.header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.subtitle { color: var(--muted); margin-top: 4px; font-size: 14.5px; }
.header-tools { display: flex; align-items: center; gap: 10px; }
.search { position: relative; width: 280px; }
.search input, .field input, .field select, .filters select, .filters input, .settings input, .settings select {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.search input, .field input, .field select, .settings input, .settings select { width: 100%; }
.filters select, .filters input:not([type="hidden"]) { width: auto; min-width: 160px; }
.search input:focus, .field input:focus, .field select:focus, .filters select:focus, .settings input:focus, .settings select:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 135, 255, .2);
}
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 8px; }
.segmented, .filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.segmented button, .btn {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer;
    transition: background .18s ease, border-color .18s ease, transform .18s ease;
}
.segmented button.on, .btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--bad); border-color: #6d3038; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.date-picker { position: relative; }
.popover {
    position: absolute; top: calc(100% + 8px); left: 0; z-index: 20; width: 260px;
    background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow);
}
.popover label, .field, .settings label, .drawer label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.popover label + label { margin-top: 10px; }
.popover[hidden], .drawer[hidden], .notice-panel[hidden] { display: none; }

.page { padding: 8px 32px 40px; display: flex; flex-direction: column; gap: 20px; }
.banner { border: 1px solid var(--line); background: linear-gradient(180deg, #172033, var(--card)); border-radius: 14px; padding: 14px 16px; display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.banner.demo { border-color: rgba(251, 191, 36, .45); background: rgba(251, 191, 36, .06); }
.banner.bad { border-color: #7a3038; }
.banner.ok { border-color: #1f6b4d; }
.banner .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.stat, .card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px;
    animation: rise .22s ease both;
}
.stat { background: linear-gradient(180deg, #172033 0%, var(--card) 100%); }
.card.surface { background: #121A29; }
.stat-top, .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stat-label { color: var(--muted); font-size: 14px; font-weight: 500; }
.stat-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: rgba(99, 135, 255, .14); color: var(--accent); }
.stat-icon.ok { background: rgba(52, 211, 153, .12); color: var(--ok); }
.stat-icon.warn { background: rgba(251, 191, 36, .12); color: var(--warn); }
.stat-icon.live { background: rgba(167, 139, 250, .14); color: var(--violet); }
.stat-value { font-size: 34px; line-height: 1.1; letter-spacing: -.04em; margin: 14px 0 6px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.dash { color: #7F90AB; }
.stat-note, .hint, .fine { color: var(--muted); }
.fine { display: block; font-size: 13px; }
table.nowrap .fine { display: inline; margin-left: 6px; }
.trend { color: var(--ok); font-size: 13px; font-weight: 500; }
.meta-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: rgba(99, 135, 255, .08); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; }
.span-8 { grid-column: span 8; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-3 { grid-column: span 3; }
.span-12 { grid-column: span 12; }

.chart-frame { height: 280px; display: flex; flex-direction: column; justify-content: flex-end; }
.chart-frame.compact { height: 148px; }
.chart { width: 100%; height: 240px; overflow: visible; }
.chart-frame.compact .chart { height: 120px; }
.chart text { fill: var(--muted); font-size: 12px; font-family: Inter, sans-serif; }
.chart-empty, .empty { min-height: 140px; display: grid; place-items: center; text-align: center; color: var(--muted); gap: 8px; padding: 20px; }
.chart-frame.compact .chart-empty { min-height: 120px; padding: 12px; }
.empty-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--card-2); color: var(--accent); margin: 0 auto 8px; }
.chart-actions { margin-top: 10px; display: flex; justify-content: center; gap: 8px; }

.countries, .stack, .activity, .dist, .checklist, .legend, .portal-summary { list-style: none; padding: 0; margin: 12px 0 0; }
.countries li, .stack li, .activity li, .dist li, .checklist li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.portal-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0 0 8px; }
.portal-summary li { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.portal-summary strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.place { display: inline-flex; align-items: center; gap: 8px; }
.flag { width: 20px; height: 15px; object-fit: cover; border-radius: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.14); display: block; }
.bar { flex: 1; height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #809dff); }
.dist-label { min-width: 92px; }
.insights { display: grid; grid-template-columns: 140px 1fr; gap: 18px; align-items: center; }
.donut-wrap { width: 140px; height: 140px; position: relative; }
.donut-wrap svg { width: 100%; height: 100%; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; }
.donut-center strong { font-size: 22px; line-height: 1; }
.legend { margin: 0; }
.legend li { border: 0; padding: 8px 0; gap: 10px; justify-content: flex-start; }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.legend .count { margin-left: auto; color: var(--text); font-weight: 600; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: var(--card); scrollbar-color: #3d4d68 transparent; }
.table-wrap::-webkit-scrollbar { height: 8px; width: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #3d4d68; border-radius: 99px; }
.card > .table-wrap { border: 0; border-radius: 12px; background: transparent; margin: 8px -8px -8px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
table.nowrap { min-width: 1080px; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.nowrap th, table.nowrap td { white-space: nowrap; }
th { color: var(--muted); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; font-weight: 650; }
tbody tr { transition: background .18s ease; }
tbody tr:hover { background: rgba(99, 135, 255, .06); }
.person { display: flex; align-items: center; gap: 10px; }
.mono { font-family: Consolas, "Segoe UI Mono", monospace; font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 10px; font-size: 12px; border: 1px solid transparent; white-space: nowrap; font-weight: 600; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { color: var(--ok); background: rgba(52, 211, 153, .12); }
.badge-warn { color: var(--warn); background: rgba(251, 191, 36, .12); }
.badge-bad { color: var(--bad); background: rgba(240, 113, 120, .12); }
.badge-info { color: #9DB4FF; background: rgba(99, 135, 255, .16); }
.badge-neutral { color: var(--muted); background: rgba(152, 168, 193, .1); }
.sample { margin-left: 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); animation: pulse 1.8s ease infinite; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }
.actions-cell form { display: inline; }
.order-controls { display: flex; align-items: center; gap: 6px; }
.drawer {
    position: fixed; top: 0; right: 0; height: 100vh; width: min(440px, 100vw); background: #121A2B;
    border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 40; padding: 22px; overflow: auto;
    transform: translateX(16px); animation: slide .2s ease both;
}
.drawer h3 { margin: 20px 0 4px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.notice-panel { position: absolute; right: 0; top: calc(100% + 8px); width: 320px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); z-index: 25; }
.notice-wrap { position: relative; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); z-index: 50; }
dl { margin: 0; }
dl div { display: grid; grid-template-columns: 140px 1fr; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
dt { color: var(--muted); }
.settings, .stack-form { display: grid; gap: 16px; max-width: 820px; }
.check { flex-direction: row !important; align-items: center; }
.pager { display: flex; gap: 12px; align-items: center; color: var(--muted); }
.pager .off { opacity: .4; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 400px at 50% -10%, rgba(99, 135, 255, .18), transparent 60%), var(--bg); }
.login-card { width: min(440px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px; display: grid; gap: 16px; }
.login-card h1 { font-size: 32px; }
.login-card label, .stack-form label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input, .stack-form input { width: 100%; background: #101827; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.login-card .check, .stack-form .check { flex-direction: row; align-items: center; color: var(--text); }
.login-card .check input, .stack-form .check input { width: auto; }
.is-loading { position: relative; }
.is-loading::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent); animation: shimmer 1.1s linear infinite; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes slide { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); } }
@keyframes shimmer { from { transform: translateX(-40%); } to { transform: translateX(40%); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 1100px) {
    .stats { grid-template-columns: 1fr 1fr; }
    .span-8, .span-4, .span-6, .span-3 { grid-column: span 12; }
    .header, .page { padding-left: 20px; padding-right: 20px; }
    .header-row { flex-wrap: wrap; }
    .header-tools { flex: 1 1 100%; }
    .search { width: min(320px, 100%); }
    .insights { grid-template-columns: 120px 1fr; }
}
@media (max-width: 800px) {
    .shell, body.is-collapsed .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; z-index: 30; width: min(280px, 88vw); transform: translateX(-105%); height: 100vh; }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 25; }
    .menu { display: inline-flex; }
    .collapse { display: none; }
    .header-row, .toolbar, .banner { flex-direction: column; align-items: stretch; }
    .search { width: 100%; }
    .header-tools { flex-wrap: wrap; }
    h1 { font-size: 26px; }
    .stat-value { font-size: 30px; }
    .portal-summary { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .stats { grid-template-columns: 1fr; }
    .insights { grid-template-columns: 1fr; justify-items: center; }
    dl div { grid-template-columns: 1fr; }
}
