/* app.css - the workspace layout and the shared pieces (rail, topbar, cards,
   tables, forms, buttons, chips, modals, toasts). Only uses names from
   tokens.css. Each block adds its own small styles inside its own file. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: var(--t-md); line-height: var(--leading); }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 600; }
p { margin: 0 0 var(--s3); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: var(--t-sm); }
.xs { font-size: var(--t-xs); }
.right { text-align: right; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- the frame: rail + topbar + page ---------- */
.frame { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }
.rail { background: var(--iron); color: var(--on-iron); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.rail__brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s4) var(--s3); border-bottom: 1px solid rgba(255,255,255,.12); }
.rail__logo { width: 40px; height: 40px; object-fit: contain; }
.rail__word { font-family: var(--font-display); letter-spacing: .12em; font-size: .95rem; text-transform: uppercase; background: var(--chrome); -webkit-background-clip: text; background-clip: text; color: transparent; }
.rail__sub { display: block; font-family: var(--font-condensed); font-size: .8rem; letter-spacing: .12em; color: var(--chrome-mid); text-transform: uppercase; }
.rail__nav { display: flex; flex-direction: column; padding: var(--s3) var(--s2); gap: 2px; }
.rail__link { display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s3); border-radius: var(--radius-sm); color: var(--chrome-mid); text-decoration: none; font-family: var(--font-condensed); font-size: 1.02rem; letter-spacing: .04em; text-transform: uppercase; }
.rail__link:hover { background: rgba(255,255,255,.07); color: #fff; }
.rail__link.is-active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--chrome-solid); }
.rail__link svg { width: 18px; height: 18px; flex: none; }
.rail__foot { margin-top: auto; padding: var(--s3) var(--s4) var(--s4); border-top: 1px solid rgba(255,255,255,.12); font-size: var(--t-xs); color: var(--chrome-mid); }
.rail__foot strong { color: #fff; display: block; font-weight: 600; font-size: var(--t-sm); }
.rail__foot button { background: none; border: 0; color: var(--chrome-mid); padding: 0; cursor: pointer; text-decoration: underline; font-size: var(--t-xs); }
.rail__foot button:hover { color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s5); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar__title { font-size: var(--t-lg); font-weight: 600; }
.topbar__crumb { color: var(--muted); font-size: var(--t-sm); }
.topbar__crumb a { color: var(--muted); text-decoration: none; } .topbar__crumb a:hover { text-decoration: underline; }
.page { padding: var(--s5); max-width: var(--content-max); width: 100%; margin: 0 auto; }
.page--narrow { max-width: var(--sheet-max); }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s5); }
.page-head h1 { font-size: var(--t-xl); }
.page-head .sub { color: var(--muted); margin-top: var(--s1); }
.eyebrow { font-family: var(--font-condensed); text-transform: uppercase; letter-spacing: .12em; font-size: var(--t-xs); color: var(--muted); font-weight: 600; }
.menu-btn { display: none; }

