/* Phan Home Money - styles (builder: shell). Contract: MONEY-CONTRACT.md v1.

   =====================================================================================
   SHARED CLASSES - money-spend.js and money-grow.js use EXACTLY these names (do not invent
   look-alikes; ask shell for a new one). Everything else in this file (.mt-*, .mc-*, .ms-*)
   is shell-private.
   -------------------------------------------------------------------------------------
   AREAS (r349: each area its own tint + 2px darker border; neighbours never share a hue)
     .m-card                 a section card (padding, radius, 2px border). ALWAYS add one tint:
     .m-card--blue  .m-card--gold  .m-card--green  .m-card--purple
     .m-card--rose  .m-card--teal  .m-card--slate  .m-card--orange
                             pick so two cards next to each other never share a tint.
     .m-card-head            flex row at the top of a card: <h2> on the left, buttons right.
     .m-card-sub             small muted line under the head.
     .m-banner               full-width notice inside a card (white, 2px border).
     .m-banner--red          red alert banner (interest you pay, charge after cancel).
     .m-banner--green        good-news banner.
   TILES / ROWS (items inside a card: white, 1.5px border, 6px colour bar left, alternate tint)
     .m-list                 vertical stack of .m-tile (gap 8px). Alternating faint tint is
                             automatic for .m-tile children of .m-list.
     .m-tile                 one record. Default bar = slate. Bar colour modifiers:
     .m-tile--blue .m-tile--gold .m-tile--green .m-tile--purple .m-tile--rose
     .m-tile--teal .m-tile--red .m-tile--orange .m-tile--slate
                             or set style.setProperty('--bar', '#hex') for a custom bar.
     .m-tile-main            flex:1 text column inside a tile.  .m-tile-title  bold name line.
     .m-tile-meta            small muted line (dates via ctx.fmtDate).
     .m-tile-side            right column (amount + Edit button).
     .m-row                  label left / value right line (flex, space-between, wraps).
     .m-grid2                two-column grid (one column under 360px).
   BUTTONS (all >= 44px tap targets)
     .m-btn                  plain white button, 1.5px border.
     .m-btn--primary         filled accent (main action, e.g. Save).
     .m-btn--danger          red outline (Remove). .m-btn--small = 44px tall compact padding
     .m-btn--add             round "+" button for card heads (aria-label required).
     .m-btn--block           full width.
     .m-actions              row of buttons with gap (wraps).
   CHIPS / SEGMENTS
     .m-chip                 small pill (button or span). .m-chip--on = selected.
     .m-chip--green .m-chip--red .m-chip--gold .m-chip--blue   status chips (text + tint).
     .m-seg                  segmented switch container (Week | Month | ...); children are
                             <button class="m-chip"> with aria-pressed="true" on the chosen one.
   NUMBERS
     .m-in                   money in: green #0f6b3a. ALWAYS also write "+" (never colour alone).
     .m-out                  money out: red #b42318. ALWAYS also write "−" / "-".
     .m-big                  big number (card headline figure).
     .m-muted                muted small text (4.5:1 on white and on every tint).
   PROGRESS
     .m-bar                  progress track; put ONE <span> inside and set span.style.width.
     .m-bar--over            red fill (over budget).   .m-bar--good  green fill.
   EMPTY / LOADING
     .m-empty                friendly empty-state box (dashed border, centred).
   FORMS (ctx.field / ctx.select / ctx.moneyInput / ctx.dateInput already use these)
     .m-field  .m-field-label  .m-field-hint  .m-input   (inputs, selects, textareas)
     .m-err                  red error line inside a sheet.
   ===================================================================================== */

