:root {
  color-scheme: light;
  --ink: #172c2a;
  --muted: #657673;
  --brand: #176b5b;
  --brand-dark: #124f44;
  --canvas: #f2f6f4;
  --surface: #ffffff;
  --line: #dfe8e4;
  --soft: #e8f2ee;
  --shadow: 0 12px 32px rgb(24 63 53 / 7%);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
main { width: min(1440px, 100% - 48px); margin: 0 auto; padding: 30px 0 56px; }
main > h1 { margin: 0; color: var(--brand-dark); font-size: clamp(1.8rem, 3vw, 2.35rem); letter-spacing: -.045em; }
.app-header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin:0 0 18px; }
.app-header h1 { margin:0; color:var(--brand-dark); font-size:clamp(1.8rem, 3vw, 2.35rem); letter-spacing:-.045em; }
.app-brand { min-width:0; }
.app-sync-meta { margin:2px 0 0; color:var(--muted); font-size:.78rem; line-height:1.3; }
.logout-form { margin:0; }
.logout-button { min-width:88px; background:var(--brand); color:white; }
.logout-button:hover { background:var(--brand-dark); color:white; }
.login-page { display: grid; min-height: 100vh; place-items: center; }
.login-shell { width: min(440px, calc(100% - 32px)); margin: 24px auto; padding: 30px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.login-shell h1 { color: var(--brand-dark); font-size: 2.2rem; letter-spacing: -.045em; }
.login-shell h2 { margin-top: 25px; }
.login-shell form { display: grid; align-items: stretch; gap: 14px; margin-top: 16px; }
.login-shell label input { width: 100%; }
.login-shell button { width: 100%; background: var(--brand); color: white; }
.login-shell button:hover { background: var(--brand-dark); color: white; }
h2 { margin: 0 0 17px; font-size: 1.2rem; letter-spacing: -.02em; }
h3 { margin: 0 0 12px; font-size: 1rem; }
.tabs {
  position: sticky;
  z-index: 5;
  top: 8px;
  display: flex;
  gap: 5px;
  width: max-content;
  max-width: 100%;
  margin: 0 0 22px;
  padding: 6px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgb(255 255 255 / 94%);
  box-shadow: 0 5px 20px rgb(20 48 41 / 7%);
  backdrop-filter: blur(12px);
}
.tabs button, button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}
.tabs button { flex: 0 0 auto; color: var(--muted); }
.tabs button:hover, button:hover { background: var(--soft); color: var(--brand-dark); }
.tabs button.active, button.primary { background: var(--brand); color: white; }
.tabs button.active:hover, button.primary:hover { background: var(--brand-dark); color: white; }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #8fcabd; outline-offset: 2px; }
main > section, .summary-card {
  min-width: 0;
  margin: 0 0 20px;
  padding: clamp(17px, 2vw, 25px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
main > section { overflow: auto; }
main > section[hidden], [hidden] { display: none !important; }
.notice { margin: 0 0 15px; padding: 12px 15px; border: 1px solid #bcdfd2; border-radius: 10px; background: #edf8f2; color: #1e634c; }
form { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin: 0 0 16px; }
label { display: grid; gap: 4px; color: var(--muted); font-size: .84rem; font-weight: 650; }
input, select {
  min-height: 40px;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccd9d4;
  border-radius: 8px;
  background: white;
  color: var(--ink);
  font: inherit;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .9rem; }
th { padding: 11px 12px; background: #f4f8f6; color: #45615a; font-size: .76rem; font-weight: 750; letter-spacing: .045em; text-align: left; text-transform: uppercase; white-space: nowrap; }
th:first-child { border-radius: 8px 0 0 8px; }
th:last-child { border-radius: 0 8px 8px 0; }
td { padding: 12px; border-bottom: 1px solid #edf1ef; vertical-align: middle; }
tbody tr:hover td { background: #fbfdfc; }
td form { flex-wrap: nowrap; margin: 0; }
td select { min-width: 145px; }
td button { min-height: 36px; padding: 7px 12px; background: var(--soft); color: var(--brand-dark); white-space: nowrap; }
.summary-page { overflow: visible !important; border: 0 !important; padding: 0 !important; background: transparent !important; box-shadow: none !important; }
.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.summary-card { margin: 0; overflow: hidden; }
.summary-card:first-child, .summary-card:nth-child(2) { grid-column: span 1; }
.summary-card.summary-chart-card { grid-column: 1 / -1; }
.summary-card h3 span, .muted { color: var(--muted); font-weight: 450; }
.summary-period-row { display:flex; align-items:center; gap:12px; margin:0 0 10px; padding:12px 15px; border:1px solid var(--line); border-radius:11px; background:#f4f8f6; }
.summary-period-row span, .summary-owner-toolbar > span { color:var(--muted); font-size:.82rem; font-weight:700; }
.summary-period-row strong { color:var(--brand-dark); font-size:.9rem; }
.summary-owner-toolbar { display:flex; align-items:center; flex-wrap:wrap; gap:7px; margin:0 0 18px; padding:10px 12px; border:1px solid var(--line); border-radius:11px; background:#f4f8f6; }
.summary-owner-toolbar > span { margin-right:4px; }
.summary-owner-toolbar button { min-height:36px; padding:7px 12px; border-color:#dce7e2; background:white; color:var(--brand-dark); font-size:.86rem; }
.summary-owner-toolbar button.active { border-color:var(--brand); background:var(--brand); color:white; }
.summary-owner-toolbar button:focus-visible { outline-offset:1px; }
.summary-line-chart { width:100%; overflow-x:auto; }
.summary-line-chart svg { display:block; width:100%; min-width:620px; height:auto; }
.summary-category-chart { display:grid; gap:12px; }
.summary-category-row { display:grid; grid-template-columns:minmax(130px, 1.2fr) minmax(100px, 4fr) minmax(120px, 1fr); align-items:center; gap:14px; }
.summary-category-name { color:var(--ink); font-size:.92rem; }
.summary-category-track { display:block; height:12px; overflow:hidden; border-radius:999px; background:#edf2ef; }
.summary-category-bar { display:block; height:100%; border-radius:inherit; }
.summary-category-bar.is-expense { background:#397fb6; }
.summary-category-bar.is-income { background:#176b5b; }
.summary-category-value { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }
.summary-chart-gridline { stroke:#e2ebe7; stroke-width:1; }
.summary-chart-y-label, .summary-chart-x-label { fill:var(--muted); font:11px/1.2 Inter,ui-sans-serif,system-ui,sans-serif; }
.summary-chart-line { fill:none; stroke-width:3; stroke-linecap:round; stroke-linejoin:round; }
.summary-line-legend { display:flex; flex-wrap:wrap; gap:8px 15px; margin-top:10px; }
.summary-line-legend-item { display:inline-flex; align-items:center; gap:7px; color:var(--muted); font-size:.8rem; }
.summary-line-legend-item::before { width:10px; height:10px; border-radius:50%; background:var(--series-color); content:""; }
.table-sort-link { color:inherit; text-decoration:none; }
.table-sort-link:hover, .table-sort-link:focus-visible { text-decoration:underline; }
.profile-permission-list { display:grid; gap:16px; grid-template-columns:repeat(auto-fit,minmax(min(100%,360px),1fr)); }
.profile-permission-card { padding:18px; border:1px solid var(--line); border-radius:14px; background:#fff; }
.profile-permission-card h3 { margin:0 0 6px; }
.profile-permission-card fieldset { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:8px 14px; margin:14px 0; padding:12px; border:1px solid var(--line); border-radius:10px; }
.profile-permission-option { display:flex; align-items:center; gap:8px; }
.compact-table { font-size: .82rem; }
.compact-table th { font-size: .68rem; }
.compact-table td { padding: 9px 8px; }
.compact-table td form { display: none; }
.category-chart { display: grid; grid-template-columns: minmax(190px, .7fr) minmax(250px, 1.3fr); align-items: center; gap: 28px; margin-top: 18px; }
.donut-chart { position: relative; width: min(230px, 100%); aspect-ratio: 1; margin: 0 auto; }
.donut-chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.donut-segment { fill: none; stroke: currentColor; stroke-width: 15; stroke-linecap: butt; }
.segment-0, .swatch-0 { color: #176b5b; }
.segment-1, .swatch-1 { color: #397fb6; }
.segment-2, .swatch-2 { color: #d28b35; }
.segment-3, .swatch-3 { color: #8062a8; }
.segment-4, .swatch-4 { color: #cc5d68; }
.segment-5, .swatch-5 { color: #65758b; }
.segment-6, .swatch-6 { color: #3eaaa1; }
.segment-7, .swatch-7 { color: #a26d54; }
.donut-center { position: absolute; top: 17%; left: 17%; display: grid; width: 66%; height: 66%; align-content: center; justify-items: center; border-radius: 50%; background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); text-align: center; }
.donut-center strong { font-size: clamp(1rem, 2vw, 1.35rem); letter-spacing: -.04em; }
.donut-center span { color: var(--muted); font-size: .76rem; }
.chart-legend { display: grid; gap: 5px; }
.legend-item { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 39px; padding: 7px 9px; border-color: var(--line); text-align: left; }
.legend-item .swatch { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.legend-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item b { font-size: .84rem; }
.empty-state { color: var(--muted); }
.tab-filters { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; margin: 0 0 18px; padding: 13px; border-radius: 10px; background: #f4f8f6; }
.tab-filters label { display: flex; align-items: center; gap: 8px; }
footer { padding: 18px 0; color: var(--muted); }

@media (max-width: 760px) {
  main { width: min(100% - 24px, 620px); padding: 19px 0 32px; }
  .tabs { position: sticky; top: 4px; width: calc(100% + 4px); margin: 0 -2px 15px; border-radius: 12px; }
  .tabs button { min-height: 38px; padding: 8px 12px; font-size: .88rem; }
  main > section, .summary-card { margin-bottom: 14px; padding: 15px; border-radius: 13px; }
  .summary-grid { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .summary-card, .summary-card:first-child, .summary-card:nth-child(2), .summary-card.summary-chart-card { grid-column: 1; }
  .summary-period-row { margin-bottom:8px; padding:10px 12px; }
  .summary-owner-toolbar { gap:6px; margin-bottom:13px; padding:9px; }
  .summary-owner-toolbar > span { flex-basis:100%; }
  .summary-owner-toolbar button { flex:1 1 auto; padding:7px 9px; font-size:.8rem; }
  .summary-line-chart svg { min-width:640px; }
  .summary-category-row { grid-template-columns:minmax(92px,1.1fr) minmax(60px,2fr) minmax(92px,1fr); gap:8px; font-size:.82rem; }
  .category-chart { grid-template-columns: minmax(0, 1fr); gap: 17px; }
  .donut-chart { width: min(205px, 70vw); }
  main > section > table, .summary-card > table { display: block; width: 100%; }
  main > section > table thead, main > section > table > thead { display: none; }
  main > section > table tr:first-child, .summary-card > table tr:first-child { display: none; }
  main > section > table tr, .summary-card > table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; margin: 0 0 11px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
  main > section > table td, .summary-card > table td { display: block; min-width: 0; padding: 5px 0; border: 0; overflow-wrap: anywhere; }
  main > section > table td::before, .summary-card > table td::before { display: block; margin-bottom: 2px; color: var(--muted); content: attr(data-label); font-size: .68rem; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
  main > section > table td:last-child, .summary-card > table td:last-child { grid-column: 1 / -1; }
  main > section > table td form { flex-wrap: wrap; }
  main > section > table td select { flex: 1 1 160px; min-width: 0; }
  .compact-table tr { grid-template-columns: minmax(0, 1fr) auto !important; padding: 8px !important; }
  .compact-table td:nth-child(2) { text-align: right; }
  .compact-table td:nth-child(7) { display: none !important; }
  .tab-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .tab-filters label:last-child { grid-column: 1 / -1; }
  .tab-filters label { display: grid; align-items: start; }
  .tab-filters input, .tab-filters select { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}

.investment-visibility-select.is-enabled {
  border-color: #79bd91;
  background-color: #e8f5ec;
  color: #185d32;
}
.investment-visibility-select.is-disabled {
  border-color: #dc8982;
  background-color: #fdebea;
  color: #922f29;
}

.pagination { display:flex; flex-wrap:wrap; gap:12px; align-items:center; margin:18px 0; }
.pagination a { padding:8px 12px; border:1px solid var(--line); border-radius:8px; }
.page-disabled { color:var(--muted); opacity:.6; }
.category-create { display:flex; flex-wrap:wrap; align-items:end; gap:12px; margin:20px 0; }
.category-admin-table td form { display:flex; flex-wrap:wrap; align-items:end; gap:8px; }
.category-admin-table td label { display:grid; gap:5px; min-width:150px; }
.category-admin-table input, .category-admin-table select { width:100%; }
.category-admin-table summary { cursor:pointer; color:var(--brand-dark); font-weight:650; }
.category-admin-table .category-trash { display:grid; width:38px; height:38px; place-items:center; border:1px solid var(--line); border-radius:9px; background:#fff; list-style:none; }
.category-admin-table .category-trash::-webkit-details-marker { display:none; }
.category-admin-table .category-trash:hover { border-color:#dc8982; background:#fff3f2; color:#922f29; }
.category-admin-table .category-trash svg { width:19px; height:19px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.category-rules > p { max-width:1000px; }
.category-rule-form { display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); align-items:end; gap:12px; padding:18px; margin:16px 0 28px; border:1px solid var(--line); border-radius:14px; background:#f8fbfa; }
.category-rule-form h3, .category-rule-form > p, .category-rule-form .rule-backfill { grid-column:1/-1; margin:0; }
.category-rule-form label { display:grid; gap:6px; }
.category-rule-form .rule-backfill { display:flex; align-items:center; gap:8px; }
.category-rule-form .rule-backfill input { width:auto; }
.category-rule-form > button { justify-self:start; }
.category-rule-form > button:disabled { cursor:not-allowed; opacity:.5; }
.rule-preview { grid-column:1/-1; min-width:0; overflow-x:auto; padding-top:8px; }
.rule-preview h4 { margin:0 0 5px; color:var(--brand-dark); }
.rule-preview p { margin:0 0 12px; }
.rule-preview table { min-width:780px; margin:0; }
.rule-preview td:nth-child(3) { min-width:220px; }
.category-rules-table { min-width:950px; }
.category-rules-table input, .category-rules-table select { width:100%; min-width:130px; }
.category-rules-table td { vertical-align:top; }
.category-rule-edit { margin:0; }
.rule-action { display:inline-block; margin:0 4px 4px 0; }
details form { display:flex; flex-wrap:wrap; gap:10px; margin-top:12px; }

.report-filters { align-items:end; margin: 0 0 18px; padding: 14px; border-radius: 11px; background: #f4f8f6; }
.report-filters label { min-width: 145px; }
.report-filters input, .report-filters select { width: 100%; }
.report-reset { align-self:center; padding: 9px 4px; color: var(--brand-dark); font-weight: 650; }
.report-metrics { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap:12px; margin: 0 0 20px; }
.report-metrics article, .report-chart-grid article { min-width:0; padding:16px; border:1px solid var(--line); border-radius:12px; background:#fbfdfc; }
.report-metrics article { display:grid; gap:5px; }
.report-metrics span { color:var(--muted); font-size:.82rem; font-weight:650; }
.report-metrics strong { color:var(--brand-dark); font-size:1.45rem; letter-spacing:-.035em; }
.report-chart-grid { display:grid; grid-template-columns:repeat(2, minmax(0,1fr)); gap:14px; margin:0 0 24px; }
.report-chart-grid article:first-child { grid-column:1 / -1; }
.report-chart-list { display:grid; gap:5px; max-height:390px; overflow:auto; }
.report-bar { display:grid; grid-template-columns:minmax(95px, .7fr) minmax(55px, 1fr) minmax(92px, auto); align-items:center; gap:9px; width:100%; min-height:36px; padding:5px 7px; border:1px solid transparent; border-radius:7px; text-align:left; }
.report-bar:hover, .report-bar:focus-visible { border-color:#cfe1da; background:#edf6f2; }
.report-bar-name { overflow:hidden; color:var(--ink); font-size:.82rem; text-overflow:ellipsis; white-space:nowrap; }
.report-bar-track { display:block; height:11px; overflow:hidden; border-radius:99px; background:#e8efec; }
.report-bar-fill { display:block; height:100%; min-width:2px; border-radius:inherit; background:var(--brand); }
.report-bar-amount { color:var(--brand-dark); font-size:.78rem; text-align:right; white-space:nowrap; }
.report-transactions { margin-top:10px; }
.report-transactions td:nth-child(4) { min-width:210px; }
.movement-filter-bar { position:sticky; top:66px; z-index:4; display:grid; grid-template-columns:minmax(130px,.8fr) repeat(2,minmax(130px,.7fr)) minmax(140px,.8fr) minmax(180px,1.2fr) minmax(145px,.9fr) auto; align-items:end; gap:10px; margin:0 -6px 16px; padding:12px; border:1px solid var(--line); border-radius:12px; background:rgb(244 248 246 / 97%); box-shadow:0 5px 16px rgb(24 63 53 / 8%); backdrop-filter:blur(12px); }
.movement-page { overflow:visible !important; }
.movement-filter-bar label { display:grid; gap:4px; min-width:0; color:var(--muted); font-size:.78rem; font-weight:700; }
.movement-filter-bar input, .movement-filter-bar select { width:100%; min-width:0; min-height:40px; padding:8px 10px; border:1px solid var(--line); border-radius:8px; background:white; color:var(--ink); font:inherit; }
.movement-filter-bar [hidden] { display:none !important; }
.movement-filter-bar button { min-height:40px; white-space:nowrap; }
.movement-filter-bar .movement-clear { width:42px; min-width:42px; padding:5px; border:1px solid var(--line); border-radius:50%; background:white; color:var(--brand-dark); font-size:1.5rem; line-height:1; }
.movement-visible-total { color:var(--brand-dark); font-weight:700; }
.movement-visible-total strong { font-size:.95rem; }
.movement-special-toggle { display:inline-flex; align-items:center; gap:7px; padding:5px 9px; border:1px solid var(--line); border-radius:8px; background:#fff; color:var(--brand-dark); font-size:.8rem; font-weight:650; white-space:nowrap; }
.movement-special-toggle input[type=checkbox] { width:17px; min-width:17px; min-height:17px; height:17px; margin:0; padding:0; accent-color:var(--brand); }
.movement-table th { padding:0; }
.movement-sort-button { width:100%; min-height:0; padding:11px 12px; border-radius:0; color:inherit; font-size:.76rem; letter-spacing:.045em; text-align:left; text-transform:uppercase; white-space:nowrap; }
.movement-sort-button:hover { background:#eaf2ee; }
.movement-mobile-sort { display:none; }
.movement-table td:nth-child(3) { min-width:220px; }
.movement-table td:nth-child(6) form { display:flex; flex-wrap:nowrap; align-items:center; gap:7px; }
.movement-table td:nth-child(6) select { min-width:145px; }
@media (max-width:760px) {
  .report-filters { display:grid; grid-template-columns:1fr 1fr; }
  .report-filters label:nth-of-type(n+3), .report-filters button, .report-reset { grid-column:1 / -1; }
  .report-metrics { grid-template-columns:1fr 1fr; gap:8px; }
  .report-metrics article { padding:12px; }
  .report-metrics strong { font-size:1.15rem; }
  .report-chart-grid { grid-template-columns:1fr; }
  .report-chart-grid article:first-child { grid-column:1; }
  .report-bar { grid-template-columns:minmax(78px, .7fr) minmax(45px, 1fr) minmax(80px, auto); gap:6px; padding-inline:3px; }
  .report-bar-name { font-size:.75rem; }
  .report-bar-amount { font-size:.72rem; }
  .movement-filter-bar { top:56px; grid-template-columns:1fr 1fr; gap:8px; margin-inline:-4px; padding:9px; }
  .movement-filter-bar label:nth-of-type(5) { grid-column:1 / -1; }
  .movement-filter-bar label { font-size:.72rem; }
  .movement-filter-bar .movement-clear { grid-column:2; justify-self:end; }
  .movement-mobile-sort { display:flex; align-items:center; flex-wrap:wrap; gap:6px; margin:0 0 12px; }
  .movement-mobile-sort > span { flex-basis:100%; color:var(--muted); font-size:.76rem; font-weight:700; }
  .movement-mobile-sort button { min-height:32px; padding:5px 9px; border:1px solid var(--line); background:#fff; color:var(--brand-dark); font-size:.76rem; }
  .movement-mobile-sort button.active { background:var(--brand); color:#fff; }
  .movement-table td:nth-child(6) form { flex-wrap:wrap; }
  .movement-table td:nth-child(6) select { flex:1 1 150px; }
  /* Keep long mobile labels and text fields in usable card layouts. */
  .category-admin-table tr, .report-transactions tr { grid-template-columns:minmax(0,1fr) !important; }
  .category-admin-table td:last-child, .report-transactions td:last-child { grid-column:auto; }
  .category-admin-table td::before, .report-transactions td::before { white-space:nowrap; overflow-wrap:normal; }
  .category-admin-table td form { display:grid; grid-template-columns:minmax(0,1fr); }
  .category-admin-table td label { min-width:0; }
  .category-create { display:grid; grid-template-columns:minmax(0,1fr); align-items:stretch; }
  .category-create label, .category-create input { width:100%; min-width:0; }
  .movement-table tr { grid-template-columns:minmax(0,1fr) minmax(0,1fr); }
  .movement-table td { min-width:0; overflow-wrap:anywhere; }
  .movement-table td:nth-child(3), .movement-table td:nth-child(n+4) { grid-column:1 / -1; }
  .movement-table td:nth-child(3) { min-width:0; }
  .report-transactions td { min-width:0; overflow-wrap:anywhere; }
}