.support-banner { background: var(--support); color: #fff; padding: var(--s2) var(--s5); display: flex; align-items: center; gap: var(--s3); font-size: var(--t-sm); position: sticky; top: 0; z-index: 6; }
.support-banner button { background: #fff; color: var(--support); border: 0; border-radius: var(--radius-sm); padding: 4px 10px; font-weight: 600; cursor: pointer; }
.seed-banner { background: var(--warn-wash); color: var(--warn); border-bottom: 1px solid var(--line); padding: 6px var(--s5); font-size: var(--t-xs); text-align: center; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card__title { font-size: var(--t-md); font-weight: 600; }
.card__body { padding: var(--s5); }
.card__body--flush { padding: 0; }
.card__foot { padding: var(--s3) var(--s5); border-top: 1px solid var(--line); color: var(--muted); font-size: var(--t-sm); }
.grid { display: grid; gap: var(--s4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid--tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }

/* stat tiles (Xero Projects style: label, big number, sub line) */
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s4) var(--s4) var(--s3); }
.tile__label { font-size: var(--t-xs); color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-family: var(--font-condensed); font-weight: 600; }
.tile__value { font-size: var(--t-xl); font-weight: 600; font-family: var(--font-mono); font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile__sub { font-size: var(--t-xs); color: var(--muted); margin-top: 2px; }
.tile--good .tile__value { color: var(--good); } .tile--bad .tile__value { color: var(--bad); } .tile--warn .tile__value { color: var(--warn); }
.equation { display: flex; align-items: center; justify-content: center; gap: var(--s5); flex-wrap: wrap; padding: var(--s4); }
.equation__op { font-size: var(--t-xl); color: var(--muted); }
.equation .tile { border: 0; text-align: center; padding: var(--s2); background: none; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th, .table td { padding: 10px var(--s4); text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: var(--t-xs); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.table td.num, .table th.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.is-link { cursor: pointer; } .table tr.is-link:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 600; background: var(--surface-2); }
.table .cell-main { font-weight: 600; color: var(--ink); }
.table .cell-sub { color: var(--muted); font-size: var(--t-xs); }
.table-wrap { overflow-x: auto; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-family: var(--font-condensed); font-size: 1rem; letter-spacing: .05em; text-transform: uppercase; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--iron); color: var(--on-iron); border-color: var(--iron); }
.btn--primary:hover { background: var(--iron-2); }
.btn--chrome { background: var(--chrome); background-color: var(--chrome-solid); color: var(--iron); border-color: var(--chrome-lo); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); }
.btn--danger { color: var(--bad); border-color: var(--bad); background: var(--surface); }
.btn--danger:hover { background: var(--bad-wash); }
.btn--sm { padding: 5px 10px; font-size: .9rem; }
.btn--lg { padding: 12px 20px; font-size: 1.1rem; }
.btn--block { width: 100%; }
.btn svg { width: 16px; height: 16px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--info); cursor: pointer; text-decoration: underline; font: inherit; }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: var(--radius-pill); font-size: var(--t-xs); font-weight: 600; background: var(--accent-wash); color: var(--ink-2); white-space: nowrap; letter-spacing: .02em; }
.chip--good { background: var(--good-wash); color: var(--good); }
.chip--warn { background: var(--warn-wash); color: var(--warn); }
.chip--bad { background: var(--bad-wash); color: var(--bad); }
.chip--info { background: var(--info-wash); color: var(--info); }
.chip--iron { background: var(--iron); color: #fff; }
.chip--starter { background: var(--warn-wash); color: var(--warn); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }
.bucket-labor { color: var(--bucket-labor); } .bucket-materials { color: var(--bucket-materials); } .bucket-subs { color: var(--bucket-subs); }
.bucket-equipment { color: var(--bucket-equipment); } .bucket-trips { color: var(--bucket-trips); } .bucket-other { color: var(--bucket-other); }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--s4); }
.field > span, .field__label { font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: var(--t-xs); color: var(--muted); }
.input, .select, .textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); min-height: 38px; }
.input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.input.num { text-align: right; }
.input[aria-invalid="true"] { border-color: var(--bad); }
.textarea { min-height: 80px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7078' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-row { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-actions { display: flex; gap: var(--s3); justify-content: flex-end; align-items: center; margin-top: var(--s4); flex-wrap: wrap; }
.form-error { color: var(--bad); background: var(--bad-wash); border-radius: var(--radius-sm); padding: var(--s2) var(--s3); font-size: var(--t-sm); margin-bottom: var(--s4); }
.form-ok { color: var(--good); background: var(--good-wash); border-radius: var(--radius-sm); padding: var(--s2) var(--s3); font-size: var(--t-sm); margin-bottom: var(--s4); }
.check { display: flex; gap: var(--s2); align-items: center; font-size: var(--t-sm); }
.search { max-width: 340px; }
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button { border: 0; background: var(--surface); padding: 6px 12px; cursor: pointer; font-size: var(--t-sm); font-weight: 600; color: var(--muted); }
.segmented button + button { border-left: 1px solid var(--line-strong); }
.segmented button.is-on { background: var(--iron); color: #fff; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s5); overflow-x: auto; }
.tabs button, .tabs a { background: none; border: 0; padding: 10px 14px; cursor: pointer; font-family: var(--font-condensed); font-size: 1.02rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; text-decoration: none; white-space: nowrap; }
.tabs button.is-on, .tabs a.is-on { color: var(--ink); border-bottom-color: var(--iron); }
.tabs .count { display: inline-block; margin-left: 4px; background: var(--accent-wash); color: var(--ink-2); border-radius: var(--radius-pill); padding: 0 7px; font-size: var(--t-xs); }

/* ---------- empty states ---------- */
.empty { text-align: center; padding: var(--s7) var(--s5); color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: var(--s2); font-size: var(--t-lg); }
.empty p { max-width: 42ch; margin: 0 auto var(--s4); }
.empty--sm { padding: var(--s5); }

/* ---------- budget bars ---------- */
.bars { display: flex; flex-direction: column; gap: var(--s3); }
.bar { display: grid; grid-template-columns: 130px 1fr 190px; gap: var(--s3); align-items: center; font-size: var(--t-sm); }
.bar__label { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.bar__track { position: relative; height: 14px; background: var(--bucket-budget); border-radius: var(--radius-pill); overflow: hidden; }
.bar__fill { position: absolute; inset: 0 auto 0 0; background: currentColor; border-radius: var(--radius-pill); }
.bar__fill.is-over { background: var(--bad); }
.bar__nums { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; color: var(--ink-2); white-space: nowrap; }
.bar__nums small { color: var(--muted); }

/* ---------- activity ---------- */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 150px 1fr; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); font-size: var(--t-sm); }
.activity li:last-child { border-bottom: 0; }
.activity .when { color: var(--muted); font-size: var(--t-xs); }
.activity .who { color: var(--muted); font-size: var(--t-xs); }

/* ---------- modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(17, 18, 20, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh var(--gutter); z-index: var(--z-modal); overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; }
.modal--wide { max-width: 860px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); }
.modal__title { font-size: var(--t-lg); }
.modal__body { padding: var(--s5); }
.modal__close { background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; }
.toasts { position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: var(--s2); z-index: var(--z-toast); pointer-events: none; }
.toast { background: var(--iron); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: var(--t-sm); animation: toast-in .2s ease-out; pointer-events: auto; }
.toast--bad { background: var(--bad); }
.toast--good { background: var(--good); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- signed-out pages ---------- */
.door { min-height: 100vh; display: grid; place-items: center; background: var(--iron); padding: var(--s5) var(--gutter); }
.door__card { background: var(--surface); border-radius: var(--radius); padding: var(--s6); width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.door__brand { text-align: center; margin-bottom: var(--s5); }
.door__brand img { width: 72px; height: 72px; object-fit: contain; filter: invert(1); }
.door__brand .word { font-family: var(--font-display); letter-spacing: .14em; text-transform: uppercase; font-size: 1.1rem; margin-top: var(--s2); }
.door__brand .sub { font-family: var(--font-condensed); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-size: var(--t-xs); }

/* ---------- loading ---------- */
.loading { padding: var(--s7); text-align: center; color: var(--muted); }

/* ---------- kbd ---------- */
kbd { font-family: var(--font-mono); font-size: var(--t-xs); background: var(--surface-2); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }

/* ---------- responsive: tablet widths ---------- */
@media (max-width: 1024px) {
  .grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 768px) {
  .frame { grid-template-columns: 1fr; }
  .rail { position: fixed; inset: 0 auto 0 0; width: var(--rail-w); z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .rail.is-open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-flex; }
  .topbar, .page { padding-left: var(--gutter); padding-right: var(--gutter); }
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
  .form-row, .form-row--3 { grid-template-columns: 1fr; }
  .bar { grid-template-columns: 100px 1fr; }
  .bar__nums { grid-column: 2; text-align: left; }
  .activity li { grid-template-columns: 1fr; gap: 2px; }
}
