/* Hallmark · macrostructure: Product workspace · theme: existing Metella
 * Responsive entry: scene followed by a compact, content-sized action sheet.
 * Pre-emit critique: P4 H5 E4 S5 R5 V4.
 */

@import url('./tokens.css?v=mobile03');

html, body { overflow-x: clip; }
button, a, summary { touch-action: manipulation; }
:is(button, a, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

/* One model, one primary action. Grid owns the scene size, not percentages. */
body.landing main {
  display: grid;
  grid-template-columns: minmax(320px, 36%) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh;
}
body.landing #welcome {
  position: relative;
  inset: auto;
  grid-area: 1 / 1;
  width: auto;
  min-width: 0;
  padding: clamp(24px, 4vw, 64px);
  border-radius: 0;
  justify-content: center;
  gap: var(--space-2xl);
  overflow: auto;
  overscroll-behavior: contain;
}
body.landing #viewport, body.landing #loading {
  position: relative;
  inset: auto;
  grid-area: 1 / 2;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
body.landing #loading { z-index: 2; padding: var(--space-md); }
.welcome-brand { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-md); }
.welcome-brand .welcome-logo {
  display: block;
  width: 160px;
  max-width: 100%;
  height: auto;
  max-height: none;
  aspect-ratio: 400 / 93;
  object-fit: contain;
  flex: none;
}
.welcome-brand > span { font-size: 12px; letter-spacing: .08em; color: var(--color-muted); }
#welcome h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 44px);
  letter-spacing: -.04em;
  line-height: 1.08;
  font-weight: 600;
  overflow-wrap: anywhere;
  min-width: 0;
}
.welcome-size { font-size: 17px; margin: var(--space-md) 0 0; color: var(--color-accent); }
.welcome-size > span { margin-inline: var(--space-sm); }
.welcome-description { font-size: 14px; line-height: 1.6; margin: var(--space-md) 0 0; color: var(--color-muted); max-width: 30ch; }
.welcome-advice { display: none; }
.welcome-actions { display: grid; gap: var(--space-sm); }
#welcome #homeEnter {
  height: 52px;
  min-height: 52px;
  padding-inline: var(--space-lg);
  border-radius: var(--radius-action);
  margin: 0;
  font-size: 14px;
  justify-content: space-between;
  white-space: nowrap;
}
#welcome #homeEnterLabel { margin: 0; }
#welcome #homeTour {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: var(--touch-target);
  margin: 0;
  padding: var(--space-sm) var(--space-md);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  border-radius: var(--radius-action);
}
#welcome #homeTour:hover { background: var(--color-soft); }
#welcome button:disabled { opacity: .55; }
.quote-fields, .quote-previews { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.quote-fields > *, .document-bar > div { min-width: 0; }
.quote-content { min-height: 0; overscroll-behavior: contain; }

/* Touch workspace also covers tablets and phones turned sideways. */
@media (max-width: 900px), (max-width: 1024px) and (max-height: 500px), (pointer: coarse) {
  :root {
    --header-height: calc(60px + env(safe-area-inset-top));
    --dock-bottom: max(8px, env(safe-area-inset-bottom));
    --dock-clearance: calc(80px + var(--dock-bottom));
  }
  body.landing, body.landing main { background: var(--color-paper); }
  body.landing main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(180px, 1fr) auto;
    min-height: 100svh;
    height: 100dvh;
    overflow-y: auto;
  }
  body.landing #viewport, body.landing #loading { grid-area: 1 / 1; }
  body.landing #welcome {
    grid-area: 2 / 1;
    padding: var(--space-lg) max(20px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    gap: var(--space-lg);
    border-radius: 0;
    margin-top: 0;
    background: var(--color-paper);
    justify-content: flex-start;
    overflow: visible;
  }
  .welcome-brand { flex-direction: column; flex-wrap: nowrap; justify-content: center; gap: var(--space-sm); }
  .welcome-brand .welcome-logo { width: clamp(200px, 56vw, 260px); align-self: center; }
  .welcome-brand > span { font-size: 10px; line-height: 1.2; letter-spacing: .18em; text-transform: uppercase; }
  #welcome .welcome-advice { display: flex; align-items: flex-start; gap: var(--space-sm); margin: 0; padding-top: var(--space-sm); border-top: 1px solid var(--color-line); font-size: 12px; line-height: 1.5; color: var(--color-ink); }
  .welcome-advice svg { flex: 0 0 26px; color: var(--color-gold); }
  #welcome h1 { font-size: clamp(27px, 6.5vw, 38px); }
  .welcome-size { font-size: 15px; margin-top: var(--space-sm); }
  .welcome-description { font-size: 13px; margin-top: var(--space-sm); max-width: none; }
  .welcome-actions { gap: var(--space-xs); }
  #welcome #homeEnter { min-height: 50px; height: 50px; }

  .app-header {
    height: var(--header-height);
    padding: env(safe-area-inset-top) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    gap: var(--space-sm);
  }
  .project-title { display: none; }
  #homeLink { min-height: var(--touch-target); flex-shrink: 0; align-items: center; }
  body:not(.landing) .brand-logo { display: block; width: clamp(112px, 30vw, 160px); height: auto; aspect-ratio: 400 / 93; object-fit: contain; flex: none; }
  .header-views { gap: var(--space-xs); margin-left: auto; }
  #exteriorView, #overheadView { min-height: var(--touch-target); padding: 8px; gap: 4px; font-size: 11px; }
  #exteriorView .ui-icon, #overheadView .ui-icon { margin: 0; width: 18px; height: 18px; }
  body:not(.landing) #saveProject { min-height: var(--touch-target); min-width: var(--touch-target); padding: 10px; margin: 0; }
  #saveProject span { display: none; }
  #saveProject .ui-icon { margin: 0; width: 20px; height: 20px; }
  main { height: calc(100dvh - var(--header-height)); }
  body:not(.landing) #viewport { inset: 0; width: 100%; height: 100%; }
  .view-dock { display: none; }
  .mode-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    position: fixed;
    top: auto;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: var(--dock-bottom);
    transform: none;
    width: auto;
    max-width: none;
    height: 64px;
    padding: 5px;
    gap: 2px;
    border: 1px solid var(--color-line);
    border-radius: 32px;
    box-shadow: 0 4px 20px var(--color-shadow);
  }
  .mode-tabs button {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 52px;
    padding: 4px 2px;
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
    border-radius: 26px !important;
  }
  .mode-tabs .ui-icon { width: 19px; height: 19px; margin: 0; }
  .mode-tabs #walk span { max-width: none; }
  body:not(.landing) #sidePanel {
    inset: auto max(8px, env(safe-area-inset-right)) var(--dock-clearance) max(8px, env(safe-area-inset-left));
    width: auto;
    max-height: min(60dvh, calc(100% - var(--dock-clearance) - 12px));
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sheet);
    overscroll-behavior: contain;
  }
  .panel-top { padding: 8px 12px 8px 20px; }
  #closePanel { min-width: var(--touch-target); min-height: var(--touch-target); }
  aside section { padding: 16px 20px 24px; }
  aside h1, aside h2 { font-size: 27px; }
  .room-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .room-grid button { font-size: 12px; padding: 12px 4px; justify-content: center; }
  .room-symbol { display: none; }
  .options .check, summary { min-height: var(--touch-target); }
  summary { align-content: center; }
  .options select, .quote-fields input, .quote-fields textarea { font-size: 16px; }
  .options select { min-height: 48px; }
  .quote-fields { grid-template-columns: minmax(0, 1fr); }
  .quote-fields .full { grid-column: auto; }
  .quote-content { padding: var(--space-md); }
  .download-action { display: block; text-align: center; margin-right: 0; font-size: 13px; }
  #quoteDialog, #documentDialog {
    width: calc(100% - 16px);
    max-width: 850px;
    height: calc(100dvh - max(16px, env(safe-area-inset-top)) - max(16px, env(safe-area-inset-bottom)));
    max-height: none;
    margin: auto;
    border-radius: 20px;
    overflow: hidden;
  }
  .document-bar { padding: 12px 16px; gap: 8px; flex-shrink: 0; }
  .document-bar h2 { font-size: 17px; overflow-wrap: anywhere; }
  .document-bar .eyebrow { display: none; }
  #closeQuote, #closeDocument { min-width: var(--touch-target); min-height: var(--touch-target); flex-shrink: 0; }
  #documentDialog .document-controls { flex-wrap: wrap; }
  .page-navigation { width: 100%; justify-content: space-between; }
  #zoomPage, #documentDialog .document-controls a { min-height: var(--touch-target); }

  body.walking #touchpad {
    display: block;
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: calc(var(--dock-clearance) + 12px);
    width: 96px;
    z-index: 3;
    touch-action: none;
  }
  #joystick { width: 96px; height: 96px; border: 1px solid var(--color-paper); border-radius: 50%; background: var(--color-overlay); display: grid; place-items: center; touch-action: none; }
  #joystickKnob { width: 42px; height: 42px; border-radius: 50%; background: var(--color-glass); pointer-events: none; }
  .joystick-label, .key-controls { display: none; }
  body.walking #aimAction { position: absolute; display: block; bottom: calc(var(--dock-clearance) + 28px); right: max(16px, env(safe-area-inset-right)); max-width: 165px; min-height: 48px; padding: 12px; border-radius: var(--radius-action); background: var(--color-paper); color: var(--color-ink); border: 1px solid var(--color-line); z-index: 3; }
  #reticle { left: 50%; top: 50%; }
  .bottom, body.panel-closed .bottom { bottom: var(--dock-clearance); left: 12px; }
  body.walking #hint { display: none !important; }
  #stand { bottom: var(--dock-clearance); }
  #helpButton { top: 12px; right: 12px; min-height: var(--touch-target); min-width: var(--touch-target); }
  #helpButton .help-label { display: none; }
  #visitHelp { top: 12px; left: 12px; width: min(300px, calc(100% - 24px)); max-width: none; max-height: calc(100% - var(--dock-clearance) - 24px); padding: 16px; }
  #tour { top: auto; bottom: var(--dock-clearance); left: 12px; width: min(360px, calc(100% - 24px)); max-height: calc(100% - var(--dock-clearance) - 12px); overflow: auto; padding: 18px; }
  #tour h2 { font-size: 22px; }
  #tvControls { top: 16px; right: 12px; bottom: auto; transform: none; }
}

