/* Affinity Admin Portal - single stylesheet, no build step, no external resources. */

:root {
    --surface-1: #fcfcfb;
    --surface-2: #f2f1ee;
    --page-plane: #f9f9f7;
    --text-primary: #0b0b0b;
    --text-secondary: #52514e;
    --text-muted: #898781;
    --gridline: #e1e0d9;
    --baseline: #c3c2b7;
    --border: rgba(11, 11, 11, 0.1);

    --accent: #2a78d6;
    --accent-strong: #184f95;

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #d03b3b;

    --badge-completed-bg: #e3f7e3;
    --badge-completed-fg: #0a6b0a;
    --badge-processing-bg: #e4eefb;
    --badge-processing-fg: #184f95;
    --badge-pending-bg: #ecebe7;
    --badge-pending-fg: #52514e;
    --badge-error-bg: #fbe6e5;
    --badge-error-fg: #a12523;

    --sidebar-width: 220px;
    --topbar-height: 56px;
    --radius: 6px;
    --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --surface-1: #1a1a19;
        --surface-2: #232322;
        --page-plane: #0d0d0d;
        --text-primary: #ffffff;
        --text-secondary: #c3c2b7;
        --text-muted: #898781;
        --gridline: #2c2c2a;
        --baseline: #383835;
        --border: rgba(255, 255, 255, 0.1);

        --accent: #3987e5;
        --accent-strong: #86b6ef;

        --badge-completed-bg: #12321b;
        --badge-completed-fg: #4fd16a;
        --badge-processing-bg: #142a42;
        --badge-processing-fg: #6ea8f0;
        --badge-pending-bg: #2a2a28;
        --badge-pending-fg: #c3c2b7;
        --badge-error-bg: #3a1a19;
        --badge-error-fg: #f0918f;
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--page-plane);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
}

a {
    color: var(--accent);
}

button,
input,
select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* ---------- Login page ---------- */

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 28px;
    box-shadow: 0 8px 24px rgba(11, 11, 11, 0.08);
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 20px;
}

.login-card .login-sub {
    margin: 0 0 24px;
    color: var(--text-secondary);
    font-size: 13px;
}

.form-field {
    margin-bottom: 16px;
}

.form-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}

.form-field input {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text-primary);
}

.form-field input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.form-error {
    min-height: 18px;
    color: var(--status-critical);
    font-size: 13px;
    margin-bottom: 12px;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-primary);
    border-radius: var(--radius);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-block {
    width: 100%;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

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

.btn-danger {
    background: var(--status-critical);
    border-color: var(--status-critical);
    color: #ffffff;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

/* ---------- App shell ---------- */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

.sidebar {
    grid-area: sidebar;
    background: var(--surface-1);
    border-right: 1px solid var(--border);
    padding: 16px 0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    font-weight: 600;
    font-size: 15px;
    padding: 0 20px 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

.nav-item a {
    display: block;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    border-left: 3px solid transparent;
}

.nav-item a:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.nav-item.active a {
    color: var(--text-primary);
    font-weight: 600;
    border-left-color: var(--accent);
    background: var(--surface-2);
}

.topbar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-1);
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user {
    color: var(--text-secondary);
    font-size: 13px;
}

.main-content {
    grid-area: main;
    padding: 24px;
    overflow-y: auto;
}

.view-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 16px;
}

/* ---------- Cards & tiles ---------- */

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

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

.card-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.card-sub {
    font-size: 12px;
    color: var(--text-muted);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-tile {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 26px;
    font-weight: 600;
    line-height: 1.1;
}

.stat-sub {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.stat-sub .stat-sub-good {
    color: var(--status-good);
}

.stat-sub .stat-sub-bad {
    color: var(--status-critical);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .app-shell {
        grid-template-columns: 64px 1fr;
    }
    .sidebar-brand,
    .nav-item a span.nav-label {
        display: none;
    }
}

.empty-state {
    color: var(--text-muted);
    font-size: 13px;
    padding: 24px 0;
    text-align: center;
}

/* ---------- Status badges ---------- */

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-completed {
    background: var(--badge-completed-bg);
    color: var(--badge-completed-fg);
}

.badge-processing {
    background: var(--badge-processing-bg);
    color: var(--badge-processing-fg);
}

.badge-pending {
    background: var(--badge-pending-bg);
    color: var(--badge-pending-fg);
}

.badge-error,
.badge-failed {
    background: var(--badge-error-bg);
    color: var(--badge-error-fg);
}

.badge-health-healthy {
    background: var(--badge-completed-bg);
    color: var(--badge-completed-fg);
}

.badge-health-degraded {
    background: var(--badge-pending-bg);
    color: #a5710c;
}

.badge-health-unhealthy {
    background: var(--badge-error-bg);
    color: var(--badge-error-fg);
}

/* ---------- Filter bar ---------- */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
}

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

.filter-field label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-field input,
.filter-field select {
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    min-width: 130px;
}

.filter-actions {
    display: flex;
    gap: 8px;
}

/* ---------- Tables ---------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    text-align: left;
    padding: 10px 12px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr.clickable {
    cursor: pointer;
}

tbody tr.clickable:hover {
    background: var(--surface-2);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ---------- Drawer ---------- */

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.35);
    display: none;
    z-index: 40;
}

