/* ============================================================
   Bhada — Nepali Rent & Utility Ledger
   Aesthetic: Bhaktapur Newari — red brick, brass, ink on paper.
   ============================================================ */

:root {
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --brick: #B23A2E;
  --brick-deep: #8A2A20;
  --brass: #C8893C;
  --brass-soft: #E7C58A;

  --bg: #F4ECDB;
  --bg-2: #ECE0C8;
  --surface: #FBF6EC;
  --surface-2: #F6ECD8;
  --ink: #1C1714;
  --ink-soft: #6A5B4D;
  --ink-faint: #9A8A78;
  --line: rgba(28, 23, 20, 0.12);
  --line-strong: rgba(28, 23, 20, 0.22);
  --computed-bg: rgba(200, 137, 60, 0.14);
  --computed-ink: #9A6A22;
  --total-bg: #F2DDA6;
  --avg-bg: #EAD3A0;
  --good: #4E7A4A;
  --danger: #B23A2E;
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.06), 0 12px 28px -12px rgba(60, 40, 20, 0.22);
  --shadow-lg: 0 30px 70px -24px rgba(60, 30, 15, 0.40);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="dark"] {
  --bg: #13100E;
  --bg-2: #1B1612;
  --surface: #20191410;
  --surface: #211A15;
  --surface-2: #1A1410;
  --ink: #F3E9D7;
  --ink-soft: #B7A48E;
  --ink-faint: #806E5C;
  --line: rgba(243, 233, 215, 0.12);
  --line-strong: rgba(243, 233, 215, 0.22);
  --computed-bg: rgba(224, 163, 82, 0.16);
  --computed-ink: #E6B574;
  --total-bg: #4A3818;
  --avg-bg: #3C2E14;
  --brick: #E0574A;
  --brass: #E3A957;
  --brass-soft: #B9874330;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 16px 34px -14px rgba(0,0,0,0.6);
  --shadow-lg: 0 34px 80px -28px rgba(0,0,0,0.7);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.45;
  overflow-x: hidden;
  /* respect notched / home-indicator phones */
  padding-left:  env(safe-area-inset-left,  0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* atmosphere -------------------------------------------------- */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.12  0 0 0 0 0.08  0 0 0 0 0.05  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}
[data-theme="dark"] .grain { opacity: 0.35; mix-blend-mode: screen; }
.topo {
  position: fixed; top: -20%; right: -10%; width: 70vmax; height: 70vmax; z-index: 0;
  pointer-events: none; opacity: 0.06;
  background: radial-gradient(circle at 50% 50%, transparent 38%, var(--brick) 39%, transparent 40%),
              radial-gradient(circle at 50% 50%, transparent 28%, var(--brick) 29%, transparent 30%),
              radial-gradient(circle at 50% 50%, transparent 18%, var(--brick) 19%, transparent 20%);
  mask-image: radial-gradient(circle at 70% 30%, black, transparent 65%);
}
#app, #login { position: relative; z-index: 1; }

.hidden { display: none !important; }

/* buttons ----------------------------------------------------- */
.btn {
  font-family: var(--font-ui); font-weight: 600; font-size: 0.86rem;
  border: 1px solid transparent; border-radius: 999px; padding: 0.5rem 0.95rem;
  cursor: pointer; color: var(--ink); background: transparent;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, color .15s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--brick); color: #FBF6EC; box-shadow: 0 6px 16px -8px var(--brick); }
.btn-primary:hover { background: var(--brick-deep); }
[data-theme="dark"] .btn-primary { background: var(--brick); color: #14100D; }
.btn-ghost { border-color: var(--line-strong); color: var(--ink-soft); background: var(--surface); }
.btn-ghost:hover { color: var(--ink); border-color: var(--brick); }
.btn-danger { color: var(--danger); border-color: var(--line-strong); background: transparent; }
.btn-danger:hover { background: var(--danger); color: #FBF6EC; border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.ico { padding: 0.5rem 0.7rem; }
.ghost-left { margin-right: auto; }

.select {
  font-family: var(--font-ui); font-weight: 600; font-size: 0.86rem;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 0.5rem 0.85rem; cursor: pointer; appearance: none;
}
.select:hover { border-color: var(--brick); }

/* ============================================================ LOGIN */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; padding: 2.6rem 2.2rem; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 1.1rem; position: relative; overflow: hidden;
  animation: rise .5s cubic-bezier(.2,.8,.2,1) both;
}
.login-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 6px;
  background: linear-gradient(90deg, var(--brick), var(--brass), var(--brick));
}
.brand { text-align: center; display: flex; flex-direction: column; gap: .15rem; margin-bottom: .4rem; }
.brand-deva { font-family: var(--font-display); font-weight: 600; font-size: 2.6rem; color: var(--brick); line-height: 1; }
.brand-deva.sm { font-size: 1.7rem; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.4rem; letter-spacing: .02em; }
.brand-sub { font-size: 0.78rem; color: var(--ink-soft); letter-spacing: .12em; text-transform: uppercase; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field > span { font-size: 0.74rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.field input, .drawer input, .drawer select, .modal input, .modal select {
  font-family: var(--font-ui); font-size: 0.95rem; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem; width: 100%; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .drawer input:focus, .modal input:focus { outline: none; border-color: var(--brick); box-shadow: 0 0 0 3px rgba(178,58,46,.15); }
.login-err { color: var(--danger); font-size: 0.85rem; margin: 0; text-align: center; }
.login-hint { font-size: 0.78rem; color: var(--ink-faint); text-align: center; margin: 0; }

/* ============================================================ MASTHEAD */
.masthead {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 78%, transparent 100%);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
  /* avoid hiding behind status bar on notched phones */
  padding-top: env(safe-area-inset-top, 0px);
}
.mast-inner {
  padding: 1rem clamp(.8rem, 3vw, 1.8rem) .7rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.mast-brand { display: flex; align-items: center; gap: .8rem; min-width: 0; flex: 1 1 240px; }
.brand-deva.sm { color: var(--brick); }
.mast-titles { min-width: 0; }
.mast-title {
  font-family: var(--font-display); font-weight: 600; font-size: clamp(1.3rem, 2.6vw, 1.8rem);
  margin: 0; line-height: 1.05; letter-spacing: -.01em;
}
.mast-meta { margin: .15rem 0 0; font-size: 0.74rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.mast-controls { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.ctrl-group { display: flex; align-items: center; gap: .4rem; }
.icon-group { flex-wrap: wrap; justify-content: flex-end; }
.badge-ro {
  font-size: 0.7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--brass); border: 1px solid var(--brass); padding: .3rem .6rem; border-radius: 999px;
}

/* tabs */
.tabs {
  display: flex; gap: .25rem;
  padding: 0 clamp(.8rem,3vw,1.8rem);
  /* horizontal scroll on phones when 5 tabs don't fit */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  overscroll-behavior-x: contain;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  font-family: var(--font-ui); font-weight: 600; font-size: 0.9rem; cursor: pointer;
  background: transparent; border: none; color: var(--ink-soft); padding: .6rem 1rem;
  border-radius: 0; position: relative; transition: color .15s;
  flex-shrink: 0;
  scroll-snap-align: start;
  /* touch target: minimum 44px tall on phones */
  min-height: 44px;
  display: inline-flex; align-items: center;
}
.tab::after { content: ""; position: absolute; left: 1rem; right: 1rem; bottom: 0; height: 2px; background: var(--brick); transform: scaleX(0); transform-origin: left; transition: transform .2s ease; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brick); }
.tab.active::after { transform: scaleX(1); }

/* content */
#app { display: flex; flex-direction: column; min-height: 100vh; }
.content { padding: clamp(1rem,3vw,1.8rem); flex: 1; display: flex; flex-direction: column; min-height: 0; }
/* The previous `animation: rise` on .tabpane created a transform-based containing
   block that broke position:fixed descendants (e.g. the mobile edit sheet).
   Removed — the panes transition with no animation. */
.tabpane { display: none; width: 100%; }
.tabpane.active { display: block; width: 100%; }
#tab-settings.active { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; animation: none; }

/* ============================================================ LEDGER */
.ledger-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
  /* CSS-only "scroll for more" hint: subtle gradient on right edge
     when content overflows. Uses background-attachment trick:
     local gradients follow the scroll position. */
  background:
    /* left fade — solid surface on the left edge */
    linear-gradient(to right, var(--surface) 30%, rgba(251,246,236,0)) left center / 30px 100% no-repeat,
    /* right fade — solid surface on the right edge */
    linear-gradient(to left,   var(--surface) 30%, rgba(251,246,236,0)) right center / 30px 100% no-repeat,
    var(--surface);
  background-attachment: local, local, scroll;
}
[data-theme="dark"] .ledger-scroll {
  background:
    linear-gradient(to right, var(--surface) 30%, rgba(33,26,21,0)) left center / 30px 100% no-repeat,
    linear-gradient(to left,   var(--surface) 30%, rgba(33,26,21,0)) right center / 30px 100% no-repeat,
    var(--surface);
  background-attachment: local, local, scroll;
}
.ledger {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 0.88rem; box-shadow: var(--shadow); min-width: 720px;
}
.ledger thead th {
  font-family: var(--font-ui); font-weight: 700; font-size: 0.72rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--brick); text-align: right; padding: .8rem .7rem;
  background: var(--surface-2); border-bottom: 2px solid var(--line); position: sticky; top: 0; white-space: nowrap;
}
.ledger thead th:first-child, .ledger tbody td:first-child { text-align: left; }
.ledger thead th.col-month { color: var(--ink); }
.ledger thead th .col-kind { display:block; font-size: .58rem; color: var(--ink-faint); font-weight: 500; letter-spacing:.06em; }
.ledger tbody td {
  padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: right;
  font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink);
}
.ledger tbody tr { transition: background .12s; }
.ledger tbody tr:nth-child(even) { background: var(--surface-2); }
.ledger tbody tr:hover { background: rgba(178,58,46,.05); }
.ledger tbody td.cell-month { font-weight: 700; color: var(--ink); font-family: var(--font-display); letter-spacing: .01em; }
.ledger tbody td.cell-month small { display:block; font-weight: 500; font-family: var(--font-ui); font-size: .66rem; color: var(--ink-faint); letter-spacing:.05em; }
.ledger tbody td.computed { background: var(--computed-bg); color: var(--computed-ink); font-style: italic; }
.ledger tbody td.muted { color: var(--ink-faint); }
.ledger tbody td.cell-total { font-weight: 700; color: var(--brick); }
.ledger tbody td.remark-cell { text-align: left; color: var(--ink-soft); font-style: italic; max-width: 200px; overflow:hidden; text-overflow:ellipsis; }
.ledger tbody tr.admin-row { cursor: pointer; }
.ledger tbody tr.empty-row td { color: var(--ink-faint); font-style: italic; }
.ledger tbody tr .row-edit { opacity: 0; color: var(--brick); font-size: .72rem; font-weight: 700; transition: opacity .15s; }
.ledger tbody tr.admin-row:hover .row-edit { opacity: 1; }
.ledger tbody tr.row-idle { opacity: 0.5; }
.ledger tbody tr.row-idle:nth-child(even) { background: transparent; }
.ledger tbody tr.row-idle:hover { opacity: 0.7; background: rgba(178,58,46,.03); }
.ledger tbody tr.row-idle td.cell-month { color: var(--ink-faint); }

/* foot: totals + averages */
.ledger tfoot td {
  padding: .6rem .7rem; text-align: right; font-variant-numeric: tabular-nums;
  border-top: 2px solid var(--line-strong); white-space: nowrap; font-weight: 700;
}
.ledger tfoot tr.totals td { background: var(--total-bg); color: var(--brick-deep); }
[data-theme="dark"] .ledger tfoot tr.totals td { color: var(--brass); }
.ledger tfoot tr.avgs td { background: var(--avg-bg); color: var(--ink-soft); font-weight: 600; }
.ledger tfoot td.label { text-align: left; font-family: var(--font-display); letter-spacing:.02em; }

/* ============================================================ CARDS */
.grid-cards { display: grid; gap: 1rem; grid-template-columns: repeat(2, 1fr); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem 1.3rem; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 .15rem; font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }
.card-sub { margin: 0 0 1rem; font-size: .76rem; color: var(--ink-soft); letter-spacing: .04em; }
.chart-card.wide { grid-column: 1 / -1; }
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }

