:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #17231f;
    background: #f3f6f4;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-width: 320px;
    background: #f3f6f4;
}

a { color: #17684d; }

.site-header {
    min-height: 68px;
    padding: 0 max(24px, calc((100% - 1120px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: #fff;
    border-bottom: 1px solid #e0e8e3;
}

.brand {
    color: #153d30;
    font-size: 1.08rem;
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
}

nav { display: flex; align-items: center; gap: 22px; }
nav a, .nav-button { color: #41544b; font-size: .94rem; text-decoration: none; }
nav a:hover, .nav-button:hover, .actions a:hover { color: #16835d; }

.container { width: min(1120px, calc(100% - 40px)); margin: 38px auto 64px; }

.auth-card {
    width: min(440px, 100%);
    margin: 8vh auto;
    padding: 38px;
    background: #fff;
    border: 1px solid #e0e8e3;
    border-radius: 16px;
    box-shadow: 0 16px 48px rgb(23 53 39 / 7%);
}

h1 { margin: 4px 0 8px; font-size: clamp(1.7rem, 3vw, 2.15rem); letter-spacing: -.035em; }
h2 { margin: 0 0 20px; font-size: 1.18rem; }
.eyebrow { margin: 0 0 8px; color: #18815d; font-size: .73rem; font-weight: 750; letter-spacing: .12em; }
.muted { color: #6a7971; }
.stack { display: grid; gap: 10px; margin-top: 26px; }
label { display: grid; gap: 7px; color: #34443c; font-size: .9rem; font-weight: 600; }

input, select {
    width: 100%;
    min-height: 43px;
    padding: 10px 12px;
    border: 1px solid #ccd8d1;
    border-radius: 8px;
    background: #fff;
    color: #17231f;
    font: inherit;
}

input:focus, select:focus {
    outline: 3px solid rgb(38 147 106 / 18%);
    border-color: #278b67;
}

.button {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-size: .9rem;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

.button-primary { margin-top: 8px; color: #fff; background: #187653; }
.button-primary:hover { background: #125d41; }
.button-secondary { color: #315746; background: #fff; border-color: #cbd9d1; }
.button-secondary:hover { background: #f3f8f5; }

.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.panel { margin: 20px 0; padding: 24px; background: #fff; border: 1px solid #e0e8e3; border-radius: 12px; }
.statistics-filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: end; }
.statistics-filters .button-primary { margin-top: 0; }
.month-filter { grid-column: 1 / -1; min-width: 0; margin: 0; }
.month-filter:not([open]) > .month-options { display: none; }
.month-filter summary { margin-bottom: 10px; color: #34443c; font-size: .9rem; font-weight: 600; cursor: pointer; }
.month-filter summary span { color: #6a7971; font-size: .82rem; font-weight: 400; }
.month-options { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.month-option { display: flex; align-items: center; gap: 7px; min-height: 38px; padding: 7px 9px; border: 1px solid #e0e8e3; border-radius: 7px; background: #fbfcfb; font-size: .82rem; font-weight: 500; }
.month-option input { width: 16px; min-height: 16px; margin: 0; accent-color: #187653; }
.checkbox-label { display: flex; align-items: center; gap: 8px; min-height: 43px; white-space: nowrap; }
.checkbox-label input { width: 18px; min-height: 18px; margin: 0; accent-color: #187653; }
.share-checkbox, .expense-share-checkbox { grid-column: 1 / -1; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 20px 0; }
.summary-card { min-width: 0; padding: 20px; background: #fff; border: 1px solid #e0e8e3; border-radius: 12px; }
.summary-card .eyebrow { overflow-wrap: anywhere; }
.summary-value { margin: 8px 0 0; color: #153d30; font-size: clamp(1.35rem, 3vw, 2rem); font-weight: 750; letter-spacing: -.035em; overflow-wrap: anywhere; }
.summary-value span { margin-left: 6px; color: #607167; font-size: .88rem; font-weight: 600; letter-spacing: 0; }
.summary-detail { margin: 5px 0 0; color: #6a7971; font-size: .8rem; }
.chart-note { margin: 24px 0 12px; font-size: .9rem; line-height: 1.55; }
.statistics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.statistics-grid-all-years { grid-template-columns: minmax(0, 1fr); }
.chart-card { min-width: 0; padding: 20px; background: #fff; border: 1px solid #e0e8e3; border-radius: 12px; }
.chart-card h2 { margin: 0 0 12px; font-size: 1rem; }
.chart-scroll { overflow-x: auto; }
.chart-svg { display: block; width: 100%; min-width: 560px; height: auto; }
.chart-svg-wide { width: auto; min-width: 0; max-width: none; height: 300px; }
.chart-point { cursor: crosshair; }
.chart-point:focus { filter: drop-shadow(0 0 3px rgb(23 104 77 / 70%)); outline: none; }
.chart-tooltip { position: fixed; z-index: 20; max-width: min(280px, calc(100vw - 16px)); padding: 7px 10px; border-radius: 6px; background: #173d30; color: #fff; font-size: .82rem; line-height: 1.35; box-shadow: 0 4px 14px rgb(15 38 28 / 22%); pointer-events: none; }
.chart-tooltip[hidden] { display: none; }
.chart-gridline { stroke: #e7ede9; stroke-width: 1; }
.chart-axis-label { fill: #6a7971; font-family: inherit; font-size: 12px; }
.chart-empty { min-height: 180px; display: grid; place-items: center; color: #6a7971; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; align-items: end; }
.form-grid > label { min-width: 0; }
.form-grid input[type="date"] { min-width: 0; }
.form-actions { display: flex; gap: 9px; align-items: center; }
.form-actions .button-primary { margin-top: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 10px; border-bottom: 1px solid #e8edea; vertical-align: middle; }
th { color: #65756c; font-size: .78rem; font-weight: 700; }
td { font-size: .88rem; }
.sort-button { display: inline-flex; align-items: center; gap: 5px; padding: 4px 5px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: inherit; font: inherit; font-weight: inherit; white-space: nowrap; cursor: pointer; }
.sort-button:hover { border-color: #d7e3dc; background: #f3f8f5; }
.sort-button:focus-visible { outline: 3px solid rgb(38 147 106 / 18%); border-color: #278b67; }
.sort-button[aria-pressed="true"] { color: #17684d; }
.sort-indicator { font-size: .95rem; }
.sort-priority { font-size: .65rem; font-weight: 750; }
.sort-status { min-height: 1em; margin: 10px 0 0; font-size: .82rem; }
.pagination-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.pagination-controls[hidden], .pagination-nav[hidden], .page-summary[hidden] { display: none !important; }
.page-size-control { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.page-size-control select { width: auto; min-width: 76px; min-height: 36px; padding: 6px 9px; }
.pagination-nav { width: auto; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
.page-button { min-width: 34px; min-height: 34px; padding: 5px 8px; border: 1px solid #d7e3dc; border-radius: 6px; background: #fff; color: #315746; font: inherit; font-size: .82rem; cursor: pointer; }
.page-button:hover:not(:disabled) { background: #f3f8f5; }
.page-button:disabled { color: #a4b0a9; cursor: default; }
.page-button[aria-current="page"] { border-color: #187653; background: #187653; color: #fff; font-weight: 700; }
.page-ellipsis { padding: 0 3px; color: #6a7971; }
.page-summary { margin: 10px 0 0; font-size: .82rem; }
.actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.inline-form { display: inline-flex; margin: 0; }
.nav-button, .link-button { padding: 0; border: 0; background: none; font: inherit; cursor: pointer; }
.danger-text { color: #a63c3c; }
.notice { margin: 0 0 18px; padding: 12px 14px; border-radius: 8px; font-size: .92rem; }
.notice-error { color: #852d2d; background: #fff0ef; border: 1px solid #f3cfca; }
.notice-success { color: #215e43; background: #eaf7ef; border: 1px solid #c9ead4; }

@media (max-width: 760px) {
    .site-header { padding: 14px 20px; align-items: flex-start; flex-direction: column; gap: 12px; }
    nav { width: 100%; flex-wrap: wrap; justify-content: space-between; gap: 12px; }
    .container { width: min(100% - 28px, 600px); margin-top: 24px; }
    .auth-card { margin: 5vh auto; padding: 28px 22px; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .panel { padding: 18px; }
    .statistics-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .month-options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .statistics-grid { grid-template-columns: 1fr; }
    .chart-card { padding: 16px; }
}

@media (max-width: 520px) {
    .page-heading { align-items: flex-start; flex-direction: column; }
    .form-grid { grid-template-columns: 1fr; }
    .statistics-filters { grid-template-columns: 1fr; }
    .statistics-filters .button { width: 100%; }
    .month-filter summary { min-height: 43px; margin: 0; padding: 11px 38px 10px 12px; border: 1px solid #ccd8d1; border-radius: 8px; background: #fff; }
    .month-filter summary span { display: none; }
    .month-filter[open] summary { border-radius: 8px 8px 0 0; }
    .month-filter .month-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 10px; border: 1px solid #ccd8d1; border-top: 0; border-radius: 0 0 8px 8px; background: #fff; }
    .month-options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .summary-card { padding: 14px; }
    .summary-value { font-size: 1.35rem; }
    .chart-card { padding: 12px; }
    .table-wrap { overflow: visible; }
    table, tbody, tr, td { display: block; width: 100%; }
    thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
    .expense-history-table thead { position: static; display: block; width: auto; height: auto; overflow: visible; clip: auto; }
    .expense-history-table thead tr { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 10px; padding: 0; border: 0; }
    .expense-history-table thead th { display: block; width: auto; padding: 0; border: 0; }
    .expense-history-table thead th:last-child { display: none; }
    .expense-history-table .sort-button { padding: 5px 7px; border-color: #e0e8e3; background: #fbfcfb; font-size: .75rem; }
    .pagination-controls { align-items: stretch; flex-direction: column; }
    .pagination-nav { width: 100%; justify-content: center; }
    tbody tr { margin: 0 0 14px; padding: 8px 12px; border: 1px solid #e4ebe7; border-radius: 9px; }
    td { display: grid; grid-template-columns: 95px minmax(0, 1fr); gap: 10px; padding: 8px 0; overflow-wrap: anywhere; }
    td::before { content: attr(data-label); color: #6a7971; font-size: .78rem; font-weight: 700; }
    td.actions { display: flex; }
    td.actions::before { width: 85px; flex: 0 0 85px; }
}
