/* Plain CSS: nesting and light-dark(), no build step. */

:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f7f6, #121614);
  --surface: light-dark(#ffffff, #1b201e);
  --surface-2: light-dark(#eef1ef, #242a27);
  --text: light-dark(#18201c, #e6ebe8);
  --muted: light-dark(#5d6964, #9aa6a0);
  --border: light-dark(#dde3df, #2e3632);
  --accent: light-dark(#0f766e, #2dd4bf);
  --accent-text: light-dark(#ffffff, #06201d);
  --income: light-dark(#15803d, #4ade80);
  --error: light-dark(#b42318, #f97066);
  --radius: 12px;
  --gap: 16px;
  --nav-h: 64px;
  --rail-w: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.amount { font-variant-numeric: tabular-nums; }
.income { color: var(--income); }

/* Layout: bottom nav on phones, left rail from 900px. */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--gap);
  padding-top: max(var(--gap), env(safe-area-inset-top));
  &.with-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--gap)); }
}

.nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);

  .nav-brand { display: none; }
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.7rem;

  &[aria-current="page"] { color: var(--accent); }
  .icon { width: 24px; height: 24px; }
}

.nav-scan .icon {
  width: 44px;
  height: 44px;
  padding: 10px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
}

@media (min-width: 900px) {
  .nav {
    inset: 0 auto 0 0;
    flex-direction: column;
    width: var(--rail-w);
    height: auto;
    padding: var(--gap) 12px;
    gap: 4px;
    border-top: 0;
    border-right: 1px solid var(--border);

    .nav-brand { display: block; font-weight: 700; font-size: 1.2rem; padding: 0 12px 16px; }
  }
  .nav-item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.95rem;

    &:hover { background: var(--surface-2); }
    &[aria-current="page"] { background: var(--surface-2); }
  }
  .nav-scan .icon { width: 24px; height: 24px; padding: 0; background: none; color: inherit; }
  main.with-nav { margin-left: var(--rail-w); padding: 32px; }
}

/* Building blocks */
.page-head {
  margin-bottom: var(--gap);
  .back { display: inline-block; margin-bottom: 4px; font-size: 0.875rem; text-decoration: none; }
  .back::before { content: "‹ "; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: var(--gap);
}

.empty { text-align: center; padding: 40px var(--gap); }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  &:first-child { border-top: 0; padding-top: 0; }
  &:last-child { padding-bottom: 0; }
}
.row-link {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: inherit;
  text-decoration: none;
  &::after { content: "›"; color: var(--muted); font-size: 1.3rem; line-height: 1; }
}
.row-disabled { color: var(--muted); }

label { display: block; font-size: 0.875rem; font-weight: 600; margin: 12px 0 4px; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  &:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  margin-top: 12px;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;

  &:hover { filter: brightness(0.97); }
  &:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  &.btn-primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
  &.btn-quiet { background: none; border-color: transparent; color: var(--muted); margin: 0; }
  &.btn-block { width: 100%; }
}

.form-error { color: var(--error); font-size: 0.875rem; margin: 8px 0 0; }

/* Login */
.login {
  max-width: 380px;
  margin: 12vh auto 0;
  padding: 32px 24px;
  text-align: center;
  .login-logo { border-radius: 14px; margin-bottom: 8px; }
  form { text-align: left; }
}
.login-password {
  margin-top: 20px;
  summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
}

/* Toasts */
#toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  z-index: 20;
  display: grid;
  gap: 8px;
  width: min(480px, calc(100% - 32px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  background: light-dark(#18201c, #e6ebe8);
  color: light-dark(#ffffff, #121614);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
  button { margin-left: auto; background: none; border: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
}
@media (min-width: 900px) {
  #toasts { bottom: 24px; left: calc(50% + var(--rail-w) / 2); }
}
