/* Masareef — paper & cedar ledger
   ink #17201B · paper #F6F7F3 · cedar #1F7A4D · brick #BE4B3B · amber #C98A1B */
:root {
  --ink: #17201B;
  --ink-soft: #46534C;
  --paper: #F6F7F3;
  --card: #FFFFFF;
  --line: #DDE3DD;
  --cedar: #1F7A4D;
  --cedar-soft: #E3F0E8;
  --brick: #BE4B3B;
  --brick-soft: #F7E7E3;
  --amber: #C98A1B;
  --radius: 14px;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input {
  font-family: inherit; font-size: 1rem;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); width: 100%;
}
input:focus, button:focus-visible { outline: 2px solid var(--cedar); outline-offset: 1px; }
label { display: block; font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 10px; }
label input { margin-top: 4px; }

.eyebrow {
  display: block; font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-soft); margin-bottom: 6px;
}
.btn {
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  color: var(--ink); padding: 10px 16px; font-size: 0.95rem;
}
.btn.primary { background: var(--cedar); border-color: var(--cedar); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #196540; }
.btn.ghost { border: none; background: transparent; color: var(--ink-soft); }
.btn.big { padding: 14px; font-size: 1.05rem; width: 100%; }

/* ---------- auth ---------- */
.auth {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(1200px 500px at 50% -10%, var(--cedar-soft), transparent 70%),
    var(--paper);
}
.auth-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; }
.brand { text-align: center; margin-bottom: 18px; }
.brand h1 { margin: 10px 0 2px; font-size: 1.7rem; letter-spacing: -0.02em; }
.tagline { margin: 0; color: var(--ink-soft); font-size: 0.9rem; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px; background: var(--cedar); color: #fff;
  font-weight: 700; font-size: 1.05rem; letter-spacing: -0.03em;
}
.brand-mark.small { width: 26px; height: 26px; font-size: 0.68rem; border-radius: 7px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.auth-tabs button {
  flex: 1; padding: 9px; border: none; border-radius: 9px; background: transparent;
  color: var(--ink-soft); font-size: 0.95rem;
}
.auth-tabs button.active { background: var(--cedar-soft); color: var(--cedar); font-weight: 600; }
.error { color: var(--brick); font-size: 0.9rem; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- app shell ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand-mini { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav button {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px;
  width: 30px; height: 30px; font-size: 1.1rem; line-height: 1;
}
#month-label { font-weight: 600; min-width: 108px; text-align: center; font-variant-numeric: tabular-nums; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 90px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; }

/* totals */
.totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.totals.one { grid-template-columns: 1fr; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.pos { color: var(--cedar); }
.neg { color: var(--brick); }

/* ---------- pace meter (signature) ---------- */
.pace-card { border-left: 4px solid var(--cedar); }
.pace-row { display: grid; grid-template-columns: 92px 1fr 44px; align-items: center; gap: 10px; margin: 8px 0; }
.pace-label { font-size: 0.8rem; color: var(--ink-soft); }
.pace-pct { font-size: 0.8rem; text-align: right; font-variant-numeric: tabular-nums; }
.track { height: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.bar { height: 100%; width: 0; border-radius: 99px; transition: width 0.5s ease; }
.bar.time { background: var(--ink-soft); }
.bar.budget { background: var(--cedar); }
.bar.budget.warn { background: var(--amber); }
.bar.budget.over { background: var(--brick); }
.pace-verdict { margin: 10px 0 0; font-size: 0.92rem; }
.pace-verdict strong { font-variant-numeric: tabular-nums; }

/* category / list rows */
.cat-list { display: flex; flex-direction: column; }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: none; }
.cat-name { flex: 0 0 34%; font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar-track { flex: 1; height: 8px; background: var(--paper); border-radius: 99px; overflow: hidden; }
.cat-bar { height: 100%; background: var(--brick); opacity: 0.75; border-radius: 99px; }
.cat-bar.green { background: var(--cedar); }
.cat-amt { flex: 0 0 76px; text-align: right; font-variant-numeric: tabular-nums; font-size: 0.92rem; font-weight: 600; }
.empty { color: var(--ink-soft); font-size: 0.9rem; padding: 8px 0; }

/* ---------- add form ---------- */
.type-toggle { display: flex; gap: 6px; margin-bottom: 14px; }
.type-toggle button {
  flex: 1; padding: 10px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink-soft); font-size: 0.95rem;
}
.type-toggle button.active[data-type="expense"],
.type-toggle button.active[data-ctype="expense"] { background: var(--brick-soft); border-color: var(--brick); color: var(--brick); font-weight: 600; }
.type-toggle button.active[data-type="income"],
.type-toggle button.active[data-type="saving"],
.type-toggle button.active[data-ctype="income"],
.type-toggle button.active[data-ctype="saving"] { background: var(--cedar-soft); border-color: var(--cedar); color: var(--cedar); font-weight: 600; }
.amount-label input { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; padding: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line); background: var(--paper); border-radius: 99px;
  padding: 7px 14px; font-size: 0.88rem; color: var(--ink);
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
#tx-category { margin-bottom: 12px; }
.hint { font-size: 0.82rem; color: var(--ink-soft); margin: 0 0 10px; }
.msg { min-height: 1.2em; font-size: 0.9rem; margin: 10px 0 0; }
.msg.ok { color: var(--cedar); }
.msg.err { color: var(--brick); }

/* ---------- history ---------- */
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tx-item:last-child { border-bottom: none; }
.tx-date { flex: 0 0 46px; font-size: 0.78rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.tx-main { flex: 1; min-width: 0; }
.tx-cat { font-weight: 600; font-size: 0.95rem; }
.tx-note { font-size: 0.8rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-amt { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.tx-del { border: none; background: transparent; color: var(--ink-soft); font-size: 1.1rem; padding: 4px 6px; }
.tx-del:hover { color: var(--brick); }

.fineprint { color: var(--ink-soft); font-size: 0.82rem; text-align: center; }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; padding: 12px 4px; border: none; background: transparent;
  color: var(--ink-soft); font-size: 0.82rem; border-top: 3px solid transparent;
}
.tabbar button.active { color: var(--cedar); font-weight: 700; border-top-color: var(--cedar); }

@media (min-width: 640px) {
  .totals { grid-template-columns: repeat(4, 1fr); }
  .tabbar { position: sticky; top: 57px; bottom: auto; border-top: none; border-bottom: 1px solid var(--line); }
  main { padding-bottom: 24px; }
}
@media (prefers-reduced-motion: reduce) { .bar { transition: none; } }

/* ---------- v2 additions ---------- */
select {
  font-family: inherit; font-size: 1rem; width: 100%;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
.opt { color: var(--ink-soft); font-weight: 400; }
.btn.full { width: 100%; margin-top: 8px; }
.amount-row { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: end; }
.type-toggle.small button { padding: 7px; font-size: 0.85rem; }
.inline-add { display: flex; gap: 8px; margin-top: 10px; }
.inline-add input { flex: 1; min-width: 0; }
.inline-add .btn { white-space: nowrap; }
.mover-detail { flex: 1; text-align: right; font-size: 0.8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; padding-right: 8px; }
.tx-right { text-align: right; }

/* insights: 6-month trend */
.trend { display: flex; gap: 6px; align-items: flex-end; justify-content: space-between; padding: 8px 0 2px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.trend-bars { display: flex; gap: 2px; align-items: flex-end; height: 74px; }
.tb { width: 9px; border-radius: 3px 3px 0 0; }
.tb.cedar { background: var(--cedar); }
.tb.brick { background: var(--brick); opacity: 0.85; }
.tb.ink { background: var(--ink-soft); }
.trend-label { font-size: 0.68rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; margin-top: 8px; font-size: 0.78rem; color: var(--ink-soft); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot.cedar { background: var(--cedar); }
.dot.brick { background: var(--brick); }
.dot.ink { background: var(--ink-soft); }

/* insights: weekday */
.weekday { display: flex; gap: 6px; align-items: flex-end; justify-content: space-between; padding: 6px 0 2px; }
.wd-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.wd-bar { width: 70%; max-width: 34px; background: var(--brick); opacity: 0.8; border-radius: 4px 4px 0 0; height: 58px; }

/* ---------- i18n / RTL ---------- */
.lang-corner { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.lang-corner select { width: auto; padding: 6px 10px; font-size: 0.85rem; }
.cat-amt, .pace-pct, .mover-detail, .tx-right { text-align: end; }
[dir="rtl"] .pace-card { border-left: none; border-right: 4px solid var(--cedar); }
[dir="rtl"] .tb, [dir="rtl"] .wd-bar { border-radius: 3px 3px 0 0; }

/* ---------- quick NL entry ---------- */
.qe-card { border-left: 4px solid var(--amber); }
[dir="rtl"] .qe-card { border-left: 1px solid var(--line); border-right: 4px solid var(--amber); }
.qe-row { display: flex; gap: 8px; }
.qe-row input { flex: 1; font-size: 1rem; }
.btn.mic { width: 46px; flex: 0 0 46px; font-size: 1.1rem; padding: 8px; }
.btn.mic.listening { background: var(--brick-soft); border-color: var(--brick); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
@media (prefers-reduced-motion: reduce) { .btn.mic.listening { animation: none; } }
.qe-confirm { margin-top: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.qe-pills { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.pill { background: var(--paper); border: 1px solid var(--line); border-radius: 99px;
  padding: 5px 12px; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.pill.p-brick { background: var(--brick-soft); border-color: var(--brick); color: var(--brick); }
.pill.p-cedar { background: var(--cedar-soft); border-color: var(--cedar); color: var(--cedar); }
.pill.p-warn { background: #FBF3E2; border-color: var(--amber); color: var(--amber); }
.qe-actions { display: flex; gap: 6px; }
.qe-actions .btn:disabled { opacity: 0.45; cursor: not-allowed; }
.alert-card { border-left: 4px solid var(--brick); }
[dir="rtl"] .alert-card { border-left: 1px solid var(--line); border-right: 4px solid var(--brick); }

/* ---------- recovery kit ---------- */
.brand-mark.warn { background: var(--amber); }
.rk-code {
  font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; text-align: center;
  background: var(--paper); border: 1px dashed var(--amber); border-radius: 10px;
  padding: 14px 8px; margin: 12px 0; letter-spacing: 0.04em; word-break: break-all;
  user-select: all; direction: ltr;
}
.rk-check { display: flex; align-items: center; gap: 8px; margin: 12px 0; font-size: 0.9rem; color: var(--ink); }
.rk-check input { width: auto; }

/* ---------- danger zone ---------- */
.danger-card { border: 1px solid var(--brick); }
.btn.danger { background: var(--brick); border-color: var(--brick); color: #fff; }
.btn.danger:hover { background: #a63d2e; }
#delete-confirm { margin-top: 10px; }

/* ---------- legal modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(23,32,27,0.55); padding: 16px; }
.modal-card { background: var(--card); border-radius: var(--radius); max-width: 640px; width: 100%;
  max-height: 85vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px;
  border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.legal-body { padding: 8px 18px 20px; overflow-y: auto; }
.legal-body h3 { font-size: 0.95rem; margin: 16px 0 4px; color: var(--cedar); }
.legal-body p { margin: 4px 0; font-size: 0.9rem; line-height: 1.5; color: var(--ink-soft); }
