:root {
  --bg: #0b0f14;
  --card: #131a23;
  --line: #1e2937;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #4ade80;
  --danger: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 14px 40px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 620px;
  margin: 0 auto;
  padding: 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}

.topbar-main { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.brand {
  color: var(--text);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.badge {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0f1620;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card {
  margin: 12px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
}

.card h2 {
  margin: 0 0 2px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); font-size: 0.86rem; margin: 4px 0 0; }

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
}

.action span { color: var(--accent); }

/* Settle up ------------------------------------------------------------- */

.settlements, .transactions, .ccy-list, .trip-list { list-style: none; margin: 10px 0 0; padding: 0; }

.settlement, .tx {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.settlement:first-child, .tx:first-child { border-top: 0; }

.settlement .who { font-weight: 600; }
.settlement .arrow { color: var(--muted); margin: 0 2px; }

.settlement b, .tx b { font-variant-numeric: tabular-nums; white-space: nowrap; }

.tx-main { display: flex; flex-direction: column; min-width: 0; }
.tx-main strong { font-size: 0.94rem; }
.tx-main .muted { margin: 1px 0 0; font-size: 0.78rem; }

/* People ---------------------------------------------------------------- */

.person { border-top: 1px solid var(--line); }
.person:first-child { border-top: 0; }

.person > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  cursor: pointer;
  list-style: none;
}

.person > summary::-webkit-details-marker { display: none; }

.person .name { font-weight: 600; }
.person .name::after {
  content: "▸";
  display: inline-block;
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.15s ease;
}

.person[open] .name::after { transform: rotate(90deg); }

.ccy-list { margin: 0 0 10px; padding-left: 10px; border-left: 2px solid var(--line); }

.ccy-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  font-size: 0.88rem;
}

.ccy-list .ccy { color: var(--muted); letter-spacing: 0.04em; }
.ccy-list b { font-variant-numeric: tabular-nums; }

.pos { color: var(--accent); }
.neg { color: var(--danger); }
.zero { color: var(--muted); }

/* Forms ----------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

label, legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

select, input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0f1620;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }

button.primary {
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #06210f;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

button.primary:disabled { opacity: 0.6; cursor: progress; }

button.ghost { border: 0; background: none; color: var(--muted); font-size: 1.2rem; cursor: pointer; }

.ghost-link { color: var(--muted); font-size: 0.88rem; text-decoration: none; }

fieldset.people-picker { margin: 0; padding: 0; border: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.chip {
  position: relative;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0f1620;
  color: var(--text);
  font-size: 0.86rem;
  cursor: pointer;
}

.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, #0f1620); }

/* Trips ----------------------------------------------------------------- */

.trip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
}

.trip strong { font-size: 0.95rem; }
.trip .muted { margin: 0; }

/* Feedback -------------------------------------------------------------- */



.loading {
  position: fixed;
  right: 14px;
  bottom: 14px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-size: 0.8rem;
}

/* Person record tables -------------------------------------------------- */

.person-body { padding: 0 0 12px; }

.book-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 6px;
  font-size: 0.82rem;
}

.book-head .ccy { color: var(--muted); letter-spacing: 0.06em; }
.book-head b { font-variant-numeric: tabular-nums; font-size: 0.95rem; }

table.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

table.records th {
  padding: 6px 4px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-align: left;
  text-transform: uppercase;
}

table.records th.num, table.records td.col-amount, table.records td.col-total { text-align: right; }

table.records td {
  padding: 7px 4px;
  border-bottom: 1px solid #16202c;
  vertical-align: top;
  white-space: nowrap;
}

table.records td.col-date { color: var(--muted); font-size: 0.74rem; }

table.records td.col-detail { white-space: normal; line-height: 1.25; }
table.records td.col-detail strong { font-weight: 600; }
table.records td.col-detail span { display: block; color: var(--muted); font-size: 0.72rem; }

table.records td.col-amount, table.records td.col-total { font-weight: 600; }
table.records td.col-total { color: inherit; }

table.records tbody tr:last-child td { border-bottom: 0; }

/* Feedback that must survive view switches ------------------------------ */


.toast[data-tone='error'] { border-color: var(--danger); color: var(--danger); }

.form-error {
  margin: 0 0 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca;
  font-size: 13px;
  line-height: 1.4;
}

