:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-muted: #eef2f4;
    --line: #d9e1e5;
    --line-strong: #b9c5cc;
    --text: #18212a;
    --muted: #63717c;
    --accent: #0f766e;
    --accent-strong: #0a5d57;
    --blue: #2563eb;
    --green: #15803d;
    --red: #b42318;
    --amber: #b45309;
    --shadow: 0 18px 42px rgba(24, 33, 42, 0.08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    width: min(1440px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 36px;
}

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

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

h1 {
    margin-bottom: 0;
    font-size: 34px;
    line-height: 1.05;
    letter-spacing: 0;
}

.header-actions,
.plan-actions,
.plan-tabs,
.workspace-bar {
    display: flex;
    align-items: center;
}

.header-actions {
    gap: 10px;
}

.button,
.icon-button,
.plan-tab,
.row-action {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    transition: border-color 120ms ease, background 120ms ease, color 120ms ease, transform 120ms ease;
}

.button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 14px;
    border-radius: 8px;
    font-weight: 700;
}

.button.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

.button.ghost {
    background: #ffffff;
}

.button:hover,
.icon-button:hover,
.plan-tab:hover,
.row-action:hover {
    border-color: var(--accent);
}

.button.primary:hover {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.workspace-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    justify-content: space-between;
    gap: 14px;
    padding: 10px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 10px 30px rgba(24, 33, 42, 0.06);
    backdrop-filter: blur(12px);
}

.plan-tabs {
    flex: 1;
    min-width: 0;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 1px;
}

.plan-tab {
    min-width: 120px;
    max-width: 220px;
    height: 36px;
    padding: 0 14px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.plan-tab.active {
    border-color: var(--accent);
    background: #e4f2ef;
    color: var(--accent-strong);
}

.plan-actions {
    gap: 6px;
}

.icon-button,
.row-action {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-weight: 800;
}

.icon-button.danger,
.row-action.danger {
    color: var(--red);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.summary-card,
.chart-panel,
.section-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.summary-card {
    padding: 16px;
}

.summary-label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.summary-card strong {
    display: block;
    font-size: 25px;
    line-height: 1.15;
    letter-spacing: 0;
}

.summary-card.accent {
    border-color: #a7d7cf;
    background: #f0faf8;
}

.summary-card.negative {
    border-color: #f0b8b2;
    background: #fff6f5;
}

.charts-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    gap: 14px;
    margin-bottom: 18px;
}

.chart-panel {
    min-width: 0;
    overflow: hidden;
}

.panel-heading,
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}

.panel-heading > div:first-child {
    min-width: 0;
}

.panel-heading h2,
.section-heading h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: 0;
}

.panel-heading span,
.section-heading span {
    color: var(--muted);
    font-size: 13px;
}

.chart-frame {
    padding: 12px;
    overflow: hidden;
}

.library-chart {
    width: 100%;
    min-width: 520px;
    height: 360px;
}

.sankey-plot {
    height: 620px;
}

.chart-message {
    display: grid;
    place-items: center;
    min-height: 280px;
    color: var(--muted);
    font-weight: 700;
    text-align: center;
}

.tables-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.section-panel {
    min-width: 0;
    overflow: hidden;
}

.section-heading {
    background: #fbfcfc;
}

.section-total {
    font-weight: 800;
    color: var(--accent-strong);
}

.table-wrap {
    overflow-x: auto;
}

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

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

th {
    color: var(--muted);
    background: var(--surface-muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

th.amount-col,
td.amount-col {
    width: 116px;
}

th.action-col,
td.action-col {
    width: 52px;
    text-align: center;
}

.group-row td {
    border-top: 1px solid var(--line-strong);
    border-bottom-color: var(--line-strong);
    background: #f7faf9;
    color: var(--text);
    font-size: 13px;
    font-weight: 800;
}

.group-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.group-total {
    color: var(--accent-strong);
    white-space: nowrap;
}

.editable-input {
    width: 100%;
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    padding: 6px 8px;
}

.editable-input:hover,
.editable-input:focus {
    border-color: var(--line-strong);
    background: #ffffff;
    outline: none;
}

.editable-input.amount {
    text-align: right;
}

.editable-input.invalid {
    border-color: #d92d20;
    background: #fff4f2;
}

.add-row {
    width: calc(100% - 20px);
    margin: 10px;
    justify-content: center;
}

.empty-note {
    margin: 0;
    padding: 18px;
    color: var(--muted);
    font-size: 14px;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 13px;
}

.chart-label {
    fill: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.chart-muted {
    fill: var(--muted);
    font-size: 11px;
}

.chart-empty {
    fill: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

@media (max-width: 1100px) {
    .summary-grid,
    .tables-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100% - 20px, 1440px);
        padding-top: 14px;
    }

    .app-header,
    .workspace-bar,
    .status-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .header-actions,
    .plan-actions {
        width: 100%;
    }

    .header-actions .button {
        flex: 1;
        justify-content: center;
    }

    h1 {
        font-size: 29px;
    }

    .summary-grid,
    .tables-grid {
        grid-template-columns: 1fr;
    }

    .summary-card strong {
        font-size: 22px;
    }
}
