:root {
    --bg: #f6f8fb;
    --surface: #ffffff;
    --surface-soft: #eef3f7;
    --text: #172033;
    --muted: #667085;
    --line: #d9e1ea;
    --primary: #0f766e;
    --primary-strong: #0b5f59;
    --blue: #2563eb;
    --amber: #d97706;
    --danger: #dc2626;
    --good: #15803d;
    --radius: 8px;
    --shadow: 0 12px 30px rgba(23, 32, 51, 0.08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 20px 16px;
    background: #111827;
    color: #f8fafc;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    flex: 0 0 auto;
}

.brand strong,
.brand small {
    display: block;
    line-height: 1.2;
}

.brand small {
    color: #b8c0cc;
    margin-top: 3px;
}

.nav-list {
    display: grid;
    gap: 4px;
    margin-top: 28px;
}

.nav-list a,
.mobile-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #d9e2ef;
}

.nav-list a:hover,
.nav-list a.is-active {
    background: rgba(255, 255, 255, 0.11);
    color: #fff;
}

.nav-list svg,
.mobile-nav svg,
.btn svg,
.icon-btn svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.main {
    min-width: 0;
    padding: 24px 28px 40px;
}

.topbar,
.toolbar,
.panel-header,
.toolbar-actions,
.table-actions,
.card-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar {
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.86rem;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 1.7rem;
    line-height: 1.2;
}

h2 {
    margin-bottom: 0;
    font-size: 1.05rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px 8px 12px;
}

.user-chip span,
.user-chip small {
    display: block;
}

.user-chip small {
    color: var(--muted);
}

.btn,
.icon-btn {
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    font-weight: 700;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.btn {
    padding: 9px 14px;
}

.btn:hover,
.icon-btn:hover {
    transform: translateY(-1px);
}

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

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

.btn.ghost {
    color: var(--text);
    background: var(--surface);
    border-color: var(--line);
}

.btn.warning {
    color: #4b2e00;
    background: #fde68a;
}

.btn.danger,
.icon-btn.danger {
    color: #fff;
    background: var(--danger);
}

.btn.small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 0.86rem;
}

.btn.full {
    width: 100%;
}

.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    color: var(--text);
    background: var(--surface);
    border-color: var(--line);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin: 16px 0;
}

.metric-card,
.panel,
.event-card,
.resource-card,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.metric-card {
    padding: 18px;
}

.metric-card span,
.metric-card small {
    color: var(--muted);
}

.metric-card strong {
    display: block;
    margin: 8px 0 4px;
    font-size: 1.55rem;
    line-height: 1.15;
}

.metric-card.strong {
    border-left: 5px solid var(--primary);
}

.dashboard-grid,
.split-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.dashboard-grid .wide {
    grid-column: 1 / -1;
}

.chart-box {
    position: relative;
    width: 100%;
    height: 300px;
    min-height: 260px;
    overflow: hidden;
}

.chart-box.wide {
    height: 280px;
}

.chart-box.compact {
    height: 220px;
    min-height: 200px;
}

.chart-box canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.panel {
    padding: 18px;
}

.panel-header {
    margin-bottom: 14px;
}

.panel-header a {
    color: var(--primary);
    font-weight: 700;
}

.toolbar {
    flex-wrap: wrap;
    margin: 10px 0 16px;
}

.inline-form,
.grid-form,
.stack-form {
    display: grid;
    gap: 12px;
}

.inline-form {
    grid-template-columns: repeat(4, minmax(150px, auto));
    align-items: end;
}

.inline-form.filters {
    grid-template-columns: repeat(5, minmax(150px, auto));
}

.inline-form.tight {
    display: flex;
    gap: 6px;
    align-items: center;
}

.grid-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-form.compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 6px;
    color: #344054;
    font-weight: 700;
    min-width: 0;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 11px;
    color: var(--text);
    background: #fff;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(15, 118, 110, 0.18);
    border-color: var(--primary);
}

.wide-field {
    grid-column: 1 / -1;
}

.check-card {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.check-card input {
    width: 18px;
    min-height: 18px;
}

.check-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    font-weight: 700;
    white-space: nowrap;
}

