/* The dashboard's palette, so the phone and the terminal are one product.
   Values come from src/ui/mod.rs; the category dots come from the API. */

:root {
  --bg: #171a1f;
  --surface: #1e2228;
  --raised: #262b33;
  --line: #2f353e;
  --text: #dbe0e7;
  --muted: #7d8794;
  --accent: #61afef;
  --on-accent: #171a1f;
  --credit: #7ec88c;
  --debit: #e06c75;
  --scrim: rgba(10, 12, 15, .66);
  --sans: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --raised: #eef1f5;
    --line: #dfe4ea;
    --text: #1b1f26;
    --muted: #6b7480;
    --accent: #2f80c9;
    --on-accent: #ffffff;
    --credit: #2f8a4a;
    --debit: #c14350;
    --scrim: rgba(20, 24, 30, .42);
    color-scheme: light;
  }
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
}
button { cursor: pointer; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Safe areas: the real status bar and home indicator draw over the page, so
   the layout keeps clear of them rather than painting imitations. */
#app, #login {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

/* ---- login ------------------------------------------------------------ */

#login { padding-inline: 32px; justify-content: center; gap: 44px; }
.login-mark { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.login-mark svg { color: var(--accent); margin-bottom: 14px; }
.login-mark h1 { margin: 0; font-size: 27px; font-weight: 600; letter-spacing: -.03em; }
.login-mark p { margin: 0; font-size: 13.5px; color: var(--muted); text-align: center; line-height: 1.5; }

#login-form { display: flex; flex-direction: column; gap: 12px; }
#password {
  height: 52px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); font-size: 16px;
}
#password:focus { outline: none; border-color: var(--accent); }

.primary {
  height: 52px; border-radius: 12px;
  background: var(--accent); color: var(--on-accent);
  font-size: 15.5px; font-weight: 600;
}
.primary:disabled { opacity: .55; }

.error { margin: 0; color: var(--debit); font-size: 13px; text-align: center; }
.fineprint { margin: 0; font-size: 11.5px; color: var(--muted); text-align: center; line-height: 1.6; }

/* ---- ledger header ---------------------------------------------------- */

#ledger-head { flex: none; }
.bar { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
.brand svg { color: var(--accent); }

.icon {
  width: 44px; height: 44px; margin-right: -10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.icon[aria-pressed="true"] { color: var(--accent); }

.totals { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 2px 18px 16px; }
.totals-left { display: flex; flex-direction: column; gap: 5px; }
.month { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 500; }
.month::after {
  content: ""; width: 8px; height: 8px; margin-top: -3px;
  border-right: 1.6px solid currentColor; border-bottom: 1.6px solid currentColor;
  transform: rotate(45deg);
}
.net { font-size: 29px; font-weight: 500; letter-spacing: -.02em; }
.net.debit { color: var(--debit); }
.net.credit { color: var(--credit); }
.net-label { font-size: 12px; color: var(--muted); text-align: right; padding-bottom: 5px; line-height: 1.5; }

/* Who is ahead this month, under the total. The verdict is the one line on
   the page that says it in words, so it is the one that is not muted. */
.standing {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  margin-top: -8px; padding: 0 18px 14px; font-size: 13px; color: var(--muted);
}
.standing .who { display: inline-flex; align-items: center; gap: 6px; }
.standing .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.standing .who b { color: var(--text); font-weight: 500; }
.standing .lead { color: var(--text); font-weight: 600; }
.standing .lead b { color: var(--accent); }

#search-row { padding: 0 18px 14px; }
#search {
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--surface);
}
#search:focus { outline: none; border-color: var(--accent); }

.chips { display: flex; gap: 8px; padding: 0 18px 14px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  height: 44px; padding: 0 15px; border-radius: 10px; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13.5px; font-weight: 500;
}
.chips button b { color: var(--accent); font-weight: 600; }
.chips button[aria-pressed="true"] {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
}
.chips button[aria-pressed="true"] b { color: inherit; }
.chips .person { display: inline-flex; align-items: center; gap: 7px; }
.chips .person .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chips .person[aria-pressed="true"] .dot { outline: 2px solid var(--on-accent); }

/* ---- the ledger ------------------------------------------------------- */

#list { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); background: var(--surface); -webkit-overflow-scrolling: touch; }

.row { display: flex; flex-direction: column; gap: 8px; padding: 13px 18px 14px; border-bottom: 1px solid var(--line); }
.row.pending { opacity: .5; }
/* An instalment the bank has not billed yet: faint, like the dashboard draws
   it, and its chips only show what the billed instalment was given. */
