/* Phone-first layer. Spacing scale: 4, 8, 12, 16, 24. One typeface (system). Dark green and off-white from styles.css. Under 768px = phone. */
:root { --tab-h: 60px; --safe-b: 0px; --bar-h: 0px; --tot-h: 0px; }
@supports (padding: env(safe-area-inset-bottom)) { :root { --safe-b: env(safe-area-inset-bottom); } }
#mnav { display: none !important; }
.nav-h { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #8aa0a8; padding: 12px 10px 4px; }
.nav button { min-height: 40px; }
.nav-h:first-child { padding-top: 0; }
.side .status { color: #9db0b7; }

/* sign-in */
#login-root { position: fixed; inset: 0; z-index: 200; background: var(--paper); display: grid; place-items: center; padding: 16px; }
.login { width: min(360px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.login h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.login p { margin: 0; color: var(--ink-2); }
.login input { font-size: 17px; padding: 12px; min-height: 48px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.lg-l { font-size: 13px; color: var(--ink-2); margin-bottom: -6px; }
.login small { color: var(--ink-3); }
.lg-err { min-height: 20px; color: var(--danger); font-size: 14px; }

/* shared bits */
.back { display: none; }
.hello { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hello h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0 8px; }
.big-actions .btn { min-height: 64px; font-size: 17px; }
.who-pick h2 { margin: 0 0 4px; }
.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.install { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--accent-soft); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.install > div { flex: 1 1 200px; }
.warnbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.more-row { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 64px; padding: 12px 16px; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; cursor: pointer; }
.card > .more-row:first-child { border-top: 0; }
.more-row small { display: block; color: var(--ink-3); }
.more-row i { font-style: normal; font-size: 26px; color: var(--ink-3); }
.pin-show { font-size: 34px; font-weight: 700; letter-spacing: .25em; font-variant-numeric: tabular-nums; margin-top: 4px; }
.check-row { display: flex; gap: 12px; align-items: center; min-height: 44px; }
.check-row input { width: 24px; height: 24px; flex: none; }
.listsearch { margin-bottom: 8px; }
.listsearch input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 44px; font-size: 16px; background: #fff; }
.row-btns.col { flex-direction: column; }
.row-btns.col .btn { width: 100%; justify-content: center; }

/* recorder */
.rec-box { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.rec-btn { width: 88px; height: 88px; border-radius: 50%; border: 0; background: var(--danger); display: grid; place-items: center; cursor: pointer; flex: none; }
.rec-dot { width: 32px; height: 32px; border-radius: 50%; background: #fff; transition: border-radius .15s; }
.rec-btn.on { animation: pulse 1.6s infinite; } .rec-btn.on .rec-dot { border-radius: 6px; width: 28px; height: 28px; }
.rec-info { flex: 1 1 180px; min-width: 0; }
.rec-time { font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.rec-meter { display: flex; align-items: flex-end; gap: 4px; height: 36px; }
.rec-meter i { width: 8px; height: 4px; background: var(--accent); border-radius: 2px; transition: height .08s; }
.rec-state { font-size: 14px; color: var(--ink-2); margin-top: 4px; }
.rec-state.ok { color: var(--ok); } .rec-state.warn { color: var(--warn); } .rec-state.bad { color: var(--danger); } .rec-state.rec { color: var(--danger); font-weight: 600; }
.rec-file { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }
.rec-file.big { width: 100%; }

/* ---------- desktop and tablet: no phone chrome ---------- */
@media (min-width: 768px) {
  .tabbar, .pbar, .seg, .sh-grab { display: none !important; }
  .side-panel .sh-grab { display: none; }
}

/* ---------- phone ---------- */
@media (max-width: 767px) {
  html, body { height: auto; }
  body { -webkit-text-size-adjust: 100%; padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); overflow-x: hidden; }
  .shell { display: block; height: auto; min-height: 100vh; }
  .side { display: none; }
  .main { overflow: visible; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 16px 8px; gap: 8px; min-height: 56px; }
  .topbar h1 { font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .sub, .topbar .right { display: none; }
  .back { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px 0 0; color: var(--accent); font-weight: 600; }
  .back[hidden] { display: none; }
  .back::before { content: '\2039'; font-size: 28px; line-height: 1; margin-right: 4px; }
  .page { padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + var(--bar-h) + var(--tot-h) + 24px); max-width: 100%; }
  body.has-bar { --bar-h: 76px; } body.has-bar.has-tot { --tot-h: 44px; } body.has-tot:not(.has-bar) { --tot-h: 44px; }

  /* tab bar */
  .tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); display: grid; grid-template-columns: repeat(5, 1fr); background: #fff; border-top: 1px solid var(--line); }
  .tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; min-width: 44px; background: none; border: 0; color: var(--ink-2); font-size: 12px; font-weight: 600; cursor: pointer; }
  .tab.on { color: var(--accent); }
  .tab.on::before { content: ''; position: absolute; top: 0; left: 24%; right: 24%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
  .tab-main svg { flex: none; width: 24px; height: 24px; padding: 12px; margin: -12px; box-sizing: content-box; transform: translateY(-16px); background: var(--accent); color: #fff; border-radius: 50%; box-shadow: 0 4px 12px rgba(15,118,110,.35); border: 3px solid #fff; }
  .tab-main.on { color: var(--accent); } .tab-main.on::before { display: none; }
  .tab-badge { position: absolute; top: 4px; right: calc(50% - 22px); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; font-style: normal; line-height: 20px; text-align: center; }
  .tab-badge[hidden] { display: none; }

  /* pinned action bar (total, then primary action) */
  .pbar { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 45; background: #fff; border-top: 1px solid var(--line); padding: 8px 16px; }
  .pbar[hidden] { display: none; }
  .pb-tot { display: flex; justify-content: space-between; align-items: baseline; padding: 0 0 4px; font-size: 14px; color: var(--ink-2); }
  .pb-tot b { font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
  .pb-btns { display: flex; gap: 8px; }
  .pb-btns .btn.big { margin: 0; width: auto; }
  .pb-btns .primary { flex: 1 1 auto; min-width: 0; } .pb-btns .pb-more { flex: none; width: 96px; }
  .has-tot .pbar { padding-top: 8px; }
  body.has-bar { --bar-h: 68px; } body.has-bar.has-tot { --bar-h: 112px; --tot-h: 0px; }
  body.has-tot:not(.has-bar) { --bar-h: 48px; --tot-h: 0px; }

  /* touch targets and inputs */
  .btn, button.chip, .more-row, .tab, select, .nav button { min-height: 44px; }
  .btn.sm { min-height: 44px; padding: 8px 14px; font-size: 14px; }
  .btn.big { min-height: 48px; font-size: 16px; }
  .page a:not(.btn), .sheet a:not(.btn) { display: inline-flex; align-items: center; min-height: 44px; }
  .btn { display: inline-flex; align-items: center; justify-content: center; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; min-height: 44px; }
  .field input, .field select, .field textarea { padding: 10px 12px; }
  input[type=checkbox], input[type=radio] { width: 24px; height: 24px; }
  .checkline, .iv-edit { min-height: 44px; }
  .checkline { align-items: center; }
  .chip { min-height: 44px; padding: 8px 14px; font-size: 14px; }
  .list-item { min-height: 56px; padding: 12px 16px; align-items: center; }
  .acard { min-height: 44px; }
  .card { overflow: visible; }
  .card table:not(.rt) { display: block; overflow-x: auto; }
  .grid, .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .grid:has(> .kpi), .mgrid { grid-template-columns: 1fr 1fr; }
  .kpi .val { font-size: 22px; }
  .pill { font-size: 12px; padding: 4px 8px; }
  h2.sec { margin: 24px 0 8px; }

  /* tables become cards */
  table.rt, .rt thead, .rt tbody, .rt tr, .rt td { display: block; width: auto; }
  .rt thead { display: none; }
  .rt tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .rt tr:last-child { border-bottom: 0; }
  .rt tr:hover td { background: none; }
  .rt td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; min-height: 28px; overflow-wrap: anywhere; }
  .rt td::before { content: attr(data-label); flex: none; max-width: 40%; color: var(--ink-3); font-size: 13px; text-align: left; }
  .rt td[data-label=""]::before { display: none; }
  .rt td:first-child { display: block; text-align: left; font-weight: 600; padding-bottom: 4px; }
  .rt td:first-child::before { display: none; }
  .rt td.blank { display: none; }
  .rt td.empty { display: block; text-align: center; }
  .rt td input { width: 100%; }
  .rt .inv-sec td { display: block; text-align: left; }
  .rt .inv-sec td:empty { display: none; }
  .rt tr.inv-sec { background: #f4f7f8; padding: 8px 16px; }

  /* quote and invoice lines as cards */
  .lines { display: grid; gap: 8px; }
  .line-card { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-align: left; min-height: 64px; padding: 12px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; width: 100%; }
  .lc-d { font-weight: 600; grid-column: 1 / -1; overflow-wrap: anywhere; }
  .lc-m { grid-column: 1 / -1; color: var(--ink-3); font-size: 13px; }
  .lc-q { grid-column: 1; color: var(--ink-2); font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
  .lc-a { grid-column: 2; align-self: baseline; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .line-card.waived .lc-q { text-decoration: none; }
  div.line-card { cursor: default; min-height: 0; padding: 10px 16px; }
  .phone-hide { display: none !important; }
  .line-card.waived .lc-a { color: var(--warn); }

  /* invoice document on a phone */
  .inv-doc { padding: 16px !important; max-width: 100% !important; }
  .inv-doc > div:nth-child(2) { flex-direction: column; }
  .inv-doc > div:nth-child(2) > div:last-child { text-align: left !important; }
  .totals table { width: 100%; }
  .pay-qr { width: min(300px, 100%); }
  .pn-tools .btn { flex: 1 1 40%; }

  /* segmented control */
  .seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #e9eef2; border-radius: 10px; padding: 4px; margin-bottom: 16px; }
  .seg button { min-height: 44px; border: 0; background: none; border-radius: 8px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
  .seg button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 2px rgba(16,24,40,.12); }

  /* money rows */
  .age { grid-template-columns: 1fr auto; }
  .mrow { flex-wrap: wrap; }
  .toolbar { flex-wrap: wrap; } .toolbar input { flex: 1 1 100%; } .toolbar select { flex: 1 1 100%; }

  /* sheets: side panels become bottom sheets */
  .side-panel { inset: auto 0 0 0; width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 16px 16px 0 0; padding-bottom: var(--safe-b); box-shadow: 0 -16px 40px -12px rgba(0,0,0,.35); z-index: 70; transition: transform .18s ease-out; animation: sheet-in .18s ease-out; }
  .scrim { z-index: 65; }
  .side-panel .sh-grab { display: flex; padding: 8px 0 0; justify-content: center; touch-action: none; }
  .side-panel .sh-grab i { width: 40px; height: 4px; border-radius: 2px; background: #c3ced6; }
  .side-panel .ph { padding: 8px 16px; touch-action: none; }
  .side-panel .pb { padding: 16px; }
  #sheet-root .scrim { z-index: 65; } .sheet { z-index: 70; }
  #overlay .side-panel .grid.g2 { grid-template-columns: 1fr; }

  /* agents: full screen, above the content and below the tab bar */
  .fab, #dk-close, .dk-grip { display: none !important; }
  .dock { top: 0; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); width: 100%; height: auto; border: 0; border-radius: 0; box-shadow: none; z-index: 40; padding-top: env(safe-area-inset-top); }
  body.dock-open .dock { display: flex; }
  .dk-head { min-height: 56px; }
  .dk-compose { padding-bottom: 8px; }
  .dk-compose textarea { font-size: 16px; min-height: 44px; }
  .dk-compose .btn { min-height: 44px; }
  .dk-who select, .dk-who input { min-height: 44px; font-size: 16px; }
  body.on-agents .pbar { display: none; }
  body.on-agents { overflow: hidden; }
  body.dock-open .shell { margin-right: 0; }
  .toast { bottom: calc(var(--tab-h) + var(--safe-b) + var(--bar-h) + 12px); max-width: 92vw; }

  /* schedule grid never used on phones, but keep it from widening the page */
  .week { display: none; }
  /* print is unchanged */
}
@media (max-width: 767px) and (prefers-reduced-motion: reduce) { .sheet, .side-panel { animation: none; transition: none; } .rec-btn.on { animation: none; } }
@media print { .tabbar, .pbar, #login-root { display: none !important; } }

@media print { .screen-only, .rf-note { display: none !important; } .phone-hide { display: table !important; } }
.rf-note { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tab-h, 0px) + 16px); z-index: 90; display: flex; align-items: center; gap: 12px; justify-content: space-between; background: #1d2a35; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.3); font-size: 14px; }
.rf-note .btn { flex: none; min-height: 40px; }
@media (min-width: 768px) { .rf-note { left: auto; right: 24px; max-width: 420px; bottom: 24px; } }
.dk-off { margin: 0 14px 6px; padding: 8px 10px; border-radius: 8px; background: var(--warn-soft, #fff4e0); color: var(--warn, #8a5a00); font-size: 13px; }
.dk-off[hidden] { display: none; }
.tmp-pass { font: 600 20px/1.3 ui-monospace, Menlo, monospace; letter-spacing: .04em; margin: 8px 0; padding: 10px 12px; background: #fff; border: 1px dashed var(--line); border-radius: 8px; user-select: all; overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
