@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans-400.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans-500.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans-600.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-400.woff2") format("woff2");
}

@font-face {
    font-family: "IBM Plex Mono";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/ibm-plex-mono-500.woff2") format("woff2");
}

:root {
    --bg: oklch(0.965 0.012 220);
    --surface: oklch(0.992 0.004 220);
    --surface-2: oklch(0.948 0.014 220);
    --ink: oklch(0.24 0.022 240);
    --muted: oklch(0.4 0.02 230);
    --line: oklch(0.88 0.014 220);
    --accent: oklch(0.44 0.09 198);
    --accent-hover: oklch(0.38 0.09 198);
    --accent-soft: oklch(0.93 0.035 198);
    --ok: oklch(0.44 0.08 155);
    --ok-soft: oklch(0.95 0.03 155);
    --warn: oklch(0.52 0.1 70);
    --warn-soft: oklch(0.95 0.04 80);
    --danger: oklch(0.5 0.14 25);
    --danger-soft: oklch(0.95 0.03 25);
    --on-accent: oklch(0.99 0.005 200);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 2px oklch(0.24 0.022 240 / 0.05), 0 8px 24px oklch(0.24 0.022 240 / 0.04);
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --sidebar: 248px;
    --z-sticky: 30;
    --z-sidebar: 40;
    --z-overlay: 50;
    --font: "IBM Plex Sans", "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
    --bs-body-font-family: var(--font);
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--bg);
    --bs-primary: oklch(0.4 0.07 200);
    --bs-border-color: var(--line);
    --bs-emphasis-color: var(--ink);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -48px;
    z-index: 80;
    padding: 8px 12px;
    background: var(--ink);
    color: var(--surface);
    border-radius: var(--radius);
}

.skip-link:focus {
    top: 12px;
}

