* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: #172033;
    background: #f5f7fb;
    font-family: Arial, Helvetica, sans-serif;
}

button,
input {
    font: inherit;
}

[hidden] {
    display: none !important;
}

button {
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    color: #ffffff;
    background: #22577a;
    cursor: pointer;
    font-weight: 700;
    padding: 0 14px;
}

button:hover {
    background: #173f5f;
}

button:focus-visible,
input:focus-visible {
    outline: 3px solid #80ed99;
    outline-offset: 2px;
}

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

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

.period-toolbar {
    display: grid;
    grid-template-columns: auto minmax(230px, 1fr) auto auto;
    gap: 12px;
    align-items: center;
    margin-bottom: 18px;
    border: 1px solid #d7dde8;
    border-radius: 8px;
    background: #ffffff;
    padding: 10px;
}

.view-switch {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    padding: 3px;
    border: 1px solid #cdd6e3;
    border-radius: 8px;
    background: #edf2f7;
}

.view-switch button {
    min-height: 34px;
    border-radius: 6px;
    color: #506176;
    background: transparent;
    padding: 0 12px;
}

.view-switch button:hover {
    color: #172033;
    background: #dfe7f0;
}

.view-switch button.active {
    color: #ffffff;
    background: #22577a;
}

.period-navigation {
    display: grid;
    grid-template-columns: 40px minmax(150px, 190px) 40px;
    justify-content: center;
    gap: 6px;
}

.period-navigation input {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    border: 1px solid #cdd6e3;
    border-radius: 8px;
    color: #172033;
    background: #ffffff;
    padding: 0 10px;
    text-align: center;
}

.icon-button {
    width: 40px;
    padding: 0;
    font-size: 1.6rem;
    line-height: 1;
}

.data-actions {
    display: flex;
    gap: 6px;
}

.data-actions button {
    min-height: 36px;
    color: #22577a;
    background: #e8f1f7;
}

.data-actions button:hover {
    background: #d6e7f1;
}

.storage-status {
    color: #4d6a5c;
    font-size: 0.78rem;
    white-space: nowrap;
}

.storage-status.storage-error {
    color: #b42346;
}

.eyebrow {
    margin: 0 0 6px;
    color: #5f6c7b;
    font-size: 0.84rem;
    font-weight: 700;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
}

h1 {
    font-size: 2rem;
}

h2 {
    color: #203047;
    font-size: 1.1rem;
}

.balance-summary {
    min-width: 190px;
    border: 1px solid #d7dde8;
    border-radius: 8px;
    background: #ffffff;
    padding: 14px 16px;
    text-align: right;
}

.balance-summary span,
.totals span,
.donut-center span,
.legend-amount {
    color: #607086;
    font-size: 0.84rem;
}

.balance-summary strong {
    display: block;
    margin-top: 4px;
    color: #0f9f6e;
    font-size: 1.45rem;
}

.balance-summary.negative strong {
    color: #c2410c;
}

.budget-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
    gap: 18px;
}

.entry-panel,
.chart-panel,
.annual-panel {
    border: 1px solid #d7dde8;
    border-radius: 8px;
    background: #ffffff;
    padding: 18px;
}

.chart-panel {
    grid-column: 1 / -1;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.chart-heading button {
    background: #2d6a4f;
}

.chart-heading button:hover {
    background: #1b4332;
}

.export-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.export-actions button {
    min-width: 72px;
}

.export-actions button:first-child {
    min-width: 122px;
}

.entry-list {
    display: grid;
    gap: 10px;
}

.entry-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(110px, 160px) 88px;
    gap: 10px;
    align-items: center;
}

.entry-row input {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    border: 1px solid #cdd6e3;
    border-radius: 8px;
    color: #172033;
    background: #ffffff;
    padding: 0 12px;
}

.entry-row input::placeholder {
    color: #8a97a8;
}

.remove-entry {
    color: #7f1d1d;
    background: #fee2e2;
}

.remove-entry:hover {
    background: #fecaca;
}

.chart-layout {
    display: grid;
    grid-template-columns: minmax(260px, 360px) 1fr;
    gap: 26px;
    align-items: center;
}

