:root {
  color-scheme: light;
  --page: #f4f7fb;
  --surface: #fff;
  --ink: #12243b;
  --muted: #4e6076;
  --border: #dce5ef;
  --nav: #11243b;
  --nav-text: #c1d1e2;
  --accent: #274cb6;
  --accent-hover: #1d3d99;
  --accent-soft: #eef3ff;
  --positive: #136743;
  --negative: #a33243;
  --amber: #795100;
  --focus: #246bda;
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 100%;
  line-height: 1.45;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--page); }
button, input, select { font: inherit; }
a { color: var(--accent); text-underline-offset: 0.2em; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.62; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.75rem, 3.4vw, 2.4rem); line-height: 1.13; letter-spacing: -0.047em; }
h2 { font-size: 1.13rem; line-height: 1.25; letter-spacing: -0.019em; }
h3 { font-size: 1rem; line-height: 1.25; }
.muted { color: var(--muted); }
.secondary { font-size: 0.875rem; color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.skip-link { position: fixed; z-index: 50; top: 8px; left: 8px; transform: translateY(-150%); background: var(--surface); padding: 12px; border-radius: 8px; }
.skip-link:focus { transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { display: grid; grid-template-columns: 206px minmax(0, 1fr); min-height: 100vh; }
.sidebar { display: flex; position: sticky; top: 0; flex-direction: column; height: 100vh; padding: 26px 15px 20px; background: var(--nav); color: #fff; }
.brand { display: inline-flex; align-items: center; gap: 10px; width: fit-content; margin: 0 8px; color: inherit; text-decoration: none; font-size: 1.12rem; font-weight: 740; letter-spacing: -0.045em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: #395fcb; color: #fff; box-shadow: inset 0 0 0 1px #ffffff24; font-size: 0.82rem; font-weight: 750; letter-spacing: -0.06em; }
.navigation { display: grid; gap: 5px; margin-top: 38px; }
.nav-link { display: flex; align-items: center; min-height: 43px; padding: 9px 12px; color: var(--nav-text); text-decoration: none; border: 1px solid transparent; border-radius: 8px; font-size: 0.94rem; font-weight: 610; }
.nav-link:hover { color: white; background: #ffffff12; }
.nav-link[aria-current] { color: #fff; background: #304a72; border-color: #ffffff17; }
.sign-out { margin-top: auto; }
.sign-out button { width: 100%; border: 1px solid #ffffff30; border-radius: 8px; padding: 9px 12px; background: transparent; color: var(--nav-text); text-align: left; font-size: 0.875rem; }
.sign-out button:hover { color: #fff; background: #ffffff12; }

.workspace { min-width: 0; max-width: 1710px; width: 100%; margin: 0 auto; padding: 31px clamp(16px, 3vw, 43px) 46px; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 23px; }
.page-header p { margin-top: 7px; color: var(--muted); }
.section-stack { display: grid; gap: 17px; }
.surface { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 4px 16px #182b4310; }
.panel { padding: 19px; }
.section-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }
.section-header p { margin-top: 4px; }
.empty-state { padding: 30px 17px; text-align: center; color: var(--muted); }
.empty-state h3 { margin-bottom: 5px; color: var(--ink); }

.metrics { display: grid; grid-template-columns: minmax(230px, 1.35fr) repeat(2, minmax(140px, 1fr)); gap: 12px; }
.metric { min-width: 0; padding: 17px 18px 15px; display: grid; align-content: start; gap: 5px; }
.metric-accent { border-color: #becdee; background: linear-gradient(115deg, #edf2ff, #f7faff); }
.metric-label { color: var(--muted); font-size: 0.91rem; font-weight: 650; }
.metric-value { font-size: clamp(1.32rem, 2.2vw, 2rem); line-height: 1.18; letter-spacing: -0.041em; font-weight: 760; overflow-wrap: anywhere; white-space: normal; }
.metric-accent .metric-value { color: #203e89; }
.metric-note { color: var(--muted); font-size: 0.82rem; }
.accounts { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 9px; }
.account { padding: 10px 13px; min-width: 0; border: 1px solid var(--border); border-radius: 9px; background: #f7f9fd; }
.account-head { display: flex; align-items: baseline; justify-content: space-between; gap: 9px; }
.account-head strong { font-size: 0.94rem; }
.account-amount { display: block; margin-top: 3px; font-weight: 740; }

.upload-panel { display: grid; gap: 12px; padding: 17px 19px; }
.upload-panel .section-header { margin-bottom: 0; }
.upload-form { display: flex; align-items: end; flex-wrap: wrap; gap: 9px; }
.upload-input { flex: 1 1 290px; min-width: 0; }
input[type="file"] { width: 100%; min-width: 0; padding: 4px 8px 4px 5px; }
input[type="file"]::file-selector-button { margin-right: 9px; padding: 4px 8px; border: 0; border-radius: 5px; background: var(--accent-soft); color: var(--accent); font-weight: 650; cursor: pointer; }
.upload-details summary { padding: 13px 18px; cursor: pointer; font-weight: 710; }
.upload-details[open] summary { border-bottom: 1px solid var(--border); }
.upload-details .upload-panel { box-shadow: none; }

.button { display: inline-flex; justify-content: center; align-items: center; min-height: 39px; padding: 7px 13px; gap: 5px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent); color: white; text-decoration: none; font-size: 0.875rem; line-height: 1.25; font-weight: 680; white-space: nowrap; }
.button:hover { background: var(--accent-hover); }
.button-secondary { border-color: var(--border); color: var(--ink); background: var(--surface); }
.button-secondary:hover { border-color: #b7c6da; background: #f0f4f9; }
.button-danger { border-color: #ebced3; color: var(--negative); background: #fff; }
.button-danger:hover { background: #fff0f3; }
.button-small { min-height: 33px; padding: 5px 9px; }
.button-text { border: 0; padding: 4px; background: transparent; color: var(--accent); font-size: 0.875rem; font-weight: 650; text-decoration: underline; text-underline-offset: 3px; }
.button-text:hover { color: var(--accent-hover); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span, .field > label { font-size: 0.875rem; font-weight: 660; }
.field-grow { flex: 1 1 215px; }
.field-short { flex: 1 1 145px; }
input:not([type="hidden"]), select { color: var(--ink); width: 100%; min-height: 39px; padding: 7px 9px; border: 1px solid #c6d2e0; border-radius: 7px; background-color: var(--surface); font-size: 0.875rem; }
input::placeholder { color: #65768c; }
select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, #536780 50%), linear-gradient(135deg, #536780 50%, transparent 50%); background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-repeat: no-repeat; background-size: 5px 5px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.filters { padding: 15px 17px; display: flex; flex-wrap: wrap; align-items: end; gap: 8px; border-bottom: 1px solid var(--border); background: #f9fbfe; }
.filters .field { flex: 1 1 110px; }
.filters .search-field { flex: 2 1 175px; }
.filters .date-field { flex: 1 1 137px; }
.filter-actions { display: flex; align-items: center; gap: 6px; }
.bulk-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 14px; padding: 10px 17px; border-bottom: 1px solid var(--border); }
.bulk-selection, .bulk-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.bulk-controls select { flex: 1 1 145px; width: auto; }
.bulk-check-label { display: inline-flex; min-height: 34px; align-items: center; gap: 7px; cursor: pointer; font-size: 0.875rem; }
input.bulk-checkbox { flex: 0 0 auto; width: 1.1rem; height: 1.1rem; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); cursor: pointer; }
.bulk-selection-cell { width: 1%; padding: 0 8px 0 14px; }
.bulk-selection-cell .bulk-check-label { min-width: 26px; }
.bulk-mobile-label { display: none; }
.bulk-actions button:disabled { cursor: default; }
.table-panel > .section-header { padding: 16px 17px 0; }
.table-scroll { max-width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.875rem; }
caption { text-align: left; }
th, td { padding: 10px 12px; border-bottom: 1px solid #e8edf4; vertical-align: middle; }
thead th { padding-top: 9px; padding-bottom: 9px; background: #f6f8fc; color: #354b65; font-weight: 680; white-space: nowrap; }
tbody tr:hover { background: #fafcff; }
tbody tr:last-child td { border-bottom: 0; }
.ledger-table { min-width: 790px; }
.ledger-table .transaction-description { min-width: 175px; }
.ledger-table tr:has([data-bulk-transaction]:checked) { background: var(--accent-soft); }
.date-cell { white-space: nowrap; }
.transaction-description { overflow-wrap: anywhere; }
.bank-cell { min-width: 72px; }
.bank-cell strong { display: block; }
.numeric { text-align: right; }
.inline-category { display: flex; min-width: 183px; align-items: center; gap: 5px; }
.inline-category select { min-height: 33px; }
.row-actions { min-width: 84px; }
.badge { display: inline-flex; width: fit-content; padding: 3px 7px; border-radius: 6px; background: #eef2f7; color: #465972; font-size: 0.8125rem; line-height: 1.3; font-weight: 650; white-space: nowrap; }
.badge-transfer { background: var(--accent-soft); color: #2a4590; }
.badge-income { background: #e7f6ee; color: var(--positive); }
.badge-expense { background: #fff0f2; color: var(--negative); }
.badge-review { background: #fff3d9; color: var(--amber); }
.pagination { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 17px; border-top: 1px solid var(--border); }

.paired-list { list-style: none; margin: 0; padding: 0; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid #e8edf4; }
.pair:last-child { border-bottom: 0; padding-bottom: 0; }
.pair:first-child { padding-top: 0; }
.pair-leg { min-width: 0; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #f9fbfe; font-size: 0.875rem; overflow-wrap: anywhere; }
.pair-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 5px; margin-bottom: 3px; }
.pair-leg > .secondary { display: block; margin-bottom: 3px; }
.selected-leg { margin-bottom: 12px; }
.pair-action { display: grid; justify-items: start; gap: 4px; }
.categories-table { min-width: 540px; }
.categories-table th:last-child { width: 1%; }
.edit-form { min-width: 280px; }
.category-name { min-width: min(200px, 25vw); }
.category-details[open] { display: grid; gap: 8px; }
.category-details summary { width: fit-content; list-style: none; cursor: pointer; }
.category-details summary::-webkit-details-marker { display: none; }

.flash-list { display: grid; gap: 7px; margin-bottom: 16px; }
.flash { padding: 11px 13px; border: 1px solid #c9d8ed; border-radius: 9px; background: #eef4fe; color: #214585; font-size: 0.9rem; overflow-wrap: anywhere; }
.flash-error, .flash-danger { border-color: #eccbd1; background: #fff0f3; color: #8a2636; }
.flash-warning { border-color: #e9d095; background: #fff6dc; color: #684600; }
.flash-success { border-color: #bcdccb; background: #ebf8f0; color: #1a5a3f; }

.login-shell { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(ellipse at 40% 10%, #294775, #12243b 65%); }
.login-panel { width: min(100%, 410px); padding: 30px; box-shadow: 0 20px 54px #06112a55; }
.login-panel .brand { margin: 0 0 24px; }
.login-panel p { margin: 8px 0 18px; }
.login-panel form { display: grid; gap: 12px; }
.login-panel .button { margin-top: 4px; }

@media (max-width: 1020px) {
  .app-shell { grid-template-columns: 168px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .workspace { padding-inline: 19px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 11px; height: auto; padding: 12px 14px 10px; }
  .brand { margin: 0; }
  .navigation { grid-column: 1 / -1; grid-row: 2; display: flex; flex-wrap: wrap; margin: 0; }
  .nav-link { min-height: 35px; padding: 5px 10px; }
  .sign-out { margin: 0; }
  .sign-out button { padding: 6px 8px; }
  .workspace { padding: 20px 13px 27px; }
  .page-header { margin-bottom: 14px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric-accent { grid-column: 1 / -1; }
  .metric { padding: 12px; }
  .panel, .upload-panel { padding: 13px; }
  .pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pair > form { grid-column: 1 / -1; }
  .ledger-table, .ledger-table tbody { display: block; min-width: 0; }
  .ledger-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .ledger-table tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 12px; padding: 13px; border-bottom: 1px solid var(--border); }
  .ledger-table tr:last-child { border-bottom: 0; }
  .ledger-table td { display: block; min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; }
  .ledger-table td::before { display: block; margin-bottom: 2px; color: var(--muted); content: attr(data-label); font-size: 0.82rem; }
  .ledger-table :is(.transaction-description, .transaction-category, .row-actions, .bulk-selection-cell) { grid-column: 1 / -1; min-width: 0; }
  .ledger-table .bulk-selection-cell { width: auto; }
  .ledger-table .bulk-selection-cell::before, .ledger-table .bulk-selection-cell-empty { display: none; }
  .bulk-mobile-label { display: inline; }
  .bulk-controls { width: 100%; }
  .inline-category { min-width: 0; }
  .row-actions form { display: inline-block; }
}

@media (max-width: 400px) {
  .filters .field { min-width: 100%; }
  .pair { grid-template-columns: minmax(0, 1fr); }
}

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