:root {
    --bg: #0b0f17;
    --surface: #111827;
    --surface-2: #182235;
    --border: #243044;
    --text: #e5ecf6;
    --muted: #8fa1ba;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.14);
    --error: #f43f5e;
    --error-bg: rgba(244, 63, 94, 0.14);
    --amber: #f59e0b;
    --radius: 10px;
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 13.5px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
}

a {
    color: #60a5fa;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

code, .mono {
    font-family: var(--font-mono);
    font-size: 12px;
}

.muted {
    color: var(--muted);
    margin: 0;
    font-size: 12.5px;
}

.nowrap {
    white-space: nowrap;
}

.is-hidden {
    display: none !important;
}

/* Auth Shell */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at top, #172033 0%, #0b0f17 65%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.auth-brand h1 {
    margin: 0 0 2px;
    font-size: 18px;
}

.brand-badge {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #10b981);
    color: #fff;
    font-weight: 800;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Topbar */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 9px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-title {
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}

.brand-sub {
    font-size: 11.5px;
    color: var(--muted);
}

.nav-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.nav-tab {
    padding: 6px 12px;
    border-radius: 7px;
    color: var(--muted);
    font-weight: 500;
    font-size: 13px;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.nav-tab:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}

.nav-tab.is-active {
    background: rgba(59, 130, 246, 0.16);
    color: #93c5fd;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pill-muted {
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    color: var(--muted);
}

.user-chip {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
}

/* Main Container */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 14px 18px 28px;
}

.tab-panel {
    display: none;
}

.tab-panel.is-active {
    display: block;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 14px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.card-head h2 {
    margin: 0 0 2px;
    font-size: 15px;
    font-weight: 650;
}

/* Forms & Inputs */
.stack-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 480px;
}

.auth-card .stack-form {
    max-width: none;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field span {
    font-weight: 500;
    font-size: 12.5px;
    color: var(--text);
}

.hint {
    color: var(--muted);
    font-size: 11.5px;
}

input[type="text"],
input[type="password"],
input[type="datetime-local"],
select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    padding: 7px 10px;
    font-size: 13px;
    font-family: inherit;
    height: 34px;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Compact inline inputs for filter bars */
.compact-input {
    height: 30px !important;
    padding: 4px 9px !important;
    font-size: 12.5px !important;
    border-radius: 6px !important;
}

.w-country { width: 108px; }
.w-code    { width: 128px; }
.w-video   { width: 132px; }

/* Searchable Combobox Dropdown */
.combobox {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.combobox-input {
    width: 100%;
    padding-right: 24px !important;
}

.combobox-toggle {
    position: absolute;
    right: 2px;
    top: 2px;
    bottom: 2px;
    width: 22px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.combobox-toggle:hover {
    color: var(--text);
    background: var(--surface-2);
}

.combobox-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    width: max-content;
    max-width: 240px;
    max-height: 220px;
    overflow-y: auto;
    background: #0d131f;
    border: 1px solid #334155;
    border-radius: 7px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
    z-index: 50;
    padding: 4px;
}

.combobox-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 12.5px;
    padding: 6px 8px;
    border-radius: 5px;
    cursor: pointer;
    text-align: left;
}

.combobox-item:hover,
.combobox-item.is-highlighted {
    background: rgba(59, 130, 246, 0.2);
    color: #fff;
}

.combobox-item-count {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
}

.combobox-empty {
    padding: 7px 9px;
    font-size: 12px;
    color: var(--muted);
}
.w-msg     { width: 175px; }
.w-ip      { width: 128px; }
.input-site { width: 140px; }
.input-dt   { width: 165px; }

.inline-form {
    display: inline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border-radius: 7px;
    border: 1px solid transparent;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    white-space: nowrap;
}

.btn:hover {
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: #3f5275;
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--muted);
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--surface-2);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.16);
    border-color: rgba(244, 63, 94, 0.35);
    color: #fda4af;
}

.btn-danger:hover {
    background: rgba(244, 63, 94, 0.28);
}

.btn-sm {
    height: 32px;
    padding: 0 12px;
    font-size: 12.5px;
}

