/* The shell: sticky top bar (left = where am I, middle = 5 tabs, right = tools), sub-tabs under it. */
:root { --tb-on: #9FB9EA; --tb-on-text: #0A2A66; }
.topbar { position: sticky; top: 0; z-index: 40; background: var(--primary-dark); color: #fff; box-shadow: var(--shadow); }
.topbar-in { max-width: none; margin: 0 auto; display: flex; align-items: center; gap: var(--s4); padding: 0 var(--s5); height: 60px; }
.tb-left { display: flex; align-items: center; gap: var(--s3); min-width: 0; flex: 1; overflow: hidden; }
.site-id { color: #fff; font-weight: 800; font-size: 1.25rem; letter-spacing: .04em; text-decoration: none; }
.client-btn { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 2px solid rgba(255,255,255,.7); border-radius: var(--r-button); background: transparent; color: #fff; font: inherit; font-weight: 700; cursor: pointer; max-width: 130px; }
.client-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-state { flex: none; font-size: .8125rem; font-weight: 700; color: #BFE8CF; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.save-state.unsaved { color: #fff; background: var(--guess); padding: 2px 8px; border-radius: 999px; }
.tabs { display: flex; gap: 0; flex: none; }
.tab { white-space: nowrap; color: #fff; text-decoration: none; font-weight: 700; font-size: .9375rem; padding: 0 var(--s3); height: 40px; display: inline-flex; align-items: center; border-radius: var(--r-button); border-bottom: 3px solid transparent; }
.tab:hover { background: rgba(255,255,255,.12); }
.tab[aria-current="page"] { background: var(--tb-on); color: var(--tb-on-text); text-decoration: underline; text-underline-offset: 6px; text-decoration-thickness: 3px; }
:root[data-theme="dark"] { --tb-on: var(--primary); --tb-on-text: var(--on-primary); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --tb-on: var(--primary); --tb-on-text: var(--on-primary); } }
.tb-right { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex: none; }
.tb-right > .field { width: 132px !important; }
.save-state .save-word { display: none; }
@media (max-width: 1399px) { .find-btn .find-word { display: none; } .tb-right > .field { width: 104px !important; } .client-btn { max-width: 120px; } .tab { padding: 0 9px; } .topbar-in { gap: 10px; padding: 0 16px; } .tb-right { gap: 4px; } .site-id { font-size: 1.125rem; } }
/* Top bar controls: outlined, not white blocks. Clear borders so they still read as buttons;
   the one that is on (pressed or current) gets the light blue fill, same as the current tab. */
.topbar .icon-btn { background: transparent; color: #fff; border: 2px solid rgba(255,255,255,.75); box-shadow: none; }
.topbar .icon-btn:hover { background: rgba(255,255,255,.14); border-color: #fff; }
.topbar .icon-btn[disabled] { opacity: .4; }
.topbar .icon-btn[aria-pressed="true"] { background: var(--tb-on); color: var(--tb-on-text); border-color: var(--tb-on); outline: none; }
.topbar .field { background: transparent; border-color: rgba(255,255,255,.75); height: 34px; color: #fff; }
.topbar .field input { color: #fff; }
.topbar .field input::placeholder { color: rgba(255,255,255,.8); }
.topbar .field svg { color: #fff; }
.topbar .seg { border-color: rgba(255,255,255,.75); background: transparent; }
.topbar .seg button { color: #fff; min-height: 30px; padding: 0 10px; background: transparent; }
.topbar .seg button + button { border-left-color: rgba(255,255,255,.45); }
.topbar .seg button[aria-pressed="true"] { background: var(--tb-on); color: var(--tb-on-text); }
.find-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: var(--r-button); border: 2px solid rgba(255,255,255,.75); background: transparent; color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
.find-btn:hover { background: rgba(255,255,255,.14); border-color: #fff; }
.find-btn kbd { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }

.subtabs { position: sticky; top: 60px; z-index: 30; background: var(--card); border-bottom: 1.5px solid var(--border-row); }
.subtabs[hidden] { display: none; }
.topbar .more-btn { display: inline-flex; align-items: center; width: auto; padding: 0 8px 0 10px; gap: 2px; font-weight: 700; font-size: .9375rem; }
.more-menu .btn { justify-content: flex-start; width: 100%; }
.subtabs-in { max-width: none; margin: 0 auto; display: flex; flex-wrap: wrap; row-gap: 4px; align-items: center; gap: var(--s2); padding: var(--s2) var(--s5); } /* Nov 6: a tab's name never wraps inside it; with many tabs (Plan has 9) whole tabs go to a second row */
.subtab { flex: none; white-space: nowrap; display: inline-flex; align-items: center; gap: var(--s2); height: 38px; padding: 0 var(--s3); border-radius: var(--r-button); color: var(--text); text-decoration: none; font-weight: 700; border: 2px solid transparent; }
.subtab:hover { border-color: var(--border-row); }
.subtab[aria-current="page"] { background: var(--primary); color: var(--on-primary); }
.subtab .count { font-size: .75rem; font-weight: 700; padding: 1px 6px; border-radius: 999px; background: var(--chip); color: var(--chip-text); }
.subtab[aria-current="page"] .count { background: rgba(255,255,255,.25); color: inherit; }
.subtab .count.done { background: var(--good); color: #fff; }
.subtabs .spacer { flex: 1; }

.banner { max-width: none; margin: var(--s3) auto 0; padding: 0 var(--s5); }
.banner > div { display: flex; align-items: center; gap: var(--s3); background: var(--card); border: 2px solid var(--warn); border-radius: var(--r-card); padding: var(--s2) var(--s4); font-weight: 600; }
.shell-page { max-width: none; margin: 0 auto; padding: var(--s5) var(--s5) 96px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s4); }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

.find-overlay { position: fixed; inset: 0; background: rgba(6,14,31,.45); z-index: 90; display: flex; justify-content: center; align-items: flex-start; padding-top: 90px; }
.find-box { width: 640px; background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow-lift); padding: var(--s4); }
.find-box .field { width: 100%; height: 44px; }
.find-results { list-style: none; margin: var(--s3) 0 0; padding: 0; max-height: 420px; overflow: auto; }
.find-results li button { all: unset; box-sizing: border-box; width: 100%; display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r-button); cursor: pointer; }
.find-results li button:hover, .find-results li button[aria-selected="true"] { background: var(--primary-light); }
.find-results .where { color: var(--text-2); font-size: .875rem; }

.notes { list-style: none; margin: var(--s3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); max-height: 280px; overflow: auto; }
.notes li { display: flex; align-items: center; gap: var(--s2); }
.notes li .text { flex: 1; }
.notes li.filed .text { text-decoration: line-through; color: var(--text-2); }
textarea.note-input { width: 100%; min-height: 70px; border: 2px solid var(--border-input); border-radius: var(--r-input); background: var(--card); color: var(--text); font: inherit; padding: var(--s2); resize: vertical; }
.client-menu { display: flex; flex-direction: column; gap: var(--s2); }
.highlight { animation: hl 2s ease-out; }
@keyframes hl { 0%, 40% { box-shadow: 0 0 0 4px var(--primary); } 100% { box-shadow: none; } }

/* Client view (R075, R170): coach-only things disappear. */
:root[data-client-view="on"] .coach-only { display: none !important; }

/* Quick fill box (a locked number's "Add take-home" opens it in place). */
.field.big { height: 48px; font-size: 1.25rem; }
.btn.need { vertical-align: middle; margin: 2px 0; }

/* Dark: the top bar's whites softened to match the page; borders quieter. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) :is(.topbar, .site-id, .client-btn, .tab, .find-btn, .topbar .icon-btn, .topbar .seg button, .topbar .field input, .find-btn kbd, .topbar .field svg, .toast) { color: #E4E7EC; }
  :root:not([data-theme="light"]) .topbar { border-bottom: 1px solid #1C2029; }
  :root:not([data-theme="light"]) :is(.tab[aria-current="page"], .topbar .seg button[aria-pressed="true"], .topbar .icon-btn[aria-pressed="true"]) { color: var(--on-primary); }
  :root:not([data-theme="light"]) :is(.client-btn, .find-btn, .topbar .icon-btn, .topbar .field, .topbar .seg) { border-color: rgba(228, 231, 236, .45); }
}
:root[data-theme="dark"] :is(.topbar, .site-id, .client-btn, .tab, .find-btn, .topbar .icon-btn, .topbar .seg button, .topbar .field input, .find-btn kbd, .topbar .field svg, .toast) { color: #E4E7EC; }
:root[data-theme="dark"] .topbar { border-bottom: 1px solid #1C2029; }
:root[data-theme="dark"] :is(.tab[aria-current="page"], .topbar .seg button[aria-pressed="true"], .topbar .icon-btn[aria-pressed="true"]) { color: var(--on-primary); }
:root[data-theme="dark"] :is(.client-btn, .find-btn, .topbar .icon-btn, .topbar .field, .topbar .seg) { border-color: rgba(228, 231, 236, .45); }

/* Between a phone and 1280px (or a laptop with display scaling): no sideways scroll. The tools drop to a second
   line; the left group keeps its size so the client button never clips; the sub-tabs scroll with the page. */
@media (min-width: 761px) and (max-width: 1279px) {
  body { min-width: 0; }
  .topbar { position: static; }
  .topbar-in { flex-wrap: wrap; height: auto; padding: 8px 16px; row-gap: 6px; }
  .tb-left { flex: none; }
  .tb-right { margin-left: auto; flex-wrap: wrap; }
  .subtabs { top: 0; }
  .subtabs-in { flex-wrap: wrap; }
}

/* Phone: laptop first, but every screen works at phone width with no sideways page scroll.
   Wide tables scroll inside their own box; boxes open as a sheet at the bottom. */
@media (max-width: 760px) {
  body { min-width: 0; }
  .topbar { position: static; }
  .topbar-in { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
  .tb-left { flex: 1 1 100%; }
  .tabs { order: 2; width: 100%; overflow-x: auto; }
  .tb-right { order: 3; width: 100%; flex-wrap: wrap; justify-content: flex-start; row-gap: 6px; padding-bottom: 2px; } /* batch 8: wraps, nothing hides past the edge */
  .tb-right > .field { display: none; }
  .subtabs { top: 0; }
  .subtabs-in { flex-wrap: nowrap; overflow-x: auto; padding: 8px 12px; }
  .subtab { flex: none; }
  .banner { padding: 0 12px; }
  .banner > div { flex-wrap: wrap; }
  .shell-page { padding: 16px 12px 96px; }
  .page-head { flex-wrap: wrap; align-items: flex-start; }
  .strip { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; } .strip .metric { min-width: 0; overflow-wrap: anywhere; } /* batch 10: a long locked label wraps instead of widening the page */
  .metric { min-height: 0; padding: 10px 12px; }
  .metric .big { font-size: 1.5rem; }
  .metric.locked .big { font-size: .9375rem; }
  .card { padding: 12px; }
  .row-line { flex-wrap: wrap; }
  .pop { position: fixed !important; left: 8px !important; right: 8px !important; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important; width: auto !important; min-width: 0; max-height: 80vh; overflow: auto; }
  /* One finger scrolls the page: lists only scroll sideways on a phone, never up and down inside. */
  .list-scroll { max-height: none; overflow-x: auto; position: relative; touch-action: pan-x pan-y; }
  table.rows th, table.rows tfoot td { position: static; }
  /* Rows become cards: name on top, amount and the quick buttons under it. Side details stay behind More. */
  table.rows, table.rows tbody, table.rows tfoot { display: block; }
  table.rows thead { display: none; }
  table.rows tr.row, table.rows tfoot tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border-row); }
  table.rows tr.row td, table.rows tfoot td { display: block; height: auto; padding: 0; border: 0; }
  table.rows tr.row td:empty, table.rows tfoot td:empty { display: none; }
  table.rows tr.row td.check-cell { flex: none; width: 28px; }
  table.rows tr.row td.col-first { flex: 1 1 calc(100% - 36px); min-width: 0; }
  table.rows td.col-first .field { width: 100% !important; }
  table.rows tr.row td.num { text-align: left; }
  table.rows td.num .row-line { justify-content: flex-start !important; flex-wrap: wrap !important; }
  table.rows tr.row td.col-amount-is, table.rows tr.row td.col-date-is { display: none; }
  table.rows td.col-actions .icon-btn { display: none; }
  table.rows tr.group, table.rows tr.more { display: block; }
  table.rows tr.group td, table.rows tr.more td { display: block; height: auto; padding: 10px 12px; }
  .list-scroll { overflow-x: visible; }
  .card { overflow-x: auto; }
  .footer { flex-wrap: wrap; gap: 8px 12px; padding: 12px; }
  .footer .spacer { flex-basis: 100%; height: 0; }
  .grid2 { grid-template-columns: 1fr !important; }
  .toast { left: 12px !important; right: 12px !important; transform: none !important; width: auto !important; max-width: none !important; bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important; }
  .find-box { width: calc(100% - 24px); }
  .find-overlay { padding-top: 24px; }
  /* Long choice rows (Who pays) wrap inside the screen instead of running off it. */
  .seg { flex: 0 1 auto; flex-wrap: wrap; max-width: 100%; }
  .seg button { flex: 1 1 auto; min-height: 40px; }
}

/* Fix pass 5: slimmer chrome. */
/* Saved: a button; a small amber dot when a backup is due (coach only). */
.save-btn { position: relative; flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 32px; height: 32px; padding: 0 6px; border: 2px solid transparent; border-radius: var(--r-button); background: transparent; color: #BFE8CF; font: inherit; font-size: .8125rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.save-btn:hover { border-color: rgba(255,255,255,.6); }
.save-btn:focus-visible { outline: 3px solid #fff; outline-offset: 1px; }
.save-btn.unsaved { color: #fff; background: var(--guess); border-radius: 999px; padding: 0 10px; }
.backup-dot { position: absolute; top: 3px; right: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 2px var(--primary-dark); }
/* The client's name shows in full at 1440, at least 16 characters at 1280. */
.client-btn { max-width: 360px; }
@media (max-width: 1399px) { .client-btn { max-width: 224px; } }
/* Find and add in one box. */
.find-add { position: relative; flex: none; }
.find-add .field { width: 220px; }
.find-add kbd { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); margin-left: 4px; }
.find-drop { position: absolute; top: calc(100% + 6px); right: 0; width: 420px; z-index: 70; background: var(--card); color: var(--text); border: 2px solid var(--border-input); border-radius: var(--r-card); box-shadow: var(--shadow-lift); padding: var(--s2); margin: 0; max-height: 60vh; }
.find-drop li.muted { padding: var(--s2) var(--s3); }
.find-drop li button { min-height: 36px; align-items: center; }
.find-drop .add-line { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--primary); }
@media (max-width: 1399px) { .find-add .field { width: 160px; } }
/* $ / Hours / FI days as one compact control. */
.tb-right > .field.time-pick { width: auto !important; }
.topbar .field.time-pick { padding: 0 4px 0 6px; height: 32px; }
.topbar .time-pick select { color: #fff; font-weight: 700; cursor: pointer; padding-right: 2px; }
.topbar .time-pick select option { color: var(--text); }
/* Page head: one slim line under the sub-tabs. The title stays for screen readers; the sub-tab already says it. */
.page-head { align-items: center; margin-bottom: var(--s3); min-height: 0; }
.page-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.page-head p { margin: 0; font-size: .875rem; }
.page-head:not(:has(p)):has(> .row-line:empty) { display: none; }
/* Toast: bottom left, out of the way. */
.toast { left: 24px; right: auto; transform: none; max-width: 440px; }
@media (max-width: 760px) { .tb-right > .field.time-pick { display: inline-flex; flex: none; min-width: 76px; } }
/* Phones: the five tabs (Home, Net worth, Cash flow, Plan, Report) sit in a bar at the bottom. The top bar is unchanged. */
@media (max-width: 760px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; order: 0; width: auto; overflow: visible; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); background: var(--primary-dark); border-top: 1px solid rgba(228, 231, 236, .14); }
  .tab { justify-content: center; height: 44px; padding: 0 2px; font-size: .8125rem; text-align: center; line-height: 1.1; text-decoration: none !important; }
  .toast { bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important; }
  .report-this { bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
}
