/* Shared app styles. Colours, spacing and fonts come from theme.css (generated from design-tokens/tokens.json). */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ds-background); color: var(--ds-text); font: 15px/1.45 var(--ds-font-body); -webkit-text-size-adjust: 100%; }
h1 { font-size: 1.45rem; margin: 0 0 var(--ds-space-3); letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: var(--ds-space-5) 0 var(--ds-space-2); }
a { color: var(--ds-primary); }
:focus-visible { outline: 3px solid var(--ds-primary); outline-offset: 2px; }
button { font: inherit; }

.ds-shell { display: flex; flex-direction: column-reverse; height: 100%; }
.ds-main { flex: 1; min-height: 0; overflow: auto; padding: var(--ds-space-4) max(var(--ds-space-4), env(safe-area-inset-left, 0px)) var(--ds-space-5); }
.ds-nav { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ds-surface); border-top: 1px solid var(--ds-border); padding-bottom: env(safe-area-inset-bottom, 0px); }
.ds-brand { display: none; }
.ds-tab { display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 56px; justify-content: center; color: var(--ds-text-muted); text-decoration: none; font-size: 12px; font-weight: 600; }
.ds-tab-ico { font-size: 18px; line-height: 1; padding: 3px 14px; border-radius: 14px; }
.ds-tab.active { color: var(--ds-primary-strong); }
.ds-tab.active .ds-tab-ico { background: var(--ds-tint); }

@media (min-width: 1000px) {
  .ds-shell { flex-direction: row; }
  .ds-nav { width: 220px; display: flex; flex-direction: column; gap: 2px; border-top: 0; border-right: 1px solid var(--ds-border); padding: var(--ds-space-3); }
  .ds-brand { display: block; font-size: 20px; font-weight: 700; padding: var(--ds-space-2) var(--ds-space-3) var(--ds-space-4); }
  .ds-brand b { color: var(--ds-primary); }
  .ds-tab { flex-direction: row; justify-content: flex-start; gap: var(--ds-space-3); min-height: 44px; padding: 0 var(--ds-space-3); border-radius: var(--ds-radius-md); font-size: 14px; }
  .ds-tab-ico { padding: 0; background: none !important; }
  .ds-tab.active { background: var(--ds-tint); }
  .ds-main { padding: var(--ds-space-5) var(--ds-space-6); }
}

.ds-card { background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-lg); padding: var(--ds-space-4); }
.ds-muted { color: var(--ds-text-muted); }
.ds-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 var(--ds-space-4); border-radius: var(--ds-radius-md); border: 0; background: var(--ds-primary); color: var(--ds-on-primary); font-weight: 700; cursor: pointer; text-decoration: none; }
.ds-btn.outline { background: transparent; color: var(--ds-primary); border: 1.5px solid var(--ds-primary); }
.ds-row { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); align-items: center; }
.ds-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--ds-space-2); }
.ds-stat { background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); padding: var(--ds-space-3); }
.ds-stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.ds-stat span { color: var(--ds-text-muted); font-size: 12px; }
.ds-canvas-host { position: relative; height: 420px; border: 1px solid var(--ds-border); border-radius: var(--ds-radius-lg); overflow: hidden; background: var(--ds-canvas); touch-action: none; }
.ds-canvas-host canvas { width: 100%; height: 100%; display: block; }
.ds-mono { font-family: var(--ds-font-mono); font-size: 12px; }

