:root {
  --bg: #eef1ec;
  --bg-deep: #dfe6de;
  --paper: #fffdf8;
  --ink: #14241f;
  --ink-soft: #4d5c56;
  --muted: #7a8882;
  --line: #e3e8e2;
  --forest: #15241f;
  --forest-mid: #2a5a3a;
  --gold: #c9a227;
  --gold-soft: #f6eed4;
  --pos: #1c6b45;
  --pos-bg: #e4f3ea;
  --neg: #9a3d3d;
  --neg-bg: #f6e6e4;
  --auto: #2b5f78;
  --auto-bg: #e4eef3;
  --radius: 14px;
  --shadow: 0 12px 34px rgba(20, 36, 31, 0.08);
  --font: "Source Sans 3", system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 420px at 8% -8%, #e8efe4 0%, transparent 55%),
    radial-gradient(800px 380px at 100% 0%, #efe6c8 0%, transparent 48%),
    var(--bg);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 1.15rem;
  background: var(--forest);
  color: #f7f3ea;
  min-height: 2.4rem;
}
.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand-mark {
  width: 1.45rem; height: 1.45rem; border-radius: 5px;
  background: var(--gold); color: var(--forest);
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; font-size: 0.82rem;
}
.brand-name { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 0.92rem; }
.top-link {
  color: #f3e3aa;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}
.top-link:hover { text-decoration: underline; }

.kicker {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.hint { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.82rem; }

.stand-bar {
  width: min(1240px, calc(100% - 1.5rem));
  margin: 0.75rem auto 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.85rem 1.05rem 0.9rem;
}
.stand-bar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.7rem;
}
.stand-now .kicker { color: var(--muted); }
.stand-now .date {
  margin: 0.05rem 0 0;
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.stand-notes { display: flex; flex-direction: column; gap: 0.45rem; }
.stand-note {
  display: grid;
  grid-template-columns: 7.2rem 1fr auto;
  gap: 0.55rem 0.75rem;
  align-items: start;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf4;
}
.stand-note.latest {
  background: var(--gold-soft);
  border-color: #ead9a0;
}
.stand-note .when { color: var(--ink-soft); font-size: 0.88rem; padding-top: 0.12rem; }
.stand-note .note-text {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.stand-note .snap {
  margin: 0.28rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}
.stand-note-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: stretch;
}
.stand-older { margin-top: 0.45rem; display: flex; flex-direction: column; gap: 0.45rem; }
.stand-older[hidden] { display: none; }
.stand-toggle {
  margin-top: 0.55rem;
  background: transparent;
  border: 0;
  color: var(--forest-mid);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.2rem 0;
  text-align: left;
}

.layout {
  width: min(1240px, calc(100% - 1.5rem));
  margin: 0.75rem auto 3rem;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1rem;
  align-items: start;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.panel-head {
  padding: 1rem 1.05rem 0.35rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.7rem;
}
.panel-head h1, .detail-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
}
.lede { margin: 0.35rem 0 0; color: var(--ink-soft); font-size: 0.92rem; }

.figure-list { padding: 0.7rem 0.75rem 0.9rem; display: flex; flex-direction: column; gap: 0.55rem; }
.figure-card {
  width: 100%;
  text-align: left;
  background: #fbfaf4;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 0.85rem;
  display: grid;
  gap: 0.2rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.figure-card:hover { border-color: #c9d4c8; }
.figure-card.active {
  border-color: var(--forest-mid);
  box-shadow: inset 0 0 0 1px var(--forest-mid);
  background: #f4f7f1;
}
.figure-card .row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.figure-name { font-weight: 600; font-size: 0.98rem; }
.figure-amount { font-family: var(--serif); font-weight: 600; font-size: 1.15rem; }
.amt-pos { color: var(--pos); }
.amt-neg { color: var(--neg); }
.amt-zero { color: inherit; }
.stand .amount.amt-pos { color: #b7e7c8; }
.stand .amount.amt-neg { color: #f5b4ae; }
.stand .sub .amt-pos { color: #b7e7c8; }
.stand .sub .amt-neg { color: #f5b4ae; }
.snap .amt-pos, .snap .amt-neg { font-weight: 600; }
.figure-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.25rem; }
.badge {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.badge.asset { background: var(--pos-bg); color: var(--pos); }
.badge.debt { background: var(--neg-bg); color: var(--neg); }
.badge.flow { background: var(--auto-bg); color: var(--auto); }
.badge.auto { background: var(--gold-soft); color: #7a7818; }

.detail { min-height: 640px; }
.detail-inner { padding: 1.15rem 1.25rem 1.4rem; }
.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.85rem;
}
.detail-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.stand {
  background: var(--forest);
  color: #f7f3ea;
  border-radius: 16px;
  padding: 1.15rem 1.25rem 1.2rem;
  display: grid;
  gap: 0.15rem;
}
.stand .label { margin: 0; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.7; }
.stand .amount {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.1rem, 4vw, 2.8rem);
  font-weight: 600;
  letter-spacing: -0.03em;
}
.stand .sub { margin: 0.15rem 0 0; opacity: 0.78; font-size: 0.9rem; }
.stand-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.9rem; }
.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.btn.primary { background: var(--gold); color: var(--forest); }
.btn.ghost {
  background: transparent;
  border: 1px solid rgba(247, 243, 234, 0.28);
  color: #f7f3ea;
}
.btn.soft { background: var(--gold-soft); color: var(--forest); border: 1px solid #ead9a0; }
.btn.outline { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--neg-bg); color: var(--neg); }
.btn.tiny {
  padding: 0.22rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 7px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
  margin: 1rem 0 1.15rem;
}
.meta-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #fbfaf4;
}
.meta-card p { margin: 0; }
.meta-card .v { font-weight: 600; margin-top: 0.15rem; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0.4rem 0 0.55rem;
}
.section-title h3 { margin: 0; font-size: 1rem; }
.section-title span { color: var(--muted); font-size: 0.82rem; }

.history { display: flex; flex-direction: column; }
.hist-row {
  display: grid;
  grid-template-columns: 7.2rem 1fr auto auto auto;
  gap: 0.55rem;
  align-items: center;
  padding: 0.72rem 0.15rem;
  border-top: 1px solid var(--line);
}
.hist-row.start { background: linear-gradient(90deg, #f6eed4, transparent 55%); margin: 0 -0.2rem; padding-left: 0.45rem; padding-right: 0.45rem; border-radius: 8px; border-top: 0; }
.hist-date { color: var(--ink-soft); font-size: 0.88rem; }
.hist-note { font-weight: 600; }
.hist-note small { display: block; font-weight: 400; color: var(--muted); }
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.plus { color: var(--pos); }
.delta.minus { color: var(--neg); }
.saldo { font-variant-numeric: tabular-nums; color: var(--ink-soft); min-width: 6.5rem; text-align: right; }
.hist-actions { display: flex; gap: 0.3rem; justify-content: flex-end; }

.auto-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.1rem; }
.auto-item {
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border: 1px dashed #d3c58a;
  background: var(--gold-soft);
  border-radius: 12px;
}
.auto-item p { margin: 0; }
.auto-item small { color: #6d6418; }
.auto-item-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }

.modal {
  position: fixed; inset: 0;
  background: rgba(20, 36, 31, 0.45);
  display: grid; place-items: center;
  padding: 1rem;
  z-index: 20;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(520px, 100%);
  background: var(--paper);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(20, 36, 31, 0.28);
  padding: 1.1rem 1.15rem 1.2rem;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-family: var(--serif); font-size: 1.25rem; }
.icon-btn {
  width: 2rem; height: 2rem; border: 0; border-radius: 8px;
  background: var(--bg); font-size: 1.2rem;
}
.form { display: grid; gap: 0.7rem; margin-top: 0.9rem; }
.field { display: grid; gap: 0.25rem; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: #fff;
}
.field textarea { resize: vertical; min-height: 4.5rem; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.4rem; flex-wrap: wrap; }
.modal-actions .push { margin-right: auto; }

.toast {
  position: fixed; bottom: 1.1rem; left: 50%;
  transform: translateX(-50%);
  background: var(--forest); color: #f7f3ea;
  padding: 0.6rem 0.9rem; border-radius: 999px;
  z-index: 30;
}

.empty { color: var(--muted); padding: 1rem 0; }

.app-foot {
  width: min(1240px, calc(100% - 1.5rem));
  margin: 0 auto 2rem;
  display: flex;
  justify-content: flex-end;
}

.pwa-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--gold);
  color: var(--forest);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(20, 36, 31, 0.18);
}

.offline-box {
  padding: 1.5rem 0.2rem;
}
.offline-box h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.4rem;
}

.backup-page {
  width: min(760px, calc(100% - 1.5rem));
  margin: 0.75rem auto 3rem;
}
.backup-panel { padding-bottom: 0.9rem; }
.backup-list {
  padding: 0.7rem 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.backup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfaf4;
}
.backup-when {
  margin: 0;
  font-weight: 600;
  font-size: 0.98rem;
}

.login-page {
  width: min(440px, calc(100% - 1.5rem));
  margin: 2.5rem auto 3rem;
}
.login-panel { padding-bottom: 1.15rem; }
.login-form { padding: 0 1.05rem 0.3rem; }
.login-error {
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: var(--neg-bg);
  color: var(--neg);
  font-weight: 600;
  font-size: 0.9rem;
}
.topbar-actions { display: flex; align-items: center; gap: 0.85rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .panel-head { flex-wrap: wrap; }
  .hist-row { grid-template-columns: 1fr auto; }
  .hist-date, .hist-actions { grid-column: 1 / -1; }
  .hist-actions { justify-content: flex-start; }
  .meta-grid { grid-template-columns: 1fr; }
  .detail-actions { justify-content: flex-start; }
  .stand-note { grid-template-columns: 1fr auto; }
  .stand-note .when { grid-column: 1 / -1; }
  .stand-note-actions { flex-direction: row; }
  .backup-row { flex-wrap: wrap; }
}