.row.projected { opacity: .62; }
.row.projected .row-desc { font-style: italic; }
.chip.inherited { border-style: dashed; }
.pick.projected .name { color: var(--muted); }
.row-top { display: flex; align-items: baseline; gap: 12px; }
.row-main { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.row-desc { font-size: 15px; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amount { font-size: 15px; font-weight: 500; flex: none; }
.row-amount.debit { color: var(--debit); }
.row-amount.credit { color: var(--credit); }
.row-chips { display: flex; gap: 8px; }

.chip {
  display: flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px;
  font-size: 12.5px; font-weight: 500; white-space: nowrap;
  max-width: 52%;
}
.chip span.label { overflow: hidden; text-overflow: ellipsis; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.chip.owner { color: var(--muted); }
.chip.unset { border-color: var(--accent); color: var(--accent); }
.chip.unset.owner { border-color: var(--line); color: var(--muted); }

.empty { padding: 56px 32px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.6; }

/* ---- tab bar ---------------------------------------------------------- */

#tabs {
  flex: none; display: flex;
  border-top: 1px solid var(--line); background: var(--bg);
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}
#tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 9px 0; color: var(--muted); font-size: 11px; font-weight: 500;
}
#tabs button[aria-pressed="true"] { color: var(--accent); }

/* ---- bottom sheet ----------------------------------------------------- */

#sheet-scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 10; }
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: 78vh; display: flex; flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { #sheet { animation: none; } }

.grab { display: flex; justify-content: center; padding: 9px 0 4px; flex: none; }
.grab div { width: 38px; height: 4px; border-radius: 2px; background: var(--line); }

.sheet-head { display: flex; flex-direction: column; gap: 12px; padding: 8px 20px 14px; flex: none; }
.sheet-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.sheet-title h2 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.sheet-title span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sheet-search {
  display: flex; align-items: center; gap: 10px;
  height: 46px; padding: 0 14px;
  border: 1px solid var(--accent); border-radius: 11px; background: var(--raised);
}
.sheet-search input { flex: 1; min-width: 0; background: none; }
.sheet-search input:focus { outline: none; }
.sheet-search .count { font-size: 11.5px; color: var(--muted); flex: none; }

.picks { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); }
.pick {
  display: flex; align-items: center; gap: 12px;
  width: 100%; height: 52px; padding: 0 20px;
  border-bottom: 1px solid var(--line); text-align: left;
}
.pick .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.pick .name { flex: 1; font-size: 15px; font-weight: 500; }
.pick .sub { font-size: 11.5px; color: var(--muted); }
.pick.current { background: var(--raised); }
.pick.clear { color: var(--muted); font-size: 14.5px; font-weight: 400; border-bottom: 0; }
.pick.clear .dot { background: none; border: 1.5px dashed var(--muted); }

/* ---- queue ------------------------------------------------------------ */

#queue { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
.queue-bar { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 10px; }
.queue-bar button { color: var(--muted); font-size: 13.5px; font-weight: 500; height: 44px; }
.queue-bar span { font-size: 13px; color: var(--muted); font-weight: 500; }
.progress { height: 3px; background: var(--raised); margin: 0 18px; border-radius: 2px; overflow: hidden; flex: none; }
.progress div { height: 100%; background: var(--accent); transition: width .2s ease-out; }

.queue-card { display: flex; flex-direction: column; gap: 10px; padding: 38px 22px 30px; }
.queue-amount { font-size: 38px; font-weight: 500; letter-spacing: -.03em; }
.queue-amount.debit { color: var(--debit); }
.queue-amount.credit { color: var(--credit); }
.queue-desc { display: flex; align-items: center; gap: 8px; font-size: 19px; font-weight: 600; letter-spacing: -.015em; }
.queue-memo { font-size: 13px; color: var(--muted); line-height: 1.6; word-break: break-word; }

.queue-pick { display: flex; flex-direction: column; gap: 11px; padding: 0 18px; flex: 1; }
.queue-label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .06em; }
.queue-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.queue-grid button {
  display: flex; align-items: center; gap: 9px;
  height: 56px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  font-size: 14px; font-weight: 500; text-align: left;
}
.queue-grid .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.queue-grid span.label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-more { display: flex; align-items: center; justify-content: center; height: 48px; color: var(--accent); font-size: 14px; font-weight: 500; }
.queue-actions { display: flex; gap: 10px; padding: 0 18px 30px; }
.queue-actions button { height: 52px; flex: 1; border-radius: 12px; font-size: 14.5px; font-weight: 500; }
.queue-skip { border: 1px solid var(--line); color: var(--muted); }

/* ---- breakdown -------------------------------------------------------- */

#breakdown { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; padding: 8px 18px 24px; }
.card { display: flex; flex-direction: column; gap: 14px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.card-head { display: flex; flex-direction: column; gap: 3px; }
.card-head h2, .section-head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.card-head p { margin: 0; font-size: 12px; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 14px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }
.section-head span { font-size: 12px; color: var(--muted); }

.bar-row { display: flex; flex-direction: column; gap: 8px; }
.bar-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.bar-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-name .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.bar-name strong { font-size: 14.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-name em { font-style: normal; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.bar-amount { font-size: 14px; flex: none; }
.track { height: 7px; border-radius: 4px; background: var(--raised); overflow: hidden; }
.track div { height: 100%; border-radius: 4px; }

/* ---- toast ------------------------------------------------------------ */

#toast {
  position: fixed; left: 18px; right: 18px; z-index: 20;
  bottom: calc(86px + env(safe-area-inset-bottom));
  padding: 13px 16px; border-radius: 11px;
  background: var(--raised); border: 1px solid var(--line);
  color: var(--text); font-size: 13.5px; text-align: center;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .3);
}
#toast.bad { border-color: var(--debit); color: var(--debit); }

/* An instalment counter: "3/10" is part of what the charge is, so it sits with
   the name rather than in the grey line under it. */
.instalment {
  flex: none;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.row-desc { display: flex; align-items: center; gap: 7px; }
.row-desc > span:first-child { overflow: hidden; text-overflow: ellipsis; }
.queue-memo { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