/* ---------- Phase 1 screens ---------- */
.ds-block { display: flex; width: 100%; }
.ds-home-head { margin-bottom: var(--ds-space-4); }
.ds-wordmark { font-size: 1.8rem; font-weight: 700; margin: 0; }
.ds-wordmark span { color: var(--ds-primary); font-weight: 800; }
.ds-page-head { display: flex; align-items: center; gap: var(--ds-space-2); margin-bottom: var(--ds-space-3); }
.ds-page-head h1 { margin: 0; }
.ds-icon-btn { display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--ds-text); font-size: 20px; cursor: pointer; text-decoration: none; }
.ds-icon-btn:disabled { opacity: .35; cursor: default; }
.ds-icon-btn.on { background: var(--ds-tint); color: var(--ds-primary-strong); }
.ds-btn.sm { min-height: 36px; padding: 0 var(--ds-space-3); font-size: 13px; }
.ds-btn.danger { background: var(--ds-error); color: var(--ds-surface); }
.ds-btn:disabled, .ds-btn.disabled { opacity: .45; pointer-events: none; }
.ds-badge { font-size: 10px; font-weight: 800; letter-spacing: .06em; padding: 3px 7px; border-radius: 6px; }
.ds-badge.free { background: var(--ds-tint); color: var(--ds-primary-strong); }
.ds-badge.pro { background: var(--ds-warning-bg); color: var(--ds-warning); }
.ds-list { list-style: none; margin: 0; padding: 0; display: grid; }
.ds-list-item { display: flex; align-items: center; gap: var(--ds-space-3); padding: var(--ds-space-3) 0; border-bottom: 1px solid var(--ds-border); }
.ds-list-item:last-child { border-bottom: 0; }
.ds-list-item.planned { opacity: .55; }
.ds-list-text { flex: 1; min-width: 0; display: grid; gap: 2px; color: var(--ds-text); text-decoration: none; text-align: left; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
.ds-list-text span { color: var(--ds-text-muted); font-size: 13px; overflow-wrap: anywhere; }
.ds-glyph { width: 40px; height: 40px; border-radius: var(--ds-radius-md); display: grid; place-items: center; background: var(--ds-tint); color: var(--ds-primary-strong); font-size: 20px; flex: none; }
.ds-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--ds-tint); color: var(--ds-primary-strong); font-weight: 800; font-size: 12px; flex: none; }
.ds-form { display: grid; gap: var(--ds-space-3); max-width: 720px; padding-bottom: 80px; }
.ds-form h2 { margin-bottom: 0; }
.ds-field { display: grid; gap: 4px; border: 0; padding: 0; margin: 0; min-width: 0; }
.ds-field label, .ds-field legend { font-size: 12px; font-weight: 700; color: var(--ds-text-muted); padding: 0; }
.ds-input { min-height: 44px; border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); background: var(--ds-surface); color: var(--ds-text); padding: 0 var(--ds-space-3); font: inherit; width: 100%; }
.ds-input.invalid { border: 2px solid var(--ds-error); }
.ds-field-error, .ds-help { font-size: 12px; color: var(--ds-text-muted); margin: 0; }
.ds-field-error { color: var(--ds-error); }
.ds-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--ds-space-3); }
.ds-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); overflow: hidden; background: var(--ds-surface); }
.ds-seg button { min-height: 40px; border: 0; border-left: 1px solid var(--ds-border); background: transparent; color: var(--ds-text-muted); font: inherit; font-weight: 600; cursor: pointer; }
.ds-seg button:first-child { border-left: 0; }
.ds-seg button.on { background: var(--ds-tint); color: var(--ds-primary-strong); font-weight: 700; }
.ds-chips { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
.ds-chip { min-height: 36px; padding: 0 var(--ds-space-3); border-radius: 18px; border: 1px solid var(--ds-border); background: var(--ds-surface); color: var(--ds-text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.ds-chip.on { background: var(--ds-tint); border-color: var(--ds-primary); color: var(--ds-primary-strong); }
.ds-frame-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr auto; gap: var(--ds-space-2); align-items: end; padding: var(--ds-space-2) 0; border-bottom: 1px solid var(--ds-border); }
@media (max-width: 640px) { .ds-frame-row { grid-template-columns: 1fr 1fr; } }
.ds-alert { border-radius: var(--ds-radius-md); padding: var(--ds-space-2) var(--ds-space-3); font-size: 13px; font-weight: 600; margin: var(--ds-space-2) 0; }
.ds-alert.warning { background: var(--ds-warning-bg); color: var(--ds-warning); }
.ds-alert.error { background: var(--ds-warning-bg); color: var(--ds-error); }
.ds-sticky-actions { position: sticky; bottom: 0; padding: var(--ds-space-3) 0; background: var(--ds-background); }
.ds-sticky-actions .ds-btn { width: 100%; }
.ds-tint { background: var(--ds-tint); border-color: transparent; }
.ds-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ds-plain { margin: 0; padding-left: 1.2em; }
.ds-check { display: flex; gap: var(--ds-space-2); margin: 0 0 var(--ds-space-2); font-size: 14px; }
.ds-check.warning span:first-child { color: var(--ds-warning); }
.ds-check.error span:first-child { color: var(--ds-error); }
.ds-check.info span:first-child { color: var(--ds-primary); }
.ds-check.ok span:first-child { color: var(--ds-success); }
.ds-hang { margin: 0; padding-left: 1.4em; display: grid; gap: var(--ds-space-2); }
.ds-hang li span { display: block; color: var(--ds-text-muted); font-size: 13px; }
.ds-export { display: grid; gap: var(--ds-space-2); max-width: 420px; }

/* Editor: canvas over the panels on phones; canvas beside the panels on wide screens. */
.ds-editor { display: grid; gap: var(--ds-space-2); grid-template-columns: minmax(0, 1fr); }
.ds-editor-bar { display: flex; align-items: center; gap: 4px; }
.ds-editor-title { flex: 1; min-width: 0; display: grid; }
.ds-editor-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-save { font-size: 12px; color: var(--ds-success); }
.ds-save.saving { color: var(--ds-text-muted); }
.ds-save.failed { color: var(--ds-error); }
.ds-editor-canvas { height: 55vh; min-height: 280px; }
.ds-canvas-tools { position: absolute; right: 8px; top: 8px; display: grid; gap: 6px; }
.ds-canvas-tools .ds-icon-btn { background: var(--ds-surface); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); font-size: 18px; min-width: 40px; min-height: 40px; }
.ds-canvas-tools .ds-icon-btn.on { background: var(--ds-tint); border-color: var(--ds-primary); }
.ds-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--ds-border); overflow-x: auto; scrollbar-width: none; }
.ds-tabs::-webkit-scrollbar { display: none; }
.ds-tabs button { min-height: 44px; padding: 0 var(--ds-space-3); border: 0; border-bottom: 3px solid transparent; background: none; color: var(--ds-text-muted); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; }
.ds-tabs button.on { color: var(--ds-primary-strong); border-color: var(--ds-primary); }
.ds-panel { padding: var(--ds-space-3) 0 var(--ds-space-6); }
@media (min-width: 1000px) {
  .ds-editor { grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "bar bar" "canvas alert" "canvas tabs" "canvas panel"; grid-template-rows: auto auto auto 1fr; }
  .ds-editor > .ds-alert { margin: 0; }
  .ds-tabs button { padding: 0 10px; }
  .ds-editor-bar { grid-area: bar; }
  .ds-editor-canvas { height: calc(100vh - 200px); }
  .ds-editor > .ds-alert { grid-area: alert; }
  .ds-tabs { grid-area: tabs; }
  .ds-panel { grid-area: panel; overflow: auto; max-height: calc(100vh - 230px); padding-right: var(--ds-space-2); align-self: start; }
}

