/* ============================================================
   k8scost — design system
   One stylesheet, no build pipeline. Replaces PicoCSS entirely.
   Inspired by Linear / Grafana / Kubecost.
   ============================================================ */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd,
figure, blockquote, fieldset, legend { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: none;
         padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }
hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---------- Tokens ---------- */
:root {
    --bg:           #f8fafc;
    --surface:      #ffffff;
    --surface-2:    #f1f5f9;
    --surface-3:    #e2e8f0;
    --border:       #e2e8f0;
    --border-strong:#cbd5e1;

    --text:         #0f172a;
    --text-muted:   #475569;
    --text-faint:   #94a3b8;

    --primary:      #2563eb;
    --primary-hov:  #1d4ed8;
    --primary-bg:   #eff6ff;
    --primary-bord: #bfdbfe;

    --success:      #16a34a;
    --success-bg:   #ecfdf5;
    --success-bord: #a7f3d0;

    --warning:      #f59e0b;
    --warning-bg:   #fffbeb;
    --warning-bord: #fde68a;

    --danger:       #dc2626;
    --danger-bg:    #fef2f2;
    --danger-bord:  #fecaca;

    --info:         #0891b2;
    --info-bg:      #ecfeff;
    --info-bord:    #a5f3fc;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow:    0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .06), 0 2px 4px rgba(15, 23, 42, .04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);

    --radius-sm: 4px;
    --radius:    6px;
    --radius-lg: 10px;

    --sidebar-w: 240px;
    --topbar-h:  56px;

    --font-sans:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono:
        ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo,
        Consolas, "Liberation Mono", monospace;
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}
h1 { font-size: 1.5rem;  line-height: 1.25; }
h2 { font-size: 1.25rem; line-height: 1.3; }
h3 { font-size: 1rem;    line-height: 1.35; }
h4 { font-size: .9rem;   line-height: 1.4; }
p  { color: var(--text); }
small { font-size: .8125rem; color: var(--text-muted); }
code, pre {
    font-family: var(--font-mono);
    font-size: .8125rem;
}
code {
    background: var(--surface-2);
    padding: .1rem .35rem;
    border-radius: var(--radius-sm);
    color: var(--text);
}
a { color: var(--primary); }
a:hover { color: var(--primary-hov); text-decoration: underline; }

/* ---------- Layout ---------- */
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
}
.app-shell.no-sidebar {
    grid-template-columns: 1fr;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar-header {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    color: var(--text);
    font-weight: 600;
    font-size: .95rem;
    letter-spacing: -.01em;
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark {
    width: 28px; height: 28px;
    border-radius: 7px;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 2px 6px rgba(37, 99, 235, .35);
}
.brand-mark svg { width: 16px; height: 16px; }

.sidebar-nav {
    flex: 1;
    padding: .75rem .5rem;
    display: flex;
    flex-direction: column;
    gap: .125rem;
    overflow-y: auto;
}
.nav-section-label {
    font-size: .6875rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 1rem .75rem .375rem;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    font-size: .875rem;
    transition: background .12s, color .12s;
}
.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
    text-decoration: none;
}
.nav-item.active {
    background: var(--primary-bg);
    color: var(--primary);
}
.nav-item.active svg { color: var(--primary); }
.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--text-faint);
}
.nav-item:hover svg { color: var(--text-muted); }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: .75rem;
    flex-shrink: 0;
}
.user-card {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem .625rem;
    border-radius: var(--radius);
}
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-bg);
    color: var(--primary);
    display: grid; place-items: center;
    font-weight: 600;
    font-size: .8125rem;
    flex-shrink: 0;
}
.user-info { min-width: 0; flex: 1; }
.user-name {
    font-weight: 500;
    font-size: .8125rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-meta {
    font-size: .75rem;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-footer-links {
    display: flex;
    flex-direction: column;
    gap: .125rem;
    margin-top: .375rem;
}
.sidebar-footer-links .nav-item { padding: .375rem .625rem; font-size: .8125rem; }
.sidebar-footer .logout-form { margin: 0; }
.sidebar-footer .logout-btn {
    display: flex;
    align-items: center;
    gap: .625rem;
    width: 100%;
    padding: .375rem .625rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: .8125rem;
    font-weight: 500;
    text-align: left;
    transition: background .12s, color .12s;
}
.sidebar-footer .logout-btn:hover {
    background: var(--danger-bg);
    color: var(--danger);
}
.sidebar-footer .logout-btn svg { width: 18px; height: 18px; }

/* ---------- Main / topbar ---------- */
.main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-title {
    font-size: .9375rem;
    font-weight: 600;
    color: var(--text);
}
.topbar-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}
.sidebar-toggle {
    display: none;
    width: 36px; height: 36px;
    border-radius: var(--radius);
    color: var(--text-muted);
    align-items: center;
    justify-content: center;
}
.sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }
.sidebar-toggle svg { width: 20px; height: 20px; }