/* KPIs */
.grid-kpi { display: grid; gap: 1rem; grid-template-columns: repeat(4, 1fr); margin-bottom: 1.2rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi::after { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--brass); }
.kpi-label { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); }
.kpi-value { font-family: var(--font-mono); font-weight: 600; font-size: clamp(1.3rem, 2.4vw, 1.7rem); color: var(--ink); margin-top: .3rem; }
.kpi-value small { font-family: var(--font-ui); font-size: .8rem; color: var(--ink-soft); font-weight: 500; }

.summary-table { min-width: 640px; }
.summary-table td.k { text-align: left; font-family: var(--font-display); font-weight: 600; }

/* ============================================================ DRAWER */
.scrim { position: fixed; inset: 0; background: rgba(28,18,12,.5); z-index: 50; backdrop-filter: blur(2px); animation: fade .2s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%);
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  z-index: 60; display: flex; flex-direction: column; animation: slidein .3s cubic-bezier(.2,.8,.2,1);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-family: var(--font-display); font-size: 1.3rem; }
.drawer-body { padding: 1.1rem 1.3rem; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 1.1rem; }
.field-group { display: flex; flex-direction: column; gap: .55rem; }
.field-group > legend { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--brass); padding: 0; }
.drawer-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.editor-live { font-family: var(--font-mono); font-weight: 600; color: var(--brick); font-size: 1.05rem; align-self: center; }
.editor-live small { font-family: var(--font-ui); color: var(--ink-soft); font-weight: 500; font-size: .72rem; display:block; letter-spacing:.08em; text-transform:uppercase; }
.drawer-foot { display: flex; align-items: center; gap: .6rem; padding: 1rem 1.3rem; border-top: 1px solid var(--line); }

/* ============================================================ MODAL */
.modal-backdrop { position: fixed; inset: 0; background: rgba(28,18,12,.55); z-index: 70; display: grid; place-items: center; padding: 1.2rem; animation: fade .2s; }
.modal {
  width: min(620px, 100%); max-height: 86vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 1.5rem 1.6rem; animation: rise .3s cubic-bezier(.2,.8,.2,1);
}
.modal h3 { margin: 0 0 .2rem; font-family: var(--font-display); font-size: 1.4rem; }
.modal p.sub { margin: 0 0 1.1rem; color: var(--ink-soft); font-size: .85rem; }
.modal .modal-row { display: flex; align-items: center; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.modal .modal-row:last-child { border-bottom: none; }
.modal .modal-row .grow { flex: 1; min-width: 0; }
.modal .modal-row .mono { font-family: var(--font-mono); font-size: .8rem; color: var(--ink-soft); word-break: break-all; }
.modal .field-list { display: flex; flex-direction: column; gap: .35rem; }
.field-item { display: flex; align-items: center; gap: .5rem; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.field-item .grip { color: var(--ink-faint); cursor: grab; }
.field-item .fi-label { flex: 1; font-weight: 600; }
.field-item .fi-meta { font-size: .72rem; color: var(--ink-soft); }
.field-item .fi-key { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-faint); }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.1rem; }
.modal-section { margin-top: 1.3rem; padding-top: 1rem; border-top: 1px dashed var(--line); }

/* ============================================================ TOAST */
.toast {
  position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: .7rem 1.1rem; border-radius: 999px;
  font-size: .85rem; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 90;
  animation: toastin .25s ease; max-width: 90vw; text-align: center;
  /* lift toast above iPhone home-indicator */
  bottom: calc(1.4rem + env(safe-area-inset-bottom, 0px));
}
.toast.err { background: var(--brick); color: #FBF6EC; }

/* ============================================================ ANIMATIONS */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%); } }

/* ============================================================ RESPONSIVE */
@media (max-width: 1080px) {
  .grid-cards { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .mast-inner { flex-direction: column; align-items: stretch; gap: .6rem; }
  .mast-brand { justify-content: center; text-align: center; flex-direction: column; gap: .25rem; }
  .mast-title { text-align: center; }
  .mast-controls { justify-content: center; gap: .5rem; }
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .drawer-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  /* tighter ledger, drawer goes full-width */
  .ledger { font-size: .82rem; }
  .ledger thead th, .ledger tbody td, .ledger tfoot td { padding: .5rem .5rem; }
  .drawer { width: 100%; }
  .mast-inner { padding-left: .8rem; padding-right: .8rem; }
  /* form-bar fills the row instead of staying 280px wide */
  .ledger-fbar { min-width: 0; width: 100%; }
  .ledger-toolbar { gap: .6rem; }
  .col-card { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  /* phones: single-col KPIs, stacked masthead controls, comfortable tap targets */
  .grid-kpi { grid-template-columns: 1fr; }
  .mast-controls { flex-direction: column; align-items: stretch; gap: .55rem; }
  .ctrl-group { justify-content: center; flex-wrap: wrap; }
  .icon-group { justify-content: center; }
  .tabs { padding: 0 .8rem; }
  .tab { padding: .6rem .8rem; font-size: .85rem; }
  .card { padding: 1rem .9rem; }
  .grid-cards { gap: .7rem; }
  .modal { padding: 1.2rem 1rem; }
  .modal-backdrop { padding: .7rem; }
  .login-card { padding: 2rem 1.4rem; border-radius: 16px; }
  .brand-name { font-size: 1.2rem; }
  .kpi { padding: .9rem 1rem; }
  .kpi-value { font-size: 1.25rem; }
  /* table cells: even tighter on tiny phones */
  .ledger thead th, .ledger tbody td, .ledger tfoot td { padding: .4rem .35rem; }
  .ledger { font-size: .76rem; }
}

/* ============================================================ TOUCH DEVICES */
/* Bump tap targets to 44x44 minimum on coarse-pointer devices (phones, tablets) */
@media (hover: none) and (pointer: coarse) {
  .btn { min-height: 44px; padding: .65rem 1rem; }
  .btn.ico { min-width: 44px; padding: .65rem .8rem; }
  .select { min-height: 44px; padding: .65rem 1rem; }
  .search { min-height: 44px; padding: .65rem 1rem; }
  .tab { min-height: 44px; }
  .settings-nav .chip { min-height: 44px; padding: .55rem 1rem; }
  .type-opt { min-height: 60px; padding: 1rem; }
  .col-head-add { width: 44px; height: 36px; }
  .modal-actions .btn { min-height: 44px; }
  /* disable hover lift on touch — feels wrong without hover */
  .btn:hover { transform: none; }
  /* larger modal/drawer touch targets inside rows */
  .drawer-row .btn,
  .modal .modal-row .btn { min-height: 40px; }
}

/* ============================================================ LOGO / WORDMARK */
.logo-slot, .login-logo { display: inline-flex; }
.logo-slot svg, .login-logo svg { width: 40px; height: 40px; display: block; }
.login-logo svg { width: 56px; height: 56px; }
.wordmark { font-size: .62rem; font-weight: 700; letter-spacing: .26em; color: var(--brick); }
.mast-brand { align-items: center; }

/* ============================================================ SEARCH */
.search {
  font-family: var(--font-ui); font-size: .85rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px;
  padding: .5rem .9rem; min-width: 150px; transition: border-color .15s, box-shadow .15s;
}
.search:focus { outline: none; border-color: var(--brick); box-shadow: 0 0 0 3px rgba(178,58,46,.15); }

.admin-only { } /* visibility toggled by JS adding .hidden */

/* ============================================================ ACTIVITY */
.activity-list { display: flex; flex-direction: column; }
.activity-item { display: flex; gap: .9rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: .45rem; flex: none; background: var(--brass); }
.activity-item .ai-main { flex: 1; min-width: 0; }
.activity-action { font-weight: 600; font-size: .9rem; }
.activity-action .ai-tag { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-soft); font-weight: 500; }
.activity-detail { font-size: .8rem; color: var(--ink-soft); margin-top: .1rem; word-break: break-word; }
.activity-time { font-size: .72rem; color: var(--ink-faint); font-family: var(--font-mono); white-space: nowrap; }
.activity-empty { color: var(--ink-faint); font-style: italic; padding: 1rem 0; }

/* ============================================================ SETTINGS */
.settings-nav { position: static; display: flex; gap: .4rem; flex-wrap: wrap; justify-content: center; padding: .5rem 0; background: var(--bg); border-bottom: 1px solid var(--line); }
.settings-nav .chip {
  font-size: .78rem; font-weight: 600; padding: .4rem .8rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft);
  text-decoration: none; transition: all .15s;
}
.settings-nav .chip:hover { color: var(--ink); border-color: var(--brick); }
.settings-nav .chip.active { background: var(--brick); color: #FBF6EC; border-color: var(--brick); }
.settings-body { display: flex; flex-direction: column; gap: .8rem; margin-top: .6rem; }
.settings-pages { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 0; width: 100%; }
.settings-page { display: none; width: 100%; }
.settings-page.active { display: block; width: 100%; animation: rise .35s ease both; }
.settings-page > .card { width: 100%; }
.s-row { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; padding: .6rem 0; border-bottom: 1px dashed var(--line); }
.s-row:last-child { border-bottom: none; }
.s-row .grow { flex: 1; min-width: 160px; }
.s-row .label-strong { font-weight: 600; }
.s-row .muted { color: var(--ink-soft); font-size: .82rem; }
.year-pill {
  font-family: var(--font-display); font-weight: 600; font-size: 1.05rem;
  padding: .45rem .9rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
}

/* column manager redesign */
.col-group-label { font-size: .72rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--brass); margin: .6rem 0 .3rem; }
.col-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: center;
  padding: .8rem .9rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); transition: border-color .15s, box-shadow .15s;
}
.col-card:hover { border-color: var(--brass-soft); box-shadow: var(--shadow); }
.col-card .cc-main { min-width: 0; }
.col-card .cc-label { font-weight: 600; font-size: .95rem; }
.col-card .cc-key { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-faint); }
.col-card .cc-formula { font-family: var(--font-mono); font-size: .78rem; color: var(--ink-soft); margin-top: .2rem; }
.col-card input.cc-inline { font-family: var(--font-ui); font-size: .9rem; padding: .35rem .5rem; border:1px solid var(--line-strong); border-radius:6px; background:var(--surface); width:100%; max-width: 260px; }
.col-card input.cc-inline.mono { font-family: var(--font-mono); }
.cc-meta { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; margin-top: .25rem; }
.tag { font-size: .68rem; font-weight: 600; padding: .18rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line); letter-spacing:.03em; }
.tag.t-input { color: #4E7A4A; }
.tag.t-computed { color: var(--brass); }
.tag.t-text { color: var(--ink-soft); }
.tag.t-locked { color: var(--brick); }
.cc-actions { display: flex; flex-direction: column; gap: .2rem; }
.cc-updown { display: flex; gap: .2rem; }
.col-add-card {
  margin-top: 1rem; padding: 1.1rem; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  background: var(--surface-2);
}
.type-pick { display: grid; grid-template-columns: repeat(3,1fr); gap: .6rem; margin: .6rem 0; }
.type-opt {
  cursor: pointer; padding: .8rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); text-align: center; transition: all .15s;
}
.type-opt:hover { border-color: var(--brass); }
.type-opt.sel { border-color: var(--brick); background: rgba(178,58,46,.06); }
.type-opt .to-title { font-weight: 700; font-size: .88rem; }
.type-opt .to-desc { font-size: .72rem; color: var(--ink-soft); margin-top: .15rem; }
.key-chips { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .4rem; }
.key-chip { font-family: var(--font-mono); font-size: .72rem; padding: .22rem .5rem; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); cursor: pointer; }
.key-chip:hover { border-color: var(--brick); color: var(--brick); }
.help-note { font-size: .78rem; color: var(--ink-soft); line-height: 1.5; }
.help-note code { font-family: var(--font-mono); background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }

/* share builder */
.scope-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: .6rem 0; }
.scope-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem .8rem; background: var(--bg); max-height: 220px; overflow:auto; }
.scope-box h4 { margin: 0 0 .4rem; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.checkrow { display: flex; align-items: center; gap: .45rem; padding: .25rem 0; font-size: .85rem; }
.checkrow input { width: auto; }
.share-link-row { display:flex; gap:.4rem; align-items:center; padding:.5rem 0; border-bottom:1px solid var(--line); }
.share-link-row:last-child{border-bottom:none;}
.share-link-row .mono { font-family: var(--font-mono); font-size: .76rem; color: var(--ink-soft); word-break: break-all; flex:1; }
.scope-summary { font-size:.78rem; color:var(--ink-soft); margin-top:.4rem; }
.scope-summary b { color: var(--ink); }

/* trash */
.trash-item { display:flex; align-items:center; gap:.7rem; padding:.55rem 0; border-bottom:1px solid var(--line); }
.trash-item:last-child { border-bottom:none; }
.trash-item .ti-title { font-weight:600; flex:1; }
.trash-item .ti-sub { font-size:.74rem; color:var(--ink-faint); font-family:var(--font-mono); }
.empty-state { color: var(--ink-faint); font-style: italic; padding: 1.2rem 0; text-align:center; }
.danger-card { border-color: rgba(178,58,46,.25); }

/* confirm modal */
.confirm-body { font-size: .92rem; color: var(--ink-soft); margin: .3rem 0 1.1rem; }
.confirm-body b { color: var(--ink); }

/* responsive additions */
@media (max-width: 860px) {
  .scope-grid { grid-template-columns: 1fr; }
  .type-pick { grid-template-columns: 1fr; }
  .col-card { grid-template-columns: 1fr; }
  .cc-actions { flex-direction: row; }
  .search { display: none; }
}

/* toast action + misc */
.toast.with-action { display:flex; align-items:center; gap:.7rem; }
.toast-action { background: rgba(255,255,255,.18); color: inherit; border:1px solid rgba(255,255,255,.35); border-radius:999px; padding:.25rem .7rem; font-weight:700; font-size:.78rem; cursor:pointer; }
.toast-action:hover { background: rgba(255,255,255,.3); }
.ledger .zero { color: var(--ink-faint); }
.th-calc { }
.help-note { line-height: 1.5; }

/* payment status visuals */
.sdot { display:inline-block; width:9px; height:9px; border-radius:50%; margin-right:.4rem; vertical-align:middle; background:var(--ink-faint); }
.sdot.st-settled, .sdot.st-paid { background:var(--good); }
.sdot.st-partial { background:#C8893C; }
.sdot.st-unpaid { background:var(--brick); }
.sdot.st-credit { background:#3E7DBE; }
.badge-status { font-size:.62rem; font-weight:700; letter-spacing:.06em; text-transform:uppercase; padding:.12rem .4rem; border-radius:999px; margin-right:.3rem; }
.badge-status.st-settled, .badge-status.st-paid { background:rgba(78,122,74,.16); color:var(--good); }
.badge-status.st-partial { background:rgba(200,137,60,.18); color:#9A6A22; }
.badge-status.st-unpaid { background:rgba(178,58,46,.16); color:var(--brick); }
.badge-status.st-credit { background:rgba(62,125,190,.16); color:#3E7DBE; }
.bal-due { color:var(--brick) !important; font-weight:700; }
.bal-credit { color:#3E7DBE; font-weight:700; }
.editor-live .badge-status { vertical-align:middle; }
[data-theme="dark"] .bal-credit { color:#7FB3E8; }
/* ============================================================
   EXCEL-STYLE LEDGER
   ============================================================ */
.ledger-toolbar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: .6rem; padding: .25rem 0;
}
.ledger-hint {
  font-size: .78rem; color: var(--ink-soft); line-height: 1.5;
}
.ledger-hint code { font-family: var(--font-mono); background: var(--bg); padding: .05rem .3rem; border-radius: 4px; }
.ledger-fbar {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .15rem .35rem .15rem .55rem; min-width: 280px; max-width: 100%;
  box-shadow: var(--shadow);
}
.ledger-fbar-eq {
  font-family: var(--font-display); font-weight: 600; color: var(--brass);
  font-size: 1rem; padding: 0 .25rem;
}
#ledger-fbar-input {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-size: .85rem;
  border: none; background: transparent; color: var(--ink);
  padding: .3rem .4rem; outline: none;
}

/* Editable cells */
.ledger.editable { border-collapse: separate; border-spacing: 0; }
.ledger.editable thead th { position: sticky; top: 0; z-index: 2; }
.ledger.editable tbody td.cell {
  position: relative;
  padding: .35rem .55rem;
  border: 1px solid transparent;
  border-right-color: var(--line);
  border-bottom-color: var(--line);
  min-width: 70px;
  transition: background .12s;
  cursor: text;
  outline: none;
}
.ledger.editable tbody td.cell::before {
  /* extend the click target to the full cell */
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.ledger.editable tbody td.cell:hover { background: rgba(178,58,46,.04); }
.ledger.editable tbody td.cell:focus,
.ledger.editable tbody td.cell.editing {
  background: #FFFCF1;
  box-shadow: inset 0 0 0 2px var(--brick);
  z-index: 1;
}
[data-theme="dark"] .ledger.editable tbody td.cell:focus,
[data-theme="dark"] .ledger.editable tbody td.cell.editing {
  background: rgba(178,58,46,.12);
}
.ledger.editable tbody td.cell-readonly { cursor: not-allowed; color: var(--ink-faint); }
.ledger.editable tbody td.cell-formula { background: rgba(200,137,60,.08); }
.ledger.editable tbody td.cell-formula::after {
  content: "ƒ"; position: absolute; top: 2px; right: 4px;
  font-family: var(--font-display); font-size: .7rem; color: var(--brass);
  opacity: .7;
}
.ledger.editable tbody td.cell.muted,
.ledger.editable tbody td.cell span.muted { color: var(--ink-faint); font-style: italic; }
.ledger.editable tbody td.cell.cell-empty { color: var(--ink-faint); font-style: italic; opacity: .7; }
.ledger.editable tbody td.cell.remark-cell { text-align: left; color: var(--ink-soft); font-style: italic; }
.ledger.editable tbody td.cell.cell-total { font-weight: 700; color: var(--brick); }
.ledger.editable tbody td.cell.computed { background: var(--computed-bg); color: var(--computed-ink); font-style: italic; }

/* Column header button */
.col-head-btn {
  display: inline-flex; align-items: center; gap: .25rem;
  background: none; border: none; cursor: pointer;
  font: inherit; color: inherit; padding: 0; text-align: left;
}
.col-head-btn:hover { color: var(--brick); }
.col-head-btn .col-kind { color: var(--ink-faint); }
.col-head-add {
  background: var(--surface); border: 1.5px dashed var(--line-strong);
  color: var(--ink-faint); width: 32px; height: 28px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 1.1rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.col-head-add:hover { color: var(--brick); border-color: var(--brick); }

/* Column sheet (right-side drawer) */
.col-sheet {
  position: fixed; inset: 0; z-index: 60;
  display: flex; justify-content: flex-end;
}
.col-sheet.hidden { display: none !important; }
.col-sheet-scrim {
  position: absolute; inset: 0;
  background: rgba(28,18,12,.45);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
.col-sheet-card {
  position: relative;
  width: min(420px, 100%); height: 100%; max-height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-bottom-left-radius: 18px;
  box-shadow: -16px 0 40px -16px rgba(0,0,0,.35);
  animation: sheet-in-right .3s cubic-bezier(.22,.7,.3,1) both;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet-in-right {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}
.col-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem;
  padding: .8rem 1.1rem .5rem;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.col-sheet-eyebrow {
  font-size: .65rem; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--brass);
}
.col-sheet-title {
  margin: .15rem 0 0;
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.25rem; color: var(--ink);
}
/* Close button reuses .ma-sheet-close styles (defined earlier). */
.col-sheet-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.1rem 1.1rem;
  display: flex; flex-direction: column; gap: .55rem;
}

/* Content styles (formerly .col-menu) */
.col-sheet .cm-row { display: grid; grid-template-columns: 80px 1fr; align-items: center; gap: .5rem; }
.col-sheet .cm-row > span { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); font-weight: 600; }
.col-sheet .cm-row input, .col-sheet .cm-kind-opts { font: inherit; }
.col-sheet input {
  width: 100%; padding: .35rem .5rem;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg);
  color: var(--ink); font-size: .9rem;
}
.col-sheet input:focus { outline: none; border-color: var(--brick); box-shadow: 0 0 0 3px rgba(178,58,46,.15); }
.col-sheet input.mono { font-family: var(--font-mono); font-size: .82rem; }
.col-sheet .cm-kind-opts { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .35rem; }
.col-sheet .cm-kind-opt {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: .35rem .4rem; cursor: pointer; font-size: .78rem; font-weight: 600;
  color: var(--ink-soft);
}
.col-sheet .cm-kind-opt.sel { background: rgba(178,58,46,.08); color: var(--brick); border-color: var(--brick); }
.col-sheet .cm-kind-opt:disabled { opacity: .5; cursor: not-allowed; }
.col-sheet .cm-formula.hidden { display: none; }
.col-sheet .cm-check.hidden { display: none; }
.col-sheet .cm-check input[type="checkbox"] { width: auto; justify-self: start; }
.col-sheet .cm-actions { display: flex; gap: .4rem; justify-content: space-between; padding-top: .35rem; border-top: 1px dashed var(--line); }
.col-sheet .cm-foot { display: flex; justify-content: flex-end; padding-top: .35rem; border-top: 1px dashed var(--line); }
.col-sheet .help-note { margin: 0; }

/* Columns list popover (sheet body) */
.col-sheet .cm-list-section { display: flex; flex-direction: column; gap: .15rem; }
.col-sheet .cm-list-head { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); margin-top: .25rem; }
.col-sheet .cm-list-row { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: .4rem; padding: .25rem .35rem; border-radius: 5px; cursor: pointer; }
.col-sheet .cm-list-row:hover { background: var(--bg); }
.col-sheet .cm-list-row .cm-list-icon { font-family: var(--font-mono); color: var(--brass); width: 14px; text-align: center; }
.col-sheet .cm-list-row .cm-list-label { font-size: .88rem; font-weight: 600; }
.col-sheet .cm-list-row .cm-list-key { font-family: var(--font-mono); font-size: .7rem; color: var(--ink-faint); }
.col-sheet .cm-list-row input[type="checkbox"] { margin: 0; }

/* Make settings pages work as a single scroll page */
.settings-pages { display: flex; flex-direction: column; gap: 1rem; }
.settings-page { display: none; }
.settings-page.active { display: block; }

/* Settings nav uses buttons in the new HTML */
.settings-nav .chip { background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft); border-radius: 999px; padding: .35rem .8rem; cursor: pointer; font: inherit; font-size: .82rem; }
.settings-nav .chip:hover { color: var(--ink); border-color: var(--brick); }
.settings-nav .chip.active { background: var(--brick); color: #FBF6EC; border-color: var(--brick); }

/* Columns list popover */









/* Sequential-month lock */
.ledger.editable tbody tr.row-locked td { background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(178,58,46,.04) 6px 7px); }
.ledger.editable tbody td.cell.cell-locked { cursor: not-allowed; color: var(--ink-faint); user-select: none; }
.ledger.editable tbody td.cell.cell-locked:hover { background: rgba(178,58,46,.06); }
.ledger.editable tbody td.cell-month .lock-glyph { font-size: .8rem; margin-left: .3rem; opacity: .7; }

/* ============================================================
   MOBILE SHARE — phone-first stacked read-only layout
   Activated when role=share and viewport ≤ 640px (see app.js).
   Coherent with the Bhaktapur aesthetic: brick, brass, paper.
   ============================================================ */
#tab-share-mobile { display: none; padding: 0; }
#tab-share-mobile.active { display: block; animation: rise .35s ease both; }

.ms-shell {
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 1.1rem 1rem 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  /* Fill the pane so the footer can stick to the bottom on short content
     (single-month / no-billings shared views) instead of floating mid-page. */
  flex: 1 0 auto;
  min-height: 0;
}

/* ---- header card ---- */
.ms-head {
  position: relative;
  background:
    radial-gradient(120% 80% at 0% 0%, rgba(178,58,46,.10), transparent 60%),
    radial-gradient(120% 80% at 100% 100%, rgba(200,137,60,.10), transparent 60%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.1rem 1.1rem 0.9rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ms-head::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: linear-gradient(90deg, var(--brick), var(--brass), var(--brick));
  opacity: .8;
}
.ms-head-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem; margin-bottom: .4rem;
}
.ms-label {
  font-size: .66rem; font-weight: 700; letter-spacing: .18em;
  text-transform: uppercase; color: var(--brick);
}
.ms-badge-ro {
  font-family: var(--font-mono); font-weight: 600;
  font-size: .72rem; letter-spacing: .04em;
  color: var(--brass);
  background: rgba(200,137,60,.10);
  border: 1px solid rgba(200,137,60,.35);
  padding: .25rem .55rem; border-radius: 999px;
}
.ms-title {
  margin: .1rem 0 .25rem;
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.65rem; line-height: 1.1; color: var(--ink);
}
.ms-sub {
  margin: 0 0 .9rem; font-size: .82rem; color: var(--ink-soft);
}

/* year picker (chip strip, horizontally scrollable) */
.ms-year-picker {
  display: flex; gap: .4rem;
  overflow-x: auto;
  margin: 0 -1.1rem;
  padding: .25rem 1.1rem .85rem;
  scrollbar-width: none;
}
.ms-year-picker::-webkit-scrollbar { display: none; }
.ms-year-chip {
  flex: none;
  font-family: var(--font-mono); font-weight: 600;
  font-size: .82rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: .45rem .85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.ms-year-chip:hover { color: var(--ink); border-color: var(--brass); }
.ms-year-chip.active {
  background: var(--brick); color: #FBF6EC; border-color: var(--brick);
  box-shadow: 0 6px 16px -8px var(--brick);
}

/* ---- KPI strip ---- */
.ms-kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .55rem;
}
.ms-kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .7rem .8rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.ms-kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brass);
}
.ms-kpi.ms-kpi-due::before { background: var(--brick); }
.ms-kpi.ms-kpi-credit::before { background: #3E7DBE; }
.ms-kpi-label {
  font-size: .62rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-soft); font-weight: 600;
}
.ms-kpi-value {
  font-family: var(--font-mono); font-weight: 600;
  font-size: 1.05rem; color: var(--ink);
  margin-top: .2rem;
  line-height: 1.15;
}
.ms-kpi-value small {
  display: block; font-family: var(--font-ui); font-weight: 500;
  font-size: .68rem; color: var(--ink-faint); margin-top: .1rem;
}
.ms-kpi.ms-kpi-due .ms-kpi-value { color: var(--brick); }
.ms-kpi.ms-kpi-credit .ms-kpi-value { color: #3E7DBE; }

/* ---- month list ---- */
.ms-months {
  list-style: none;
  margin: 0; padding: 0;
  display: flex; flex-direction: column;
  gap: .55rem;
}
.ms-month {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.ms-month.open { box-shadow: 0 10px 28px -16px rgba(178,58,46,.45); }
.ms-month-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem;
  padding: .85rem 1rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.ms-month-head:hover { background: rgba(178,58,46,.04); }
.ms-month-name {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.02rem; letter-spacing: .02em;
  color: var(--ink);
  display: flex; align-items: center; gap: .55rem;
}
.ms-month-name .sdot { width: 8px; height: 8px; }
.ms-month-empty .ms-month-name { color: var(--ink-faint); font-style: italic; }
.ms-month-total {
  font-family: var(--font-mono); font-weight: 700;
  font-size: 1rem; color: var(--brick);
  white-space: nowrap;
}
.ms-month-total.muted { color: var(--ink-faint); font-weight: 500; }
.ms-month-total.credit { color: #3E7DBE; }
.ms-month-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: .05rem;
}
.ms-month-meta small {
  font-family: var(--font-mono); font-size: .66rem; color: var(--ink-faint);
}
.ms-caret {
  width: 12px; height: 12px;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg);
  margin-left: .3rem;
  transition: transform .15s ease;
  flex: none;
}
.ms-month.open .ms-caret { transform: rotate(225deg); }

.ms-month-body {
  display: none;
  padding: 0 1rem 1rem;
  border-top: 1px dashed var(--line);
}
.ms-month.open .ms-month-body { display: block; animation: rise .25s ease both; }

.ms-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .8rem;
  padding: .55rem 0;
  border-bottom: 1px dashed var(--line);
}
.ms-row:last-child { border-bottom: none; }
.ms-row-label {
  font-size: .82rem; color: var(--ink-soft);
  display: flex; flex-direction: column; gap: .05rem;
  min-width: 0;
}
.ms-row-label b {
  font-weight: 600; color: var(--ink); font-size: .88rem;
  font-family: var(--font-ui);
}
.ms-row-label small {
  font-size: .65rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint);
}
.ms-row-value {
  font-family: var(--font-mono); font-weight: 600;
  font-size: .95rem; color: var(--ink);
  text-align: right; white-space: nowrap;
}
.ms-row-value.muted { color: var(--ink-faint); font-style: italic; font-weight: 400; }
.ms-row-value.computed {
  color: var(--computed-ink, var(--brass)); font-style: italic;
}
.ms-row-value.tot {
  color: var(--brick); font-weight: 700;
}
.ms-row-value.due { color: var(--brick); font-weight: 700; }
.ms-row-value.credit { color: #3E7DBE; font-weight: 700; }
.ms-remark {
  margin-top: .6rem;
  padding: .65rem .8rem;
  background: var(--bg);
  border-radius: 10px;
  font-style: italic; color: var(--ink-soft);
  font-size: .85rem; line-height: 1.45;
}
.ms-remark:empty { display: none; }

/* ---- footer ---- */
.ms-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem;
  padding-top: .8rem;
  border-top: 1px dashed var(--line);
  margin-top: auto;
  flex: 0 0 auto;
}
.ms-foot-credit {
  display: inline-flex; align-items: center; gap: .45rem;
  font-size: .76rem; color: var(--ink-soft);
  letter-spacing: .02em;
}
.ms-foot-credit b { color: var(--ink); font-weight: 700; }
.ms-foot-credit #ms-credit-year {
  font-family: var(--font-mono); font-weight: 600;
  color: var(--brick);
}
.ms-exit-btn {
  font-family: var(--font-ui); font-weight: 600;
  font-size: .82rem;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  padding: .55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ms-exit-btn:hover { color: var(--ink); border-color: var(--brick); }
.ms-exit-btn:active { transform: translateY(1px); }

/* ---- desktop: mobile share stays hidden ---- */
@media (min-width: 641px) {
  #tab-share-mobile { display: none !important; }
}

/* ---- small phone refinements ---- */
@media (max-width: 420px) {
  .ms-shell { padding: .9rem .85rem 1.3rem; gap: .9rem; }
  .ms-title { font-size: 1.45rem; }
  .ms-kpis { grid-template-columns: 1fr; }
  .ms-month-head { padding: .75rem .85rem; }
  .ms-month-body { padding: 0 .85rem .9rem; }
  .ms-row-label b { font-size: .85rem; }
  .ms-row-value { font-size: .92rem; }
}

/* On mobile-share: hide the desktop masthead + tabs entirely so the
   shared link feels like its own app, not a broken admin shell. */
@media (max-width: 640px) {
  body.ms-mode .masthead { display: none; }
  body.ms-mode .content { padding: 0; }
}
body.ms-mode #app { min-height: 100vh; }

/* ---- bulb (footer credit) ---- */
.ms-bulb {
  width: 18px; height: 18px; flex: none;
  overflow: visible;
  filter: drop-shadow(0 0 0 rgba(232, 168, 36, 0));
  animation: bulb-pulse 2.6s ease-in-out infinite;
}
.ms-bulb .bulb-base {
  fill: var(--brass);
  stroke: var(--brick-deep);
  stroke-width: 0.4;
  stroke-linejoin: round;
}
.ms-bulb .bulb-glow {
  fill: var(--brass);
  opacity: 0.65;
  animation: bulb-flicker 1.8s ease-in-out infinite;
}
.ms-bulb .bulb-filament {
  stroke: var(--brick);
  stroke-width: 0.9;
  stroke-linecap: round;
  fill: none;
  animation: bulb-glow 2.6s ease-in-out infinite;
}
.ms-bulb .bulb-rays {
  stroke: var(--brass);
  stroke-width: 1.4;
  stroke-linecap: round;
  fill: none;
  opacity: 0;
  transform-origin: 12px 12px;
  animation: bulb-rays 2.6s ease-in-out infinite;
}
@keyframes bulb-pulse {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(232, 168, 36, 0)); }
  50%      { filter: drop-shadow(0 0 4px rgba(232, 168, 36, .55)); }
}
@keyframes bulb-flicker {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 0.95; }
}
@keyframes bulb-glow {
  0%, 100% { stroke: var(--brick); opacity: 0.7; }
  50%      { stroke: var(--brass); opacity: 1; }
}
@keyframes bulb-rays {
  0%, 100% { opacity: 0; transform: scale(.85); }
  45%      { opacity: .85; transform: scale(1); }
  60%      { opacity: .55; transform: scale(1.05); }
}
@media (prefers-reduced-motion: reduce) {
  .ms-bulb, .ms-bulb .bulb-glow, .ms-bulb .bulb-filament, .ms-bulb .bulb-rays {
    animation: none;
  }
}