.btn-xs {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-block {
    width: 100%;
}

/* Alerts & Creds */
.alert {
    padding: 9px 12px;
    border-radius: 7px;
    margin-bottom: 12px;
    font-size: 13px;
    border: 1px solid transparent;
}

.alert-error {
    background: var(--error-bg);
    border-color: rgba(244, 63, 94, 0.35);
    color: #fecdd3;
}

.alert-success {
    background: var(--success-bg);
    border-color: rgba(16, 185, 129, 0.35);
    color: #a7f3d0;
}

.cred-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 10px;
}

.cred-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.cred-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--muted);
    display: block;
    margin-bottom: 2px;
}

.cred-box code {
    word-break: break-all;
    color: #a7f3d0;
}

/* Top One-Line Filter Bar */
.filter-panel {
    padding: 10px 14px;
}

.top-filter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.preset-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.preset-pill {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 11px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
    white-space: nowrap;
}

.preset-pill:hover {
    color: var(--text);
    border-color: #425577;
    text-decoration: none;
}

.preset-pill.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.top-filter-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.custom-range-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.range-sep {
    font-size: 12px;
    color: var(--muted);
}

.range-meta {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: var(--muted);
}

.active-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    background: rgba(59, 130, 246, 0.16);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #bfdbfe;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11.5px;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
}

.kpi-success {
    border-top: 3px solid var(--success);
}

.kpi-error {
    border-top: 3px solid var(--error);
}

.kpi-label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.15;
    margin-bottom: 2px;
}

.kpi-slash {
    color: var(--muted);
    font-weight: 400;
}

.kpi-sub {
    font-size: 11.5px;
    color: var(--muted);
}

/* Analytics Grid */
.analytics-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 14px;
    align-items: stretch;
}

.legend {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--muted);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    display: inline-block;
}

.dot-success { background: var(--success); }
.dot-error   { background: var(--error); }

.chart-stage {
    position: relative;
    width: 100%;
    min-height: 235px;
}

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: #090d14;
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 7px 10px;
    font-size: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 10;
    white-space: nowrap;
}

.breakdown-group {
    margin-top: 10px;
}

.breakdown-group + .breakdown-group {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.breakdown-group h3 {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    margin: 0 0 7px;
}

.bar-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bar-row {
    display: grid;
    grid-template-columns: 95px 1fr 40px;
    align-items: center;
    gap: 8px;
    color: var(--text);
    padding: 2px 4px;
    border-radius: 5px;
}

.bar-row:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.bar-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
}

.bar-track {
    height: 6px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill {
    display: block;
    height: 100%;
    background: var(--error);
    border-radius: 999px;
}

.bar-fill-amber {
    background: var(--amber);
}

.bar-count {
    text-align: right;
    font-size: 11.5px;
    color: var(--muted);
    font-family: var(--font-mono);
}

.empty-mini, .empty-state {
    color: var(--muted);
    font-size: 12.5px;
    padding: 10px 0;
}

.empty-state {
    text-align: center;
    padding: 24px 14px;
}

/* Table & One-Line Failure Filter Bar */
.table-head-row {
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.table-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table th {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--muted);
    font-weight: 600;
    background: rgba(255, 255, 255, 0.015);
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

.msg-cell {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.actions-cell {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 11.5px;
    font-weight: 600;
    font-family: var(--font-mono);
}

.badge-success {
    background: var(--success-bg);
    color: #6ee7b7;
}

.badge-error {
    background: var(--error-bg);
    color: #fda4af;
}

.badge-neutral {
    background: rgba(59, 130, 246, 0.16);
    color: #93c5fd;
}

.badge-muted {
    background: var(--surface-2);
    color: var(--muted);
}

.pagination {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.code-block {
    margin: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 12px;
    overflow-x: auto;
    color: #cbd5e1;
    font-size: 12px;
    line-height: 1.5;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 60;
}

.modal-card {
    width: 100%;
    max-width: 620px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.modal-head h3 {
    margin: 0;
    font-size: 15px;
}

.detail-dl {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 7px 12px;
    margin: 0;
}

.detail-dl dt {
    color: var(--muted);
    font-size: 12px;
}

.detail-dl dd {
    margin: 0;
    word-break: break-word;
    font-size: 13px;
}

@media (max-width: 1024px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .analytics-grid,
    .two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .w-country, .w-code, .w-video, .w-msg, .w-ip, .input-site, .input-dt {
        width: 100%;
    }
}