/* Feedback ---------------------------------------------------------------- */

[hidden] { display: none !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 440px);
  margin: 0;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: #1f2937;
  color: #f8fafc;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: 0 16px 40px rgba(2, 6, 23, 0.55);
  animation: toast-in 160ms ease-out;
}

.toast[data-tone="ok"] { background: #15803d; border-color: #22c55e; color: #f0fdf4; }
.toast[data-tone="error"] { background: #b91c1c; border-color: #ef4444; color: #fef2f2; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Settle up --------------------------------------------------------------- */

.settlement { display: grid; grid-template-columns: 1fr auto auto; }

.settle {
  -webkit-appearance: none;
  appearance: none;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease, opacity 120ms ease;
}

.settle:hover { background: var(--accent); color: #04160d; }
.settle:active { transform: translateY(1px); }
.settle:disabled { opacity: 0.55; cursor: progress; }
.settle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 380px) { .settle { padding: 8px 11px; font-size: 12px; } }

/* --- Confirmation dialog (every write is reviewed first) --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: rgba(8, 12, 20, 0.62);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: 100%;
  max-width: 440px;
  margin: 0;
  padding: 18px 18px 16px;
  border: 1px solid var(--line, #2a3444);
  border-radius: 18px;
  background: var(--surface, #141b26);
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.6);
  animation: modal-in 180ms ease-out;
}

.modal-card h2 {
  margin: 0 0 12px;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.confirm-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 14px;
  margin: 0 0 12px;
}

.confirm-fields dt {
  color: var(--muted, #93a1b5);
  font-size: 13px;
}

.confirm-fields dd {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.confirm-note {
  margin: 0 0 14px;
  color: var(--muted, #93a1b5);
  font-size: 12.5px;
  line-height: 1.4;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions button {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
}

.modal-actions .ghost {
  border: 1px solid var(--line, #2a3444);
  background: transparent;
  color: inherit;
}

.modal-actions .primary {
  border: 1px solid transparent;
  background: var(--accent, #4f8cff);
  color: #08111f;
}

.modal-actions button:disabled {
  opacity: 0.55;
  cursor: progress;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.book-head .order {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.55;
}

label .optional {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(147, 161, 181, 0.16);
  color: var(--muted, #93a1b5);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  vertical-align: middle;
}

/* ------------------------------------------------ workspace settings ---- */

#settings-view .card + .card { margin-top: 14px; }
#settings-view h2 { margin: 0 0 2px; font-size: 1rem; }
#settings-view .muted { margin: 0 0 12px; font-size: 0.84rem; line-height: 1.4; }
#settings-view .stack { gap: 10px; }
#settings-view .row { align-items: center; gap: 10px; }

.hint { color: var(--muted); font-weight: 400; font-size: 0.78rem; }

.chip-x {
  margin-left: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: 6px;
}

.chip-x:hover, .chip-x:focus-visible { color: var(--text); background: rgba(255, 255, 255, 0.08); }

/* members: one name per line, a switch, and a quiet remove */

.member-list, .backup-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.member-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.switch { flex: 0 0 auto; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.switch-track {
  display: block;
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  transition: background 120ms ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 120ms ease;
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  line-height: 1;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.icon-btn:hover, .icon-btn:focus-visible { color: var(--text); border-color: var(--muted); }
.member-row .icon-btn { border-color: transparent; color: #ff8f8f; }
.member-row .icon-btn:hover, .member-row .icon-btn:focus-visible { background: rgba(248, 113, 113, 0.12); color: #ffb4b4; }

/* backups: label and meta on the left, actions on the right */

.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.backup-label {
  display: grid;
  gap: 3px;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}

.backup-label .muted { margin: 0; font-size: 0.76rem; font-weight: 400; }
.backup-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.backup-actions .download { color: var(--accent); border-color: rgba(74, 222, 128, 0.35); }
.backup-actions .download:hover, .backup-actions .download:focus-visible { background: rgba(74, 222, 128, 0.12); }

.backup-preview {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.backup-preview h3 { margin: 0 0 4px; font-size: 0.95rem; }
.backup-preview .transactions { max-height: 320px; overflow: auto; margin: 8px 0; }

@media (max-width: 420px) {
  .member-row .icon-btn, .backup-actions .icon-btn { padding: 8px; }
}