:root {
  --m-bg: #f4f3ef;
  --m-text: #1d2723;
  --m-muted: #4d5752;
  --m-line: #9aa3ab;
  --m-accent: #1f5d48;
  --m-accent-ink: #ffffff;
  --m-in: #0f6b3a;
  --m-out: #b42318;
  --m-tabbar-h: 64px;
  --m-topbar-h: 56px;
  --m-safe-b: env(safe-area-inset-bottom, 0px);
  --m-safe-t: env(safe-area-inset-top, 0px);

  /* tints: background + 2px border (darker) + bar colour */
  --t-blue: #e7effb;   --t-blue-b: #5f86c2;   --bar-blue: #3e6db5;
  --t-gold: #fbf2d8;   --t-gold-b: #b98f2a;   --bar-gold: #c08a12;
  --t-green: #e3f2e7;  --t-green-b: #4e9264;  --bar-green: #2e8048;
  --t-purple: #efe9fa; --t-purple-b: #8467c0; --bar-purple: #6d4bb5;
  --t-rose: #fbe8ee;   --t-rose-b: #c06a86;   --bar-rose: #b34a6d;
  --t-teal: #e0f2f2;   --t-teal-b: #3f9393;   --bar-teal: #1f7f7f;
  --t-slate: #eceff3;  --t-slate-b: #7d8a99;  --bar-slate: #66768a;
  --t-orange: #fdeedf; --t-orange-b: #c47a35; --bar-orange: #c4610e;
  --bar-red: #b42318;

  /* number arrows (numstep.js) */
  --ns-bg: #e2ece8;
  --ns-ink: #1d2723;
  --ns-line: #8fa79e;
  /* addopt sheet colours */
  --ao-bg: #ffffff;
  --ao-ink: #1d2723;
  --ao-accent: #1f5d48;
}