a {
    color: var(--accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

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

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    display: block;
    flex-shrink: 0;
}

/* Shell */
.app-shell {
    min-height: 100dvh;
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 22px 16px 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px 20px;
    color: inherit;
    text-decoration: none;
}

.brand:hover {
    color: inherit;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--on-accent);
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-name {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.brand-sub {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.3;
}

.app-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.app-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 0 10px;
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 180ms var(--ease), color 180ms var(--ease);
}

.app-nav a:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.app-nav a.is-current {
    background: var(--accent-soft);
    color: var(--accent);
}

.sidebar-foot {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.sidebar-user {
    padding: 0 10px 10px;
    color: var(--muted);
    font-size: 12px;
}

.sidebar-user strong {
    display: block;
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
}

.app-main {
    margin-left: var(--sidebar);
    min-height: 100dvh;
    padding: 32px 40px 56px;
}

.app-main main {
    max-width: 1120px;
}

.sidebar-foot .btn {
    width: 100%;
    justify-content: flex-start;
}

.topbar {
    display: none;
}

.nav-backdrop {
    display: none;
}

/* Page */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 28px;
}

.page-head h1,
h1 {
    margin: 0 0 6px;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.15;
    text-wrap: balance;
}

h2 {
    margin: 0 0 8px;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-lead,
.muted {
    margin: 0;
    color: var(--muted);
    max-width: 62ch;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

/* Buttons */
body.nav-open {
    overflow: hidden;
}

.btn {
    --bs-btn-padding-x: 14px;
    --bs-btn-padding-y: 9px;
    --bs-btn-font-size: 14px;
    --bs-btn-font-weight: 500;
    --bs-btn-line-height: 1.25;
    --bs-btn-border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 1px solid transparent;
    cursor: pointer;
    touch-action: manipulation;
    text-decoration: none;
    transition: background 180ms var(--ease), border-color 180ms var(--ease), transform 120ms var(--ease), color 180ms var(--ease);
}

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

.btn:active {
    transform: translateY(1px);
}

.btn-primary,
.btn-primary:hover,
.btn-primary:focus-visible {
    --bs-btn-color: var(--on-accent);
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-bg: var(--accent-hover);
    --bs-btn-hover-border-color: var(--accent-hover);
    --bs-btn-hover-color: var(--on-accent);
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: var(--on-accent);
}

.btn-secondary,
.btn-outline-primary,
.btn-outline-success,
.btn-outline-warning {
    background: var(--surface);
    border-color: var(--line);
    color: var(--ink);
}

.btn-secondary:hover,
.btn-outline-primary:hover,
.btn-outline-success:hover,
.btn-outline-warning:hover {
    background: var(--surface-2);
    border-color: oklch(0.8 0.016 220);
    color: var(--ink);
}

.btn-danger,
.btn-outline-danger {
    background: var(--surface);
    border-color: var(--line);
    color: var(--danger);
}

.btn-danger:hover,
.btn-outline-danger:hover {
    background: var(--danger-soft);
    border-color: oklch(0.82 0.05 25);
    color: var(--danger);
}

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

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

.btn:disabled,
.btn.disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.btn-primary:disabled,
.btn-primary.disabled {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.btn-sm {
    min-height: 32px;
    padding: 4px 10px;
    font-size: 13px;
}

.btn-icon {
    width: 40px;
    padding: 0;
}

/* Forms */
.form-label {
    margin-bottom: 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 500;
}

.form-control,
.form-select {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: none;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px oklch(0.4 0.07 200 / 0.16);
}

.form-control::placeholder {
    color: oklch(0.5 0.02 230);
}

.form-check-input {
    width: 18px;
    height: 18px;
    margin-top: 0.15em;
    border-color: oklch(0.72 0.02 220);
}

.form-check-input:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

.field-help {
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
}

.password-field {
    position: relative;
}

.password-field .form-control {
    padding-right: 44px;
}

.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: var(--radius);
    cursor: pointer;
}

.password-toggle:hover {
    color: var(--ink);
}

/* Surfaces */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}

.panel-body {
    padding: 22px 24px;
}

.panel + .panel,
.panel + .toolbar {
    margin-top: 16px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

/* Metrics / overview */
.overview {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.status-list {
    display: grid;
}

.status-row {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 16px;
    padding: 16px 0;
    border-top: 1px solid var(--line);
}

.status-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.status-row:last-child {
    padding-bottom: 0;
}

.status-row dt {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.status-row dd {
    margin: 0;
}

.status-value {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.status-value.is-ok {
    color: var(--ok);
}

.status-value.is-off {
    color: var(--danger);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
    padding: 8px 20px;
    border-left: 1px solid var(--line);
}

.metric:first-child {
    border-left: 0;
    padding-left: 0;
}

.metric-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.metric-value {
    margin-top: 4px;
    font-family: var(--mono);
    font-size: 22px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

/* Tables */
.table-wrap {
    overflow: auto;
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--ink);
    --bs-table-border-color: var(--line);
    --bs-table-hover-bg: var(--surface-2);
    margin: 0;
    font-size: 14px;
}

.table > :not(caption) > * > * {
    padding: 14px 16px;
    background: transparent;
    border-bottom-width: 1px;
}

.table thead th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    border-bottom: 1px solid var(--line);
}

.table tbody tr:last-child > * {
    border-bottom: 0;
}

.table .num,
td.num {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

.row-title {
    font-weight: 500;
}

.row-meta {
    color: var(--muted);
    font-size: 12px;
    font-family: var(--mono);
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

/* Status chips */
.status,
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    line-height: 1;
    border: 0;
}

.status-ok,
.badge.status-ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.status-running,
.badge.status-running {
    background: var(--accent-soft);
    color: var(--accent);
}

.status-warning,
.badge.status-warning {
    background: var(--warn-soft);
    color: var(--warn);
}

.status-danger,
.badge.status-danger,
.badge.text-bg-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.status-pending,
.status-muted,
.badge.status-pending,
.badge.status-muted,
.badge.text-bg-warning,
.badge.text-bg-light {
    background: var(--surface-2);
    color: var(--muted);
}

/* Alerts / empty */
.alert {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--ink);
    padding: 14px 16px;
}

.alert-success {
    background: var(--ok-soft);
    border-color: oklch(0.86 0.04 155);
}

.alert-danger {
    background: var(--danger-soft);
    border-color: oklch(0.86 0.04 25);
}

.alert-warning {
    background: var(--warn-soft);
    border-color: oklch(0.88 0.05 80);
}

.callout {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
    padding: 14px 16px;
    border: 1px solid oklch(0.88 0.05 80);
    border-radius: var(--radius-lg);
    background: var(--warn-soft);
}

.empty {
    display: grid;
    justify-items: start;
    gap: 8px;
    padding: 40px 24px;
}

.empty .icon {
    color: var(--muted);
}

.empty p {
    margin: 0;
    color: var(--muted);
    max-width: 48ch;
}

/* Settings */
.props {
    display: grid;
    gap: 0;
    margin: 16px 0 0;
}

.prop {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 16px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.prop:first-child {
    border-top: 0;
    padding-top: 0;
}

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

.prop dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
}

.code-block {
    margin: 0;
    padding: 14px 16px;
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 12px;
    white-space: pre-wrap;
}

.log-box {
    max-height: 420px;
    overflow: auto;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.6;
}

.log-line {
    display: grid;
    grid-template-columns: 148px auto 1fr;
    gap: 10px;
    padding: 6px 0;
    border-top: 1px solid var(--line);
}

.log-line:first-child {
    border-top: 0;
}

.log-time {
    color: var(--muted);
}

pre {
    white-space: pre-wrap;
}

/* Auth */
.auth-body {
    min-height: 100dvh;
    background: var(--bg);
}

.auth-shell {
    display: grid;
    grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
    min-height: 100dvh;
}

.auth-panel {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px 44px;
    border-right: 1px solid var(--line);
    background: var(--surface);
}

.auth-panel h1 {
    max-width: 12ch;
    font-size: 40px;
}

.auth-panel p {
    margin: 12px 0 0;
    color: var(--muted);
    max-width: 32ch;
}

.auth-kicker {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.auth-kicker .brand-mark {
    width: 28px;
    height: 28px;
}

.auth-foot {
    color: var(--muted);
    font-size: 13px;
}

.auth-main {
    display: grid;
    align-content: center;
    padding: 40px;
}

.auth-card {
    width: min(420px, 100%);
    margin: 0 auto;
}

.auth-card h2 {
    font-size: 22px;
}

.auth-card .page-lead {
    margin-bottom: 24px;
}

/* Setup */
.setup-wrap {
    width: min(640px, calc(100% - 32px));
    margin: 48px auto;
}

.setup-wrap ol {
    padding-left: 18px;
}

.setup-wrap li + li {
    margin-top: 8px;
}

/* Mobile */
@media (max-width: 960px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 200ms var(--ease);
    }

    body.nav-open .app-sidebar {
        transform: none;
    }

    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: var(--z-overlay);
        background: oklch(0.24 0.022 240 / 0.32);
        opacity: 0;
        pointer-events: none;
        transition: opacity 200ms var(--ease);
    }

    body.nav-open .nav-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    .app-main {
        margin-left: 0;
        padding: 20px 18px 40px;
    }

    .topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin: -8px 0 20px;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .overview,
    .metrics {
        grid-template-columns: 1fr;
    }

    .metric {
        border-left: 0;
        border-top: 1px solid var(--line);
        padding: 16px 0;
    }

    .metric:first-child {
        border-top: 0;
        padding-top: 0;
    }

    .status-row,
    .prop,
    .log-line {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .auth-shell {
        grid-template-columns: 1fr;
        align-content: start;
    }

    .auth-panel {
        justify-content: flex-start;
        gap: 20px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 28px 22px;
    }

    .auth-panel h1 {
        font-size: 28px;
    }

    .auth-main {
        padding: 28px 22px 40px;
        align-content: start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .nav-backdrop {
        background: oklch(0.24 0.022 240 / 0.7);
    }
}