.check-inline input {
    width: 16px;
    min-height: 16px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.84rem;
    text-transform: uppercase;
}

td small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 8px;
    border-radius: 999px;
    color: #344054;
    background: var(--surface-soft);
    font-size: 0.84rem;
    font-weight: 800;
}

.status.closed,
.status.deleted,
.status.cancelled,
.event-card.overdue {
    color: #fff;
    background: var(--danger);
}

.status.open,
.status.done,
.status.active,
.status.receipt-ok,
.status.acknowledged,
.status.reimbursed {
    color: #fff;
    background: var(--good);
}

.status.extra-home {
    color: #fff;
    background: var(--blue);
}

.status.planned,
.status.partial,
.status.corrected,
.status.deposit,
.status.adjustment,
.status.missing-receipt,
.status.unsettled {
    color: #3f2f05;
    background: #fde68a;
}

.status.withdrawal,
.status.ignored {
    color: #fff;
    background: var(--danger);
}

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin: 10px 0;
    border: 1px solid var(--line);
    background: var(--surface);
}

.flash.success {
    border-color: #86efac;
    background: #f0fdf4;
}

.flash.error {
    border-color: #fecaca;
    background: #fef2f2;
}

.alert-strip {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 14px;
    border-radius: 8px;
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.alert-strip svg {
    color: var(--amber);
}

.alert-strip.danger {
    border-color: #fecaca;
    background: #fef2f2;
}

.alert-strip.danger svg {
    color: var(--danger);
}

.alert-strip.success {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.alert-strip.success svg {
    color: var(--good);
}

.list,
.timeline {
    display: grid;
    gap: 10px;
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.list-row:last-child {
    border-bottom: 0;
}

.list-row small,
.muted {
    color: var(--muted);
}

.list-row.danger {
    color: var(--danger);
}

.list-row.warning {
    color: #8a5700;
}

.timeline-item {
    display: grid;
    grid-template-columns: 12px 1fr;
    gap: 12px;
}

.timeline-item > span {
    width: 10px;
    height: 10px;
    margin-top: 6px;
    border-radius: 50%;
    background: var(--blue);
}

.timeline-item small {
    display: block;
    color: var(--muted);
    margin-top: 4px;
}

pre {
    max-width: 100%;
    overflow: auto;
    padding: 12px;
    border-radius: 8px;
    background: #111827;
    color: #f8fafc;
}

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

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

.resource-card,
.event-card,
.fund-card {
    padding: 16px;
}

.fund-card {
    display: grid;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.fund-card.is-deleted,
.is-muted {
    opacity: .58;
}

.fund-card-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.fund-card-main strong,
.fund-card-main small {
    display: block;
}

.fund-card-main small {
    color: var(--muted);
    margin-top: 3px;
}

.fund-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--fund-color, var(--primary));
    background: color-mix(in srgb, var(--fund-color, var(--primary)), #ffffff 86%);
    border: 1px solid color-mix(in srgb, var(--fund-color, var(--primary)), #ffffff 65%);
    flex: 0 0 auto;
}

.fund-icon svg {
    width: 23px;
    height: 23px;
}

.fund-progress {
    display: grid;
    gap: 7px;
}

.fund-progress > div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-weight: 800;
}

.fund-progress progress {
    width: 100%;
    height: 12px;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background: var(--surface-soft);
}

.fund-progress progress::-webkit-progress-bar {
    background: var(--surface-soft);
}

.fund-progress progress::-webkit-progress-value {
    border-radius: 999px;
    background: var(--fund-color, var(--primary));
}

.fund-progress progress::-moz-progress-bar {
    border-radius: 999px;
    background: var(--fund-color, var(--primary));
}

.fund-progress.large progress {
    height: 16px;
}

.fund-hero {
    display: grid;
    gap: 14px;
    border-left: 5px solid var(--fund-color, var(--primary));
}

.resource-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.resource-card svg {
    width: 28px;
    height: 28px;
    color: var(--primary);
}

.resource-card small,
.event-card small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.event-card {
    display: grid;
    gap: 12px;
}

.event-card dl,
.details-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
}

dt {
    color: var(--muted);
    font-size: 0.84rem;
}

dd {
    margin: 2px 0 0;
    font-weight: 700;
}

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

.attachment-tile {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.attachment-tile a {
    display: flex;
    gap: 8px;
    align-items: center;
    min-width: 0;
}

.attachment-tile span {
    overflow-wrap: anywhere;
}

.attachment-tile.is-deleted {
    opacity: .6;
}

.quick-actions {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin: 12px 0 16px;
}

.quick-card {
    min-height: 92px;
    display: grid;
    place-items: center;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    font-weight: 800;
    color: var(--text);
}

.quick-card svg {
    width: 26px;
    height: 26px;
    color: var(--primary);
}

.quick-card.is-active {
    border-color: var(--primary);
    outline: 3px solid rgba(15, 118, 110, 0.16);
}

.tab-panel {
    display: none;
}

.tab-panel.is-active {
    display: block;
}

.quick-amounts {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.quick-amounts button {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    min-height: 36px;
    padding: 6px 10px;
}

.inline-delete {
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-delete input {
    min-height: 34px;
    width: 120px;
}

.row-details summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 800;
}

.settlement-details {
    min-width: 260px;
}

.settlement-form {
    display: grid;
    gap: 8px;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.settlement-form input,
.settlement-form select {
    min-height: 36px;
}

.chip-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip-cloud span {
    border: 1px solid color-mix(in srgb, var(--chip), #ffffff 65%);
    background: color-mix(in srgb, var(--chip), #ffffff 88%);
    color: #1f2937;
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 700;
}

.empty-state {
    min-height: 320px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 30px;
}

.empty-state svg {
    width: 42px;
    height: 42px;
    color: var(--primary);
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: #eef3f7;
}

.auth-card {
    width: min(460px, 100%);
    padding: 28px;
}

.auth-brand {
    margin-bottom: 22px;
}

.auth-switch {
    margin: 14px 0 0;
    text-align: center;
}

.auth-switch a {
    color: var(--primary);
    font-weight: 800;
}

.mobile-nav {
    display: none;
}

.text-danger {
    color: var(--danger);
    font-weight: 800;
}

.text-good {
    color: var(--good);
    font-weight: 800;
}

.danger-zone {
    border-color: #fecaca;
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .main {
        padding: 18px 16px 92px;
    }

    .metric-grid,
    .dashboard-grid,
    .split-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .mobile-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        display: flex;
        gap: 0;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        background: #111827;
        border-top: 1px solid #293241;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    }

    .mobile-nav::-webkit-scrollbar {
        display: none;
    }

    .mobile-nav a {
        flex: 0 0 72px;
        min-height: 56px;
        padding: 6px 4px;
        display: grid;
        place-items: center;
        gap: 2px;
        color: #cbd5e1;
        font-size: 0.72rem;
        text-align: center;
    }

    .mobile-nav a.is-active {
        color: #fff;
        background: rgba(255, 255, 255, 0.10);
    }
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
    }

    .user-chip {
        padding: 7px;
    }

    .user-chip > span,
    .user-chip > small {
        display: none;
    }

    h1 {
        font-size: 1.35rem;
    }

    .metric-grid,
    .dashboard-grid,
    .split-grid,
    .grid-form,
    .grid-form.compact,
    .quick-actions,
    .event-card dl,
    .details-grid {
        grid-template-columns: 1fr;
    }

    .quick-actions {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .quick-card {
        min-height: 74px;
    }

    .inline-form,
    .inline-form.filters {
        width: 100%;
        grid-template-columns: 1fr;
    }

    .toolbar,
    .toolbar-actions {
        align-items: stretch;
    }

    .toolbar > .btn,
    .toolbar-actions,
    .toolbar-actions .btn,
    .toolbar-actions form {
        width: 100%;
    }

    .panel {
        padding: 14px;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead {
        display: none;
    }

    tr {
        padding: 12px 0;
        border-bottom: 1px solid var(--line);
    }

    td {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        border-bottom: 0;
        padding: 7px 0;
    }

    td::before {
        content: attr(data-label);
        color: var(--muted);
        font-weight: 800;
        flex: 0 0 110px;
    }

    .table-actions,
    .inline-delete {
        justify-content: flex-end;
        flex-wrap: wrap;
    }
}
