/* Shell and shared components. Adapted from poc/ux/css/base.css (same classes and look):
   kept shell, pills, buttons, segmented, switch, cards, rows, inputs, choice cards, sheet, toast;
   removed set-only parts (budget bar, meters, hold-to-confirm, live pill). */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--base); color: var(--text-body);
  font: 400 var(--fs-15)/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; border-radius: var(--r-4); }
a { color: var(--brand-text); }
.ico { width: 20px; height: 20px; flex: none; display: block; }
.ico.lg { width: 26px; height: 26px; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.grow { flex: 1 1 auto; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; height: 100dvh; grid-template-columns: calc(var(--rail) + var(--safe-l)) minmax(0, 1fr); grid-template-rows: calc(var(--top) + var(--safe-t)) minmax(0, 1fr); grid-template-areas: "rail top" "rail main"; }
.app.bare { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr); grid-template-areas: "main"; }
.app.bare .rail, .app.bare .topbar { display: none; }
.rail { grid-area: rail; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: calc(10px + var(--safe-t)) 0 calc(12px + var(--safe-b)) var(--safe-l); background: var(--panel); border-right: 1px solid var(--line); }
.rail-mark { width: 40px; height: 40px; display: grid; place-items: center; margin-bottom: 10px; color: var(--brand-text); }
.rail-mark .ico { width: 28px; height: 28px; }
.rail-btn { position: relative; width: 60px; min-height: 56px; border-radius: var(--r-8); color: var(--text-3); display: grid; place-items: center; gap: 3px; padding: 6px 0; text-decoration: none; }
.rail-btn span { font-size: var(--fs-11); line-height: 1; }
.rail-btn:hover { color: var(--text); background: var(--field); }
.rail-btn[aria-current="page"] { color: var(--text); background: var(--active); }
.rail-btn[aria-current="page"]::before { content: ""; position: absolute; left: -6px; top: 14px; bottom: 14px; width: 3px; border-radius: 2px; background: var(--brand); }
.rail-grow { flex: 1; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: var(--safe-t) calc(12px + var(--safe-r)) 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; }
.crumb { display: flex; align-items: baseline; gap: 6px; min-width: 0; white-space: nowrap; overflow: hidden; }
.crumb b { color: var(--text); font-weight: 600; font-size: var(--fs-15); overflow: hidden; text-overflow: ellipsis; }
.crumb span { color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.main { grid-area: main; position: relative; overflow: hidden; background: var(--base); }
.page { position: absolute; inset: 0; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.page-inner { max-width: 1120px; margin: 0 auto; padding: 24px 24px calc(48px + var(--safe-b)); }
.page-head { display: flex; align-items: flex-end; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: var(--fs-24); line-height: 1.15; color: var(--text); font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.page-head p { margin: 4px 0 0; color: var(--text-2); max-width: 64ch; }

@media (max-width: 759px) {
  .app { grid-template-columns: minmax(0,1fr); grid-template-rows: calc(48px + var(--safe-t)) minmax(0,1fr) calc(60px + var(--safe-b)); grid-template-areas: "top" "main" "rail"; }
  .rail { flex-direction: row; justify-content: space-around; padding: 2px 4px var(--safe-b); border-right: 0; border-top: 1px solid var(--line); }
  .rail-mark, .rail-grow { display: none; }
  .rail-btn { width: auto; flex: 1; min-height: 56px; }
  .rail-btn[aria-current="page"]::before { left: 30%; right: 30%; top: -2px; bottom: auto; width: auto; height: 3px; }
  .topbar { padding-left: 16px; gap: 6px; }
  .page-inner { padding: 16px 16px calc(32px + var(--safe-b)); }
  .page-head h1 { font-size: var(--fs-20); }
  .hide-phone { display: none !important; }
}

/* ---------------------------------------------------------------- pills */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: var(--r-4); font: 600 var(--fs-12)/1 var(--font); white-space: nowrap; background: var(--field); color: var(--text-2); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.rec { background: var(--rec-wash); color: var(--rec-text); }
.pill.rec .dot { animation: blink 1.2s steps(2, jump-none) infinite; }
.pill.ok { background: var(--ok-wash); color: var(--ok); }
.pill.warn { background: var(--warn-wash); color: var(--warn); }
.pill.info { background: var(--info-wash); color: var(--info); }
.pill.brand { background: var(--brand-wash); color: var(--brand-text); }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pill.rec .dot { animation: none; } }

/* ---------------------------------------------------------------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--ctl); padding: 0 14px; border-radius: var(--r-6); background: var(--field); color: var(--text); font-weight: 550; white-space: nowrap; text-decoration: none; transition: background var(--t) var(--ease); }
.btn:hover { background: var(--raised); }
.btn.primary { background: var(--brand); color: var(--on-brand); font-weight: 650; }
.btn.primary:hover { background: var(--brand-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--field); color: var(--text); }
.btn.danger { color: var(--rec-text); }
.btn.danger.solid { background: var(--rec); color: #fff; }
.btn.lg { min-height: 52px; padding: 0 20px; font-size: var(--fs-17); border-radius: var(--r-8); }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-13); }
:root[data-input="touch"] .btn.sm { min-height: var(--hit); }
@media (pointer: coarse) { .btn.sm { min-height: var(--hit); } }
.btn[disabled], .btn[aria-busy="true"] { opacity: .5; pointer-events: none; }
.icon-btn { display: inline-grid; place-items: center; width: var(--ctl); height: var(--ctl); min-width: var(--ctl); border-radius: var(--r-6); color: var(--text-2); }
.icon-btn:hover { color: var(--text); background: var(--field); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------------- segmented, switch */
.seg { display: inline-flex; padding: 2px; border-radius: var(--r-8); background: var(--field); gap: 2px; max-width: 100%; overflow-x: auto; }
.seg > * { display: inline-flex; align-items: center; justify-content: center; min-height: calc(var(--ctl) - 4px); min-width: 44px; padding: 0 14px; border-radius: var(--r-6); color: var(--text-2); font-weight: 550; white-space: nowrap; text-decoration: none; }
.seg > [aria-pressed="true"], .seg > [aria-current="page"], .seg > [aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line-2) inset, 0 1px 2px rgba(0,0,0,.12); }
.switch { position: relative; width: 51px; height: 31px; flex: none; -webkit-appearance: none; appearance: none; margin: 0; border-radius: 16px; background: var(--raised); cursor: pointer; transition: background var(--t) var(--ease); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; transition: transform var(--t) var(--ease); box-shadow: 0 2px 4px rgba(0,0,0,.3); }
.switch:checked { background: var(--ok); }
.switch:checked::after { transform: translateX(20px); }

/* ---------------------------------------------------------------- cards, sections, rows */
.card { background: var(--card); border-radius: var(--r-12); padding: 16px; box-shadow: 0 0 0 1px var(--card-edge); }
.section { margin: 0 0 28px; }
.section > h2, .section-head h2 { margin: 0 0 10px; font-size: var(--fs-17); color: var(--text); font-weight: 650; }
.section > p.lead { margin: -4px 0 12px; color: var(--text-2); max-width: 70ch; }
.rows { background: var(--card); border-radius: var(--r-12); overflow: hidden; box-shadow: 0 0 0 1px var(--card-edge); }
.row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 16px; border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.row:first-child { border-top: 0; }
a.row:hover, button.row:hover { background: var(--field); }
button.row { width: 100%; text-align: left; }
.row .lbl { flex: 1 1 auto; min-width: 0; }
.row .lbl b { display: block; color: var(--text); font-weight: 550; overflow-wrap: anywhere; }
.row .lbl small { display: block; color: var(--text-3); font-size: var(--fs-13); margin-top: 1px; overflow-wrap: anywhere; }
.row .val { color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }
.input { width: 100%; min-height: var(--ctl); padding: 0 12px; border-radius: var(--r-6); border: 0; background: var(--field); color: var(--text); font-size: 16px; min-width: 0; box-shadow: inset 0 0 0 1px var(--line-2); }
:root[data-input="touch"] .input { min-height: var(--hit); }
.input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--brand-text); }
.input.bad, .input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--rec); }
select.input { padding-right: 28px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }

