/* ===========================================================================
   ALMOND Finance — warm cream / terracotta theme
   Fonts: Playfair Display (headings), Nunito (body), DM Mono (labels)
   =========================================================================== */

:root {
  /* Palette */
  --bg:        #fdf6ee;
  --surface:   #ffffff;
  --surface-2: #fbf2e8;
  --accent:    #c9622a;   /* terracotta */
  --accent-dk: #a84e1f;
  --accent-sf: #f6e4d6;   /* accent tint surface */
  --ink:       #2e2620;
  --ink-soft:  #6b5d52;
  --ink-faint: #a2958a;
  --line:      #ece0d3;
  --line-strong:#dccab8;

  /* Type badges */
  --badge-bill:    #2f6fb0;  --badge-bill-bg:    #e6f0f9;
  --badge-loan:    #7a4fb0;  --badge-loan-bg:    #efe7f7;
  --badge-plan:    #1f8f86;  --badge-plan-bg:    #def0ee;
  --badge-arrears: #c0392b;  --badge-arrears-bg: #fae6e3;

  /* Priority dots */
  --pri-critical:      #d63a2f;
  --pri-essential:     #e8772a;
  --pri-committed:     #e6b325;
  --pri-discretionary: #4f9d52;

  /* Status */
  --ok:   #4f9d52;
  --warn: #e8772a;
  --err:  #d63a2f;

  /* Shape & motion */
  --radius:   14px;
  --radius-sm:10px;
  --shadow:   0 2px 8px rgba(80, 50, 25, 0.06), 0 8px 24px rgba(80, 50, 25, 0.05);
  --shadow-lg:0 10px 40px rgba(80, 50, 25, 0.14);

  --header-h: 60px;
  --tabbar-h: 60px;
  --income-h: 60px;

  --ff-head: 'Playfair Display', Georgia, serif;
  --ff-body: 'Nunito', system-ui, -apple-system, sans-serif;
  --ff-mono: 'DM Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ff-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Global guard: no single element may drag the page sideways. Horizontal
   scrolling for wide content (the desktop entries table) happens INSIDE its
   own overflow-x container (.entries-table-wrap), never on the document. */
html, body { overflow-x: hidden; max-width: 100%; }

h1, h2, h3, h4 { font-family: var(--ff-head); font-weight: 600; margin: 0; color: var(--ink); }
a { color: var(--accent); text-decoration: none; }

[hidden] { display: none !important; }

/* ===================== Buttons ===================== */
.btn {
  font-family: var(--ff-body);
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dk); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-small { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

/* ===================== Login ===================== */
.login-screen {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--accent-sf), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2.2rem 1.8rem;
  text-align: center;
  display: flex; flex-direction: column;
}
.login-mark { font-size: 2.4rem; line-height: 1; }
.login-title {
  font-size: 2rem; letter-spacing: 0.14em; margin-top: 0.5rem; color: var(--accent);
}
.login-sub {
  font-family: var(--ff-mono); font-size: 0.8rem; letter-spacing: 0.3em;
  text-transform: uppercase; color: var(--ink-faint); margin: 0.1rem 0 1.6rem;
}
.login-label {
  font-family: var(--ff-mono); font-size: 0.72rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-soft); text-align: left; margin-bottom: 0.4rem;
}
.login-input, .input {
  font-family: var(--ff-body); font-size: 1rem;
  width: 100%; padding: 0.75rem 0.9rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.login-input:focus, .input:focus {
  outline: none; border-color: var(--accent);
  background: #fff; box-shadow: 0 0 0 3px var(--accent-sf);
}
.login-btn { margin-top: 1.2rem; padding: 0.8rem; font-size: 1rem; }
.login-error {
  color: var(--err); font-size: 0.88rem; font-weight: 600; margin: 0.9rem 0 0;
}

/* ===================== App shell ===================== */
.app {
  min-height: 100%;
  display: flex; flex-direction: column;
  padding-bottom: calc(var(--income-h) + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky; top: 0; z-index: 30;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1rem;
  background: rgba(253, 246, 238, 0.88);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 0.45rem; }
.brand-mark { font-size: 1.4rem; }
.brand-name {
  font-family: var(--ff-head); font-weight: 700; font-size: 1.35rem;
  letter-spacing: 0.08em; color: var(--accent);
}
.brand-sub {
  font-family: var(--ff-mono); font-size: 0.68rem; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ink-faint);
}
.header-right { display: flex; align-items: center; gap: 0.6rem; }
.cycle-pill {
  font-family: var(--ff-mono); font-size: 0.72rem; color: var(--ink-soft);
  background: var(--accent-sf); border: 1px solid var(--line-strong);
  padding: 0.3rem 0.7rem; border-radius: 999px; white-space: nowrap;
}

/* ---- Budget switcher ---- */
.budget-switcher { position: relative; }
.bs-toggle {
  display: flex; align-items: center; gap: 0.35rem; cursor: pointer;
  font-family: var(--ff-body); font-size: 0.82rem; font-weight: 700; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  padding: 0.32rem 0.6rem; border-radius: 999px; max-width: 190px;
}
.bs-toggle:hover { border-color: var(--accent); }
.bs-tlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bs-caret { color: var(--ink-faint); font-size: 0.7rem; }
.bs-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60; width: 250px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 0.35rem;
}
.bs-row { display: flex; align-items: center; gap: 0.2rem; }
.bs-item {
  flex: 1; display: flex; align-items: center; gap: 0.5rem; text-align: left;
  background: none; border: none; cursor: pointer; width: 100%;
  font-family: var(--ff-body); font-size: 0.9rem; color: var(--ink);
  padding: 0.5rem 0.55rem; border-radius: var(--radius-sm);
}
.bs-item:hover { background: var(--surface-2); }
.bs-item.selected { background: var(--accent-sf); }
.bs-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bs-count {
  font-family: var(--ff-mono); font-size: 0.68rem; color: var(--ink-faint);
  background: var(--surface-2); padding: 0.05rem 0.4rem; border-radius: 999px;
}
.bs-check { color: var(--accent); font-weight: 700; width: 0.9rem; text-align: center; }
.bs-rename {
  flex: none; background: none; border: none; cursor: pointer; color: var(--ink-faint);
  font-size: 0.85rem; padding: 0.3rem 0.35rem; border-radius: var(--radius-sm);
}
.bs-rename:hover { color: var(--accent-dk); background: var(--accent-sf); }
.bs-divider { height: 1px; background: var(--line); margin: 0.3rem 0.2rem; }
.bs-new { color: var(--accent-dk); font-weight: 700; }
.bs-cap { font-size: 0.78rem; color: var(--ink-faint); padding: 0.45rem 0.55rem; }
.bs-newbox { padding: 0; }
.bs-form { display: flex; gap: 0.35rem; padding: 0.3rem; }
.bs-form input {
  flex: 1; min-width: 0; font-family: var(--ff-body); font-size: 0.88rem;
  padding: 0.4rem 0.5rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.bs-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-sf); }
.bs-err { color: var(--err); font-size: 0.8rem; padding: 0.1rem 0.4rem 0.4rem; }

