/* Layout: a ledger split — month grid on the left, the selected day's cash-flow sheet on the right; stacks on phones */
:root {
  --bg: #eff2ef;
  --surface: #ffffff;
  --sunken: #e5eae6;
  --ink: #17201c;
  --muted: #5d6862;
  --line: #d6ddd8;
  --accent: #2f45bd;
  --accent-ink: #ffffff;
  --accent-soft: #e2e6fa;
  --income: #13774a;
  --income-soft: #dcf0e4;
  --expense: #b8352e;
  --expense-soft: #f7dfdc;
  --scrim: rgba(14, 20, 17, 0.45);

  --font-display: 'Unbounded', 'Golos Text', system-ui, sans-serif;
  --font-body: 'Golos Text', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-num: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #111513;
    --surface: #191f1c;
    --sunken: #212824;
    --ink: #e4ebe6;
    --muted: #97a29c;
    --line: #2b3430;
    --accent: #8c9bff;
    --accent-ink: #111513;
    --accent-soft: #252c4d;
    --income: #4fc68c;
    --income-soft: #183326;
    --expense: #f07c72;
    --expense-soft: #3a1f1c;
    --scrim: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #111513;
  --surface: #191f1c;
  --sunken: #212824;
  --ink: #e4ebe6;
  --muted: #97a29c;
  --line: #2b3430;
  --accent: #8c9bff;
  --accent-ink: #111513;
  --accent-soft: #252c4d;
  --income: #4fc68c;
  --income-soft: #183326;
  --expense: #f07c72;
  --expense-soft: #3a1f1c;
  --scrim: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 40px;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-weight: 600;
}
.tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.opening {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.money-input {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
}
.money-input:focus-within {
  border-color: var(--accent);
}
.money-input input {
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: none;
  font: 500 14px/1 var(--font-num);
  font-variant-numeric: tabular-nums;
  width: 8.5em;
  padding: 8px 0;
  text-align: right;
}
.money-input.big input {
  font-size: 22px;
  width: 100%;
  text-align: left;
  padding: 10px 0;
}
.money-input.big {
  display: flex;
  font-size: 20px;
}

/* ---------- Buttons ---------- */
.btn {
  font: 500 14px/1 var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.15s,
    border-color 0.15s;
}
.btn:hover {
  border-color: var(--muted);
}
.btn.small {
  padding: 7px 11px;
  font-size: 13px;
}
.btn.ghost {
  background: transparent;
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover {
  filter: brightness(1.08);
}
.btn.income {
  background: var(--income-soft);
  border-color: transparent;
  color: var(--income);
  font-weight: 600;
}
.btn.expense {
  background: var(--expense-soft);
  border-color: transparent;
  color: var(--expense);
  font-weight: 600;
}
.btn.income:hover {
  border-color: var(--income);
}
.btn.expense:hover {
  border-color: var(--expense);
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0 0 3px;
}
.icon-btn:hover {
  border-color: var(--muted);
}
.link-btn {
  background: none;
  border: 0;
  padding: 4px 2px;
  cursor: pointer;
  font: 500 13px/1.2 var(--font-body);
  color: var(--muted);
}
.link-btn:hover {
  color: var(--ink);
  text-decoration: underline;
}
.link-btn.danger:hover,
.link-btn.armed {
  color: var(--expense);
}
.link-btn.armed {
  font-weight: 600;
}

/* ---------- Banner ---------- */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  background: var(--expense-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
}
.banner p {
  margin: 0;
  min-width: 0;
  flex: 1 1 280px;
}
.tools form {
  margin: 0;
}
.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ---------- Login ---------- */
.login {
  max-width: 380px;
  margin: 12vh auto 0;
  display: grid;
  gap: 22px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  display: grid;
  gap: 16px;
}
.login-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 24px;
}
.login-card .btn {
  padding: 12px;
  font-size: 15px;
}

/* ---------- Month bar ---------- */
.month-bar {
  display: grid;
  gap: 14px;
}
.month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.month-nav h1 {
  margin: 0;
  min-width: 9.5em;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(20px, 3.2vw, 28px);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.month-nav .btn {
  margin-left: 4px;
}
.month-stats {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.month-stats > div {
  padding: 10px 14px;
  display: grid;
  gap: 2px;
  min-width: 0;
}
.month-stats > div + div {
  border-left: 1px solid var(--line);
}
.month-stats dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.month-stats dd {
  margin: 0;
  font: 500 17px/1.3 var(--font-num);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.pos {
  color: var(--income);
}
.neg {
  color: var(--expense);
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 370px);
  gap: 20px;
  align-items: start;
}

/* ---------- Calendar ---------- */
.calendar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--sunken);
  border-bottom: 1px solid var(--line);
}
.weekdays span {
  padding: 8px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.weekdays .we {
  color: var(--expense);
  opacity: 0.8;
}
.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-height: 96px;
  min-width: 0;
  padding: 8px 8px 10px;
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: background-color 0.12s;
}
.cell:nth-child(7n) {
  border-right: 0;
}
.grid .cell:nth-last-child(-n + 7) {
  border-bottom: 0;
}
.cell:hover {
  background: var(--sunken);
}
.cell:focus-visible {
  outline-offset: -2px;
}
.cell .num {
  font: 500 14px/1 var(--font-num);
  width: 28px;
  height: 28px;
  margin: -4px 0 4px -4px;
  display: grid;
  place-items: center;
  border-radius: 50%;
}
.cell.weekend .num {
  color: var(--expense);
}
.cell.other {
  color: var(--muted);
}
.cell.other .num,
.cell.other .amt {
  opacity: 0.55;
}
.cell.today .num {
  background: var(--ink);
  color: var(--bg);
}
.cell.selected {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.amt {
  font: 500 12px/1.25 var(--font-num);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.amt.in {
  color: var(--income);
}
.amt.out {
  color: var(--expense);
}
.dots {
  display: none;
  gap: 3px;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.dot.in {
  background: var(--income);
}
.dot.out {
  background: var(--expense);
}

/* ---------- Day sheet ---------- */
.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  display: grid;
  gap: 14px;
  min-width: 0;
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
}
.eyebrow {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  font-weight: 600;
}
.sheet h2 {
  margin: -8px 0 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.flow {
  margin: 0;
  display: grid;
}
.flow-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
}
.flow-row dt {
  color: var(--muted);
  font-size: 14px;
}
.flow-row dd {
  margin: 0;
  font: 500 15px/1.3 var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow-wrap: anywhere;
}
.flow-row.total {
  border-bottom: 0;
  border-top: 2px solid var(--ink);
  margin-top: 4px;
  padding-top: 10px;
}
.flow-row.total dt {
  color: var(--ink);
  font-weight: 600;
}
.flow-row.total dd {
  font-size: 20px;
  font-weight: 500;
}
.add-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.add-row .btn {
  padding: 12px;
  font-size: 15px;
}
.list-title {
  margin: 4px 0 -4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.tx-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.tx {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: baseline;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--sunken);
  border-left: 3px solid var(--income);
}
.tx.expense {
  border-left-color: var(--expense);
}
.tx-main {
  display: grid;
  min-width: 0;
}
.tx-cat {
  font-weight: 500;
  overflow-wrap: anywhere;
}
.tx-note {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.tx-amt {
  font: 500 15px/1.3 var(--font-num);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tx.income .tx-amt {
  color: var(--income);
}
.tx.expense .tx-amt {
  color: var(--expense);
}
.tx-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 14px;
}
.empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.status {
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  max-width: calc(100% - 32px);
  z-index: 5;
}

/* ---------- Footer & theme switch ---------- */
.foot {
  display: flex;
  justify-content: center;
  padding-top: 8px;
}
.theme-switch {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  color: var(--muted);
}
.theme-switch span {
  margin-right: 4px;
}
.theme-switch button {
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font: inherit;
  color: var(--muted);
}
.theme-switch button:hover {
  color: var(--ink);
}
.theme-switch button[aria-pressed='true'] {
  color: var(--ink);
  background: var(--sunken);
  font-weight: 500;
}

/* ---------- Dialogs ---------- */
dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
}
dialog::backdrop {
  background: var(--scrim);
}
dialog form,
.backup {
  padding: 20px;
  display: grid;
  gap: 14px;
}
dialog h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 19px;
}
.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.field > input,
.field textarea {
  font: 400 15px/1.3 var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
.field textarea {
  font: 400 12px/1.4 var(--font-num);
  resize: vertical;
}
.field > input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 0;
  margin: 0;
  padding: 3px;
  background: var(--sunken);
  border-radius: 10px;
}
.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.seg label {
  text-align: center;
  padding: 9px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--muted);
}
.seg input:focus-visible + label {
  outline: 2px solid var(--accent);
}
#type-income:checked + label {
  background: var(--surface);
  color: var(--income);
  box-shadow: 0 1px 2px var(--line);
}
#type-expense:checked + label {
  background: var(--surface);
  color: var(--expense);
  box-shadow: 0 1px 2px var(--line);
}
.form-error {
  margin: 0;
  color: var(--expense);
  font-size: 14px;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
.backup hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2px 0;
  width: 100%;
}
#backup-file {
  font-size: 13px;
  color: var(--muted);
  max-width: 100%;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .sheet {
    position: static;
  }
}
@media (max-width: 640px) {
  body {
    padding-block: 14px 32px;
    font-size: 14px;
  }
  .month-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .month-stats > div:nth-child(3) {
    border-left: 0;
  }
  .month-stats > div:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }
  .month-nav {
    justify-content: space-between;
  }
  .month-nav {
    gap: 6px;
  }
  .month-nav h1 {
    min-width: 0;
    flex: 1;
    font-size: 17px;
    white-space: nowrap;
  }
  .month-nav .btn {
    margin-left: 0;
  }
  .cell {
    min-height: 58px;
    padding: 6px 4px 8px;
    align-items: center;
  }
  .cell .num {
    margin: 0 0 2px;
  }
  .cell .amt {
    display: none;
  }
  .cell .dots {
    display: flex;
  }
  .weekdays span {
    padding: 7px 0;
    text-align: center;
  }
  .opening {
    flex: 1 1 auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- Version ---------- */
.foot {
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
}
.version {
  font: 400 12px/1 var(--font-num);
  color: var(--muted);
}