.donut-chart {
    position: relative;
    display: grid;
    place-items: center;
    width: min(100%, 340px);
    aspect-ratio: 1;
    margin: 0 auto;
    border-radius: 50%;
    background: conic-gradient(#dbe3ef 0% 100%);
    box-shadow: inset 0 0 0 1px rgba(23, 32, 51, 0.08);
}

.donut-chart::after {
    position: absolute;
    width: 58%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 0 1px rgba(23, 32, 51, 0.08);
    content: "";
}

.donut-center {
    position: relative;
    z-index: 1;
    display: grid;
    max-width: 58%;
    gap: 6px;
    text-align: center;
}

.donut-center strong {
    color: #172033;
    font-size: 1.35rem;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.chart-side {
    display: grid;
    gap: 18px;
}

.totals {
    display: grid;
    grid-template-columns: repeat(2, minmax(130px, 1fr));
    gap: 12px;
}

.totals div {
    border: 1px solid #d7dde8;
    border-radius: 8px;
    padding: 14px;
}

.totals strong {
    display: block;
    margin-top: 4px;
    font-size: 1.25rem;
}

.legend {
    display: grid;
    gap: 10px;
}

.legend-row {
    display: grid;
    grid-template-columns: 14px minmax(110px, 1fr) auto;
    gap: 10px;
    align-items: center;
    min-height: 28px;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.legend-name {
    min-width: 0;
    overflow: hidden;
    color: #203047;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.legend-empty {
    margin: 0;
    color: #607086;
}

.annual-totals {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.annual-totals div {
    border-right: 1px solid #d7dde8;
    padding: 6px 18px;
}

.annual-totals div:last-child {
    border-right: 0;
}

.annual-totals span {
    color: #607086;
    font-size: 0.84rem;
}

.annual-totals strong {
    display: block;
    margin-top: 5px;
    font-size: 1.3rem;
}

.annual-totals div:nth-child(1) strong {
    color: #2d6a4f;
}

.annual-totals div:nth-child(2) strong {
    color: #b42346;
}

.comparison-key {
    display: flex;
    justify-content: flex-end;
    gap: 16px;
    margin-bottom: 8px;
    color: #607086;
    font-size: 0.78rem;
}

.comparison-key span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.comparison-key i {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.comparison-key i.income {
    background: #2d6a4f;
}

.comparison-key i.expense {
    background: #ef476f;
}

.annual-comparison {
    display: grid;
    gap: 8px;
    margin-bottom: 24px;
}

.month-comparison {
    display: grid;
    grid-template-columns: 82px minmax(180px, 1fr) minmax(150px, auto);
    gap: 14px;
    align-items: center;
    width: 100%;
    min-height: 54px;
    border: 1px solid transparent;
    color: #172033;
    background: transparent;
    padding: 6px 8px;
    text-align: left;
}

.month-comparison:hover,
.month-comparison:focus-visible {
    border-color: #cdd6e3;
    background: #f5f7fb;
}

.month-name {
    font-weight: 700;
}

.comparison-bars {
    display: grid;
    gap: 5px;
}

.comparison-track {
    height: 8px;
    overflow: hidden;
    border-radius: 4px;
    background: #e7ecf2;
}

.comparison-bar {
    display: block;
    height: 100%;
    min-width: 0;
    border-radius: inherit;
}

.comparison-bar.income {
    background: #2d6a4f;
}

.comparison-bar.expense {
    background: #ef476f;
}

.comparison-values {
    display: grid;
    grid-template-columns: repeat(2, minmax(70px, 1fr));
    gap: 10px;
    font-size: 0.82rem;
    text-align: right;
}

.comparison-values span:first-child {
    color: #2d6a4f;
}

.comparison-values span:last-child {
    color: #b42346;
}

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

.annual-table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
}

.annual-table th,
.annual-table td {
    border-bottom: 1px solid #e1e6ed;
    padding: 11px 8px;
    text-align: right;
}

.annual-table th {
    color: #506176;
    font-size: 0.78rem;
    text-transform: uppercase;
}

.annual-table th:first-child,
.annual-table td:first-child {
    text-align: left;
}

.annual-table button {
    min-height: 32px;
    color: #22577a;
    background: transparent;
    padding: 0;
}

.annual-table button:hover {
    color: #173f5f;
    background: transparent;
    text-decoration: underline;
}

.value-negative {
    color: #c2410c;
}

.value-positive {
    color: #0f7b59;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 920px) {
    .period-toolbar {
        grid-template-columns: auto minmax(240px, 1fr);
    }

    .data-actions {
        justify-content: flex-start;
    }

    .storage-status {
        text-align: right;
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: 100%;
        max-width: 680px;
        padding: 18px 10px;
    }

    .app-header,
    .panel-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .period-toolbar {
        grid-template-columns: 1fr;
        width: 100%;
        min-width: 0;
    }

    .period-navigation {
        grid-template-columns: 40px minmax(0, 1fr) 40px;
        width: 100%;
        min-width: 0;
    }

    .view-switch,
    .data-actions {
        width: 100%;
        min-width: 0;
    }

    .data-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .data-actions button {
        width: 100%;
        min-width: 0;
        padding: 0 6px;
        font-size: 0.9rem;
        overflow-wrap: anywhere;
    }

    .storage-status {
        text-align: center;
    }

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

    .export-actions button,
    .export-actions button:first-child {
        min-width: 0;
        width: 100%;
    }

    .balance-summary {
        text-align: left;
    }

    .budget-grid,
    .chart-layout,
    .totals,
    .annual-totals {
        grid-template-columns: 1fr;
    }

    .annual-totals div {
        border-right: 0;
        border-bottom: 1px solid #d7dde8;
        padding: 10px 4px;
    }

    .annual-totals div:last-child {
        border-bottom: 0;
    }

    .month-comparison {
        grid-template-columns: 66px minmax(0, 1fr);
    }

    .comparison-values {
        grid-column: 1 / -1;
    }

    .entry-row {
        grid-template-columns: 1fr;
    }

    .remove-entry {
        grid-column: auto;
    }
}