.content {
    padding: 1.5rem;
    max-width: 100%;
}

/* ---------- Toolbar (page header inside content) ---------- */
.toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.toolbar-title h1 { margin: 0; }
.toolbar-title p {
    margin: .25rem 0 0;
    color: var(--text-muted);
    font-size: .875rem;
}
.toolbar-actions {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ---------- Cards / surfaces ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-body { padding: 1.25rem; }
.card-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
.card-header h2,
.card-header h3 { margin: 0; }
.card-footer {
    padding: .875rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Stack of cards */
.stack { display: flex; flex-direction: column; gap: 1.25rem; }
.stack-sm { display: flex; flex-direction: column; gap: .5rem; }

/* ---------- KPI cards ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.125rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}
.kpi-label {
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}
.kpi-value {
    font-size: 1.625rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -.02em;
    line-height: 1.15;
}
.kpi-value.kpi-value-sm { font-size: 1.375rem; }
.kpi-meta {
    font-size: .8125rem;
    color: var(--text-muted);
    margin-top: .25rem;
}
.kpi-delta {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-weight: 600;
}
.kpi-delta.up    { color: var(--danger); }
.kpi-delta.down  { color: var(--success); }
.kpi-delta.flat  { color: var(--text-faint); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .375rem;
    padding: .5rem .875rem;
    border-radius: var(--radius);
    font-size: .8125rem;
    font-weight: 500;
    line-height: 1.15;
    border: 1px solid transparent;
    background: var(--surface);
    color: var(--text);
    transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:disabled,
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-sm  { padding: .3125rem .625rem; font-size: .75rem; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg  { padding: .625rem 1.125rem; font-size: .875rem; }

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

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

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

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover { background: #15803d; border-color: #15803d; color: #fff; }

.btn-link {
    background: transparent;
    border-color: transparent;
    color: var(--primary);
    padding: .25rem .375rem;
}
.btn-link:hover { color: var(--primary-hov); background: transparent; text-decoration: underline; }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: .375rem; margin: 0 0 1rem; }
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.form-group label {
    font-size: .8125rem;
    font-weight: 500;
    color: var(--text);
}
.form-group small,
.form-help {
    font-size: .75rem;
    color: var(--text-muted);
}
.form-required { color: var(--danger); margin-left: 2px; }

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="tel"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: .5rem .75rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .875rem;
    line-height: 1.4;
    transition: border-color .12s, box-shadow .12s;
}
.form-control:hover,
input:not([type=checkbox]):not([type=radio]):hover,
select:hover,
textarea:hover { border-color: #94a3b8; }
.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
textarea { min-height: 80px; resize: vertical; }
input[type="checkbox"], input[type="radio"] {
    accent-color: var(--primary);
    width: 16px; height: 16px;
    margin: 0 .375rem 0 0;
    vertical-align: middle;
}
.form-control[disabled],
select[disabled] { background: var(--surface-2); color: var(--text-faint); cursor: not-allowed; }

fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.125rem 0;
    margin: 0 0 1rem;
    background: var(--surface);
}
fieldset legend {
    font-weight: 600;
    font-size: .8125rem;
    padding: 0 .375rem;
    color: var(--text);
}

.field-error,
.errors {
    color: var(--danger);
    font-size: .75rem;
    margin-top: .125rem;
}

/* Inline filters bar (toolbar-like form) */
.filters {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: .875rem 1rem;
    display: flex;
    gap: .875rem;
    align-items: flex-end;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}
.filters .form-group { margin: 0; }
.filters label {
    font-size: .6875rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    color: var(--text-muted);
}
.filters select,
.filters input { min-width: 140px; }

/* ---------- Tables ---------- */
.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
    font-size: .875rem;
}
.data-table thead th {
    text-align: left;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: .625rem .875rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}
.data-table tbody td {
    padding: .75rem .875rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions-col { text-align: right; white-space: nowrap; }
.data-table .actions-col a,
.data-table .actions-col button { margin-left: .375rem; }

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table-card .data-table { border-radius: 0; }
.table-card > .data-table thead th:first-child { border-top-left-radius: 0; }

.table-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- Chips / badges ---------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .125rem .5rem;
    font-size: .6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-radius: 9999px;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    line-height: 1.5;
    white-space: nowrap;
}
.chip::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    flex-shrink: 0;
}
.chip-success { background: var(--success-bg); color: #14532d; border-color: var(--success-bord); }
.chip-success::before { background: var(--success); }
.chip-warning { background: var(--warning-bg); color: #92400e; border-color: var(--warning-bord); }
.chip-warning::before { background: var(--warning); }
.chip-error,
.chip-danger { background: var(--danger-bg); color: #7f1d1d; border-color: var(--danger-bord); }
.chip-error::before,
.chip-danger::before { background: var(--danger); }
.chip-info { background: var(--info-bg); color: #155e75; border-color: var(--info-bord); }
.chip-info::before { background: var(--info); }
.chip-primary { background: var(--primary-bg); color: var(--primary); border-color: var(--primary-bord); }
.chip-primary::before { background: var(--primary); }
.chip-neutral { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.chip-bare { background: transparent; }
.chip-bare::before { display: none; }

/* legacy `.badge` keeps working */
.badge {
    display: inline-block;
    padding: .125rem .5rem;
    font-size: .6875rem;
    font-weight: 600;
    border-radius: 9999px;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge-default { background: var(--primary-bg); color: var(--primary); border-color: var(--primary-bord); }
.badge-ok { background: var(--success-bg); color: #14532d; border-color: var(--success-bord); }
.badge-error { background: var(--danger-bg); color: #7f1d1d; border-color: var(--danger-bord); }

.dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: .25rem;
    vertical-align: middle;
}
.dot-green { background: var(--success); }
.dot-red   { background: var(--danger); }

/* ---------- Status pill (legacy) ---------- */
.status,
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    font-size: .75rem;
    font-weight: 500;
}
.status-ok       { color: var(--success); }
.status-error    { color: var(--danger); }
.status-idle     { color: var(--text-muted); }
.status-pending  { color: var(--warning); }
.status-sent     { color: var(--success); }
.status-failed   { color: var(--danger); }
.status-draft    { color: var(--text-muted); }

/* ---------- Alerts / messages ---------- */
.alert {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    background: var(--surface);
    color: var(--text);
    margin-bottom: .75rem;
}
.alert-success { background: var(--success-bg); border-color: var(--success-bord); color: #14532d; }
.alert-error,
.alert-danger { background: var(--danger-bg); border-color: var(--danger-bord); color: #7f1d1d; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-bord); color: #92400e; }
.alert-info { background: var(--info-bg); border-color: var(--info-bord); color: #155e75; }
.alert ul { margin: .25rem 0 0 1rem; list-style: disc; }
.alert details summary { cursor: pointer; }

/* Toast container */
.toasts {
    list-style: none;
    margin: 0 0 1.25rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.toast {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .625rem .875rem;
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: .625rem;
    font-size: .875rem;
}
.toast.toast-success,
.toast.msg-success { background: var(--success-bg); border-color: var(--success-bord); color: #14532d; }
.toast.toast-error,
.toast.msg-error,
.toast.msg-danger { background: var(--danger-bg); border-color: var(--danger-bord); color: #7f1d1d; }
.toast.toast-warning,
.toast.msg-warning { background: var(--warning-bg); border-color: var(--warning-bord); color: #92400e; }
.toast.toast-info,
.toast.msg-info { background: var(--info-bg); border-color: var(--info-bord); color: #155e75; }

/* messages list (legacy class) */
.messages { list-style: none; margin: 0 0 1.25rem; padding: 0;
            display: flex; flex-direction: column; gap: .5rem; }
.messages .msg,
.messages .message {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .625rem .875rem;
    background: var(--surface);
    font-size: .875rem;
}
.messages .msg-success,
.messages .message-success { background: var(--success-bg); border-color: var(--success-bord); color: #14532d; }
.messages .msg-error,
.messages .msg-danger,
.messages .message-error { background: var(--danger-bg); border-color: var(--danger-bord); color: #7f1d1d; }
.messages .msg-warning,
.messages .message-warning { background: var(--warning-bg); border-color: var(--warning-bord); color: #92400e; }
.messages .msg-info,
.messages .message-info { background: var(--info-bg); border-color: var(--info-bord); color: #155e75; }

/* ---------- Empty state ---------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
    gap: .75rem;
}
.empty-state svg {
    width: 44px; height: 44px;
    color: var(--text-faint);
    margin-bottom: .25rem;
}
.empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}
.empty-state-message {
    font-size: .875rem;
    color: var(--text-muted);
    max-width: 32rem;
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-top: 1rem;
    font-size: .8125rem;
    color: var(--text-muted);
}
.pagination a {
    padding: .375rem .625rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text-muted);
    background: var(--surface);
    text-decoration: none;
}
.pagination a:hover { color: var(--text); border-color: var(--border-strong); text-decoration: none; }

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    gap: .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.tabs button {
    padding: .625rem .875rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 500;
    font-size: .875rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    border-radius: var(--radius) var(--radius) 0 0;
    transition: color .12s, border-color .12s, background .12s;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

/* ---------- Description list (key/value) ---------- */
.kv {
    display: grid;
    grid-template-columns: 12rem 1fr;
    row-gap: .5rem;
    column-gap: 1rem;
    font-size: .875rem;
}
.kv dt { color: var(--text-muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--text); }
.kv dd code { font-size: .8125rem; }

[x-cloak] { display: none !important; }

/* ---------- HTMX ---------- */
.htmx-indicator { display: none; color: var(--text-muted); font-size: .8125rem; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline; }
.htmx-request.htmx-swapping { opacity: .55; }

/* ---------- Charts container ---------- */
.chart-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.25rem;
}
.chart-card { padding: 1.25rem; }
.chart-card h3 { margin: 0 0 .75rem; font-size: .9375rem; }
.chart-canvas { position: relative; height: 300px; }
.chart-canvas-lg { position: relative; height: 380px; }

/* ---------- Login page ---------- */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
        radial-gradient(1200px 600px at 0% 0%, rgba(37, 99, 235, .07), transparent 60%),
        radial-gradient(800px 500px at 100% 100%, rgba(124, 58, 237, .06), transparent 60%),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.875rem;
}
.auth-brand {
    display: flex;
    align-items: center;
    gap: .625rem;
    justify-content: center;
    margin-bottom: 1rem;
}
.auth-brand .brand-mark { width: 36px; height: 36px; border-radius: 9px; }
.auth-brand .brand-mark svg { width: 20px; height: 20px; }
.auth-brand-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}
.auth-card h1 {
    font-size: 1.125rem;
    text-align: center;
    margin: 0 0 .25rem;
}
.auth-card .auth-sub {
    text-align: center;
    color: var(--text-muted);
    font-size: .875rem;
    margin: 0 0 1.5rem;
}
.auth-card .form-group { margin-bottom: .875rem; }
.auth-card .btn { width: 100%; }

/* ---------- Tree (cost tree page) ---------- */
.tree-table .tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    border-radius: 4px;
    color: var(--primary);
    background: var(--primary-bg);
    margin-right: .375rem;
    font-size: .75rem;
}
.tree-table .tree-toggle:hover { background: #dbeafe; }
.tree-table .tree-spacer {
    display: inline-block;
    width: 22px;
    margin-right: .375rem;
}
.tree-table .tree-label-cluster { font-weight: 600; }
.tree-table .tree-label-ns      { font-weight: 500; }

/* ---------- Modal (used by Alpine inline) ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    display: grid;
    place-items: center;
    z-index: 50;
    padding: 1.5rem;
}
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 480px;
    width: 100%;
    padding: 1.5rem;
}
.modal h2 { margin: 0 0 .5rem; font-size: 1.125rem; }
.modal-actions {
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
}

/* ---------- Misc utility ---------- */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.text-mono { font-family: var(--font-mono); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.num { font-variant-numeric: tabular-nums; }

.flex      { display: flex; }
.flex-col  { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm    { gap: .5rem; }
.gap       { gap: .75rem; }
.gap-md    { gap: 1rem; }
.gap-lg    { gap: 1.5rem; }
.wrap      { flex-wrap: wrap; }
.mt-sm { margin-top: .5rem; }
.mt    { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.mb    { margin-bottom: 1rem; }
.w-full { width: 100%; }
.max-w-form { max-width: 720px; }
.max-w-sm { max-width: 480px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
@media (max-width: 720px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- Send actions panel (billing) ---------- */
.send-actions {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: .875rem 1rem;
    margin-bottom: 1.25rem;
}
.send-actions > summary {
    cursor: pointer;
    font-weight: 600;
    font-size: .875rem;
    color: var(--text);
    list-style: none;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.send-actions > summary::-webkit-details-marker { display: none; }
.send-actions > summary::before {
    content: "+";
    width: 18px; height: 18px;
    border-radius: 4px;
    background: var(--primary-bg);
    color: var(--primary);
    display: grid; place-items: center;
    font-weight: 600;
}
.send-actions[open] > summary::before { content: "−"; }
.send-actions h3 {
    font-size: .8125rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin: 1rem 0 .5rem;
}
.send-actions .grid-2 { gap: 1.25rem; padding: .5rem 0 0; }
.send-actions p { margin: .5rem 0; }
.send-result { margin-top: 1rem; }

.line-items-row td { padding: 0 .875rem .75rem !important; }
.line-items-row details { border-left: 2px solid var(--border); padding: .25rem .75rem; }
.line-items-row summary { color: var(--text-muted); font-size: .8125rem; cursor: pointer; }
.line-items { margin: .5rem 0 0 1rem; list-style: disc; font-size: .8125rem; color: var(--text-muted); }

/* ---------- Page header (legacy class used in templates) ---------- */
.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; }
.header-tools {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .8125rem;
    color: var(--text-muted);
}

/* Inactive row in tables */
.row-inactive td { color: var(--text-faint); }

/* Notice paragraph */
.notice {
    background: var(--info-bg);
    border: 1px solid var(--info-bord);
    border-radius: var(--radius);
    padding: .625rem .875rem;
    color: #155e75;
    font-size: .8125rem;
}

/* Actions container in forms */
.actions {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-top: 1rem;
}

/* Warning paragraph */
.warning {
    background: var(--warning-bg);
    border: 1px solid var(--warning-bord);
    color: #92400e;
    border-radius: var(--radius);
    padding: .625rem .875rem;
    font-size: .8125rem;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
    .chart-grid { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 9rem 1fr; }
}

@media (max-width: 880px) {
    :root { --sidebar-w: 0px; }
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: 240px;
        z-index: 60;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: inline-flex; }
    .content { padding: 1rem; }
    .topbar { padding: 0 1rem; }
    .filters select, .filters input { min-width: 0; }
    .toolbar { gap: .75rem; }
    .data-table thead th,
    .data-table tbody td { padding: .5rem .625rem; }
    .kv { grid-template-columns: 1fr; row-gap: .25rem; }
    .kv dt { color: var(--text-faint); margin-top: .375rem; }
}
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    z-index: 55;
}
@media (max-width: 880px) {
    .sidebar-overlay.open { display: block; }
}