/* dark theme touch-ups */
[data-theme="dark"] .ms-month { background: var(--surface); }
[data-theme="dark"] .ms-kpi { background: var(--surface); }
[data-theme="dark"] .ms-remark { background: rgba(255,255,255,.03); }
[data-theme="dark"] .ms-year-chip { background: rgba(255,255,255,.04); }

/* ============================================================
   GLOBAL CREDIT BAR — pinned to viewport bottom in every view
   (mobile share, mobile admin, and desktop admin). The bar uses
   a glassy surface so page content scrolls underneath it.
   ============================================================ */
.app-credit {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  padding: .5rem 1rem calc(.5rem + env(safe-area-inset-bottom));
  background: rgba(251, 246, 236, .88);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px -16px rgba(0,0,0,.25);
  pointer-events: none;
  font-family: var(--font-ui);
}
.app-credit.hidden { display: none !important; }
.app-credit-inner {
  display: inline-flex; align-items: center; gap: .5rem;
  font-size: .78rem;
  color: var(--ink-soft);
  letter-spacing: .02em;
}
.app-credit-inner b { color: var(--ink); font-weight: 700; }
.app-credit-inner #app-credit-year {
  font-family: var(--font-mono); font-weight: 600;
  color: var(--brick);
}
[data-theme="dark"] .app-credit {
  background: rgba(20, 16, 13, .85);
  border-top-color: var(--line);
}
/* Reserve scroll space so the credit bar never covers the last row. */
body { padding-bottom: 56px; }
/* Hide the in-flow legacy footer (ms-foot) since the fixed bar replaces it. */
.ms-foot { display: none; }
/* ============================================================
   MOBILE ADMIN — phone-first interactive editor
   Reuses the share view's vocabulary (ms-*) and adds interactive
   affordances: tappable cards, sticky bottom bar, edit sheet.
   ============================================================ */