html { font-size: 17px; -webkit-text-size-adjust: 100%; }
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--m-bg);
  color: var(--m-text);
  font-family: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.45;
  min-height: var(--vvh, 100dvh);
  overflow-x: hidden;
}
body.signed-in { padding-bottom: calc(var(--m-tabbar-h) + var(--m-safe-b) + 24px); }
body.sheet-open { overflow: hidden; }
h1, h2, h3 { font-weight: 700; line-height: 1.2; margin: 0; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--m-accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.noscript, .loading { padding: 32px 16px; text-align: center; color: var(--m-muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar (shell) ---------- */
.mt-top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--m-topbar-h); padding: calc(6px + var(--m-safe-t)) 12px 6px 16px;
  background: #1f5d48; color: #ffffff; border-bottom: 2px solid #12392c;
}
.mt-brand { font-size: 1.3rem; flex: 1 1 auto; display: flex; align-items: center; gap: 8px; }
.mt-logo { width: 28px; height: 28px; border-radius: 22%; display: block; flex: 0 0 auto; }
.mt-logo--gate { width: 56px; height: 56px; margin: 0 auto 8px; }
.mt-who { font-size: .95rem; font-weight: 700; color: #ffffff; }
.mt-menu {
  min-width: 48px; min-height: 48px; border-radius: 12px; font-size: 1.5rem; line-height: 1;
  background: #2c735b; color: #ffffff; border: 1.5px solid #9cc7b6; cursor: pointer;
}

/* ---------- main view ---------- */
.mt-view { max-width: 720px; margin: 0 auto; padding: 12px 16px 16px; display: grid; gap: 14px; }

/* ---------- bottom tab bar (shell) ---------- */
.mt-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(7, 1fr);
  min-height: var(--m-tabbar-h); padding-bottom: var(--m-safe-b);
  background: #ffffff; border-top: 2px solid #7d8a99;
}
.kb-open .mt-tabs { display: none; }
.mt-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 56px; padding: 4px 0; border: 0; background: #ffffff; color: #3d4741;
  font-size: .72rem; font-weight: 700; cursor: pointer; -webkit-tap-highlight-color: transparent;
  /* btn-look-ok: bottom tab bar - navigation, active tab highlighted by fill and top bar */
}
.mt-tab .ti { font-size: 1.25rem; line-height: 1; }
.mt-tab[aria-current="page"] { color: #1f5d48; background: #e3f2e7; box-shadow: inset 0 3px 0 #1f5d48; }

/* ---------- cards ---------- */
.m-card {
  border-radius: 14px; padding: 14px; border: 2px solid var(--t-slate-b); background: var(--t-slate);
  color: var(--m-text); min-width: 0;
}
.m-card--blue { background: var(--t-blue); border-color: var(--t-blue-b); }
.m-card--gold { background: var(--t-gold); border-color: var(--t-gold-b); }
.m-card--green { background: var(--t-green); border-color: var(--t-green-b); }
.m-card--purple { background: var(--t-purple); border-color: var(--t-purple-b); }
.m-card--rose { background: var(--t-rose); border-color: var(--t-rose-b); }
.m-card--teal { background: var(--t-teal); border-color: var(--t-teal-b); }
.m-card--slate { background: var(--t-slate); border-color: var(--t-slate-b); }
.m-card--orange { background: var(--t-orange); border-color: var(--t-orange-b); }
.m-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.m-card-head > h2, .m-card-head > h3 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.m-card-sub { margin: -4px 0 10px; font-size: .9rem; color: var(--m-muted); }
.m-banner {
  margin: 8px 0; padding: 10px 12px; border-radius: 10px; font-weight: 700;
  background: #ffffff; color: var(--m-text); border: 2px solid var(--t-slate-b);
}
.m-banner--red { background: #fdecea; color: #8a1a12; border: 2px solid #b42318; }
.m-banner--green { background: #e6f4ea; color: #0c5a30; border: 2px solid #2e8048; }

/* ---------- tiles ---------- */
.m-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.m-tile {
  --bar: var(--bar-slate);
  display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 10px 10px 10px 12px; border-radius: 10px;
  background: #ffffff; color: var(--m-text);
  border: 1.5px solid #a9b2ba; border-left: 6px solid var(--bar);
}
.m-list > .m-tile:nth-child(even) { background: #f6f8fa; }
.m-tile--blue { --bar: var(--bar-blue); }
.m-tile--gold { --bar: var(--bar-gold); }
.m-tile--green { --bar: var(--bar-green); }
.m-tile--purple { --bar: var(--bar-purple); }
.m-tile--rose { --bar: var(--bar-rose); }
.m-tile--teal { --bar: var(--bar-teal); }
.m-tile--red { --bar: var(--bar-red); }
.m-tile--orange { --bar: var(--bar-orange); }
.m-tile--slate { --bar: var(--bar-slate); }
.m-tile-main { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.m-tile-title { font-weight: 700; }
.m-tile-meta { font-size: .88rem; color: var(--m-muted); }
.m-tile-side { flex: none; display: flex; align-items: center; gap: 8px; text-align: right; }
.m-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; padding: 3px 0; }
.m-row > :last-child { font-weight: 700; text-align: right; }
.m-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 359px) { .m-grid2 { grid-template-columns: 1fr; } }

/* ---------- buttons ---------- */
.m-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; min-width: 48px; padding: 8px 16px;
  border-radius: 12px; border: 2px solid #6b7a8c; background: #f1f4f8; color: var(--m-text);
  font-weight: 700; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.m-btn:active { transform: translateY(1px); }
.m-btn:disabled { opacity: .55; }
.m-btn--primary { background: #1f5d48; border-color: #1f5d48; color: #ffffff; }
.m-btn--danger { background: #fdecea; border-color: #b42318; color: #b42318; } /* r367: soft red fill */
.m-btn--small { min-height: 44px; min-width: 44px; padding: 6px 12px; font-size: .92rem; }
.m-btn--add { min-width: 48px; min-height: 48px; padding: 0; border-radius: 50%; font-size: 1.5rem; line-height: 1; background: #1f5d48; border-color: #1f5d48; color: #ffffff; }
.m-btn--block { width: 100%; }
/* r367: a non-primary block button is an escape button: uniform 260px, centered */
.m-btn--block:not(.m-btn--primary) { display: flex; width: min(100%, 260px); margin-left: auto; margin-right: auto; }
.m-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.m-actions > .m-btn { flex: 1 1 auto; }

/* ---------- chips / segments ---------- */
.m-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px; padding: 4px 14px; border-radius: 999px;
  background: #ffffff; color: var(--m-text); border: 2px solid #6b7a8c;
  font-size: .9rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
span.m-chip { min-height: 28px; padding: 2px 10px; cursor: default; font-size: .82rem; }
.m-chip--on, .m-chip[aria-pressed="true"] { background: #1f5d48; border-color: #1f5d48; color: #ffffff; }
.m-chip--green { background: #e6f4ea; color: #0c5a30; border-color: #2e8048; }
.m-chip--red { background: #fdecea; color: #8a1a12; border-color: #b42318; }
.m-chip--gold { background: #fdf3d6; color: #5c4400; border-color: #b98f2a; }
.m-chip--blue { background: #e7effb; color: #1d3f78; border-color: #5f86c2; }
.m-seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.m-seg > .m-chip { flex: 1 1 0; }

/* ---------- numbers ---------- */
.m-in { color: #0f6b3a; font-weight: 700; }
.m-out { color: #b42318; font-weight: 700; }
.m-big { font-size: 1.7rem; font-weight: 700; line-height: 1.15; }
.m-muted { color: var(--m-muted); font-size: .9rem; }

/* ---------- progress ---------- */
.m-bar { position: relative; height: 12px; border-radius: 999px; background: #ffffff; border: 1.5px solid #7d8a99; overflow: hidden; margin: 6px 0; }
.m-bar > span { display: block; height: 100%; width: 0; max-width: 100%; background: #3e6db5; border-radius: 999px; }
.m-bar--over > span { background: #b42318; }
.m-bar--good > span { background: #2e8048; }

/* Reports tab (money-reports.js) */
.m-bar.mr-bar-purple > span { background: #6d4bb5; }
.m-bar.mr-bar-orange > span { background: #c4610e; }
.mr-stack { display: flex; height: 26px; border-radius: 8px; overflow: hidden; border: 2px solid #4e9264; background: #ffffff; margin: 4px 0 12px; }
.mr-stack > span { display: block; height: 100%; min-width: 3px; border-right: 2px solid #ffffff; }
.mr-stack > span:last-child { border-right: 0; }
.mr-dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 8px; vertical-align: -2px; border: 1px solid #1d2b24; }
.mr-needs { background: #3e6db5; }
.mr-wants { background: #c4610e; }
.mr-giving { background: #b34a6d; }
.mr-savings { background: #1f7f7f; }
.mr-business { background: #6d4bb5; }
.mr-other { background: #66768a; }
.mr-left { background: #2e8048; }
.mr-rate { font-size: 1.05rem; font-weight: 700; margin: 8px 0 4px; }
.mr-pair { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; font-size: .9rem; }
.mr-pair .m-bar { margin: 3px 0; }
.mr-k { color: var(--m-muted); font-weight: 700; }

/* ---------- empty ---------- */
.m-empty {
  padding: 14px; border-radius: 10px; text-align: center;
  background: #ffffff; color: var(--m-muted); border: 1.5px dashed #7d8a99;
}

/* ---------- forms ---------- */
.m-field { display: block; margin: 0 0 12px; }
.m-field-label { display: block; font-weight: 700; font-size: .92rem; margin-bottom: 4px; color: var(--m-text); }
.m-field-hint { display: block; font-size: .85rem; color: var(--m-muted); margin-top: 4px; }
.m-input {
  display: block; width: 100%; min-height: 48px; padding: 10px 12px;
  border-radius: 10px; border: 1.5px solid #66768a; background: #ffffff; color: var(--m-text);
  font-size: 1rem;
}
textarea.m-input { min-height: 88px; resize: vertical; }
.m-input:focus { outline: 3px solid #93c5fd; border-color: #1d4ed8; }
.m-check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 700; margin-bottom: 8px; }
.m-check input { width: 24px; height: 24px; }
.m-err { color: #8a1a12; font-weight: 700; margin: 0 0 10px; }

/* ---------- sheet (shell) ---------- */
.ms-back { position: fixed; inset: 0; z-index: 40; background: rgba(10, 20, 16, .5); }
.ms-sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: var(--kb, 0px);
  max-height: calc(var(--vvh, 100dvh) - 24px); overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 16px calc(16px + var(--m-safe-b));
  background: #ffffff; color: var(--m-text);
  border-radius: 18px 18px 0 0; border: 2px solid #7d8a99; border-bottom: 0;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, .22);
}
@media (min-width: 700px) { .ms-sheet { left: 50%; right: auto; width: 560px; transform: translateX(-50%); } }
.ms-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.ms-title { flex: 1 1 auto; font-size: 1.25rem; outline: none; min-width: 0; overflow-wrap: anywhere; }
.ms-close { flex: none; min-width: 48px; min-height: 48px; border-radius: 12px; border: 1.5px solid #7d8a99; background: #ffffff; color: var(--m-text); font-size: 1.3rem; cursor: pointer; }
.ms-acts { display: grid; gap: 10px; margin-top: 14px; }

/* ---------- toast ---------- */
.mt-toast {
  position: fixed; left: 16px; right: 16px; z-index: 90;
  bottom: calc(var(--m-tabbar-h) + var(--m-safe-b) + 14px + var(--kb, 0px));
  max-width: 560px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: #1d2723; color: #ffffff; font-weight: 700; border: 2px solid #000000;
}
.mt-toast.is-error { background: #8a1a12; color: #ffffff; border-color: #5c0f0a; }

/* ---------- sign-in (shell) ---------- */
.mt-sign { max-width: 420px; margin: 24px auto; }
.mt-sign .m-card { text-align: center; }
.mt-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.mt-pick .m-btn { min-height: 88px; font-size: 1.25rem; }
.mt-sign form { text-align: left; margin-top: 12px; }

/* ---------- calendar (shell) ---------- */
.mc-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mc-nav h2 { flex: 1 1 auto; text-align: center; font-size: 1.2rem; }
.mc-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.mc-dow { text-align: center; font-size: .75rem; font-weight: 700; color: var(--m-muted); padding: 2px 0; }
.mc-day {
  display: flex; flex-direction: column; align-items: stretch; min-width: 0; min-height: 60px;
  padding: 3px 2px; border-radius: 8px; cursor: pointer; text-align: center;
  background: #ffffff; color: var(--m-text); border: 1.5px solid #a9b2ba; font-size: .7rem; line-height: 1.15;
}
.mc-day.is-other { background: #eef1f4; color: #4d5752; }
.mc-day.is-today { border: 2px solid #1f5d48; box-shadow: inset 0 0 0 1px #1f5d48; }
.mc-num { font-weight: 700; font-size: .85rem; }
.mc-amt { display: block; overflow: hidden; text-overflow: clip; white-space: nowrap; font-weight: 700; font-size: .66rem; }
.mc-amt.m-in { color: #0f6b3a; }
.mc-amt.m-out { color: #b42318; }
.mc-dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; margin-top: auto; padding-top: 2px; }
.mc-dot { width: 6px; height: 6px; border-radius: 50%; background: #66768a; }
.mc-dot.k-income { background: #0f6b3a; }
.mc-dot.k-bill, .mc-dot.k-card_due { background: #b42318; }
.mc-dot.k-subscription, .mc-dot.k-sub_ends { background: #6d4bb5; }
.mc-dot.k-btc { background: #c4610e; }
.mc-dot.k-savings, .mc-dot.k-goal { background: #3e6db5; }
.mc-dot.k-profit_first { background: #c08a12; }
.mc-sum { margin-top: 10px; padding: 10px; border-radius: 10px; background: #ffffff; color: var(--m-text); border: 1.5px solid #5f86c2; }
.mc-sum p { margin: 2px 0; }
.mc-key { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: .8rem; color: var(--m-muted); }
.mc-key span { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- menu list (shell) ---------- */
.mt-menulist { display: grid; gap: 8px; }
.mt-menulist .m-btn { justify-content: flex-start; width: 100%; }

/* ---------- csv preview (shell) ---------- */
.mt-csv { overflow-x: auto; max-width: 100%; border: 1.5px solid #a9b2ba; border-radius: 10px; background: #ffffff; }
.mt-csv table { border-collapse: collapse; font-size: .82rem; }
.mt-csv td, .mt-csv th { padding: 4px 8px; border-bottom: 1px solid #d5dade; white-space: nowrap; text-align: left; }
