/* Donald — one stylesheet, mobile-first. */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-soft: #475569;
  --ink-faint: #94a3b8;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --ok: #059669;
  --owe-bg: #fef2f2;
  --owe-ink: #b91c1c;
  --owed-bg: #ecfdf5;
  --owed-ink: #047857;
  --settled-bg: #eef2ff;
  --settled-ink: #4338ca;
  --me-accent: #2563eb;
  --them-accent: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131c2e;
    --surface-2: #0f1728;
    --ink: #e8edf6;
    --ink-soft: #a9b6cc;
    --ink-faint: #6b7a94;
    --border: #26324a;
    --primary: #4f83f1;
    --owe-bg: #2a1518;
    --owe-ink: #f7a9a6;
    --owed-bg: #10241d;
    --owed-ink: #8ee6c4;
    --settled-bg: #1a1e3a;
    --settled-ink: #b7bdf5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

/* An explicit `display` rule (e.g. label{display:flex}) beats the UA
   [hidden]{display:none}, so restate it with priority. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  max-width: 720px;
  margin-inline: auto;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }

.muted { color: var(--ink-soft); font-size: 0.9rem; }
.spacer { flex: 1; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.brand {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.icon-btn {
  border: 0;
  background: var(--surface);
  color: var(--ink-soft);
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.icon-btn:hover { color: var(--ink); }

/* ---- balance banner ---- */
.balance {
  margin: 8px 16px 4px;
  padding: 18px;
  border-radius: var(--radius);
  background: var(--settled-bg);
  color: var(--settled-ink);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
  box-shadow: var(--shadow);
}
.balance.owe { background: var(--owe-bg); color: var(--owe-ink); }
.balance.owed { background: var(--owed-bg); color: var(--owed-ink); }
.balance-line { margin: 0; font-size: 1.15rem; }
.balance-line strong { font-weight: 800; }
.balance .btn { align-self: stretch; }

@media (min-width: 480px) {
  .balance { flex-direction: row; align-items: center; justify-content: space-between; }
  .balance .btn { align-self: auto; }
}

/* ---- the board: two columns, always side by side ---- */
.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 16px 4px;
  align-items: start;
}
.col {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-top: 3px solid var(--col-accent, var(--border));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.col-head {
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.col-name { font-weight: 700; font-size: 0.98rem; }
.col-total { font-size: 0.82rem; color: var(--ink-soft); }

.add-btn {
  margin: 0 12px 10px;
  padding: 9px 10px;
  font-size: 0.9rem;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px dashed var(--border);
}
.add-btn:hover { border-color: var(--col-accent, var(--primary)); color: var(--col-accent, var(--primary)); }

.expense-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.expense {
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
  border: 1px solid transparent;
}
.expense:hover { border-color: var(--border); }
.expense-main {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.expense-desc { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.expense-amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.88rem; }
.expense-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 3px;
  font-size: 0.75rem;
  color: var(--ink-faint);
}
.badge {
  background: var(--bg);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.68rem;
}
.empty {
  padding: 10px;
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.82rem;
}

/* ---- repayments ---- */
.repayments { margin: 12px 16px 0; }
.section-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pill {
  background: var(--border);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 0.75rem;
  min-width: 20px;
  text-align: center;
}
.repay-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.repay {
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}
.repay-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.repay .note { flex-basis: 100%; }
.link-btn {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 6px;
}
.link-btn:hover { color: var(--danger); }

/* ---- version ---- */
.version {
  text-align: center;
  color: var(--ink-faint);
  font-size: 0.72rem;
  margin: 22px 0 16px;
}

/* ---- buttons ---- */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 11px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { filter: brightness(0.98); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger, .btn .danger { color: var(--danger); }
.btn.ghost.danger { border-color: transparent; }
.btn.block { display: block; width: 100%; }

/* ---- dialogs / sheets ---- */
dialog.sheet {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 460px;
  width: calc(100% - 24px);
  margin: auto auto 0;
}
@media (min-width: 480px) { dialog.sheet { margin: auto; } }
dialog.sheet::backdrop { background: rgba(2, 6, 23, 0.55); backdrop-filter: blur(2px); }
dialog.sheet form {
  background: var(--surface);
  color: var(--ink);
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
  max-height: 88vh;
  overflow-y: auto;
}
@media (min-width: 480px) { dialog.sheet form { border-radius: 18px; } }
dialog.sheet h2 { font-size: 1.15rem; }
dialog.sheet h3 { font-size: 0.95rem; color: var(--ink-soft); }
dialog.sheet hr { border: 0; border-top: 1px solid var(--border); margin: 2px 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}
input[type="text"], input[type="password"], input[type="date"], input[type="color"], input[name] {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 500;
}
input:focus-visible, .btn:focus-visible, .seg-opt:focus-within {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
input[type="color"] { padding: 4px; height: 42px; }

.amount-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  padding-left: 12px;
}
.amount-wrap .cur-symbol { color: var(--ink-soft); font-weight: 700; }
.amount-wrap input { border: 0; background: transparent; flex: 1; padding-left: 0; }
.amount-wrap:focus-within { outline: 2px solid var(--primary); outline-offset: 1px; }

/* segmented control */
.seg {
  border: 0;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.seg legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  padding: 0;
  float: left;
  width: 100%;
}
.seg-opt {
  flex-direction: row;
  align-items: center;
  gap: 0;
}
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span {
  display: block;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface-2);
  cursor: pointer;
}
.seg-opt input:checked + span {
  background: var(--primary);
  border-color: transparent;
  color: var(--primary-ink);
}
.seg-opt span em { font-style: normal; }

.split-preview {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 1px;
}
.split-preview:empty { display: none; }

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.error { color: var(--danger); font-size: 0.85rem; margin: 0; font-weight: 600; }
.ok { color: var(--ok); font-size: 0.85rem; margin: 0; font-weight: 600; }

/* ---- login ---- */
.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  padding: 28px 24px;
  border-radius: 18px;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card .brand { font-size: 1.8rem; }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; text-align: left; }
.login-card label { color: var(--ink); }