/* Web print view */
.ds-print-main { padding: var(--ds-space-4); background: #fff; color: #163039; min-height: 100%; }
.ds-print-bar { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); align-items: center; margin-bottom: var(--ds-space-4); }
.ds-print h1 { font-size: 1.5rem; margin: 0; }
.ds-print h2 { font-size: 1.05rem; }
.ds-print-drawing { border: 1px solid #D5E1E3; margin-top: var(--ds-space-3); }
.ds-small { font-size: 12px; color: #52656D; }
@media print { .no-print { display: none !important; } .ds-print-main { padding: 0; } @page { margin: 12mm; } }

/* ---------- Phase 2 ---------- */
.ds-form-fields { display: grid; gap: var(--ds-space-3); }
.ds-field-wrap { display: grid; gap: 4px; }
.ds-toggle { display: flex; align-items: center; gap: var(--ds-space-2); min-height: 44px; font-weight: 600; cursor: pointer; }
.ds-toggle input { width: 20px; height: 20px; accent-color: var(--ds-primary); }
.ds-items { border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); padding: var(--ds-space-3); display: grid; gap: var(--ds-space-2); min-width: 0; }
.ds-items legend { font-size: 12px; font-weight: 700; color: var(--ds-text-muted); padding: 0 4px; }
.ds-item-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)) auto; gap: var(--ds-space-2); align-items: end; padding-bottom: var(--ds-space-2); border-bottom: 1px solid var(--ds-border); }
.ds-search .ds-input { border-radius: 22px; }
.ds-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--ds-space-2); }
.ds-tile { display: flex; align-items: center; gap: var(--ds-space-2); padding: var(--ds-space-2); border: 1px solid var(--ds-border); border-radius: var(--ds-radius-md); background: var(--ds-surface); color: var(--ds-text); text-decoration: none; font-size: 13px; }
.ds-tile .ds-glyph { width: 32px; height: 32px; font-size: 16px; }
.ds-tile b { flex: 1; min-width: 0; }
.ds-sec { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ds-text-muted); margin: var(--ds-space-3) 0 var(--ds-space-2); }
.ds-link-btn { background: none; border: 0; padding: 0; color: var(--ds-primary); font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; }
.ds-meter { height: 6px; border-radius: 3px; background: var(--ds-border); margin: 8px 0; overflow: hidden; }
.ds-meter span { display: block; height: 100%; background: var(--ds-primary); }
.ds-scrim { position: fixed; inset: 0; background: rgba(12, 28, 33, .45); z-index: 40; }
.ds-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow: auto; background: var(--ds-surface); color: var(--ds-text); border-radius: 22px 22px 0 0; padding: var(--ds-space-4) max(var(--ds-space-4), env(safe-area-inset-left, 0px)) calc(var(--ds-space-5) + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -10px 30px -12px rgba(0,0,0,.35); display: grid; gap: var(--ds-space-2); }
@media (min-width: 700px) { .ds-sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: min(520px, 92vw); border-radius: var(--ds-radius-lg); } }
.ds-ticks { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.ds-ticks li::before { content: "✓"; color: var(--ds-success); font-weight: 800; margin-right: 8px; }
.ds-price { display: flex; gap: var(--ds-space-2); align-items: baseline; justify-content: center; margin: var(--ds-space-2) 0; }
.ds-price s { color: var(--ds-text-muted); }
.ds-price b { font-size: 1.8rem; }
.ds-editor-canvas-wrap { position: relative; display: grid; gap: var(--ds-space-2); min-width: 0; }
.ds-arrange { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
.ds-shop { display: grid; grid-template-columns: 1fr 96px auto; gap: 8px 10px; align-items: center; font-size: 14px; }
.ds-shop b { text-align: right; font-variant-numeric: tabular-nums; }
.ds-shop .tot { border-top: 1px solid var(--ds-border); padding-top: 8px; font-weight: 800; }
.ds-price-in { min-height: 36px; padding: 0 8px; }
.ds-lines li { margin-bottom: 4px; }
@media (min-width: 1000px) {
  .ds-editor { grid-template-areas: "bar bar" "canvas alert" "canvas tabs" "canvas panel"; }
  .ds-editor-canvas-wrap { grid-area: canvas; }
  .ds-editor-canvas-wrap .ds-editor-canvas { height: calc(100vh - 200px); }
}
/* Plans sheet: Free, Pro, Business */
.ds-plans { display: grid; gap: var(--ds-space-3); margin-top: var(--ds-space-3); }
@media (min-width: 760px) { .ds-plans { grid-template-columns: repeat(3, 1fr); } }
.ds-plan { border: 1px solid var(--ds-border); border-radius: var(--ds-radius-lg, 16px); padding: var(--ds-space-3); background: var(--ds-surface); }
.ds-plan h3 { margin: 0; display: flex; gap: 8px; align-items: center; }
.ds-plan.pro { border-color: var(--ds-primary); border-width: 2px; }
.ds-plan.current { box-shadow: 0 0 0 3px var(--ds-tint); }
.ds-plan.muted { opacity: .75; }
.ds-plan-price { margin: 6px 0 10px; }
.ds-plan-price b { font-size: 24px; }
.ds-plan .ds-seg { margin: 8px 0; }
.ds-plan .ds-btn { margin-top: 4px; }
.ds-sheet { max-height: 92vh; overflow-y: auto; }
.ds-views { margin: 0 0 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.ds-views::-webkit-scrollbar { display: none; }
.ds-views .ds-chip { flex: none; }
/* Cabinet editor */
.ds-cab { display: grid; gap: var(--ds-space-3); }
.ds-cab-run { display: grid; gap: var(--ds-space-2); }
.ds-cab-runhead { flex-wrap: nowrap; }
.ds-cab-runhead .ds-input { font-weight: 700; }
.ds-cab-strip { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.ds-cab-chip { min-width: 64px; min-height: 64px; display: grid; align-content: center; gap: 2px; padding: 6px; border: 1.5px solid var(--ds-border); border-radius: var(--ds-radius-md); background: var(--ds-surface); color: var(--ds-text); font: inherit; font-size: 12px; text-align: center; cursor: pointer; }
.ds-cab-chip b { font-size: 14px; }
.ds-cab-chip.muted { background: var(--ds-canvas); color: var(--ds-text-muted); }
.ds-cab-chip.on { border-color: var(--ds-primary); background: var(--ds-tint); box-shadow: 0 0 0 2px var(--ds-primary); }
.ds-cab-panel { border-top: 1px solid var(--ds-border); padding-top: var(--ds-space-2); display: grid; gap: var(--ds-space-2); }
.ds-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--ds-border); margin-right: 2px; vertical-align: -1px; }
.ds-label { font-weight: 600; font-size: 14px; }
.ds-cab-chip b, .ds-cab-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Handoff: the QR code sheet */
.ds-handoff .ds-qr-wrap { display: grid; place-items: center; margin: var(--ds-space-3) 0; }
.ds-qr { width: min(280px, 70vw); height: auto; border-radius: 8px; }
.ds-steps { margin: var(--ds-space-2) 0 0; padding-left: 1.4em; display: grid; gap: 4px; }
.ds-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--ds-border); border-top-color: var(--ds-primary); border-radius: 50%; animation: ds-spin 0.9s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes ds-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ds-spinner { animation: none; } }
