:root {
    color-scheme: light;
    --fg: #1a1a1a;
    --bg: #ffffff;
    --border: #d8dce0;
    --accent: #2c5f8a;
    --danger: #a12424;
    --danger-bg: #fbecec;
    --neutral: #6b7280;
    --neutral-bg: #f6f7f9;
    --muted-bg: #f6f7f9;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 1.5rem;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--fg);
    background: var(--bg);
    line-height: 1.4;
}

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

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

th, td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.6rem;
    text-align: left;
}

form {
    margin: 0;
}

input, button, select {
    font: inherit;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 3px;
}

button {
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
}

button.danger {
    background: var(--danger);
}

.notice {
    padding: 0.6rem 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 1rem;
}

/* --- Dashboard shell (increment 12, dashboard-ui-spec.md) --- */

:root {
    --success: #1b6e2f;
    --success-bg: #eef6ee;
    --warning-bg: #fff8e5;
    --warning-border: #b8860b;
    --space-1: 0.4rem;
    --space-2: 0.8rem;
    --space-3: 1.5rem;
    --space-4: 2.5rem;
    --radius: 4px;
}

h1 { font-size: 1.5rem; font-weight: 700; margin: 0 0 var(--space-2); }
h2 { font-size: 1.125rem; font-weight: 700; margin: var(--space-3) 0 var(--space-2); }
h3 { font-size: 1rem; font-weight: 600; color: #444; margin: 0 0 var(--space-1); }

.field { display: block; margin-bottom: var(--space-2); }
.field label { display: block; font-weight: 600; margin-bottom: var(--space-1); }
.field input, .field select { width: 100%; }

.auth-shell {
    max-width: 22rem;
    margin: var(--space-4) auto;
}
.page-shell {
    max-width: 40rem;
    margin: var(--space-3) auto;
}

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

body {
    font-size: 16px;
}

.skip-link {
    position: absolute;
    left: -999px;
    top: 0;
    background: var(--accent);
    color: #fff;
    padding: var(--space-1) var(--space-2);
    z-index: 10;
}
.skip-link:focus {
    left: var(--space-1);
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-3);
}
.brand {
    font-weight: bold;
    font-size: 1.375rem;
    letter-spacing: 0.02em;
}
.env-badge {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.1rem 0.5rem;
    font-size: 0.875rem;
    font-weight: bold;
}
.env-badge-paper {
    background: var(--muted-bg);
    color: #555;
    border-color: var(--border);
}
.env-badge-live {
    border-color: var(--danger);
    color: var(--danger);
}
.logout-form {
    margin-left: auto;
}

.nav {
    list-style: none;
    display: flex;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
}
.nav a {
    display: inline-block;
    padding: var(--space-1) var(--space-2);
    text-decoration: none;
    min-height: 44px;
    display: flex;
    align-items: center;
}
.nav a.current {
    text-decoration: none;
    font-weight: bold;
    border-bottom: 2px solid var(--accent);
}
@media (max-width: 480px) {
    .topbar { flex-direction: column; align-items: stretch; }
    .nav { flex-direction: column; }
    .nav a { width: 100%; }
}

.flash {
    padding: var(--space-2);
    border-left: 4px solid var(--border);
    margin-bottom: var(--space-3);
}
.flash-success { border-left-color: var(--success); }
.flash-info { border-left-color: var(--accent); }
.flash-error { border-left-color: var(--danger); }

.empty {
    color: #555;
    font-style: italic;
}

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
}
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2);
}
@media (min-width: 640px) {
    .card-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
.fund-card, .approval-card, .stat-card {
    /* inherits .card */
}

.status-band {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
}
.status-halted {
    background: var(--warning-bg);
    border-color: var(--warning-border);
}
.stat-ok { background: var(--success-bg); border-left: 4px solid var(--success); }
.stat-pending { background: var(--neutral-bg); border-left: 4px solid var(--neutral); }
.stat-warning { background: var(--warning-bg); border-left: 4px solid var(--warning-border); }

.callout {
    background: var(--warning-bg);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
}

.badge {
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 0.4rem;
    font-size: 0.875rem;
}
.badge-danger {
    border-color: var(--danger);
    color: var(--danger);
}
.stepup-badge {
    display: inline-block;
    border: 1px solid var(--warning-border);
    background: var(--warning-bg);
    border-radius: var(--radius);
    padding: 0.1rem 0.5rem;
    font-size: 0.875rem;
}

.money, .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.negative {
    color: var(--danger);
}

.button-link {
    display: inline-block;
    min-height: 44px;
    line-height: 44px;
    padding: 0 var(--space-2);
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius);
}
.button-link.primary {
    font-weight: bold;
}
.button-link.danger {
    background: var(--danger);
}

/* A cell-filling link so a whole responsive-table row is tappable without JS: every <td>
   in the row wraps its content in one of these, rather than only the first cell. */
.row-link {
    display: block;
    width: 100%;
    height: 100%;
    color: inherit;
    text-decoration: none;
}
.row-link:hover, .row-link:focus-visible {
    text-decoration: underline;
}

button {
    min-height: 44px;
    min-width: 44px;
}

.approval-actions, .confirm-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

details {
    margin-top: var(--space-2);
}

.diff th, .diff td {
    font-size: 0.875rem;
}

.meta {
    font-size: 0.875rem;
    color: #555;
}

/* Responsive table: each <tr> becomes a block under 480px, with a
   data-label-driven pseudo-header per cell (pure CSS, no JS). */
@media (max-width: 480px) {
    .responsive-table thead {
        display: none;
    }
    .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td {
        display: block;
        width: 100%;
    }
    .responsive-table tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: var(--space-2);
        padding: var(--space-1);
    }
    .responsive-table td {
        border: none;
        display: flex;
        justify-content: space-between;
        gap: var(--space-2);
    }
    .responsive-table td::before {
        content: attr(data-label);
        font-weight: bold;
    }
}
