/* TAI Quote — mobile-first layout (390 px reference, centred column on tablets/desktop). */
html, body { min-height: 100%; }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); overscroll-behavior-y: none; }
body.editing { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

.appbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: env(safe-area-inset-top) 12px 0 16px; padding-top: max(env(safe-area-inset-top), 0px);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.appbar .brand { flex: 1; min-width: 0; gap: 10px; }
.appbar .brand .mark { width: 28px; height: 28px; font-size: 11px; border-radius: 7px; }
.appbar .title { font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-actions { display: flex; gap: 4px; }
#backBtn:not([hidden]) + .brand .mark { display: none; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 24px; display: grid; gap: 16px; }
main:focus { outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.tab { display: grid; justify-items: center; gap: 2px; min-height: 56px; padding: 6px 4px; border: 0; background: transparent; color: var(--text-2); font: 500 12px/1.2 inherit; font-family: inherit; cursor: pointer; border-radius: 12px; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--accent-text); }
.tab-new svg { background: var(--action); color: var(--action-text); border-radius: 10px; width: 40px; height: 28px; padding: 3px 9px; }
.tab-new { color: var(--text); }

/* list */
.search-row { display: grid; gap: 12px; }
.chips-scroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips-scroll::-webkit-scrollbar { display: none; }
.chips-scroll .chip { flex: none; }
.qlist { display: grid; gap: 10px; }
.qcard {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; text-align: left; width: 100%;
  padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
}
.qcard:hover { border-color: var(--line-strong); }
.qcard .client { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qcard .total { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.qcard .meta { font-size: 13px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qcard .badges { justify-self: end; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.badge.b-sample { color: var(--text-2); background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); }
.badge.b-sample::before { display: none; }
.empty { display: grid; justify-items: center; gap: 12px; text-align: center; padding: 40px 16px; color: var(--text-2); }
.empty svg { width: 56px; height: 56px; color: var(--product); }
.empty .btn { width: 100%; max-width: 320px; }
.onboard { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }

/* sections / forms */
.section { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.section > h2 { font-size: 15px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid2 > *, .grid3 > * { min-width: 0; }
.hint { font-size: 13px; color: var(--text-3); }
.warn-text { font-size: 13px; color: var(--warn); }
.err-text { font-size: 14px; color: var(--bad); }

/* items */
.item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: var(--surface-2); }
.item.bad { border-color: var(--bad); }
.item-head { display: flex; align-items: center; gap: 8px; }
.item-head .no { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-size: 13px; font-weight: 700; flex: none; }
.item-head .line-total { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }
.item-grid { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }
.item-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-grid > *, .item-grid2 > * { min-width: 0; }
.item label.field { font-size: 12px; gap: 4px; }
.item .rm { color: var(--text-3); }
.add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.totals { display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.totals .r { display: flex; justify-content: space-between; gap: 12px; color: var(--text-2); }
.totals .r span:last-child { color: var(--text); }
/* very large amounts wrap instead of widening the page (390 px phones) */
.totals .r span, .totals .grand span, .item-head .line-total { min-width: 0; overflow-wrap: anywhere; }
.totals .r span:last-child, .totals .grand span:last-child { text-align: right; }
.totals .grand { margin-top: 6px; padding: 12px 14px; border-radius: 12px; background: var(--action); color: var(--action-text); font-weight: 750; font-size: 18px; display: flex; justify-content: space-between; }
.not-invoice { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--info); background: var(--info-bg); border-radius: 10px; padding: 10px 12px; }
.not-invoice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; display: flex; gap: 8px; justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line);
}
.actionbar .btn { flex: 1; max-width: 340px; }
.danger-zone { display: flex; gap: 8px; flex-wrap: wrap; }
.confirm { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: var(--bad-bg); color: var(--bad); }
.confirm span { flex: 1; min-width: 160px; font-weight: 600; }

/* catalog */
.clist { display: grid; gap: 8px; }
.crow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-align: left; color: var(--text); font: inherit; cursor: pointer; width: 100%; }
.crow .n { font-weight: 600; overflow-wrap: anywhere; }
.crow .p { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.crow .m { font-size: 13px; color: var(--text-3); }

/* settings */
.logo-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-prev { width: 120px; height: 60px; border-radius: 10px; border: 1px dashed var(--line-strong); display: grid; place-items: center; background: #fff; overflow: hidden; }
.logo-prev img { max-width: 100%; max-height: 100%; }
.logo-prev.none { background: var(--surface-2); color: var(--text-3); font-size: 12px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns .btn { flex: 1 1 160px; }
.seg { display: inline-grid; grid-auto-flow: column; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; }
.seg button { min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--text); font: 500 15px inherit; font-family: inherit; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--action); color: var(--action-text); }
.links { display: flex; gap: 8px; flex-wrap: wrap; }
.foot { text-align: center; font-size: 12px; color: var(--text-3); padding: 8px 0 0; }

/* bottom sheet (dialog) */
dialog.sheet { margin: auto auto 0; width: 100%; max-width: 720px; max-height: 86vh; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); overflow: auto; }
dialog.sheet h2 { font-size: 18px; margin-bottom: 12px; }
.pick-list { display: grid; gap: 6px; margin-top: 12px; }
.pick-list button { text-align: left; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

.toast { bottom: calc(88px + env(safe-area-inset-bottom)); }

@media (min-width: 760px) {
  main { padding: 24px; }
  .item-grid { grid-template-columns: 1fr 1fr 1.2fr 1fr 1fr; }
}
@media (max-width: 360px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .item-grid { grid-template-columns: 1fr 1fr; }
}

/* touch: every tappable control ≥ 44 px */
.chip, .btn.small { min-height: 44px; }
.qcard, .crow { min-height: 64px; }
