/* ---------------- buttons ---------------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-line: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--btn-line);
  background: var(--btn-bg); color: var(--btn-fg); font-weight: 560; cursor: pointer;
  text-decoration: none; white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-1);
  /* release: a damped spring back to full size, a touch past it, then settles (video 1 #1) */
  transition: transform 420ms var(--spring), background-color var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { background: var(--surface-2); }
/* press: down to 95% quickly. Only the drawing shrinks; the tap area stays put. */
.btn:active:not(:disabled), .btn.is-pressed:not(:disabled) { transform: scale(.95); transition-duration: 90ms, var(--t-fast), var(--t-fast); transition-timing-function: var(--ease-out); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary {
  --btn-bg: var(--brand); --btn-fg: var(--on-brand); --btn-line: transparent;
  background: linear-gradient(color-mix(in srgb, var(--brand) 88%, white), var(--brand));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), inset 0 -2px 0 rgba(0,0,0,.18), 0 1px 2px rgba(0,0,0,.25), 0 6px 18px -8px color-mix(in srgb, var(--brand) 70%, transparent);
}
.btn.primary:hover { background: var(--brand-hi); }
.btn.primary:active:not(:disabled), .btn.primary.is-pressed:not(:disabled) { transform: scale(.95); box-shadow: inset 0 2px 4px rgba(0,0,0,.25); }
.btn.danger { --btn-fg: var(--bad); }
.btn.danger.solid { --btn-bg: var(--bad); --btn-fg: #fff; --btn-line: transparent; }
.btn.ghost { --btn-bg: transparent; --btn-line: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-sunk); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: var(--step--1); border-radius: 8px; }
.btn.large { min-height: 52px; padding: 0 22px; font-size: var(--step-1); border-radius: 14px; }
.btn.icon { width: 40px; padding: 0; }
.btn.icon.small { width: 32px; }
.btn.block { width: 100%; }
/* busy state: keep the width, swap the label for a spinner */
.btn[aria-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--btn-fg); border-right-color: transparent; animation: spin .7s linear infinite;
}
.btn.done { --btn-bg: var(--good); --btn-fg: #fff; --btn-line: transparent; }

/* ---------------- form fields ---------------- */
.field { display: grid; gap: 6px; align-content: start; }   /* a taller neighbour (one with a hint) never stretches the label away from its box */
.field > label, .label { font-size: var(--step--1); font-weight: 600; color: var(--text-2); }
.field .hint { font-size: var(--step--1); color: var(--muted); }
.field .error-text { font-size: var(--step--1); color: var(--bad); }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { min-height: 88px; resize: vertical; line-height: 1.45; }
.input::placeholder { color: var(--muted); opacity: .8; }
.input:focus { outline: none; border-color: var(--brand-hi); box-shadow: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input:disabled, .input[readonly] { background: var(--surface-sunk); }
.field.shake, .shake { animation: shake 420ms linear; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand-hi); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 36px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background var(--t); flex: none; }
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform var(--t) var(--spring);
}
.switch input:checked + .track { background: var(--brand-hi); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

/* segmented control */
.segmented { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-sunk); border: 1px solid var(--line); gap: 2px; }
.segmented button { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; border: 0; background: transparent; min-height: 32px; padding: 0 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 560; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

/* ---------------- surfaces ---------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 16px; box-shadow: var(--shadow-1); }
.card.flush { padding: 0; overflow: hidden; }
.card > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card > header h3 { font-size: var(--step-1); }
.card-link { display: block; color: inherit; text-decoration: none; transition: box-shadow var(--t), transform var(--t-fast); }
.card-link:hover { box-shadow: var(--shadow-2); }
.card-link:active { transform: scale(.995); }
.section-title { font-size: var(--step--1); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; }

/* ---------------- badges & chips ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; background: var(--surface-sunk); color: var(--text-2); border: 1px solid transparent; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.outline { background: transparent; border-color: var(--line-strong); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.svc { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 650; white-space: nowrap; }
.svc.cabinets { background: var(--svc-cabinets-soft); color: var(--svc-cabinets); }
.svc.cabinet_install { background: var(--svc-install-soft); color: var(--svc-install); }
.svc.countertops { background: var(--svc-countertops-soft); color: var(--svc-countertops); }
.svc .stage { font-weight: 500; opacity: .9; }
.svc .stage::before { content: "·"; margin-right: 6px; }
.pending-sync { display: inline-flex; align-items: center; gap: 6px; color: var(--warn); font-size: var(--step--1); font-weight: 600; }
.pending-sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }

/* ---------------- tabs (sliding indicator) ---------------- */
.tabs { position: relative; display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a, .tabs button { position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 12px; border: 0; background: none; color: var(--text-2); font-weight: 600; text-decoration: none; white-space: nowrap; cursor: pointer; }
.tabs [aria-current="page"], .tabs [aria-selected="true"] { color: var(--text); }
.tabs .indicator { position: absolute; bottom: -1px; left: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--brand-hi); transition: transform var(--t-slow) var(--ease-out), width var(--t-slow) var(--ease-out); pointer-events: none; }
.tabs .count { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------------- lists & tables ---------------- */
.list { display: grid; grid-template-columns: minmax(0, 1fr); }   /* rows never grow past the screen; long text truncates */
.list > * { min-width: 0; }
.list > * { border-top: 1px solid var(--line); }
.list > *:first-child { border-top: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: inherit; text-decoration: none; min-height: 56px; }
a.list-item:hover, button.list-item:hover { background: var(--surface-2); }
button.list-item { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: var(--step--1); color: var(--muted); font-weight: 650; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.table tbody tr:hover { background: var(--surface-2); }
.table tr[aria-selected="true"] { background: var(--brand-soft); }
.table td.num, .table th.num { text-align: right; }
.bulkbar { position: sticky; bottom: 12px; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-3); animation: rise var(--t) var(--ease-out); }
.bulkbar .btn { --btn-bg: transparent; --btn-fg: var(--bg); --btn-line: color-mix(in srgb, var(--bg) 35%, transparent); box-shadow: none; }

/* ---------------- feedback ---------------- */
.toasts { position: fixed; z-index: 90; right: 16px; bottom: 16px; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: var(--shadow-3); animation: rise var(--t) var(--ease-out); }
.toast.leaving { animation: sink var(--t) var(--ease-out) forwards; }
.toast .t-icon { flex: none; width: 20px; height: 20px; margin-top: 1px; }
.toast.good .t-icon { color: #7ee2a8; } .toast.bad .t-icon { color: #ff9c99; } .toast.warn .t-icon { color: #f3c776; }
.toast .t-body { flex: 1; min-width: 0; }
.toast .t-title { font-weight: 650; }
.toast .t-detail { font-size: var(--step--1); opacity: .85; }
.toast .t-action { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 2px 4px; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; font-weight: 550; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner.good { background: var(--good-soft); color: var(--good); }
.empty { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 32px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .6; }
.empty h3 { color: var(--text); }
.error-state { display: grid; justify-items: start; gap: 10px; padding: 16px; border-radius: 12px; background: var(--bad-soft); color: var(--bad); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line-strong); border-top-color: var(--brand-hi); animation: spin .8s linear infinite; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-sunk); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand-hi); border-radius: inherit; transition: width var(--t) var(--ease-out); }
.progress.indeterminate > span { width: 35%; animation: indeterminate 1.2s ease-in-out infinite; }

/* skeletons: shapes match the content they stand in for */
.skel { position: relative; overflow: hidden; background: color-mix(in srgb, var(--text) 10%, transparent); border-radius: 8px; }   /* visible on light and dark surfaces */
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 9%, transparent), transparent); animation: shimmer 1.4s ease-in-out infinite; }
.skel.line { height: 12px; }
.skel.title { height: 20px; width: 45%; }
.skel.circle { border-radius: 50%; }
.skel.block { height: 96px; }