/* ---------------------------------------------------------------- choice cards (radio / checkbox as big cards) */
.choices { display: grid; gap: 8px; }
.choice { position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px; align-items: center; text-align: left; width: 100%; min-height: 60px; padding: 12px 14px; border-radius: var(--r-12); background: var(--field); color: var(--text-body); box-shadow: inset 0 0 0 1px transparent; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .radio { width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--text-3); grid-row: span 2; }
.choice .check { width: 22px; height: 22px; border-radius: 6px; box-shadow: inset 0 0 0 2px var(--text-3); grid-row: span 2; display: grid; place-items: center; color: var(--on-brand); }
.choice b { color: var(--text); font-weight: 600; }
.choice small { grid-column: 2; color: var(--text-2); font-size: var(--fs-13); line-height: 1.35; }
.choice .side { grid-row: span 2; color: var(--text-3); font-size: var(--fs-12); text-align: right; }
.choice:has(input:checked) { box-shadow: inset 0 0 0 2px var(--brand-text); background: var(--active); }
.choice:has(input:checked) .radio { box-shadow: inset 0 0 0 7px var(--brand); }
.choice:has(input:checked) .check { background: var(--brand); box-shadow: none; }
.choice:has(input:focus-visible) { outline: 2px solid var(--brand-text); outline-offset: 2px; }
.choice:has(input:disabled) { opacity: .5; cursor: default; }

