:root {
  color-scheme: light;
  --paper: #f6f7f4;
  --surface: #ffffff;
  --ink: #16221d;
  --muted: #68736d;
  --line: #dce1dc;
  --accent: #176b4d;
  --accent-soft: #e4f2eb;
  --expense: #a33c31;
  --expense-soft: #f8e9e6;
  --focus: #155eef;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button { color: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible, label:has(input:focus-visible) span { outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 2px; }
.app-shell { min-height: 100svh; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; max-width: 1180px; margin: auto; padding: 0 28px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; color: var(--ink); font-size: 15px; font-weight: 750; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; aspect-ratio: 1; background: var(--ink); color: #fff; font-family: Georgia, serif; font-size: 18px; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.name-picker { display: flex; align-items: center; gap: 7px; }
.name-picker label { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.name-picker select { width: 136px; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 700; }
.small-icon-button { width: 36px; height: 36px; }
.privacy-note { color: var(--muted); font-size: 12px; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--accent); }
.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: transparent; cursor: pointer; }
.icon-button:hover { background: #fff; }
svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
main { max-width: 1180px; margin: auto; padding: 48px 28px 72px; }
.entry-section { padding-bottom: 48px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: 45px; font-weight: 500; line-height: 1.05; letter-spacing: 0; }
.section-heading > p { max-width: 300px; margin-bottom: 2px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.entry-form { display: grid; grid-template-columns: minmax(210px, 1fr) minmax(150px, .75fr) minmax(150px, .75fr) minmax(210px, 1fr) minmax(150px, .7fr) auto; gap: 12px; align-items: end; }
.type-control { display: grid; grid-template-columns: 1fr 1fr; min-width: 0; padding: 0; border: 0; }
.type-control legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.type-control label { cursor: pointer; }
.type-control input { position: absolute; opacity: 0; pointer-events: none; }
.type-control span { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 51px; padding: 0 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 700; }
.type-control label:first-of-type span { border-radius: 6px 0 0 6px; }
.type-control label:last-of-type span { border-left: 0; border-radius: 0 6px 6px 0; }
.type-control input:checked + span { position: relative; z-index: 1; border-color: var(--ink); background: var(--ink); color: #fff; }
.field { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.field small { font-size: 10px; font-weight: 500; text-transform: none; }
.field input, .field select { width: 100%; height: 51px; padding: 0 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 15px; text-transform: none; }
.field input::placeholder { color: #9aa39e; }
.amount-field-wrap { position: relative; min-width: 0; }
.amount-input { position: relative; }
.amount-input > span { position: absolute; z-index: 1; top: 16px; left: 14px; color: var(--muted); font-size: 15px; }
.amount-input input { padding-left: 28px; font-variant-numeric: tabular-nums; }
.calculator-panel { position: absolute; z-index: 10; top: calc(100% + 8px); left: 0; width: min(292px, calc(100vw - 32px)); padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 18px 55px #14241c2b; }
.calculator-readout { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px; padding: 0 3px 8px; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.calculator-readout output { color: var(--ink); font-size: 14px; font-weight: 850; text-transform: none; font-variant-numeric: tabular-nums; }
.calculator-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.calculator-grid button { height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #f8faf7; color: var(--ink); cursor: pointer; font-size: 14px; font-weight: 800; }
.calculator-grid button:hover { background: var(--accent-soft); }
.calculator-grid .calculator-use { grid-column: span 3; background: var(--ink); color: #fff; }
.primary-button, .secondary-button, .danger-button { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-height: 51px; padding: 0 19px; border: 0; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 750; white-space: nowrap; }
.primary-button { background: var(--accent); color: #fff; transition: transform .16s ease, background .16s ease; }
.primary-button:hover { background: #10583f; transform: translateY(-1px); }
.primary-button:disabled, .secondary-button:disabled, .danger-button:disabled { cursor: not-allowed; opacity: .65; transform: none; }
.primary-button.saved { transform: scale(.97); }
.form-error { grid-column: 2 / -1; min-height: 18px; margin: 0; color: var(--expense); font-size: 12px; }
.text-button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 700; }
.cancel-edit { grid-column: 6; font-size: 12px; }
.ledger-section { padding-top: 38px; }
.ledger-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.period-tabs { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: #ebeeea; }
.period-tabs button { min-width: 74px; height: 36px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 750; }
.period-tabs button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px #12231c18; }
.period-nav { display: flex; align-items: center; gap: 5px; }
.date-jump { min-width: 185px; height: 40px; border: 0; background: transparent; cursor: pointer; font-size: 13px; font-weight: 750; }
.summary { display: grid; grid-template-columns: minmax(250px, 1.4fr) minmax(320px, 1fr); align-items: end; margin-top: 34px; padding: 0 0 34px; border-bottom: 1px solid var(--line); }
.net-summary span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.net-summary strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 72px; font-weight: 500; line-height: 1; letter-spacing: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.positive { color: var(--accent); }
.negative { color: var(--expense); }
.summary dl { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 0; }
.summary dl > div { padding-left: 20px; border-left: 1px solid var(--line); }
.summary dt { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; }
.summary dd { margin: 0; font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.direction-icon { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 13px; }
.income-icon { background: var(--accent-soft); color: var(--accent); }
.expense-icon { background: var(--expense-soft); color: var(--expense); }
.entries-heading { display: flex; align-items: baseline; justify-content: space-between; margin-top: 31px; }
.entries-heading h2 { margin-bottom: 0; font-size: 15px; }
.entries-heading span { color: var(--muted); font-size: 12px; }
.entries-list { margin-top: 13px; }
.entry-row { display: grid; grid-template-columns: 40px 1fr auto 92px; gap: 14px; align-items: center; min-height: 72px; border-top: 1px solid var(--line); animation: row-in .25s ease both; }
.entry-row:last-child { border-bottom: 1px solid var(--line); }
@keyframes row-in { from { opacity: 0; transform: translateY(6px); } }
.entry-direction { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.expense .entry-direction { background: var(--expense-soft); color: var(--expense); }
.entry-details { min-width: 0; }
.entry-details strong, .entry-details span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-details strong { font-size: 14px; }
.entry-details span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.entry-amount { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.income .entry-amount { color: var(--accent); }
.expense .entry-amount { color: var(--expense); }
.entry-actions { display: flex; gap: 5px; opacity: 0; transition: opacity .15s ease; }
.entry-row:hover .entry-actions, .entry-row:focus-within .entry-actions { opacity: 1; }
.empty-state { display: grid; justify-items: center; padding: 52px 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
.empty-state > span { display: grid; place-items: center; width: 42px; height: 42px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 50%; color: var(--muted); font-family: Georgia, serif; }
.empty-state strong { font-size: 14px; }
.empty-state p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
footer { display: flex; justify-content: space-between; max-width: 1180px; margin: auto; padding: 24px 28px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
dialog { width: min(520px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 8px; box-shadow: 0 24px 80px #101c1740; }
dialog::backdrop { background: #10221b80; backdrop-filter: blur(2px); }
.dialog-content { padding: 28px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.dialog-heading h2, .confirm-dialog h2 { margin-bottom: 15px; font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.dialog-content > p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.secondary-button { border: 1px solid var(--line); background: var(--surface); }
.file-button { position: relative; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-button:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 2px; }
.security-panel { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.security-panel strong { display: block; margin-bottom: 4px; font-size: 13px; }
.security-panel p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.danger-panel strong { color: var(--expense); }
.cloud-panel { grid-template-columns: minmax(0, 1fr); }
.cloud-controls { display: grid; grid-template-columns: .6fr 1fr auto; gap: 10px; align-items: end; }
.compact-field { margin-top: 0; }
.compact-field input, .compact-field select { height: 44px; font-size: 13px; }
.sync-buttons { display: flex; gap: 8px; }
.sync-buttons .secondary-button { min-height: 44px; padding: 0 14px; }
.dialog-status.error, .delete-status.error, #syncStatus.error { color: var(--expense) !important; }
.dialog-field { margin-top: 14px; }
.dialog-field input { height: 47px; }
.dialog-status { min-height: 20px; margin: 15px 0 0 !important; color: var(--accent) !important; }
.delete-status { min-height: 18px; margin-bottom: 0 !important; color: var(--expense) !important; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.danger-button { min-height: 44px; background: var(--expense); color: #fff; }

@media (max-width: 960px) {
  .entry-form { grid-template-columns: 1fr 1fr; }
  .type-control { grid-column: 1 / -1; }
  .primary-button { align-self: end; }
  .form-error { grid-column: 1 / -1; }
  .cancel-edit { grid-column: auto; }
}
@media (max-width: 640px) {
  .topbar { height: 62px; padding: 0 16px; }
  .brand span:last-child { display: none; }
  .header-actions { gap: 8px; }
  .name-picker { gap: 5px; }
  .name-picker label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .name-picker select { width: 112px; height: 36px; font-size: 12px; }
  .small-icon-button { width: 36px; height: 36px; }
  .privacy-note { display: none; }
  main { padding: 30px 16px 52px; }
  h1 { font-size: 34px; }
  .section-heading { display: block; }
  .section-heading > p { margin: 14px 0 0; }
  .entry-form { grid-template-columns: 1fr; }
  .type-control { grid-column: auto; }
  .calculator-panel { position: static; width: 100%; margin-top: 8px; box-shadow: none; }
  .date-field, .primary-button { grid-column: auto; }
  .form-error, .cancel-edit { grid-column: auto; }
  .ledger-toolbar { align-items: stretch; flex-direction: column; }
  .period-tabs { display: grid; grid-template-columns: repeat(3, 1fr); }
  .period-tabs button { min-width: 0; }
  .period-nav { justify-content: space-between; }
  .date-jump { min-width: 0; flex: 1; }
  .summary { grid-template-columns: 1fr; gap: 30px; }
  .net-summary strong { font-size: 50px; }
  .summary dl { gap: 12px; }
  .summary dl > div { padding-left: 13px; }
  .summary dd { font-size: 18px; }
  .entry-row { grid-template-columns: 36px minmax(0, 1fr) auto; gap: 10px; padding: 10px 0; }
  .entry-actions { grid-column: 2 / -1; opacity: 1; justify-content: flex-end; margin-top: -4px; }
  .entry-actions .icon-button { width: 44px; height: 44px; }
  footer { padding: 22px 16px; }
  .dialog-actions { grid-template-columns: 1fr; }
  .security-panel { grid-template-columns: 1fr; }
  .security-panel .secondary-button, .security-panel .danger-button { width: 100%; }
  .cloud-controls { grid-template-columns: 1fr; }
  .sync-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sync-buttons .secondary-button { padding: 0 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