/* success check: circle draws, then the tick */
.success-mark { width: 56px; height: 56px; color: var(--good); }
.success-mark circle { stroke-dasharray: 160; stroke-dashoffset: 160; animation: draw 300ms var(--ease-out) forwards; }   /* circle, then check: 470 ms in all (video 1 #6) */
.success-mark path { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw 170ms 300ms var(--ease-out) forwards; }

/* ---------------- dialogs & sheets ---------------- */
dialog.dialog { border: 0; padding: 0; border-radius: var(--radius-l); background: var(--surface); color: var(--text); box-shadow: var(--shadow-3); width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); }
dialog.dialog.wide { width: min(980px, calc(100vw - 24px)); }
dialog.dialog.full { width: calc(100vw - 16px); height: calc(100dvh - 16px); max-height: none; max-width: none; }
dialog.dialog[open] { animation: pop var(--t) var(--ease-out); display: flex; flex-direction: column; }
dialog.dialog::backdrop { background: rgba(10, 18, 28, .45); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: var(--step-1); flex: 1; }
.dialog-body { padding: 16px; overflow: auto; flex: 1 1 auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius-l) var(--radius-l); }
@media (max-width: 640px) {
  dialog.dialog:not(.full) { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; max-height: 92dvh; }
  dialog.dialog[open]:not(.full) { animation: sheet var(--t-slow) var(--ease-out); }
  .dialog-foot { border-radius: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* menu */
.menu { position: absolute; z-index: 60; min-width: 200px; padding: 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-3); transform-origin: var(--origin, top right); animation: pop var(--t-fast) var(--ease-out); }
.menu button, .menu a { display: flex; width: 100%; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px; border: 0; border-radius: 8px; background: none; color: inherit; text-decoration: none; cursor: pointer; text-align: left; }
.menu button:hover, .menu a:hover, .menu button:focus-visible { background: var(--surface-sunk); }

/* ---------------- keyframes ---------------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes sink { to { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes indeterminate { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
/* each swing smaller than the last, then still */
@keyframes shake { 0%, 100% { transform: none; } 14% { transform: translateX(-9px); } 30% { transform: translateX(7px); } 46% { transform: translateX(-5px); } 62% { transform: translateX(3px); } 78% { transform: translateX(-1.5px); } }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }

/* ---------------- rolling numbers (video 1 #3) ---------------- */
.roll { display: inline-flex; font-variant-numeric: tabular-nums; }
.roll-digits { display: inline-flex; }
.roll-col { display: inline-block; height: 1.2em; line-height: 1.2em; overflow: hidden; vertical-align: bottom; }
.roll-strip { display: flex; flex-direction: column; transition: transform 480ms var(--ease-out); }
.roll-strip > span { display: block; height: 1.2em; line-height: 1.2em; text-align: center; }
.roll-sym { display: inline-block; line-height: 1.2em; white-space: pre; }

/* ---------------- drag to reorder (video 1 #4) ---------------- */
.sort-row { position: relative; }
.sort-row.sort-lifted { z-index: 5; box-shadow: 0 14px 30px -10px rgba(0,0,0,.45); background: var(--surface); border-radius: 10px; outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); }
.sort-handle { cursor: grab; touch-action: none; color: var(--text-2); }
.sort-lifted .sort-handle { cursor: grabbing; }

/* ---------------- photo viewer (video 1 #5) ---------------- */
.pv { position: fixed; inset: 0; z-index: 400; }
.pv-backdrop { position: absolute; inset: 0; background: rgba(4, 8, 14, .88); }
.pv-box { position: fixed; overflow: hidden; border-radius: 14px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.7); }
.pv-img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; }
.pv-cap { position: fixed; left: 16px; right: 16px; bottom: calc(14px + env(safe-area-inset-bottom)); margin: 0; text-align: center; color: #fff; font-size: var(--step--1); }
.pv-close { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; --btn-bg: rgba(20,24,30,.7); --btn-fg: #fff; --btn-line: rgba(255,255,255,.25); }
html.pv-open { overflow: hidden; }

/* ---------------- pull to refresh (video 1 #2) ---------------- */
html.ptr-enabled, html.ptr-enabled body { overscroll-behavior-y: contain; }
.ptr { position: fixed; left: 50%; top: calc(var(--topbar-h, 56px) + 6px); z-index: 60; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2, 0 4px 14px rgba(0,0,0,.2)); font-size: var(--step--1); color: var(--text-2, var(--text)); opacity: 0; transform: translate(-50%, -44px); pointer-events: none; }
.ptr-spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--text) 18%, transparent); border-top-color: var(--brand); }
.ptr.ready .ptr-spin { border-color: var(--brand); }
.ptr.busy .ptr-spin { animation: spin .8s linear infinite; }
.ptr-label:empty { display: none; }

/* tab bar items get the same press */
.tabbar a { transition: transform 420ms var(--spring); }
.tabbar a:active, .tabbar a.is-pressed { transform: scale(.95); transition-duration: 90ms; transition-timing-function: var(--ease-out); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .skel::after { display: none; }
  .success-mark circle, .success-mark path { stroke-dashoffset: 0; }
}
.sort-handle svg { stroke-width: 3.4; }
/* a row we just pointed to ("See it below") */
.flash { animation: flash 1.4s var(--ease-out); }
@keyframes flash { 0%, 30% { background: color-mix(in srgb, var(--brand) 22%, transparent); } }