/* ===================== Tab bar ===================== */
.tabbar {
  position: sticky; top: var(--header-h); z-index: 20;
  height: var(--tabbar-h);
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 0.25rem;
}
.tab {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  color: var(--ink-faint);
  font-weight: 600; font-size: 0.72rem;
  border-bottom: 2.5px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-icon { font-size: 1.15rem; line-height: 1; }
.tab:hover { color: var(--ink-soft); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-label { letter-spacing: 0.02em; }

/* ===================== Views ===================== */
.view {
  flex: 1;
  width: 100%; max-width: 880px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}
.view-title {
  font-size: 1.6rem; margin-bottom: 0.25rem;
}
.view-sub {
  font-family: var(--ff-mono); font-size: 0.74rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 1.2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
}
.placeholder {
  text-align: center; color: var(--ink-faint);
  padding: 3rem 1rem;
}
.placeholder-icon { font-size: 2.4rem; display: block; margin-bottom: 0.6rem; opacity: 0.6; }

/* ===================== Badges & dots ===================== */
.badge {
  font-family: var(--ff-mono); font-size: 0.68rem; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.18rem 0.5rem; border-radius: 6px; white-space: nowrap;
}
.badge-bill    { color: var(--badge-bill);    background: var(--badge-bill-bg); }
.badge-loan    { color: var(--badge-loan);    background: var(--badge-loan-bg); }
.badge-plan    { color: var(--badge-plan);    background: var(--badge-plan-bg); }
.badge-arrears { color: var(--badge-arrears); background: var(--badge-arrears-bg); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.dot-critical      { background: var(--pri-critical); }
.dot-essential     { background: var(--pri-essential); }
.dot-committed     { background: var(--pri-committed); }
.dot-discretionary { background: var(--pri-discretionary); }

/* ===================== Income footer ===================== */
.income-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--income-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line-strong);
  box-shadow: 0 -4px 20px rgba(80, 50, 25, 0.06);
}
.income-bar-inner {
  height: var(--income-h);
  max-width: 880px; margin: 0 auto;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1rem;
}
.income-label {
  font-family: var(--ff-mono); font-size: 0.72rem; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--ink-soft); white-space: nowrap;
}
/* Income-sources editor (floating popup, anchored in the viewport) */
.income-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.4);   /* plain dim — NO blur (the popup must stay sharp) */
}
.income-editor { display: none; }
.income-editor.open {
  display: block; position: fixed; z-index: 71;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(440px, 92vw); max-height: 78vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 1.1rem;
}
.ise { display: flex; flex-direction: column; gap: 0.7rem; width: 100%; }
.ise-head { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95rem; color: var(--ink); }
.ise-htitle, .ise-for { font-size: 0.95rem; }
.ise-for { color: var(--ink-soft); }
.ise-budget {
  font-family: var(--ff-body); font-size: 0.92rem; font-weight: 700; color: var(--ink);
  padding: 0.3rem 0.5rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface);
}
.ise-x {
  margin-left: auto; flex: none; background: none; border: none; cursor: pointer;
  font-size: 1.3rem; line-height: 1; color: var(--ink-faint); padding: 0 0.2rem;
}
.ise-x:hover { color: var(--accent-dk); }
.ise-rows { display: flex; flex-direction: column; gap: 0.45rem; }
.ise-row { display: flex; align-items: center; gap: 0.45rem; }
.ise-name {
  flex: 1; min-width: 0; font-family: var(--ff-body); font-size: 0.92rem;
  padding: 0.45rem 0.55rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink);
}
.ise-cur { font-family: var(--ff-mono); color: var(--ink-soft); font-size: 0.92rem; }
.ise-amt {
  width: 104px; font-family: var(--ff-mono); font-size: 0.92rem;
  padding: 0.45rem 0.55rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink);
}
.ise-name:focus, .ise-amt:focus, .ise-budget:focus {
  outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-sf);
}
.ise-del {
  flex: none; background: none; border: 1px solid #f0cfca; color: var(--err);
  width: 30px; height: 30px; border-radius: var(--radius-sm); cursor: pointer; font-size: 1.05rem; line-height: 1;
}
.ise-del:hover { background: var(--badge-arrears-bg); }
.ise-empty { font-size: 0.88rem; color: var(--ink-faint); padding: 0.3rem 0; }
.ise-foot { display: flex; align-items: center; gap: 0.6rem; padding-top: 0.2rem; border-top: 1px solid var(--line); margin-top: 0.2rem; }
.ise-total { font-family: var(--ff-head); font-size: 1rem; color: var(--accent-dk); }
.ise-foot .btn-primary { margin-left: auto; }
.ise-foot .ise-max { margin-left: auto; }
.ise-max { font-size: 0.8rem; color: var(--ink-faint); }
.ise-readonly { font-size: 0.9rem; color: var(--ink-soft); line-height: 1.45; }
.ise-err { color: var(--err); font-size: 0.84rem; }

/* ===================== Toast ===================== */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--income-h) + 1rem);
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink); color: #fff;
  padding: 0.7rem 1.1rem; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease;
}
.toast.toast-err { background: var(--err); }
.toast.toast-ok  { background: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ===================== Utilities ===================== */
.mono { font-family: var(--ff-mono); }
.muted { color: var(--ink-faint); }
.row { display: flex; align-items: center; gap: 0.6rem; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 2.5rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Dashboard ===================== */
.dash-section { margin-bottom: 1.3rem; }
.section-label {
  font-family: var(--ff-mono); font-size: 0.72rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-faint); margin: 0 0 0.6rem 0.1rem;
}

/* New-cycle banner */
.cyc-banner {
  display: flex; align-items: center; gap: 0.7rem;
  background: linear-gradient(135deg, var(--accent-sf), var(--surface));
  border: 1px solid var(--accent); border-left: 4px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0.85rem 1rem 0.85rem 0.9rem;
}
.cyc-banner-icon { font-size: 1.25rem; flex: none; line-height: 1; }
.cyc-banner-text { flex: 1; font-size: 0.92rem; color: var(--ink); line-height: 1.4; }
.cyc-banner-text b { font-weight: 700; }
.cyc-banner-amt { font-family: var(--ff-head); font-weight: 700; color: var(--accent-dk); font-size: 1.05rem; }
.cyc-banner-close {
  flex: none; background: none; border: none; cursor: pointer;
  font-size: 1.25rem; line-height: 1; color: var(--ink-faint);
  padding: 0.15rem 0.35rem; border-radius: var(--radius-sm); transition: color .12s, background .12s;
}
.cyc-banner-close:hover { color: var(--accent-dk); background: var(--accent-sf); }

/* Cycle hero */
.hero {
  background: linear-gradient(135deg, var(--surface) 60%, var(--accent-sf));
  border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.3rem 1.4rem;
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.hero-dates { font-family: var(--ff-head); font-size: 1.7rem; line-height: 1.15; color: var(--ink); }
.hero-dates .arrow { color: var(--accent); margin: 0 0.3rem; }
.hero-meta { margin-top: 0.4rem; display: flex; gap: 1.2rem; flex-wrap: wrap; }
.hero-meta-item { font-family: var(--ff-mono); font-size: 0.78rem; color: var(--ink-soft); }
.hero-meta-item b { color: var(--ink); font-weight: 500; }
.sd-badge {
  font-family: var(--ff-mono); font-size: 0.82rem; font-weight: 500;
  padding: 0.4rem 0.8rem; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent;
}
.sd-surplus { color: var(--ok);  background: #e7f3e8; border-color: #cfe6d1; }
.sd-deficit { color: var(--err); background: #fae6e3; border-color: #f0cfca; }

/* Payday progress */
.progress-wrap { margin-top: 1.1rem; }
.progress-track {
  height: 12px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-dk));
  transition: width .4s ease;
}
.progress-label {
  display: flex; justify-content: space-between;
  font-family: var(--ff-mono); font-size: 0.72rem; color: var(--ink-soft);
  margin-top: 0.45rem;
}

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.8rem; }
.stat-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem 1rem 0.9rem;
}
.stat-bar { position: absolute; top: 0; left: 0; right: 0; height: 4px; }
.bar-blue  { background: var(--badge-bill); }
.bar-red   { background: var(--badge-arrears); }
.bar-amber { background: var(--pri-committed); }
.bar-green { background: var(--ok); }
.stat-label {
  font-family: var(--ff-mono); font-size: 0.68rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-faint); margin-top: 0.3rem;
}
.stat-value { font-family: var(--ff-head); font-size: 1.5rem; margin-top: 0.2rem; color: var(--ink); }
.stat-value.neg { color: var(--err); }

