* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #FAF9F5;
  --card-bg: #FFFFFF;
  --text-primary: #1a1a1a;
  --text-secondary: #6b6b66;
  --text-tertiary: #9b9b95;
  --border: rgba(0, 0, 0, 0.1);
  --border-strong: rgba(0, 0, 0, 0.18);
  --surface: #F1EFE8;
  --green: #27500A;
  --red: #A32D2D;
  --amber: #854F0B;
  --teal: #1D9E75;
  --warn-bg: #FAEEDA;
  --warn-text: #633806;
  --bad-bg: #FCEBEB;
  --bad-text: #791F1F;
  --good-bg: #EAF3DE;
  --good-text: #27500A;
  --radius-md: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1916;
    --card-bg: #26241F;
    --text-primary: #f1efe8;
    --text-secondary: #aaa89e;
    --text-tertiary: #7a786f;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --surface: #2f2c26;
  }
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.app {
  max-width: 500px;
  margin: 0 auto;
  padding: 1rem 0.9rem calc(2rem + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  padding-top: env(safe-area-inset-top);
}

.topbar h1 { font-size: 20px; font-weight: 500; margin-bottom: 2px; }
.topbar .date { font-size: 13px; color: var(--text-secondary); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
}
.pill-good { background: var(--good-bg); color: var(--good-text); }
.pill-warn { background: var(--warn-bg); color: var(--warn-text); }
.pill-bad { background: var(--bad-bg); color: var(--bad-text); }

.card {
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  margin-bottom: 0.65rem;
}

.card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.start-card { background: var(--bad-bg); border-color: rgba(163, 45, 45, 0.3); }
.start-card .card-title { color: var(--bad-text); }
.start-card .big-num { color: var(--bad-text); }
.start-card .sub { color: var(--bad-text); }

.big-num {
  font-size: 30px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.big-num.neg { color: var(--red); }
.big-num.pos { color: var(--green); }

.sub { font-size: 13px; color: var(--text-secondary); margin-top: 5px; line-height: 1.4; }
.sub.right { text-align: right; }
.sub strong { color: var(--text-primary); font-weight: 500; }
.sub-inline { font-size: 13px; color: var(--text-secondary); }

.row-baseline {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.progress {
  height: 5px;
  background: var(--surface);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--red);
  transition: width 0.3s ease;
}
.progress-fill.yola { background: var(--teal); }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 0.65rem;
}

.btn {
  padding: 12px 8px;
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: inherit;
  -webkit-appearance: none;
}
.btn:active { opacity: 0.7; }
.btn.primary {
  background: var(--text-primary);
  color: var(--card-bg);
  border-color: var(--text-primary);
}
.btn .i {
  font-weight: 500;
  font-size: 13px;
  width: 14px;
  text-align: center;
}

.form {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  margin-bottom: 0.65rem;
  display: none;
}
.form.open { display: block; }
.form-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 100px;
  gap: 6px;
  margin-bottom: 6px;
}

.form input, .form select {
  padding: 9px 11px;
  font-size: 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
  color: var(--text-primary);
  font-family: inherit;
  width: 100%;
  -webkit-appearance: none;
}
.form input:focus, .form select:focus {
  outline: 2px solid var(--border-strong);
  outline-offset: -1px;
}

.form > input {
  width: 100%;
  margin-bottom: 6px;
}

.form-buttons {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.form-buttons .btn { flex: 1; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.mini {
  padding: 9px 11px;
  background: var(--surface);
  border-radius: var(--radius-md);
}
.mini-l {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mini-v {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.mini-v.pos { color: var(--green); }
.mini-v.neg { color: var(--red); }

.debt {
  padding: 10px 0;
  border-bottom: 0.5px solid var(--border);
}
.debt:last-child { border-bottom: none; }
.debt.done { opacity: 0.5; }
.debt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.debt-name {
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.debt-amt {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.debt-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text-secondary);
}
.rank.r1 { background: var(--bad-bg); color: var(--bad-text); }

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-top: 9px;
  line-height: 1.4;
}
.alert-warn { background: var(--warn-bg); color: var(--warn-text); }
.alert-bad { background: var(--bad-bg); color: var(--bad-text); }
.alert-good { background: var(--good-bg); color: var(--good-text); }

.activity {
  padding: 8px 0;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.activity:last-child { border-bottom: none; }
.act-label { font-size: 14px; color: var(--text-primary); }
.act-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.act-amt {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.act-amt.in { color: var(--green); }
.act-del {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 16px;
  font-family: inherit;
}

.sos {
  background: var(--bad-bg);
  border-color: rgba(226, 75, 74, 0.3);
}
.sos .card-title { color: var(--bad-text); }
.sos-text {
  font-size: 14px;
  color: var(--bad-text);
  margin-bottom: 10px;
  line-height: 1.4;
}
.sos-btn {
  width: 100%;
  padding: 13px;
  background: var(--red);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
}
.sos-btn:active { opacity: 0.85; }
.sos-hint {
  font-size: 11px;
  color: var(--good-text);
  margin-top: 8px;
  text-align: center;
}

.footer {
  text-align: center;
  padding: 1rem 0;
  font-size: 11px;
  color: var(--text-tertiary);
}
.footer a {
  color: var(--text-secondary);
  margin: 0 6px;
  text-decoration: none;
}
.footer a:hover { color: var(--text-primary); }

.empty {
  font-size: 11px;
  color: var(--text-tertiary);
  text-align: center;
  padding: 10px;
}