/* Short portrait screens: keep both actions reachable, without shrinking text. */
@media (max-width: 900px) and (max-height: 700px) {
  body.landing #welcome { gap: var(--space-md); padding-top: var(--space-md); }
  .welcome-brand .welcome-logo { width: 200px; }
}

/* Landscape uses two columns; no tall phone card squeezed into half a screen. */
@media (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {
  body.landing main { grid-template-columns: minmax(260px, 40%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); min-height: 0; }
  body.landing #viewport, body.landing #loading { grid-area: 1 / 2; }
  body.landing #welcome { grid-area: 1 / 1; margin: 0; padding: max(12px, env(safe-area-inset-top)) 20px max(8px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); border-radius: 0; gap: 12px; overflow-y: auto; justify-content: safe center; }
  .welcome-brand .welcome-logo { width: 180px; }
  #welcome h1 { font-size: 28px; }
  .welcome-size { margin-top: 6px; font-size: 14px; }
  .welcome-description { margin-top: 6px; font-size: 12px; }
  #welcome #homeEnter { height: 44px; min-height: 44px; padding-inline: 16px; }
  #welcome #homeTour { min-height: 44px; padding-block: 4px; }
  .mode-tabs { left: 50%; right: auto; transform: translateX(-50%); width: 360px; max-width: calc(100% - 24px); }
  body:not(.landing) #sidePanel { right: auto; width: min(360px, calc(100% - 24px)); max-height: calc(100% - var(--dock-clearance) - 8px); }
  #visitHelp { max-height: calc(100% - 24px); width: 280px; left: 12px; }
  body.visit-help-open #touchpad { visibility: hidden; }
  body.walking #touchpad { bottom: 16px; width: 80px; }
  #joystick { width: 80px; height: 80px; }
  #joystickKnob { width: 36px; height: 36px; }
  body.walking #aimAction { bottom: 24px; max-width: 130px; }
  #documentDialog .document-controls { flex-wrap: nowrap; }
  .page-navigation { width: auto; gap: 8px; }
}

@media (max-width: 350px) {
  .header-views { gap: 2px; }
  #exteriorView, #overheadView { font-size: 10px; padding: 6px; }
  #exteriorView .ui-icon, #overheadView .ui-icon { display: none; }
  .mode-tabs button { font-size: 10px; }
}

/* Personalization is ordered by what the visitor is changing. */
.config-group { padding: 0; border-top: 1px solid var(--color-line); }
.finish-field { margin: 0 0 24px; }
.finish-picker { min-width: 0; margin: 0; padding: 0; border: 0; }
.finish-picker legend, .finish-field > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; padding: 0; }
.finish-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.finish-choice { display: flex; flex-direction: column; gap: 7px; min-width: 0; padding: 7px; border: 1px solid var(--color-line); border-radius: 10px; background: var(--color-paper); cursor: pointer; }
.finish-choice:has(input:checked) { border-color: var(--color-accent); background: var(--color-accent-soft); box-shadow: inset 0 0 0 1px var(--color-accent); }
.finish-choice:focus-within { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.finish-choice:active { background: var(--color-soft); }
.finish-sample { display: block; width: 100%; height: 28px; border-radius: 5px; background: var(--finish-swatch); border: 1px solid var(--color-line); }
.finish-caption { display: flex; align-items: center; gap: 4px; font-size: 10px; white-space: nowrap; }
.finish-caption input { width: 12px; height: 12px; margin: 0; accent-color: var(--color-accent); flex-shrink: 0; }
.finish-field select { width: 100%; min-height: 48px; border: 1px solid var(--color-line); padding: 8px; border-radius: 8px; background: var(--color-paper); color: var(--color-ink); font-size: 14px; }
.config-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; margin: 0 0 18px; font-size: 14px; }
.config-toggle small { display: block; font-size: 11px; color: var(--color-muted); line-height: 1.5; margin-top: 4px; }
.config-toggle input { width: 22px; height: 22px; }
.config-view-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0 0 20px; }
.config-view-buttons button { font-size: 12px; padding: 10px 6px; background: var(--color-soft); }
.config-footer { display: flex; justify-content: space-between; gap: 8px; }
.config-footer button { min-height: 44px; font-size: 12px; padding: 8px 0; }
#doors { width: 100%; background: var(--color-soft); margin-bottom: 20px; }
@media (hover: hover) { .finish-choice:hover { border-color: var(--color-accent); } }
@media (max-width: 900px), (max-width: 1024px) and (max-height: 500px), (pointer: coarse) {
  body:not(.landing) #sidePanel { max-height: min(54dvh, calc(100% - var(--dock-clearance) - 170px)); }
  body:not(.landing):not(.panel-closed) #viewport { height: calc(100% - var(--active-panel-height, 0px) - var(--dock-clearance) - 8px); min-height: 120px; }
  .finish-field select { font-size: 16px; }
  body:not(.panel-closed) #helpButton, body:not(.panel-closed) #touchpad, body:not(.panel-closed) #aimAction, body:not(.panel-closed) #reticle { display: none !important; }
}
@media (max-width: 1024px) and (max-height: 500px) and (orientation: landscape) {
  body:not(.landing) #sidePanel { max-height: calc(100% - var(--dock-clearance) - 8px); width: 300px; }
  body:not(.landing):not(.panel-closed) #viewport { left: 316px; width: calc(100% - 316px); height: 100%; }
}

/* Three always-reachable categories, with one set of controls at a time. */
[data-section="configure"] { padding-top: 0; }
.config-tabs { position: sticky; top: 60px; z-index: 1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 12px 0 16px; background: var(--color-paper); }
.config-tabs button { min-height: 44px; font-size: 12px; padding: 8px 4px; border-radius: 22px; }
.config-tabs button[aria-selected="true"] { background: var(--color-accent-soft); color: var(--color-accent); box-shadow: inset 0 0 0 1px var(--color-accent); }
.config-group { padding: 0; border: 0; }
.config-tabs:has(button:focus-visible) { z-index: 2; }