/* Alerts */
.alert-group { margin-bottom: 0.7rem; }
.alert-group:last-child { margin-bottom: 0; }
.alert-group-label {
  font-family: var(--ff-mono); font-size: 0.68rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-soft); margin-bottom: 0.35rem;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  font-size: 0.82rem; font-weight: 600;
  padding: 0.32rem 0.7rem; border-radius: 999px; cursor: pointer;
  border: 1px solid transparent; transition: transform .05s, box-shadow .15s;
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.chip:hover { box-shadow: var(--shadow); }
.chip:active { transform: translateY(1px); }
.chip-red   { color: var(--badge-arrears); background: var(--badge-arrears-bg); border-color: #f0cfca; }
.chip-amber { color: #9a6a12; background: #fbf0d6; border-color: #f0dfb6; }
.chip .chip-amt { font-family: var(--ff-mono); font-size: 0.74rem; opacity: 0.85; }
.all-clear { color: var(--ok); font-weight: 600; }

/* Alerts + Needs Attention read as sibling panels: the same capped body height,
   each scrolling internally. ~2 alert groups show before the scrollbar. */
:root { --dash-panel-cap: 170px; }
.alerts-scroll { max-height: var(--dash-panel-cap); overflow-y: auto; min-height: 0; }

/* Needs Attention — per-line notes feed for entries still flagged in Alerts */
.activity-feed { max-height: var(--dash-panel-cap); overflow-y: auto; min-height: 0; }
.act-row {
  display: flex; align-items: baseline; gap: 0.55rem; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 0.42rem 0.25rem; border-bottom: 1px solid var(--line);
  font-family: var(--ff-body); font-size: 0.88rem; color: var(--ink);
}
.act-row:last-of-type { border-bottom: none; }
.act-row:hover { background: var(--surface-2); }
.act-stamp { flex: none; font-family: var(--ff-mono); font-size: 0.7rem; color: var(--ink-soft); white-space: nowrap; }
.act-stamp.undated { color: var(--ink-faint); font-style: italic; }
.act-text { flex: 1; min-width: 0; overflow-wrap: break-word; }
.act-entry {
  flex: none; font-family: var(--ff-mono); font-size: 0.66rem; color: var(--ink-faint);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 0.06rem 0.45rem; border-radius: 999px; white-space: nowrap;
  max-width: 130px; overflow: hidden; text-overflow: ellipsis;
}
.act-more { font-family: var(--ff-mono); font-size: 0.7rem; color: var(--ink-faint); padding: 0.4rem 0.25rem 0.1rem; }

/* Action Required */
.action-card { border-left: 4px solid var(--badge-arrears); margin-bottom: 0.7rem; }
.action-card:last-child { margin-bottom: 0; }
.action-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.action-name { font-family: var(--ff-head); font-size: 1.1rem; }
.flag-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.55rem 0; border-top: 1px solid var(--line); margin-top: 0.6rem;
}
.flag-row:first-of-type { margin-top: 0.7rem; }
.flag-msg { font-size: 0.9rem; color: var(--ink-soft); }
.action-btn {
  font-family: var(--ff-body); font-weight: 700; font-size: 0.82rem;
  white-space: nowrap; cursor: pointer;
  background: var(--accent-sf); color: var(--accent-dk);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 0.4rem 0.8rem; transition: background .15s;
}
.action-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Chart */
.chart-card svg { width: 100%; height: auto; display: block; }
.chart-empty { text-align: center; color: var(--ink-faint); padding: 2rem 1rem; }

/* Debt freedom */
.debt-total {
  font-family: var(--ff-mono); font-size: 0.78rem; color: var(--ink-soft);
  margin-bottom: 0.7rem;
}
.debt-total b { font-family: var(--ff-head); color: var(--ink); font-size: 1rem; }
.debt-item {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0.95rem 1.05rem; margin-bottom: 0.7rem;
}
.debt-item:last-child { margin-bottom: 0; }
.debt-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.debt-name { font-family: var(--ff-head); font-size: 1.08rem; display: flex; align-items: center; gap: 0.5rem; }
.debt-remaining { font-family: var(--ff-mono); font-size: 0.95rem; color: var(--ink); }
.debt-bar-track {
  height: 9px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line); overflow: hidden; margin: 0.65rem 0 0.5rem;
}
.debt-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); border-radius: 999px; }
.debt-meta {
  display: flex; flex-wrap: wrap; gap: 0.3rem 1rem;
  font-family: var(--ff-mono); font-size: 0.72rem; color: var(--ink-soft);
}

/* ===================== Entries: toolbar ===================== */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.filter-pills { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill {
  font-size: 0.8rem; font-weight: 700; padding: 0.42rem 0.85rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink-soft);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.pill:hover { border-color: var(--accent); color: var(--accent); }
.pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.toolbar-right { display: flex; gap: 0.5rem; margin-left: auto; align-items: center; }
.search-input {
  font-family: var(--ff-body); font-size: 0.9rem; padding: 0.5rem 0.8rem; width: 170px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
}
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-sf); }

/* ===================== Entries: table ===================== */
/* overflow-x:auto contains the table inside the card — the right-edge pay column
   is never clipped, and the page itself never overflows horizontally. The tight
   padding below keeps the 9 columns within the 880px view on desktop so the
   scrollbar only appears on genuinely narrow windows. */
.entries-table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; overflow-y: hidden; }
table.entries { width: 100%; border-collapse: separate; border-spacing: 0; }
.entries thead th {
  text-align: left; font-family: var(--ff-mono); font-size: 0.64rem; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--ink-faint); font-weight: 500;
  padding: 0.55rem 0.5rem; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