/* ---------------------------------------------------------------- sheet (bottom sheet on phone, side sheet elsewhere) */
.sheet-scrim { position: fixed; inset: 0; z-index: 80; background: var(--scrim); opacity: 0; transition: opacity 200ms var(--ease); }
.sheet-scrim.open { opacity: 1; }
.sheet { position: fixed; z-index: 81; right: calc(12px + var(--safe-r)); top: calc(12px + var(--safe-t)); bottom: calc(12px + var(--safe-b)); width: min(480px, calc(100vw - 24px)); display: flex; flex-direction: column; border-radius: var(--r-16); background: var(--glass); -webkit-backdrop-filter: blur(24px) saturate(1.4); backdrop-filter: blur(24px) saturate(1.4); box-shadow: 0 0 0 1px var(--line-2), var(--shadow); transform: translateX(24px); opacity: 0; transition: transform 220ms var(--ease), opacity 220ms var(--ease); }
.sheet.open { transform: none; opacity: 1; }
.sheet.dialog { top: 50%; bottom: auto; left: 50%; right: auto; width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); transform: translate(-50%, -46%); }
.sheet.dialog.open { transform: translate(-50%, -50%); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 6px 20px; }
.sheet-head h2 { margin: 0; flex: 1; font-size: var(--fs-17); color: var(--text); font-weight: 650; }
.sheet-body { flex: 1; overflow: auto; padding: 6px 20px 20px; overscroll-behavior: contain; }
.sheet-grip { display: none; }
@media (max-width: 759px) {
  .sheet, .sheet.dialog { left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 90dvh; border-radius: var(--r-16) var(--r-16) 0 0; transform: translateY(40px); padding-bottom: var(--safe-b); }
  .sheet.open, .sheet.dialog.open { transform: none; }
  .sheet-grip { display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--text-3); margin: 8px auto 0; opacity: .6; }
}

/* ---------------------------------------------------------------- toast */
.toasts { position: fixed; z-index: 120; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; width: min(520px, calc(100vw - 32px)); }
@media (max-width: 759px) { .toasts { bottom: calc(76px + var(--safe-b)); } }
.toast { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: var(--r-12); background: var(--glass); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); box-shadow: 0 0 0 1px var(--line-2), var(--shadow); color: var(--text); pointer-events: auto; animation: toastIn 220ms var(--ease); }
.toast.warn { box-shadow: inset 3px 0 0 var(--warn), 0 0 0 1px var(--line-2); }
.toast.bad { box-shadow: inset 3px 0 0 var(--rec), 0 0 0 1px var(--line-2); }
.toast.ok { box-shadow: inset 3px 0 0 var(--ok), 0 0 0 1px var(--line-2); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }
