:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1c2026;
    --muted: #68707c;
    --primary: #3b5bdb;
    --primary-text: #ffffff;
    --danger: #c92a2a;
    --success: #2b8a3e;
    --warning: #c77700;
    --radius: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --surface: #1c2027;
        --border: #2d333c;
        --text: #e6e8eb;
        --muted: #9aa2ad;
        --primary: #5c7cfa;
        --danger: #ff6b6b;
        --success: #51cf66;
        --warning: #fcc419;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 1.25rem; }

.nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.nav-brand { font-weight: 700; color: var(--text); text-decoration: none; }
.nav-links { display: flex; gap: 1rem; flex: 1; }
.nav-links a { color: var(--muted); text-decoration: none; }
.nav-links a:hover { color: var(--text); }
.nav-user { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); margin: 0; }

.app-main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem; }

.layout-minimal .minimal-main {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

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

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.card-title { font-size: 1rem; margin: 0 0 0.75rem; }

.empty-state { color: var(--muted); margin: 0; }

.form-field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 1rem; }
.form-field label { font-weight: 600; font-size: 0.875rem; }
.form-field input {
    font: inherit;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}
.form-field input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.button {
    font: inherit;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
}
.button-primary { background: var(--primary); color: var(--primary-text); }
.button-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.button-danger { background: var(--danger); color: #fff; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert-error { color: var(--danger); border-color: var(--danger); }
.alert-success { color: var(--success); border-color: var(--success); }
.alert-info { color: var(--muted); border-color: var(--border); }

.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid currentColor;
}
.badge-up, .badge-resolved, .badge-ok, .badge-sent, .badge-enabled { color: var(--success); }
.badge-down, .badge-unresolved, .badge-failed { color: var(--danger); }
.badge-pending { color: var(--warning); }
.badge-paused, .badge-ignored, .badge-skipped, .badge-disabled { color: var(--muted); }

.login-form {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
}
.login-form .button { width: 100%; }

.error-page { text-align: center; max-width: 900px; }
.error-details {
    text-align: left;
    font-family: var(--mono);
    font-size: 0.8rem;
    white-space: pre-wrap;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    overflow-x: auto;
}

/* Shared helpers */
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.mono { font-family: var(--mono); font-size: 0.8125rem; }
.nowrap { white-space: nowrap; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}
.stack { display: flex; flex-direction: column; gap: 1rem; }

.nav-links a[aria-current="page"] { color: var(--text); font-weight: 600; }

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; }
.page-header p { margin: 0.25rem 0 0; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0; }
.actions form { margin: 0; }
.actions-end { justify-content: flex-end; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 0.75rem; margin-top: 1rem; }
.inline-form .alert { flex-basis: 100%; margin: 0; }
.inline-form .form-field { flex: 1 1 260px; max-width: 360px; margin-bottom: 0; }

.card-header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.card-danger { border-color: var(--danger); }
.form-card { max-width: 520px; }
.form-actions { display: flex; gap: 0.5rem; }
a.button { display: inline-block; text-decoration: none; }

.form-field select {
    font: inherit;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}
.form-field-compact { margin-bottom: 0; }
.form-field input[type="search"] { min-width: 0; }

.subsection-title { font-size: 0.875rem; margin: 1rem 0 0.5rem; color: var(--muted); }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.card .data-table { border: 0; }
.data-table th, .data-table td { padding: 0.625rem 0.75rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.data-table thead th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.col-check { width: 2rem; }

.kv-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.kv-table th, .kv-table td { padding: 0.375rem 0.5rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.kv-table th { width: 30%; color: var(--muted); font-weight: 600; word-break: break-word; }
.kv-table pre { margin: 0; font-family: var(--mono); white-space: pre-wrap; word-break: break-word; }

/* Issues */
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.filters-search { flex: 1 1 220px; }
.bulk-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.bulk-actions .button { padding: 0.25rem 0.75rem; }

.issue-title { font-weight: 600; text-decoration: none; word-break: break-word; }
.issue-title:hover { text-decoration: underline; }
.issue-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 0.25rem; color: var(--muted); font-size: 0.8125rem; }
.issue-heading { word-break: break-word; margin-bottom: 0.5rem; }

.tag {
    display: inline-block;
    padding: 0 0.375rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
}
.tag-warning { color: var(--warning); border-color: var(--warning); }

.level { font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; }
.level-fatal, .level-error { color: var(--danger); }
.level-warning { color: var(--warning); }
.level-info, .level-debug { color: var(--muted); }

.issue-summary { display: grid; gap: 1rem; grid-template-columns: minmax(220px, 1fr) 2fr; margin-bottom: 1rem; }
@media (max-width: 720px) { .issue-summary { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; align-content: start; }
.stat-value { display: block; font-size: 1.25rem; font-weight: 700; word-break: break-word; }
.stat-value.mono { font-size: 0.875rem; }
.stat-label { color: var(--muted); font-size: 0.75rem; }

.event-nav { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: baseline; margin: 1.5rem 0 0.75rem; }
.event-nav-links { margin-left: auto; display: flex; gap: 1rem; }

.message, .request-line { font-family: var(--mono); font-size: 0.8125rem; white-space: pre-wrap; word-break: break-word; margin: 0 0 0.5rem; }

/* Stack trace */
.exception + .exception { margin-top: 1.5rem; }
.exception-chain { margin: 0 0 0.25rem; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; }
.exception-title { font-size: 1rem; margin: 0 0 0.25rem; word-break: break-word; }
.exception-value { font-weight: 400; }
.frames { list-style: none; margin: 0.5rem 0 0; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); }
.frame + .frame { border-top: 1px solid var(--border); }
.frame summary { padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.8125rem; display: flex; flex-wrap: wrap; gap: 0.375rem; align-items: baseline; }
.frame:not(.frame-in-app) summary { color: var(--muted); }
.frame-location { font-family: var(--mono); word-break: break-all; }
.frame-function { font-family: var(--mono); font-weight: 600; }
.frame-source { margin: 0; padding: 0.5rem 0; background: var(--bg); font-family: var(--mono); font-size: 0.8125rem; overflow-x: auto; }
.source-line { display: block; padding: 0 0.75rem; white-space: pre; }
.source-line-current { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.source-number { display: inline-block; min-width: 3rem; color: var(--muted); user-select: none; }
.frame .kv-table { margin: 0.5rem 0.75rem 0.75rem; width: calc(100% - 1.5rem); }
.frame-empty { padding: 0 0.75rem 0.5rem; margin: 0; }

/* Bar chart: thin columns, 2px gaps, 4px rounded tops anchored to the baseline */
.bar-chart { margin: 0; }
.bar-chart figcaption { font-weight: 600; font-size: 0.875rem; margin-bottom: 0.75rem; }
.bar-chart-plot { position: relative; display: flex; align-items: flex-end; gap: 2px; height: 120px; border-bottom: 1px solid var(--border); }
.bar-chart-max { position: absolute; top: -0.25rem; right: 0; font-size: 0.6875rem; color: var(--muted); }
.bar-chart-slot { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar-chart-bar { width: min(100%, 24px); background: var(--primary); border-radius: 4px 4px 0 0; }
.bar-chart-slot:hover .bar-chart-bar { opacity: 0.8; }
.bar-chart-slot:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 4px);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: var(--text);
    color: var(--bg);
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1;
}
.bar-chart-axis { display: flex; justify-content: space-between; font-size: 0.6875rem; color: var(--muted); margin-top: 0.25rem; }

/* Code */
.code-block { position: relative; }
.code-block pre {
    margin: 0;
    padding: 0.75rem 5.5rem 0.75rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 0.8125rem;
    overflow-x: auto;
}
.code-copy { position: absolute; top: 0.5rem; right: 0.5rem; padding: 0.125rem 0.625rem; font-size: 0.75rem; background: var(--surface); }

/* Pagination & danger zone */
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }
.danger-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 0.75rem 0; border-top: 1px solid var(--border); }
.danger-row:first-of-type { border-top: 0; }
.danger-row p { margin: 0.25rem 0 0.5rem; }
.danger-row .form-field { margin-bottom: 0; max-width: 320px; }

@media (max-width: 640px) {
    .nav { flex-wrap: wrap; }
    .issue-table th:nth-child(n+4), .issue-table td:nth-child(n+4) { display: none; }
    .danger-row { flex-direction: column; }
}

/* Monitors */
.stats-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.page-header .actions form { margin: 0; }