#tab-admin-mobile,
#tab-admin-settings { display: none; padding: 0; }
#tab-admin-mobile.active,
#tab-admin-settings.active { display: block; }
/* The rise animation creates a stacking context that turns these panes into
   the containing block for any position:fixed descendants (e.g. the edit
   sheet). Skip the animation on mobile panes so the sheet anchors to the
   viewport, not the pane. */
@media (min-width: 641px) {
  #tab-admin-mobile,
  #tab-admin-settings { display: none !important; }
}

/* admin header — selectors, year picker, toolbar */
.ms-head-admin .ma-selectors {
  display: grid; grid-template-columns: 1fr 1fr; gap: .55rem;
  margin: .25rem 0 .9rem;
}
.ma-sel { display: flex; flex-direction: column; gap: .25rem; }
.ma-sel > span {
  font-size: .6rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-soft);
}
.ma-sel-input {
  font: inherit; font-weight: 600; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .65rem;
  min-height: 44px;
  width: 100%;
  -webkit-appearance: none; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 12px) center;
  background-size: 6px 6px;
  background-repeat: no-repeat;
}
.ma-year-picker {
  display: flex; gap: .4rem;
  overflow-x: auto;
  margin: 0 -1.1rem;
  padding: .25rem 1.1rem .85rem;
  scrollbar-width: none;
}
.ma-year-picker::-webkit-scrollbar { display: none; }
.ma-year-picker .ms-year-chip {
  /* identical styling — same class */
}
.ma-toolbar {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-top: -.3rem;
}
.ma-tb-btn {
  font: inherit; font-weight: 600; font-size: .78rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: .45rem .7rem;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ma-tb-btn:hover { color: var(--ink); border-color: var(--brick); }

/* search box */
.ma-search {
  display: flex; align-items: center; gap: .4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .25rem .6rem;
  box-shadow: var(--shadow);
}
.ma-search-input {
  flex: 1; min-width: 0;
  font: inherit; color: var(--ink);
  background: transparent; border: 0; outline: 0;
  padding: .55rem 0;
  -webkit-appearance: none; appearance: none;
}
.ma-search-clear {
  font: inherit; font-weight: 700;
  color: var(--ink-soft);
  background: transparent; border: 0;
  padding: .35rem .5rem; border-radius: 8px;
  cursor: pointer;
}

/* month cards — same shape as share view, but interactive */
.ms-month { cursor: pointer; }
.ms-month-head:active { transform: scale(.99); }
.ms-month-add { /* empty-month "+ Add record" hint */
  font-family: var(--font-ui); font-weight: 600;
  font-size: .82rem; color: var(--brick);
  background: rgba(178,58,46,.08);
  padding: .35rem .7rem; border-radius: 999px;
  white-space: nowrap;
}

/* sticky bottom action bar */
.ma-bottombar {
  position: sticky; bottom: 36px; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr 1fr 1fr 56px;
  gap: .4rem;
  padding: .6rem .65rem calc(.6rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 22px -16px rgba(0,0,0,.18);
  z-index: 5;
}
.ma-bb-btn {
  font: inherit; font-weight: 600; font-size: .82rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: .7rem .55rem;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}
.ma-bb-btn:hover { color: var(--ink); border-color: var(--brick); }
.ma-bb-fab {
  background: var(--brick); color: #FBF6EC; border-color: var(--brick);
  font-size: 1.4rem; line-height: 1; padding: 0;
  box-shadow: 0 6px 18px -8px var(--brick);
}
.ma-bb-fab:hover { background: var(--brick-deep); }
[data-theme="dark"] .ma-bb-fab { color: #14100D; }

/* ============================================================
   EDIT SHEET — bottom-sheet modal for editing a month
   ============================================================ */
.ma-sheet {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end;
}
.ma-sheet.hidden { display: none !important; }
.ma-sheet-scrim {
  position: absolute; inset: 0;
  background: rgba(28,18,12,.45);
  backdrop-filter: blur(2px);
  animation: fade .2s ease;
}
.ma-sheet-card {
  position: relative;
  width: 100%;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  box-shadow: 0 -16px 40px -16px rgba(0,0,0,.35);
  animation: sheet-up .3s cubic-bezier(.22,.7,.3,1) both;
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheet-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.ma-sheet-grab {
  width: 42px; height: 4px; border-radius: 999px;
  background: var(--line-strong);
  margin: .55rem auto -.1rem;
  flex: none;
}
.ma-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem;
  padding: .8rem 1.1rem .5rem;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.ma-sheet-eyebrow {
  font-size: .65rem; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--brass);
}
.ma-sheet-title {
  margin: .15rem 0 0;
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.25rem; color: var(--ink);
}
.ma-sheet-close {
  font: inherit; font-weight: 700; font-size: .95rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  width: 38px; height: 38px;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ma-sheet-close:hover { color: var(--ink); border-color: var(--brick); }

.ma-sheet-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.1rem 1.1rem;
  display: flex; flex-direction: column; gap: 1rem;
}
.ma-form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .55rem;
}
.ma-field {
  display: flex; flex-direction: column; gap: .25rem;
}
.ma-field > span {
  font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-soft);
}
.ma-field input,
.ma-field textarea,
.ma-form-custom input,
.ma-form-custom textarea {
  font: inherit; font-size: .95rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .65rem .75rem;
  min-height: 44px;
  width: 100%;
  -webkit-appearance: none; appearance: none;
}
.ma-field input[type="number"] { font-family: var(--font-mono); }
.ma-field textarea,
.ma-form-custom textarea { font-family: var(--font-ui); resize: vertical; }
.ma-field input:focus,
.ma-field textarea:focus,
.ma-form-custom input:focus,
.ma-form-custom textarea:focus {
  outline: none;
  border-color: var(--brick);
  box-shadow: 0 0 0 3px rgba(178,58,46,.15);
}
.ma-form-remark .ma-field { gap: .35rem; }
.ma-form-remark textarea { min-height: 64px; }

/* computed preview (read-only computed row in the sheet) */
.ma-computed-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .8rem;
  background: var(--bg);
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: .82rem;
  color: var(--ink-soft);
}
.ma-computed-row b {
  color: var(--brick); font-weight: 700; font-family: var(--font-mono);
}

