/* Shared component vocabulary. Modules may add layout; they never redefine
 * these, and they never name a colour — only var(--accent), which a row state
 * rebinds locally. That is what lets one row component serve a subscription, an
 * envelope and a spending entry without a single branch. */

/* ── The ledger ──────────────────────────────────────────────────────────
   A money app is a column of figures that must align. Every amount is
   right-aligned on a shared axis in tabular figures, so scanning down any list
   the digits stack. Rows are separated by hairlines, not boxes. */
.ledger { border-top: 1px solid var(--rule); }

.row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title amount" "meta amount";
  column-gap: var(--s-4);
  align-items: baseline;
  padding: var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--rule);
  position: relative;
  isolation: isolate;
}

/* Envelopes: the row IS the gauge. The fill replaces a separate progress bar
   and is the physical metaphor the module is named for.
   --fill is set through the CSSOM (element.style.setProperty), never a style=""
   attribute — CSP style-src 'self' blocks the attribute but not the property. */
.row--gauge::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 0%);
  background: var(--accent-dim);
  z-index: -1;
  transition: width 320ms var(--ease);
}

.row-title {
  grid-area: title;
  font-size: var(--t-lead);
  font-weight: 500;
  color: var(--ink);
}
.row-meta {
  grid-area: meta;
  font-size: var(--t-small);
  color: var(--ink-3);
}
.row-amount {
  grid-area: amount;
  font-size: var(--t-lead);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
  color: var(--ink);
}
.row-amount.is-signed { color: var(--accent); }

.row-actions {
  grid-area: amount;
  grid-row: 2;
  display: flex;
  gap: var(--s-1);
  justify-content: flex-end;
  margin-top: var(--s-1);
}

/* State rebinds --accent locally; everything inside follows. */
.row.is-overdue { --accent: var(--out); --accent-dim: var(--out-dim); }
.row.is-due     { --accent: var(--due); --accent-dim: var(--due-dim); }
.row.is-funded  { --accent: var(--in);  --accent-dim: var(--in-dim); }

/* Wide screens: same <ul>, same DOM, one render pass — it just becomes a table. */
.ledger-head { display: none; }
@media (min-width: 720px) {
  .ledger-head {
    display: grid;
    grid-template-columns: var(--cols, 2fr 1fr 1fr auto);
    gap: var(--s-4);
    padding: var(--s-2);
    font-size: var(--t-label);
    font-weight: 500;
    color: var(--ink-3);
    border-bottom: 1px solid var(--rule-firm);
  }
  .ledger-head > :last-child { text-align: right; }
}

/* ── Tiles ───────────────────────────────────────────────────────────────── */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--s-3);
  margin-bottom: var(--s-5);
}
.tile { padding: var(--s-3) 0; border-top: 1px solid var(--rule); }
.tile-label { font-size: var(--t-label); color: var(--ink-3); }
.tile-value {
  font-size: var(--t-h2);
  font-weight: 500;
  margin-top: 2px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 40px;
  padding: 0 var(--s-4);
  border-radius: var(--r-2);
  border: 1px solid transparent;
  background: none;
  font-size: var(--t-small);
  font-weight: 500;
  text-decoration: none;   /* .btn is used on <a> as well as <button> */
  transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}
@media (hover: none) { .btn { min-height: 44px; } }

.btn--solid { background: var(--accent); color: var(--on-accent); }
.btn--solid:hover { filter: brightness(1.08); }

.btn--quiet { background: var(--surface-2); color: var(--ink); }
.btn--quiet:hover { background: var(--rule); }

.btn--ghost { border-color: var(--rule-firm); color: var(--ink-2); }
.btn--ghost:hover { color: var(--ink); border-color: var(--ink-3); }

.btn--danger { background: var(--out-dim); color: var(--out); }

.btn--sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--t-label); }
@media (hover: none) { .btn--sm { min-height: 36px; } }

.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ── Fields ──────────────────────────────────────────────────────────────── */
.field { margin-bottom: var(--s-4); }
.field-label {
  display: block;
  font-size: var(--t-label);
  font-weight: 500;
  color: var(--ink-3);
  margin-bottom: var(--s-1);
}
.field input, .field select, .field textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--s-2) var(--s-3);
  font-size: var(--t-input);   /* 16px minimum, or iOS Safari zooms on focus */
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule-firm);
  border-radius: var(--r-1);
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field-hint { font-size: var(--t-label); color: var(--ink-3); margin-top: var(--s-1); }
.field-error { font-size: var(--t-label); color: var(--out); margin-top: var(--s-1); }
.field-row { display: flex; gap: var(--s-3); }
.field-row > * { flex: 1; }

/* ── Sheet / dialog ──────────────────────────────────────────────────────
   One implementation, one visibility convention: [hidden]. The two apps this
   replaces used opposite conventions (.open to show vs .hidden to hide). */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--overlay);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-panel {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: var(--r-3) var(--r-3) 0 0;
  box-shadow: var(--shadow-sheet);
  padding: var(--s-5) var(--s-4);
  padding-bottom: calc(var(--s-5) + var(--safe-bottom));
  animation: sheet-up 180ms var(--ease);
}
@keyframes sheet-up { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 641px) {
  .sheet { align-items: center; }
  .sheet-panel {
    border-radius: var(--r-3);
    padding-bottom: var(--s-5);
    animation: none;
  }
}

.sheet-title { font-size: var(--t-h2); font-weight: 600; margin-bottom: var(--s-4); }
.sheet-actions {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  margin-top: var(--s-5);
}

/* ── Tags ────────────────────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  padding: 2px var(--s-2);
  border-radius: var(--r-1);
  font-size: var(--t-micro);
  font-weight: 500;
  background: var(--accent-dim);
  color: var(--accent);
}

/* ── Empty state: an invitation, not a statement ─────────────────────────── */
.empty {
  padding: var(--s-7) var(--s-4);
  text-align: left;
  max-width: 420px;
}
.empty-title { font-size: var(--t-lead); font-weight: 500; margin-bottom: var(--s-2); }
.empty-body { color: var(--ink-2); font-size: var(--t-small); margin-bottom: var(--s-4); }

/* ── Menu ────────────────────────────────────────────────────────────────── */
.menu {
  position: absolute;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-menu);
  padding: var(--s-1);
  z-index: 70;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--s-2) var(--s-3);
  background: none;
  border: 0;
  border-radius: var(--r-1);
  font-size: var(--t-small);
}
.menu button:hover { background: var(--surface-2); }

/* ── Bars (category breakdowns) ──────────────────────────────────────────── */
.bars { display: flex; flex-direction: column; gap: var(--s-2); }
.bar { display: grid; grid-template-columns: 1fr 2fr auto; gap: var(--s-3); align-items: center; }
.bar-label { font-size: var(--t-small); color: var(--ink-2); }
.bar-track { height: 10px; background: var(--surface-2); border-radius: var(--r-full); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: var(--r-full); }
.bar-value { font-size: var(--t-small); text-align: right; white-space: nowrap; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + var(--safe-bottom) + var(--s-4));
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}
@media (min-width: 900px) {
  .toast-host { bottom: var(--s-5); left: calc(var(--rail-w) + var(--s-5)); transform: none; }
}
.toast {
  background: var(--ink);
  color: var(--canvas);
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-2);
  font-size: var(--t-small);
  box-shadow: var(--shadow-menu);
}
.toast.is-error { background: var(--out); color: #fff; }
