/* Sized for a phone first: big tap targets, one column, readable numbers. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --good: #14804a;
  --bad: #b42318;
  --warn: #b25e09;
  --warn-bg: #fff7ed;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1d212a;
    --border: #2a2f3a;
    --text: #e8eaed;
    --muted: #9aa3b2;
    --accent: #4f8cff;
    --good: #3ddc97;
    --bad: #ff6b6b;
    --warn: #f0a44a;
    --warn-bg: #2a2015;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }

header.bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
}
header.bar h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; }
header.bar .who { color: var(--muted); font-size: 13px; }

nav.tabs {
  display: flex; gap: 4px; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 0 12px; overflow-x: auto;
}
nav.tabs a {
  padding: 11px 12px; font-size: 14px; color: var(--muted);
  text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap;
}
nav.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 12px; font-weight: 650;
}

.big { font-size: 34px; font-weight: 680; letter-spacing: -.02em;
       font-variant-numeric: tabular-nums; }
.sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.good { color: var(--good); }
.bad  { color: var(--bad); }
.warn { color: var(--warn); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat .n { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 560; }
.row .meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em;
}
.pill.ok    { background: rgba(20,128,74,.12);  color: var(--good); }
.pill.err   { background: rgba(180,35,24,.12);  color: var(--bad); }
.pill.warn  { background: rgba(178,94,9,.14);   color: var(--warn); }
.pill.muted { background: var(--surface-2); color: var(--muted); }

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  padding: 10px 14px; min-height: 42px;
  text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px;
}
button.primary, .btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
}
button:disabled { opacity: .55; cursor: default; }
button.sm { padding: 6px 10px; min-height: 34px; font-size: 13px; }

.notice {
  background: var(--warn-bg); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
  font-size: 14px;
}

/* ---- login ---- */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center;
  justify-content: center; padding: 24px;
}
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 21px; margin: 0 0 4px; }
.login-card p.lead { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 0 0 6px; }
input[type=text], input[type=password] {
  width: 100%; font: inherit; padding: 12px; min-height: 46px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); margin-bottom: 14px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.err {
  background: rgba(180,35,24,.1); color: var(--bad); border-radius: 10px;
  padding: 10px 12px; font-size: 13.5px; margin-bottom: 14px; font-weight: 550;
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 11px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ============ Transactions ============ */

.filters { position: sticky; top: 0; z-index: 8; padding: 12px; }
.filters input[type=search] {
  width: 100%; font: inherit; padding: 10px 12px; min-height: 42px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); margin-bottom: 8px;
}
.filter-row { display: flex; gap: 8px; }
.filter-row select { flex: 1; min-width: 0; }
select {
  font: inherit; padding: 9px 10px; min-height: 40px; width: 100%;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
textarea {
  font: inherit; width: 100%; padding: 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  resize: vertical;
}

.chips { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  font-size: 12.5px; padding: 6px 10px; min-height: 32px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.chip .badge {
  display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 999px;
  background: rgba(127,127,127,.22); font-size: 11px; font-weight: 700;
}

.listinfo { color: var(--muted); font-size: 12.5px; margin: 4px 2px 8px; }

.tx {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 12px; margin-bottom: 7px;
}
.tx-main { flex: 1; min-width: 0; cursor: pointer; }
.tx-merchant {
  font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-meta {
  color: var(--muted); font-size: 12px; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tx-meta .cat { color: var(--accent); }
.tx-right { display: flex; align-items: center; gap: 10px; }
.tx-amt { font-variant-numeric: tabular-nums; font-weight: 620; white-space: nowrap; }
.tx-amt.credit { color: var(--good); }

.tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-2); color: var(--muted);
  padding: 1px 5px; border-radius: 4px; font-weight: 700; vertical-align: 1px;
}
.tag.lock { background: rgba(31,111,235,.14); color: var(--accent); }

.toggle {
  min-width: 46px; min-height: 34px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.toggle.in   { background: rgba(20,128,74,.14);  color: var(--good); border-color: transparent; }
.toggle.out  { background: var(--surface-2);     color: var(--muted); }
.toggle.ask  { background: rgba(178,94,9,.16);   color: var(--warn); border-color: transparent; }

/* ============ Bottom sheet ============ */

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow-y: auto;
  transform: translateY(102%); transition: transform .24s cubic-bezier(.32,.72,0,1);
  max-width: 720px; margin: 0 auto;
}
.sheet.open { transform: translateY(0); }
.sheet-grip {
  width: 38px; height: 4px; border-radius: 999px; background: var(--border);
  margin: 6px auto 14px;
}
.sheet-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.sheet-title { font-size: 18px; font-weight: 650; }
.sheet-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.sheet-amt {
  margin-left: auto; font-size: 19px; font-weight: 680;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.sheet-actions {
  display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap;
  position: sticky; bottom: 0; background: var(--surface); padding: 10px 0 0;
}
.sheet-actions button { flex: 1; min-width: 92px; }

.fieldrow { margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; line-height: 1.45; }
.hint.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  background: var(--surface-2); padding: 8px 10px; border-radius: 8px;
  word-break: break-all;
}

.seg { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.segbtn {
  flex: 1; border: 0; border-radius: 0; background: var(--surface-2);
  color: var(--muted); font-size: 13.5px; min-height: 42px;
  border-right: 1px solid var(--border);
}
.segbtn:last-child { border-right: 0; }
.segbtn.on { background: var(--accent); color: var(--accent-ink); font-weight: 650; }

.hist { max-height: 160px; overflow-y: auto; }
.hrow {
  font-size: 12px; color: var(--muted); padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.hrow:last-child { border-bottom: 0; }

/* ============ Rules ============ */

.rule {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 7px;
}
.rule.off { opacity: .5; }
.rule-order { display: flex; flex-direction: column; gap: 2px; }
.ord {
  min-height: 22px; min-width: 26px; padding: 0; font-size: 9px;
  line-height: 1; border-radius: 6px; color: var(--muted);
}
.rule-body { flex: 1; min-width: 0; cursor: pointer; }
.rule-pattern {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rule-meta {
  color: var(--muted); font-size: 12px; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rule-actions { display: flex; gap: 6px; }
button.danger { color: var(--bad); }

.preview {
  margin: 10px 0 4px; padding: 10px; border-radius: 10px;
  background: var(--surface-2); min-height: 0;
}
.preview:empty { display: none; }
.prow {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 12.5px; padding: 4px 0; color: var(--muted);
  border-top: 1px solid var(--border); margin-top: 4px;
}
.prow span:first-child {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prow span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }

.checkline {
  display: flex; align-items: center; gap: 8px; font-size: 13.5px;
  font-weight: 500; margin-top: 10px; cursor: pointer;
}
.checkline input { width: 18px; height: 18px; margin: 0; }

/* On a phone the rule details were being squeezed into an ellipsis by the
   action buttons. Let the text use the full width and drop the buttons onto
   their own line underneath. */
.rule { flex-wrap: wrap; }
.rule-body { flex: 1 1 100%; order: 2; }
.rule-order { order: 1; flex-direction: row; gap: 4px; }
.rule-actions { order: 3; margin-left: auto; }
.rule-meta { white-space: normal; overflow: visible; line-height: 1.5; }
.rule-pattern { white-space: normal; word-break: break-word; }

@media (min-width: 560px) {
  .rule { flex-wrap: nowrap; }
  .rule-body { flex: 1 1 auto; order: 0; }
  .rule-order { order: 0; flex-direction: column; gap: 2px; }
  .rule-actions { order: 0; }
}

/* A category the app guessed rather than one you set. Rendered faintly and
   in italics so a guess never reads as a decision you made. */
.tx-meta .cat.guess { color: var(--muted); font-style: italic; opacity: .85; }

.linkbtn {
  background: none; border: 0; padding: 0; min-height: 0;
  color: var(--accent); font-size: inherit; font-weight: 600;
  text-decoration: underline; display: inline;
}
.hint em { font-style: normal; font-weight: 650; color: var(--text); }