/* sheet footer */
.ma-sheet-foot {
  display: flex; align-items: center; gap: .5rem;
  padding: .8rem 1.1rem;
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}
.ma-sheet-spacer { flex: 1; }
.ma-btn {
  font: inherit; font-weight: 600; font-size: .9rem;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line-strong);
  padding: .7rem 1rem;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.ma-btn:hover { border-color: var(--brick); }
.ma-btn-primary {
  background: var(--brick); color: #FBF6EC; border-color: var(--brick);
  box-shadow: 0 6px 16px -8px var(--brick);
}
.ma-btn-primary:hover { background: var(--brick-deep); }
[data-theme="dark"] .ma-btn-primary { color: #14100D; }
.ma-btn-danger {
  color: var(--danger); border-color: rgba(178,58,46,.4);
}
.ma-btn-danger:hover { background: var(--danger); color: #FBF6EC; border-color: var(--danger); }

/* ============================================================
   MOBILE ADMIN SETTINGS — drawer with the 5 settings pages
   ============================================================ */
.ma-settings-tabs {
  display: flex; flex-wrap: wrap; gap: .35rem;
  margin-top: .5rem;
}
.ma-st-tab {
  font: inherit; font-weight: 600; font-size: .78rem;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: .5rem .8rem;
  border-radius: 999px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 40px;
}
.ma-st-tab:hover { color: var(--ink); border-color: var(--brass); }
.ma-st-tab.active {
  background: var(--brick); color: #FBF6EC; border-color: var(--brick);
}
.ma-settings-pages { display: flex; flex-direction: column; gap: 1rem; }
.ma-settings-page { display: none; }
.ma-settings-page.active { display: block; }
.ma-settings-page > * { width: 100%; }
/* Reuse the existing settings markup but make it mobile-friendly */
#tab-admin-settings .card { padding: 1rem .9rem; }
#tab-admin-settings .s-row { flex-direction: column; align-items: flex-start; }
#tab-admin-settings .scope-grid { grid-template-columns: 1fr; }
.ma-btn-danger {
  color: var(--danger); border-color: rgba(178,58,46,.4);
}
.ma-btn-danger:hover { background: var(--danger); color: #FBF6EC; border-color: var(--danger); }
.ma-custom-title {
  margin: 0 0 .35rem;
  font-size: .68rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--brass);
}
.ma-custom-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .55rem;
}
.ma-form-remark { display: flex; }
.ma-form-remark .ma-field { flex: 1; }
#ma-sheet-preview { display: flex; flex-direction: column; gap: .35rem; }
body.ma-mode #app { min-height: 100vh; }
@media (max-width: 640px) {
  body.ma-mode .masthead { display: none; }
  body.ma-mode .content { padding: 0; }
}