.drawer-overlay.open {
    display: block;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(560px, 92vw);
    background: var(--surface-1);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.15s ease-out;
    z-index: 41;
    display: flex;
    flex-direction: column;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.drawer-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.drawer-actions {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

.detail-row {
    display: flex;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.detail-row .detail-key {
    width: 140px;
    flex: none;
    color: var(--text-muted);
}

.detail-row .detail-val {
    flex: 1;
    word-break: break-word;
}

pre.json-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    font-size: 12px;
    overflow-x: auto;
    max-height: 320px;
    white-space: pre-wrap;
    word-break: break-word;
}

.error-block {
    background: var(--badge-error-bg);
    color: var(--badge-error-fg);
    border-radius: var(--radius);
    padding: 10px;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Toggle / tabs ---------- */

.tab-group {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.tab-btn {
    padding: 7px 16px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
}

.tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

/* ---------- Chart chrome (SVG element classes; colors follow CSS vars for theme parity) ---------- */

.chart-svg {
    width: 100%;
    height: auto;
    display: block;
    overflow: visible;
}

.chart-gridline {
    stroke: var(--gridline);
    stroke-width: 1;
}

.chart-baseline {
    stroke: var(--baseline);
    stroke-width: 1;
}

.chart-axis-label {
    fill: var(--text-muted);
    font-size: 10px;
    font-family: var(--font-sans);
}

.chart-crosshair {
    stroke: var(--baseline);
    stroke-width: 1;
    visibility: hidden;
}

.chart-crosshair.visible {
    visibility: visible;
}

.chart-tooltip {
    visibility: hidden;
}

.chart-tooltip.visible {
    visibility: visible;
}

.chart-marker-ring {
    fill: var(--surface-1);
}

.chart-hover-dot {
    stroke: var(--surface-1);
    stroke-width: 2;
    visibility: hidden;
}

.chart-hover-dot.visible {
    visibility: visible;
}

.chart-tooltip-bg {
    fill: var(--surface-1);
    stroke: var(--border);
    stroke-width: 1;
}

.chart-tooltip-text {
    fill: var(--text-primary);
    font-size: 11px;
    font-family: var(--font-sans);
}

.chart-tooltip-text-muted {
    fill: var(--text-muted);
    font-size: 10px;
    font-family: var(--font-sans);
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chart-legend-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    flex: none;
}

.chart-bar {
    cursor: pointer;
}

.chart-bar:hover {
    opacity: 0.85;
}

/* ---------- Toasts ---------- */

.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.toast {
    min-width: 220px;
    max-width: 360px;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    box-shadow: 0 4px 14px rgba(11, 11, 11, 0.18);
    border: 1px solid var(--border);
    background: var(--surface-1);
    color: var(--text-primary);
}

.toast-success {
    border-left: 3px solid var(--status-good);
}

.toast-error {
    border-left: 3px solid var(--status-critical);
}

.toast-info {
    border-left: 3px solid var(--accent);
}

/* ---------- Utility ---------- */

.hidden {
    display: none !important;
}

.text-muted {
    color: var(--text-muted);
}

.mb-0 {
    margin-bottom: 0;
}

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

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
    font-size: 13px;
}