/* Selection checkbox column (narrow) + selected-row amber tint */
.entries td.col-check, .entries th.col-check { width: 34px; text-align: center; padding-left: 0.7rem; padding-right: 0; }
.row-check, .master-check { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); margin: 0; vertical-align: middle; }
.entries tbody tr.row-selected { background: #fbf0d6; }
.entries tbody tr.row-selected:hover { background: #f6e6c2; }

.btn-danger-outline { background: transparent; color: var(--err); border: 1px solid #ecc4be; font-weight: 700; }
.btn-danger-outline:hover { background: var(--arrears-bg); border-color: var(--err); }

.bulk-list { list-style: none; margin: 0.5rem 0 0.9rem; padding: 0; max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.bulk-list li { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.bulk-list li:last-child { border-bottom: none; }
.bulk-name { color: var(--ink); }

.entries thead th.sortable { cursor: pointer; user-select: none; white-space: nowrap; transition: color .12s; }
.entries thead th.sortable:hover { color: var(--accent); }
.entries thead th.sortable.active { color: var(--accent-dk); }
.sort-ind { font-family: var(--ff-body); font-weight: 700; }
.entries tbody td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; vertical-align: middle; }
.entries tbody tr:last-child td { border-bottom: none; }
.entries tbody tr { cursor: pointer; transition: background .12s; }
.entries tbody tr:hover { background: var(--surface-2); }
.cell-name { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--ink); }
.amt { font-family: var(--ff-mono); white-space: nowrap; }
.tag { font-family: var(--ff-mono); font-size: 0.64rem; padding: 0.1rem 0.4rem; border-radius: 5px; margin-left: 0.35rem; white-space: nowrap; display: inline-block; }
.tag-shortfall { color: #9a6a12; background: #fbf0d6; }
.tag-interest { color: var(--badge-loan); background: var(--badge-loan-bg); }
.mini-bar { display: flex; align-items: center; gap: 0.45rem; }
.mini-bar-track { width: 70px; height: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.mini-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); }
.mini-bar-pct { font-family: var(--ff-mono); font-size: 0.66rem; color: var(--ink-soft); }

/* partial-payment progress (paid / total owed this period) — shown only for partials */
.pay-ratio { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.25rem; }
.pay-ratio-track { width: 56px; height: 5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; }
.pay-ratio-fill { height: 100%; background: var(--pri-committed); }
.pay-ratio-text { font-family: var(--ff-mono); font-size: 0.66rem; color: #9a6a12; white-space: nowrap; }

.vspd { font-size: 0.68rem; font-weight: 700; padding: 0.18rem 0.45rem; border-radius: 999px; white-space: nowrap; }
.vspd-before { color: var(--ok); background: #e7f3e8; }
.vspd-after { color: var(--err); background: var(--badge-arrears-bg); }
.vspd-tight { color: #9a6a12; background: #fbf0d6; }

.status-pill { font-size: 0.68rem; font-weight: 700; padding: 0.18rem 0.5rem; border-radius: 999px; text-transform: capitalize; white-space: nowrap; }
.status-paid { color: var(--ok); background: #e7f3e8; }
.status-unpaid { color: var(--ink-soft); background: var(--surface-2); border: 1px solid var(--line); }
.status-partial { color: #9a6a12; background: #fbf0d6; }
.status-overdue { color: var(--err); background: var(--badge-arrears-bg); }
/* paid-then-advanced recurring entry: nothing owed until the next due date —
   calm muted green-grey, distinct from both Paid (green) and Unpaid (grey). */
.status-scheduled { color: #4f7d6b; background: #e9f0ec; border: 1px solid #d4e2da; }

.pay-circle {
  font-size: 1.15rem; line-height: 1; width: 34px; height: 34px; flex: none; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft);
  cursor: pointer; display: grid; place-items: center; transition: all .12s;
}
.pay-circle:hover { border-color: var(--accent); color: var(--accent); transform: scale(1.08); }
.pay-circle.pay-paid { color: var(--ok); border-color: #cfe6d1; }
.pay-circle.pay-partial { color: #9a6a12; border-color: #f0dfb6; }
/* Pay column: enough width for the full circle (desktop right-padding added in
   the min-width:720px block; left as-is in mobile card mode). */
.col-pay { width: 56px; text-align: center; }

.entries-empty { text-align: center; color: var(--ink-faint); padding: 2.5rem 1rem; }

/* "Due now" window toggle (segmented control) */
.window-toggle { display: flex; align-items: center; gap: 0.4rem; }
.wt-label { font-family: var(--ff-mono); font-size: 0.62rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-faint); white-space: nowrap; }
.wt-opt { font-family: var(--ff-mono); font-size: 0.72rem; padding: 0.28rem 0.55rem; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); cursor: pointer; }
.wt-opt:first-of-type { border-radius: 7px 0 0 7px; }
.wt-opt:last-of-type { border-radius: 0 7px 7px 0; }
.wt-opt + .wt-opt { border-left: none; }
.wt-opt:hover { color: var(--accent-dk); }
.wt-opt.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Today-first section headers (grouped Entries layout) */
.section-row td { padding: 0; background: transparent; }
.section-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 0.9rem 0.45rem; }
.section-title { font-family: var(--ff-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; color: var(--ink-soft); }
.section-count {
  font-family: var(--ff-mono); font-size: 0.66rem; color: var(--ink-soft);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0.04rem 0.5rem;
}
.sec-arrow { color: var(--ink-faint); font-size: 0.72rem; width: 0.85rem; text-align: center; }
.sec-collapsible .section-head { cursor: pointer; border-radius: var(--radius-sm); }
.sec-collapsible .section-head:hover { background: var(--surface-2); }
.sec-overdue .section-head { background: var(--badge-arrears-bg); border-left: 3px solid var(--err); border-radius: var(--radius-sm); }
.sec-overdue .section-title { color: var(--err); }
.sec-overdue .section-count { color: var(--err); border-color: #f0cfca; }
.sec-duenow .section-title { color: var(--accent-dk); }

@media (max-width: 719px) {
  /* section headers must read as headers, not stacked cards, on phones */
  .entries tbody tr.section-row {
    background: transparent; border: none; box-shadow: none; margin: 0.4rem 0 0.2rem; padding: 0;
  }
  .entries tbody tr.section-row td { display: block; padding: 0; }
  .entries tbody tr.section-row td::before { display: none; }
  .section-head { padding: 0.5rem 0.2rem 0.35rem; }
  .window-toggle { order: -1; }
}

/* Responsive: table → stacked cards on phones */
@media (max-width: 719px) {
  .entries thead { display: none; }
  table.entries, .entries tbody, .entries tr, .entries td { display: block; }
  .entries-table-wrap { background: transparent; border: none; box-shadow: none; overflow: visible; }
  .entries tbody tr {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 0.7rem; padding: 0.6rem 0.9rem;
  }
  .entries tbody td { border: none; padding: 0.3rem 0; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  .entries tbody td::before {
    content: attr(data-label); font-family: var(--ff-mono); font-size: 0.62rem;
    letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); flex: none;
  }
  .entries td.td-name { padding-bottom: 0.5rem; }
  .entries td.td-name::before { display: none; }
  .cell-name { font-size: 1.08rem; }
}

/* ===================== Entries: frozen panes ===================== */
/* Spreadsheet-style frozen panes: the Entries view becomes a bounded column that
   exactly fills the space between the sticky header/tabbar and the fixed income
   bar, and the table wrap becomes the ONLY vertical scroll region — so the view
   title, toolbar and column headers stay put while entry rows scroll beneath them.
   Scoped with :has() to views containing .entries-table-wrap (Entries only), so
   Dashboard/Triage/Vault/History keep normal page scrolling. In browsers without
   :has() these rules drop and the page falls back to today's full-page scroll. */
.view:has(.entries-table-wrap) {
  /* flex:none — the base .view flex:1 (basis 0%) would override the explicit
     height in .app's column flex layout; basis:auto lets the calc height win. */
  flex: none;
  height: calc(100vh - var(--header-h) - var(--tabbar-h) - var(--income-h) - env(safe-area-inset-bottom));
  height: calc(100dvh - var(--header-h) - var(--tabbar-h) - var(--income-h) - env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}
.view:has(.entries-table-wrap) > * { flex: none; }
.view:has(.entries-table-wrap) .entries-table-wrap {
  /* hug content when short, cap at the available space when tall; min-height lets
     it shrink. overflow:auto outranks both the base overflow-y:hidden and the
     phone card-layout overflow:visible, keeping the frozen toolbar on mobile too. */
  flex: 0 1 auto; min-height: 0;
  overflow: auto;
}
/* Column headers stick to the top of the scrolling wrap (desktop table layout;
   the thead is hidden in the phone card layout). Opaque background comes from
   the base th rule (--surface-2), so rows don't bleed through. */
.entries thead th {
  position: sticky; top: 0; z-index: 5;
}

/* ===================== Overlay / drawer / modal ===================== */
.overlay { position: fixed; inset: 0; background: rgba(46, 38, 32, 0.45); z-index: 50; opacity: 0; transition: opacity .2s; }
.overlay.open { opacity: 1; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(500px, 100%);
  background: var(--bg); z-index: 55; box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .25s ease;
  display: flex; flex-direction: column; overflow: hidden;
}
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 1.1rem 1.2rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface); position: relative; }
.drawer-close {
  position: absolute; top: 0.9rem; right: 1rem; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft);
  font-size: 1.1rem; cursor: pointer; display: grid; place-items: center;
}
.drawer-close:hover { background: var(--surface-2); color: var(--ink); }
.drawer-head-controls { position: absolute; top: 0.85rem; right: 1rem; z-index: 2; display: flex; gap: 0.5rem; align-items: center; }
.drawer-head-controls .drawer-close { position: static; }
.drawer-title { font-family: var(--ff-head); font-size: 1.4rem; padding-right: 7rem; }
.drawer-subtitle { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.45rem; font-size: 0.82rem; color: var(--ink-soft); }
.drawer-actions { display: flex; gap: 0.5rem; margin-top: 0.9rem; }
.drawer-actions .btn { flex: 1; }
.btn-full { background: var(--ok); color: #fff; }
.btn-full:hover { background: #3f8a43; }
.btn-partial { background: var(--pri-committed); color: #5a4410; }
.btn-partial:hover { background: #d8a81f; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.drawer-body { overflow-y: auto; padding: 1.1rem 1.2rem 2rem; flex: 1; }

.dsection { margin-bottom: 1.3rem; }
.dsection-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.55rem; }
.dsection-title { font-family: var(--ff-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.link-add {
  font-family: var(--ff-body); font-size: 0.78rem; font-weight: 700; color: var(--accent-dk);
  background: none; border: none; cursor: pointer; padding: 0.2rem 0.3rem;
}
.link-add:hover { text-decoration: underline; }

.amount-due-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.amount-due-box.amber { background: #fbf0d6; border-color: #f0dfb6; }
.due-bar-track { height: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; margin: 0.2rem 0 0.6rem; }
.due-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--ok)); border-radius: 999px; }
.due-stats { display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; font-family: var(--ff-mono); font-size: 0.76rem; color: var(--ink-soft); }
.due-stats b { color: var(--ink); font-weight: 500; }

/* inline editable ref / link rows */
.ref-row, .link-row { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem 0; border-bottom: 1px solid var(--line); }
.ref-row:last-of-type, .link-row:last-of-type { border-bottom: none; }
.ref-in, .link-in {
  font-family: var(--ff-body); font-size: 0.85rem; padding: 0.4rem 0.55rem;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--ink); min-width: 0;
}
.ref-in:focus, .link-in:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 2px var(--accent-sf); }
.ref-in-label, .link-in-label { flex: 0 0 38%; }
.ref-in-value, .link-in-url { flex: 1; }
.link-open-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 1rem; padding: 0 0.2rem; text-decoration: none; }
.link-open-btn:hover { color: var(--accent-dk); }
.link-open-btn.disabled { color: var(--ink-faint); cursor: default; }
.due-row { display: flex; justify-content: space-between; padding: 0.3rem 0; font-size: 0.92rem; }
.due-row.total { border-top: 1px solid var(--line); margin-top: 0.4rem; padding-top: 0.55rem; font-weight: 700; }
.due-row .lbl { color: var(--ink-soft); }
.due-row .val { font-family: var(--ff-mono); }
.due-row .val.amber { color: #9a6a12; }

.loan-card { background: var(--badge-loan-bg); border: 1px solid #e0d2ef; border-radius: var(--radius); padding: 1rem; }
.loan-card .loan-card-title { font-family: var(--ff-mono); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--badge-loan); margin-bottom: 0.5rem; }
.loan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; }
.loan-grid .k { font-size: 0.72rem; color: var(--ink-soft); }
.loan-grid .v { font-family: var(--ff-mono); font-size: 0.95rem; color: var(--ink); }

.paylog { list-style: none; margin: 0; padding: 0; }
.paylog-item { padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.paylog-item:last-child { border-bottom: none; }
.paylog-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.paylog-main { display: flex; flex-direction: column; gap: 0.15rem; }
.paylog-amt { font-family: var(--ff-mono); font-weight: 500; }
.paylog-meta { font-size: 0.74rem; color: var(--ink-faint); }
.paylog-tag { font-family: var(--ff-mono); font-size: 0.62rem; padding: 0.1rem 0.4rem; border-radius: 5px; flex: none; }
.paylog-full { color: var(--ok); background: #e7f3e8; }
.paylog-partial { color: #9a6a12; background: #fbf0d6; }
.paylog-split { font-family: var(--ff-mono); font-size: 0.7rem; color: var(--accent-dk); margin-top: 0.3rem; }
/* month grouping divider across periods */
.paylog-month {
  list-style: none; font-family: var(--ff-mono); font-size: 0.62rem; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-faint); padding: 0.5rem 0 0.2rem; margin-top: 0.2rem;
}
.paylog-month:first-child { margin-top: 0; padding-top: 0; }
.paylog-toggle {
  margin-top: 0.6rem; background: none; border: none; cursor: pointer; padding: 0.2rem 0;
  font-family: var(--ff-body); font-size: 0.82rem; font-weight: 700; color: var(--accent-dk);
}
.paylog-toggle:hover { text-decoration: underline; }
.empty-note { color: var(--ink-faint); font-size: 0.85rem; font-style: italic; }

.ref-row, .link-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.ref-row:last-child, .link-row:last-child { border-bottom: none; }
.ref-label { font-size: 0.75rem; color: var(--ink-soft); }
.ref-value, .link-label { font-family: var(--ff-mono); font-size: 0.9rem; }
.row-del { background: none; border: none; color: var(--ink-faint); cursor: pointer; font-size: 0.95rem; padding: 0.1rem 0.3rem; }
.row-del:hover { color: var(--err); }
.link-open { color: var(--accent); font-weight: 700; text-decoration: none; }
.link-open:hover { text-decoration: underline; }

.notes-area { width: 100%; min-height: 90px; resize: vertical; font-family: var(--ff-body); font-size: 0.92rem; padding: 0.7rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); }
.notes-area:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-sf); }

/* Notes as a date-stamped log: add-input on top, newest line first below. */
.note-add { display: flex; gap: 0.4rem; margin-bottom: 0.55rem; }
.note-input {
  flex: 1; min-width: 0; font-family: var(--ff-body); font-size: 0.9rem;
  padding: 0.5rem 0.7rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.note-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-sf); }
.note-log {
  max-height: 200px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); padding: 0.25rem 0;
}
.note-line {
  white-space: pre-wrap; word-break: break-word;
  font-size: 0.88rem; color: var(--ink); padding: 0.35rem 0.7rem;
  border-bottom: 1px solid var(--line);
}
.note-line:last-child { border-bottom: none; }
.note-log .empty-note { padding: 0.45rem 0.7rem; }

/* Tasks / follow-ups (drawer) — mirrors ref/link rows. */
.task-row { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0; border-bottom: 1px solid var(--line); }
.task-row:last-child { border-bottom: none; }
.task-check { width: 16px; height: 16px; flex: none; cursor: pointer; accent-color: var(--accent); margin: 0; }
.task-title { flex: 1; min-width: 0; font-size: 0.9rem; color: var(--ink); overflow-wrap: break-word; }
.task-due { font-family: var(--ff-mono); font-size: 0.72rem; color: var(--ink-soft); white-space: nowrap; }
.task-due.overdue { color: var(--err); font-weight: 700; }
.task-cal { flex: none; font-size: 0.95rem; text-decoration: none; }
.task-cal:hover { transform: scale(1.12); }
.task-done .task-title { color: var(--ink-faint); text-decoration: line-through; }
.task-done .task-due { color: var(--ink-faint); }
.task-new { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.55rem; }
.task-in-title {
  flex: 1; min-width: 0; font-family: var(--ff-body); font-size: 0.9rem;
  padding: 0.5rem 0.7rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.task-in-title:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-sf); }
.task-in-due {
  flex: none; font-family: var(--ff-mono); font-size: 0.8rem;
  padding: 0.42rem 0.5rem; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}

/* Open follow-ups list (dashboard) */
.fu-card { padding: 0.35rem 0.6rem; }
.fu-row {
  display: flex; align-items: center; gap: 0.55rem; width: 100%; text-align: left;
  background: none; border: none; cursor: pointer;
  padding: 0.5rem 0.25rem; border-bottom: 1px solid var(--line);
  font-family: var(--ff-body); font-size: 0.9rem; color: var(--ink);
}
.fu-row:last-child { border-bottom: none; }
.fu-row:hover { background: var(--surface-2); }
.fu-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.fu-dot.overdue { background: var(--err); }
.fu-entry { flex: none; font-weight: 700; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fu-title { flex: 1; min-width: 0; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fu-due { flex: none; font-family: var(--ff-mono); font-size: 0.72rem; color: var(--ink-soft); white-space: nowrap; }
.fu-due.overdue { color: var(--err); font-weight: 700; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.6rem; }
.doc-tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.8rem 0.7rem; text-align: center; cursor: pointer; transition: box-shadow .15s; }
.doc-tile:hover { box-shadow: var(--shadow); }
.doc-icon { font-size: 1.7rem; }
.doc-name { font-size: 0.74rem; color: var(--ink-soft); margin-top: 0.3rem; word-break: break-word; }
.doc-scanned { position: absolute; top: 4px; left: 4px; font-family: var(--ff-mono); font-size: 0.54rem; letter-spacing: 0.04em; color: var(--badge-plan); background: var(--badge-plan-bg); padding: 0.08rem 0.3rem; border-radius: 4px; }
.doc-del { position: absolute; top: 2px; right: 4px; background: none; border: none; color: var(--ink-faint); cursor: pointer; }
.doc-del:hover { color: var(--err); }

.delete-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line-strong); }
.btn-delete { width: 100%; background: var(--surface); color: var(--err); border: 1px solid #f0cfca; }
.btn-delete:hover { background: var(--badge-arrears-bg); }

/* Modal (create form + payment popup + PIN) */
.modal-wrap {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 60; padding: 1rem;
  background: rgba(46, 38, 32, 0.35);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: min(460px, 100%); max-height: 90vh; overflow-y: auto; padding: 1.4rem; position: relative; }
.modal-title { font-family: var(--ff-head); font-size: 1.35rem; margin-bottom: 1rem; }
.modal-close { position: absolute; top: 1rem; right: 1.1rem; background: none; border: none; font-size: 1.3rem; color: var(--ink-faint); cursor: pointer; }
.field { margin-bottom: 0.85rem; }
.field > label { display: block; font-family: var(--ff-mono); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 0.3rem; }
.field input, .field select, .field textarea {
  width: 100%; font-family: var(--ff-body); font-size: 0.95rem; padding: 0.6rem 0.7rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-sf); }
.field-row { display: flex; gap: 0.6rem; }
.field-row .field { flex: 1; }
.field-check { display: flex; align-items: center; gap: 0.5rem; }
.field-check input { width: auto; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; }
.modal-actions .btn { flex: 1; }
.modal-error { color: var(--err); font-size: 0.85rem; font-weight: 600; margin-top: 0.6rem; }

/* Recurrence picker — computed next-due preview line */
.next-due {
  font-size: 0.85rem; color: var(--ink-soft);
  background: var(--accent-sf); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 0.45rem 0.7rem; margin-bottom: 0.85rem;
}
.next-due b { font-family: var(--ff-head); color: var(--accent-dk); font-weight: 700; }

/* Payment popup specifics */
.pp-tabs { display: flex; gap: 0.4rem; margin-bottom: 1rem; background: var(--surface-2); padding: 0.3rem; border-radius: var(--radius-sm); }
.pp-tab { flex: 1; text-align: center; font-weight: 700; font-size: 0.88rem; padding: 0.5rem; border-radius: 8px; cursor: pointer; color: var(--ink-soft); border: none; background: none; }
.pp-tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.pp-amount-wrap { display: flex; align-items: center; justify-content: center; gap: 0.2rem; margin: 0.2rem 0 0.4rem; }
.modal .pp-cur { font-family: var(--ff-head); font-size: 32px; color: var(--ink-soft); }
.modal .pp-amount {
  font-family: var(--ff-head); font-size: 32px; text-align: center; width: 180px;
  border: none; border-bottom: 2px solid var(--line-strong); border-radius: 0;
  background: transparent; box-shadow: none; padding: 0.2rem 0.3rem; color: var(--ink);
}
.modal .pp-amount:focus { outline: none; border-bottom-color: var(--accent); box-shadow: none; }
.modal .pp-amount[readonly] { border-bottom-style: dashed; color: var(--ink); }
.pp-calc { border-radius: var(--radius-sm); padding: 0.8rem 1rem; margin: 1rem 0; border: 1px solid var(--line); }
.pp-calc.neutral { background: var(--surface-2); border-color: var(--line); }
.pp-calc.full { background: #e7f3e8; border-color: #cfe6d1; }
.pp-calc.partial { background: #fbf0d6; border-color: #f0dfb6; }
.pp-calc.full .pp-result .v { color: var(--ok); }
.pp-calc.partial .pp-result .v { color: #9a6a12; }
.pp-confirm-disabled { background: var(--surface-2); color: var(--ink-faint); border: 1px solid var(--line); cursor: not-allowed; }
.sp-status { font-family: var(--ff-mono); font-size: 0.76rem; color: var(--ink-faint); }
.sp-status.sp-ok { color: var(--ok); font-weight: 700; }
.sp-status.sp-bad { color: #9a6a12; }
.pp-calc-row { display: flex; justify-content: space-between; font-size: 0.9rem; padding: 0.18rem 0; }
.pp-calc-row .v { font-family: var(--ff-mono); }
.pp-calc-warn { font-size: 0.82rem; font-weight: 600; color: #9a6a12; margin-top: 0.4rem; }
.pp-calc.full .pp-result { color: var(--ok); font-weight: 700; }

/* ===================== Triage ===================== */
.triage-context { margin-bottom: 1rem; }
.triage-payday { font-family: var(--ff-head); font-size: 1.15rem; color: var(--ink); }
.triage-payday b { color: var(--accent); }
.triage-cyclelabel { font-family: var(--ff-mono); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); margin-top: 0.2rem; }

.triage-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.triage-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.triage-col-head { padding: 0.8rem 1rem; font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 0.4rem; }
.triage-head-before { background: #fae6e3; color: var(--badge-arrears); border-bottom: 1px solid #f0cfca; }
.triage-head-after { background: #e7f3e8; color: var(--ok); border-bottom: 1px solid #cfe6d1; }
.triage-list { flex: 1; }
.triage-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s; }
.triage-row:hover { background: var(--surface-2); }
.triage-row:last-child { border-bottom: none; }
.triage-row-main { flex: 1; min-width: 0; }
.triage-row-name { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 0.4rem; }
.triage-shortfall { font-family: var(--ff-mono); font-size: 0.64rem; color: #9a6a12; background: #fbf0d6; padding: 0.06rem 0.35rem; border-radius: 5px; }
.triage-row-due { font-family: var(--ff-mono); font-size: 0.68rem; color: var(--ink-faint); margin-top: 0.15rem; }
.triage-amt { font-family: var(--ff-mono); font-weight: 500; white-space: nowrap; }
.triage-amt-before { color: var(--err); }
.triage-amt-after { color: var(--ok); }
.triage-empty { padding: 1.5rem 1rem; text-align: center; color: var(--ink-faint); font-size: 0.85rem; font-style: italic; }
.triage-foot { padding: 0.7rem 1rem; border-top: 1px solid var(--line-strong); display: flex; justify-content: space-between; font-family: var(--ff-mono); font-size: 0.82rem; }
.triage-foot b { font-weight: 500; }

.triage-summary { margin-top: 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.9rem 1.1rem; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.triage-sum-item { text-align: center; }
.triage-sum-label { font-family: var(--ff-mono); font-size: 0.62rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-faint); }
.triage-sum-value { font-family: var(--ff-head); font-size: 1.15rem; margin-top: 0.15rem; }
.triage-sum-value.red { color: var(--err); }
.triage-sum-value.green { color: var(--ok); }
.triage-sum-value.neg { color: var(--err); }

@media (max-width: 719px) {
  .triage-cols { grid-template-columns: 1fr; }
  .triage-summary { grid-template-columns: repeat(2, 1fr); gap: 0.8rem; }
}

/* ===================== Vault ===================== */
.vault-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.vault-toolbar-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* Excel import preview */
.import-summary { font-size: 0.92rem; color: var(--ink-soft); margin: 0.2rem 0 0.7rem; }
.import-list { list-style: none; margin: 0 0 0.9rem; padding: 0; max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.import-list li { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.import-list li:last-child { border-bottom: none; }
.import-list li.dup { opacity: 0.5; }
.import-name { color: var(--ink); min-width: 0; word-break: break-word; }
.import-amt { margin-left: auto; font-family: var(--ff-mono); white-space: nowrap; }
.import-rec { font-family: var(--ff-mono); font-size: 0.62rem; color: var(--accent-dk); background: var(--accent-sf); padding: 0.1rem 0.4rem; border-radius: 5px; white-space: nowrap; }
.import-dup-tag { margin-left: auto; font-family: var(--ff-mono); font-size: 0.62rem; color: var(--ink-faint); background: var(--surface-2); padding: 0.1rem 0.4rem; border-radius: 5px; }
.btn-purple { background: var(--badge-loan); color: #fff; }
.btn-purple:hover { background: #663f96; }
.vault-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8rem; }
.vault-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; cursor: pointer; transition: box-shadow .15s, transform .05s; }
.vault-card:hover { box-shadow: var(--shadow-lg); }
.vault-card:active { transform: translateY(1px); }
.vault-card-emoji { font-size: 2rem; }
.vault-card-name { font-weight: 700; font-size: 0.9rem; margin-top: 0.4rem; word-break: break-word; }
.vault-card-meta { font-family: var(--ff-mono); font-size: 0.68rem; color: var(--ink-faint); margin-top: 0.3rem; }
.vault-card-entry { font-size: 0.74rem; color: var(--accent-dk); margin-top: 0.25rem; }
.vault-scanned { position: absolute; top: 0.6rem; right: 0.6rem; font-family: var(--ff-mono); font-size: 0.56rem; letter-spacing: 0.04em; color: var(--badge-loan); background: var(--badge-loan-bg); padding: 0.12rem 0.4rem; border-radius: 5px; }
.vault-empty { text-align: center; color: var(--ink-faint); padding: 2.5rem 1rem; }

/* document list */
.vault-list-head { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 0.8rem; margin-bottom: 0.5rem; }
.vault-list-count { font-family: var(--ff-mono); font-size: 0.7rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-soft); }
.vault-bulk-del { margin-left: auto; }
.vault-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); box-shadow: var(--shadow); }
.vault-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); transition: background .12s; }
.vault-row:last-child { border-bottom: none; }
.vault-row:hover { background: var(--surface-2); }
.vault-row.row-selected { background: #fbf0d6; }
.vault-row.row-selected:hover { background: #f6e6c2; }
.vault-row-icon { font-size: 1.1rem; flex: none; }
.vault-row-name { flex: 1; min-width: 0; text-align: left; background: none; border: none; padding: 0; cursor: pointer; font-family: var(--ff-body); font-size: 0.92rem; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault-row-name:hover { color: var(--accent-dk); text-decoration: underline; }
.vault-row-entry { flex: none; font-size: 0.74rem; color: var(--accent-dk); max-width: 32%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault-row-date { flex: none; font-family: var(--ff-mono); font-size: 0.68rem; color: var(--ink-faint); white-space: nowrap; }
.vault-row-del { flex: none; background: none; border: none; cursor: pointer; font-size: 0.95rem; padding: 0.2rem 0.3rem; border-radius: var(--radius-sm); opacity: 0.6; transition: opacity .12s, background .12s; }
.vault-row-del:hover { opacity: 1; background: var(--badge-arrears-bg); }
.vault-upload { margin-top: 1.4rem; padding-top: 1.1rem; border-top: 1px dashed var(--line-strong); display: flex; gap: 0.6rem; flex-wrap: wrap; }
.vault-upload .btn { flex: 1; min-width: 180px; }

/* scan modal */
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 1.6rem 1rem; text-align: center; color: var(--ink-soft); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-sf); }
.dropzone-icon { font-size: 2rem; display: block; margin-bottom: 0.4rem; }
.dropzone-file { font-family: var(--ff-mono); font-size: 0.82rem; color: var(--ink); margin-top: 0.5rem; }
.scan-spinner-wrap { text-align: center; padding: 1.5rem; color: var(--ink-soft); }
.scan-results { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin: 0.8rem 0; }
.scan-field { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.5rem 0.6rem; }
.scan-field.uncertain { background: #fbf0d6; border-color: #f0dfb6; }
.scan-field-k { font-family: var(--ff-mono); font-size: 0.6rem; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-faint); }
.scan-field.uncertain .scan-field-k { color: #9a6a12; }
.scan-field-v { font-size: 0.9rem; margin-top: 0.15rem; word-break: break-word; }
.scan-field-v.empty { color: var(--ink-faint); font-style: italic; }

@media (max-width: 980px) { .vault-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .vault-grid { grid-template-columns: 1fr; } .scan-results { grid-template-columns: 1fr; } .vault-row-entry { display: none; } }

/* ===================== History ===================== */
.hist-summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.6rem; margin-bottom: 1.2rem; }
.hist-sum-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: 0.7rem 0.6rem; text-align: center; }
.hist-sum-label { font-family: var(--ff-mono); font-size: 0.58rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-faint); }
.hist-sum-value { font-family: var(--ff-head); font-size: 1.05rem; margin-top: 0.2rem; }
.hist-sum-value.green { color: var(--ok); }
.hist-sum-value.red { color: var(--err); }

.hist-list { display: flex; flex-direction: column; gap: 0.7rem; }
.hist-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.hist-card.current { border-color: var(--accent); background: linear-gradient(135deg, var(--surface) 70%, var(--accent-sf)); }
.hist-close-bar { padding: 0 1rem 1rem; }
.hist-close-btn { width: 100%; }

/* Close-cycle confirmation preview */
.close-preview { margin: 0.4rem 0 0.2rem; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.cp-row { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.8rem; }
.cp-row + .cp-row { border-top: 1px solid var(--line); }
.cp-label { font-size: 0.9rem; color: var(--ink-soft); }
.cp-value { font-family: var(--ff-head); font-size: 1.05rem; }
.cp-value.red { color: var(--err); }
.cp-value.amber { color: var(--pri-committed); }
.hist-card-head { display: flex; align-items: center; gap: 0.6rem; padding: 0.85rem 1rem; }
.hist-card.closed .hist-card-head { cursor: pointer; }
.hist-card.closed .hist-card-head:hover { background: var(--surface-2); }
.hist-cyc { flex: 1; min-width: 0; }
.hist-cyc-label { font-family: var(--ff-head); font-size: 1.05rem; display: flex; align-items: center; gap: 0.5rem; }
.hist-current-tag { font-family: var(--ff-mono); font-size: 0.6rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent); background: var(--accent-sf); padding: 0.1rem 0.4rem; border-radius: 5px; }
.hist-cyc-dates { font-family: var(--ff-mono); font-size: 0.68rem; color: var(--ink-faint); margin-top: 0.15rem; }
.hist-status { font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px; white-space: nowrap; }
.hist-status.surplus { color: var(--ok); background: #e7f3e8; }
.hist-status.deficit { color: var(--err); background: var(--badge-arrears-bg); }
.hist-status.progress { color: var(--accent-dk); background: var(--accent-sf); }
.hist-caret { color: var(--ink-faint); font-size: 0.9rem; transition: transform .2s; }
.hist-card.open .hist-caret { transform: rotate(90deg); }

.hist-figures { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.3rem 0.8rem; padding: 0 1rem 0.85rem; }
.hist-fig { }
.hist-fig-k { font-family: var(--ff-mono); font-size: 0.6rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-faint); }
.hist-fig-v { font-family: var(--ff-mono); font-size: 0.9rem; margin-top: 0.1rem; }

.hist-detail { border-top: 1px solid var(--line); padding: 0.9rem 1rem; background: var(--surface-2); }
.hist-carry { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; font-family: var(--ff-mono); font-size: 0.78rem; margin-bottom: 0.7rem; }
.hist-carry .arrow { color: var(--accent); }
.hist-carry b { color: var(--ink); font-weight: 500; }
.hist-detail-title { font-family: var(--ff-mono); font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 0.4rem; }
.hist-pay-row { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.4rem 0; border-bottom: 1px solid var(--line); }
.hist-pay-row:last-child { border-bottom: none; }
.hist-pay-name { font-size: 0.88rem; }
.hist-pay-amt { font-family: var(--ff-mono); font-size: 0.85rem; }
.hist-pay-total { display: flex; justify-content: space-between; font-family: var(--ff-mono); font-weight: 500; padding-top: 0.5rem; margin-top: 0.3rem; border-top: 1px solid var(--line-strong); }

@media (max-width: 719px) {
  .hist-summary { grid-template-columns: repeat(2, 1fr); }
}

/* ===================== Settings panel ===================== */
.settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%);
  background: var(--bg); z-index: 56; box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .25s ease;
  display: flex; flex-direction: column; overflow: hidden;
}
.settings-panel.open { transform: translateX(0); }
.settings-header { padding: 1.1rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--surface); position: relative; }
.settings-title { font-family: var(--ff-head); font-size: 1.4rem; }
.settings-body { overflow-y: auto; padding: 1.2rem; flex: 1; }
.settings-section { margin-bottom: 1.5rem; }
.settings-section-title { font-family: var(--ff-mono); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 0.6rem; }
.settings-info-row { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.settings-info-row:last-child { border-bottom: none; }
.settings-info-row .k { color: var(--ink-soft); }
.settings-info-row .v { font-family: var(--ff-mono); }
.settings-msg { font-size: 0.82rem; font-weight: 600; margin-top: 0.5rem; }
.settings-msg.ok { color: var(--ok); }
.settings-msg.err { color: var(--err); }
.btn-block { width: 100%; }

/* ===================== Income footer (redesigned) ===================== */
.income-display { display: flex; align-items: center; gap: 0.9rem; width: 100%; }
.ib-stat { display: flex; align-items: baseline; gap: 0.35rem; }
.ib-label { font-family: var(--ff-mono); font-size: 0.62rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }
.ib-val { font-family: var(--ff-mono); font-size: 0.92rem; color: var(--ink); }
.ib-val.neg { color: var(--err); }
.ib-edit { margin-left: auto; background: none; border: 1px solid var(--line-strong); border-radius: 8px; color: var(--ink-soft); cursor: pointer; padding: 0.3rem 0.5rem; font-size: 0.9rem; }
.ib-edit:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 480px) {
  .ib-stat { gap: 0.25rem; min-width: 0; }
  .income-display { gap: 0.55rem; min-width: 0; }
  .ib-label { font-size: 0.56rem; }
  .ib-val { font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* the ✎ pencil must never be pushed off the right edge by the three stats */
  .income-bar-inner { min-width: 0; padding: 0 0.7rem; }
  .ib-edit { flex: none; min-width: 40px; min-height: 40px; }

  /* Entries toolbar: stack instead of one wide row. Pills already wrap; the
     right cluster becomes full-width rows — window toggle, then search, then
     the action buttons — nothing clipped, tap targets >= 40px. */
  .toolbar-right { flex-wrap: wrap; flex: 1 1 100%; margin-left: 0; gap: 0.5rem; min-width: 0; }
  .window-toggle { flex: 1 1 100%; }
  .search-input { flex: 1 1 100%; width: auto; min-width: 0; min-height: 40px; }
  #entries-bulk-del, #entries-add { flex: 1 1 auto; min-height: 40px; }
}

/* Narrow phones: the header must fit without sideways scroll. The cycle pill
   swaps to its year-less short label (spans built in app.js loadShell), the
   brand drops its subtitle, and the right cluster tightens — while the budget
   switcher and settings gear keep a >=40px touch target. */
.cp-short { display: none; }
@media (max-width: 420px) {
  .cp-full { display: none; }
  .cp-short { display: inline; }
  .app-header { padding: 0 0.6rem; }
  .brand { gap: 0.3rem; min-width: 0; }
  .brand-sub { display: none; }
  .brand-name { font-size: 1.15rem; }
  .header-right { gap: 0.35rem; min-width: 0; flex: 1; justify-content: flex-end; }
  .cycle-pill { padding: 0.3rem 0.5rem; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }
  .bs-toggle { max-width: min(150px, 38vw); min-height: 40px; }
  #settings-btn { min-width: 40px; min-height: 40px; padding: 0.4rem 0.5rem; }
}

/* ===================== Responsive (tablet+) ===================== */
@media (min-width: 720px) {
  body { font-size: 16.5px; }
  .tab { flex-direction: row; gap: 0.5rem; font-size: 0.85rem; }
  .tab-icon { font-size: 1rem; }
  .view { padding-top: 1.6rem; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .hero-dates { font-size: 1.9rem; }
  /* Pay column right-padding so the circle clears the table edge (table mode only) */
  .entries thead th.col-pay, .entries tbody td.col-pay { padding-right: 0.9rem; }
}
