/* =========================================================
   SolarPlan Pro — PV Layout Optimizer
   Professional design system for field/customer use
   ========================================================= */

:root {
  /* Surfaces */
  --bg:           #070b16;
  --bg-gradient:  radial-gradient(1200px 800px at 0% 0%, #0f1a36 0%, #070b16 55%);
  --panel:        #0f1730;
  --panel-2:      #16203d;
  --panel-3:      #1d294a;
  --surface-hi:   #243363;
  --line:         #243363;
  --line-soft:    #1b2545;
  --input-bg:     #0a1227;

  /* Text */
  --text:         #eef1f8;
  --text-strong:  #ffffff;
  --muted:        #8693b5;
  --muted-2:      #5d6b8e;

  /* Brand — Solar Amber */
  --brand:        #f59e0b;
  --brand-hi:     #fbbf24;
  --brand-lo:     #b45309;
  --brand-ink:    #1a1305;
  --brand-soft:   rgba(245, 158, 11, 0.12);
  --brand-ring:   rgba(245, 158, 11, 0.35);

  /* Status accents */
  --success:      #22c55e;
  --success-soft: rgba(34, 197, 94, 0.14);
  --info:         #60a5fa;
  --info-soft:    rgba(96, 165, 250, 0.14);
  --danger:       #ef4444;
  --danger-soft:  rgba(239, 68, 68, 0.14);

  /* Shape & motion */
  --sidebar-width: 336px;
  --radius-sm: 8px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow:    0 8px 24px rgba(0,0,0,0.45);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.55);
  --shadow-brand: 0 8px 24px rgba(245, 158, 11, 0.25);
  --t-fast:    120ms cubic-bezier(.4,0,.2,1);
  --t-med:     200ms cubic-bezier(.4,0,.2,1);

  --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  /* `none` on both axes blocks Safari's two-finger back/forward swipe */
  overscroll-behavior: none;
  overscroll-behavior-x: none;
  overflow: hidden;
  letter-spacing: -0.005em;
  /* Prevent macOS Safari from zooming the page on pinch */
  touch-action: pan-x pan-y;
}

html { overscroll-behavior: none; }

/* ── Root layout ── */
.page {
  display: flex;
  flex-direction: row;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   SIDEBAR
   ───────────────────────────────────────────── */
.sidebar {
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0f1730 0%, #0c142a 100%);
  border-right: 1px solid var(--line-soft);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* Brand header */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(245,158,11,0.04) 0%, transparent 100%);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.brand-mark {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-lo) 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-brand), inset 0 1px 0 rgba(255,255,255,0.25);
}
.brand-mark svg { width: 22px; height: 22px; color: #1a1305; }
.brand-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

/* Sidebar content wrapper */
.sidebar-inner {
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Hide the old h1 if present */
h1 { display: none; }

/* ─────────────────────────────────────────────
   WORKSPACE / TOPBAR
   ───────────────────────────────────────────── */
.workspace {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(15, 23, 48, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  font-size: 13px;
  color: var(--muted);
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
#activeModeLabel {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  letter-spacing: -0.005em;
}
#activeModeLabel::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  flex-shrink: 0;
}
#stepHint {
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

/* ── Canvas ── */
.canvas-wrap {
  flex: 1 1 0;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(800px 600px at 30% 20%, #0d1730 0%, #060a17 70%);
  min-height: 0;
  touch-action: none;
  overscroll-behavior: contain;
}
#canvas {
  display: block;
  width: 100%; height: 100%;
  cursor: crosshair;
  touch-action: none;
  overscroll-behavior: contain;
  /* Mac trackpad swipes shouldn't trigger history navigation here */
  -webkit-user-select: none;
  user-select: none;
}

/* ── Loupe ── */
.loupe {
  position: absolute; width: 170px; height: 170px; border-radius: 999px;
  overflow: hidden;
  border: 2px solid rgba(245,158,11,0.65);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 12px 40px rgba(0,0,0,0.5);
  background: #000;
  pointer-events: none; display: none; z-index: 20;
}
#loupeCanvas { width: 100%; height: 100%; display: block; }

/* ── Mobile actions bar ── */
.mobile-actions {
  display: none;
  flex: 0 0 auto;
  padding: 8px 10px;
  gap: 6px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(15, 23, 48, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  flex-wrap: wrap;
}
.mobile-actions button {
  flex: 1 1 calc(20% - 6px);
  font-size: 11px;
  padding: 8px 4px;
  min-height: 38px;
  text-align: center;
}
.mobile-only { display: none; }
.icon-btn { min-width: 40px; padding: 8px 10px; }

/* ─────────────────────────────────────────────
   ACCORDION — Step cards
   ───────────────────────────────────────────── */
.accordion { display: flex; flex-direction: column; gap: 8px; }

.acc-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: linear-gradient(180deg, var(--panel-2) 0%, #131c39 100%);
  transition: opacity var(--t-med), border-color var(--t-med), box-shadow var(--t-med);
  position: relative;
}
.acc-item.locked { opacity: 0.5; }
.acc-item.open {
  border-color: rgba(245,158,11,0.35);
  box-shadow: 0 0 0 1px rgba(245,158,11,0.12), 0 6px 20px rgba(0,0,0,0.35);
}

.acc-header {
  width: 100%; background: transparent; color: var(--text); border: 0;
  padding: 13px 14px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background var(--t-fast);
}
.acc-header:hover { background: rgba(255,255,255,0.025); }
.acc-item.locked .acc-header { cursor: not-allowed; }

/* Step number badge */
.acc-header::before {
  content: attr(data-step-num);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-3);
  color: var(--muted);
  border: 1px solid var(--line);
  flex-shrink: 0;
  letter-spacing: 0;
  transition: all var(--t-med);
}
.acc-item.open .acc-header::before {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-lo) 100%);
  color: var(--brand-ink);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}
.acc-item.done .acc-header::before {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(34, 197, 94, 0.35);
}
.acc-header > .acc-title {
  flex: 1 1 auto;
  letter-spacing: -0.01em;
}
.acc-header > .status {
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-3);
  border: 1px solid var(--line);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.acc-header > .status.s-open    { background: var(--brand-soft);   color: var(--brand-hi); border-color: rgba(245,158,11,0.3); }
.acc-header > .status.s-done    { background: var(--success-soft); color: var(--success); border-color: rgba(34,197,94,0.3); }
.acc-header > .status.s-locked  { background: var(--panel-3);      color: var(--muted-2); border-color: var(--line); }

/* Chevron */
.acc-header::after {
  content: '';
  width: 8px; height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform var(--t-med);
  margin-left: 2px;
  flex-shrink: 0;
}
.acc-item.open .acc-header::after { transform: rotate(45deg); }

.acc-body { display: none; padding: 4px 14px 14px; }
.acc-item.open .acc-body { display: block; }

/* Backward compat: old status span without class */
.status { font-size: 10.5px; color: var(--muted); font-weight: 600; flex-shrink: 0; }

/* ─────────────────────────────────────────────
   FORMS
   ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin: 11px 0; }
.field > span {
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
input[type="number"], input[type="file"], input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  -webkit-appearance: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
input[type="number"]:hover, input[type="text"]:hover {
  border-color: var(--surface-hi);
}
input[type="number"]:focus, input[type="file"]:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
  background: #0c1530;
}
input[type="number"]:disabled { opacity: 0.45; cursor: not-allowed; }
input[type="file"] {
  padding: 7px 9px;
  cursor: pointer;
}
input[type="file"]::-webkit-file-upload-button {
  background: var(--panel-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  margin-right: 10px;
  cursor: pointer;
  transition: background var(--t-fast);
}
input[type="file"]::-webkit-file-upload-button:hover { background: var(--surface-hi); }

/* Numeric input arrows */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 0.4;
}

/* ─────────────────────────────────────────────
   BUTTONS
   ───────────────────────────────────────────── */
button {
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-lo) 100%);
  color: var(--brand-ink);
  font-weight: 600;
  font-size: 12.5px;
  font-family: var(--font);
  border-radius: var(--radius);
  padding: 9px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  line-height: 1.2;
  letter-spacing: -0.005em;
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, var(--shadow-sm);
}
button:hover { filter: brightness(1.06); box-shadow: var(--shadow-brand); }
button:active { transform: translateY(1px); filter: brightness(0.95); }
button.secondary {
  background: var(--panel-3);
  color: var(--text);
  border-color: var(--line);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, var(--shadow-sm);
}
button.secondary:hover {
  background: var(--surface-hi);
  border-color: var(--surface-hi);
  filter: none;
  box-shadow: var(--shadow-sm);
}
button.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
}
button.ghost:hover { background: rgba(255,255,255,0.04); }
button:disabled, button:disabled:hover {
  opacity: 0.4;
  cursor: not-allowed;
  filter: none;
  transform: none;
  box-shadow: var(--shadow-sm);
}

/* SVG icons inside buttons */
button svg, .acc-header svg, .field svg { flex-shrink: 0; }
button svg { width: 14px; height: 14px; }

.toolrow { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.toolrow > * { flex: 1 1 auto; min-width: 0; }
.toolrow.wrap { flex-wrap: wrap; }

.radio-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.radio-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  padding: 4px 0;
  font-weight: 500;
}
.radio-row input[type="radio"] {
  width: 15px; height: 15px;
  accent-color: var(--brand);
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ─────────────────────────────────────────────
   INFO BOXES
   ───────────────────────────────────────────── */
.calibration-summary {
  margin-top: 10px;
  padding: 11px 13px;
  border-radius: var(--radius);
  background: var(--input-bg);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.65;
  white-space: pre-line;
}
.calibration-grid-preview, .inline-info {
  margin-top: 8px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}
.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 2px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--input-bg);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 500;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.toggle-field:hover { border-color: var(--surface-hi); }
.toggle-field input[type="checkbox"] {
  width: 16px; height: 16px;
  flex-shrink: 0;
  accent-color: var(--brand);
}

/* Segmented control */
.segmented-row {
  background: var(--panel-3);
  padding: 3px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  gap: 0 !important;
  display: flex;
}
.segmented-row > button {
  flex: 1 1 0;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 7px;
  box-shadow: none;
}
.segmented-row > button:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
  filter: none;
  box-shadow: none;
}
.segmented-row > button.active {
  background: var(--brand);
  color: var(--brand-ink);
  box-shadow: 0 2px 6px rgba(245,158,11,0.3);
}
.segmented-row > button.active:hover {
  background: var(--brand-hi);
  color: var(--brand-ink);
}

.export-row {
  margin-top: 0;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(245,158,11,0.04) 0%, transparent 100%);
  border-bottom: 1px solid var(--line-soft);
}

/* details/summary */
details { margin-top: 10px; }
details summary {
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: 6px 0;
  list-style: none;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
details summary::before { content: '▸ '; font-size: 10px; color: var(--brand); }
details[open] summary::before { content: '▾ '; }

/* Mobile overlay */
.mobile-overlay { display: none; }

/* ─────────────────────────────────────────────
   SHORTCUT HELP
   ───────────────────────────────────────────── */
.shortcut-help { position: fixed; bottom: 18px; right: 18px; z-index: 1000; }
.info-btn {
  width: 38px; height: 38px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: all var(--t-fast);
  font-family: 'Georgia', serif;
  font-style: italic;
}
.info-btn:hover {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: var(--brand);
  transform: scale(1.05);
  box-shadow: var(--shadow-brand);
}
.shortcut-tooltip {
  position: absolute;
  bottom: 48px;
  right: 0;
  min-width: 280px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  display: none;
  font-size: 12px;
  z-index: 2000;
}
.shortcut-help:hover .shortcut-tooltip,
.shortcut-help:focus-within .shortcut-tooltip { display: block; }
.shortcut-tooltip-title {
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text-strong);
  font-size: 12.5px;
  letter-spacing: -0.01em;
}
.shortcut-tooltip > div:not(.shortcut-tooltip-title):not(.shortcut-tooltip-section) {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
  padding: 3px 0;
}
.shortcut-tooltip > div:not(.shortcut-tooltip-title):not(.shortcut-tooltip-section) > span:first-child {
  font-weight: 600;
  color: var(--brand-hi);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}
.shortcut-tooltip-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line-soft);
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#undoBtn, #redoBtn { display: none; }


/* ─────────────────────────────────────────────
   TILE GRID FIELDS
   ───────────────────────────────────────────── */
.tile-grid-fields {
  display: grid;
  grid-template-columns: 1fr 26px 1fr;
  gap: 8px;
  align-items: end;
  margin: 10px 0;
}
.tile-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted-2);
  padding-bottom: 3px;
}
.tile-x-icon .field { margin: 0; }

/* Counts grid: Anzahl X × Anzahl Y */
.counts-grid {
  display: grid;
  grid-template-columns: 1fr 26px 1fr;
  gap: 8px;
  align-items: end;
  margin-top: 4px;
}
.counts-grid .count-cell { margin: 0; }

/* Auto-calc hint card */
.auto-calc-hint {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--brand-soft);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--brand-hi);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
  transition: opacity var(--t-med), background var(--t-med), color var(--t-med);
}
.auto-calc-hint svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}
.auto-calc-hint.is-complete {
  background: var(--success-soft);
  border-color: rgba(34, 197, 94, 0.3);
  color: var(--success);
}
.auto-calc-hint.is-incomplete {
  background: var(--panel-3);
  border-color: var(--line);
  color: var(--muted);
}

/* Mark inputs that are auto-derived (display only) */
input.auto-derived {
  color: var(--brand-hi);
  background: rgba(245, 158, 11, 0.04);
  border-color: rgba(245, 158, 11, 0.25);
  font-style: italic;
}
input.auto-derived:focus {
  font-style: normal;
}

/* ─────────────────────────────────────────────
   GRID VISIBILITY TOGGLE
   ───────────────────────────────────────────── */
.grid-vis-toggle {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 4px;
}
.grid-vis-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px 8px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--input-bg);
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
  transition: border-color var(--t-fast), background var(--t-fast), color var(--t-fast);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.grid-vis-option:hover { border-color: var(--surface-hi); color: var(--text); }
.grid-vis-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.grid-vis-option:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-hi);
}
.grid-vis-icon { font-size: 20px; line-height: 1; }
.grid-vis-option.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-hi);
}

/* ─────────────────────────────────────────────
   COMPUTED PREVIEW INPUTS
   ───────────────────────────────────────────── */
input.tile-preview::placeholder {
  color: rgba(245,158,11,0.6) !important;
  opacity: 1;
  font-style: italic;
  font-weight: 500;
}
input.tile-preview {
  border-color: rgba(245,158,11,0.4);
  background: rgba(245,158,11,0.04);
}
input.input-pending {
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px var(--brand-ring) !important;
}

/* Calc missing tile fields button */
.calc-tile-btn {
  width: 100%;
  margin-top: 10px;
  background: var(--panel-3);
  color: var(--muted);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 12px;
  cursor: default;
  transition: background var(--t-med), color var(--t-med), border-color var(--t-med), box-shadow var(--t-med);
  letter-spacing: 0.01em;
  opacity: 0.7;
  box-shadow: none;
}
.calc-tile-btn.calc-ready {
  color: var(--brand-hi);
  border-color: var(--brand);
  background: var(--brand-soft);
  cursor: pointer;
  opacity: 1;
  box-shadow: 0 0 0 1px var(--brand-ring);
  animation: pulse-ready 1.8s ease-in-out infinite;
}
.calc-tile-btn.calc-ready:hover {
  background: rgba(245,158,11,0.18);
  box-shadow: 0 0 0 2px var(--brand-ring), 0 4px 12px rgba(245,158,11,0.2);
}
.calc-tile-btn.calc-ready:active {
  transform: scale(0.98);
  background: rgba(245,158,11,0.25);
}
@keyframes pulse-ready {
  0%, 100% { box-shadow: 0 0 0 1px var(--brand-ring); }
  50%       { box-shadow: 0 0 0 4px rgba(245,158,11,0.35); }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════ */

@media (max-width: 1100px) {
  :root { --sidebar-width: 300px; }
  .brand-name { font-size: 14px; }
  button { font-size: 12px; }
  input[type="number"] { font-size: 12px; padding: 8px 10px; }
}

@media (max-width: 900px) {
  :root { --sidebar-width: 280px; }
  .grid2 { grid-template-columns: 1fr; gap: 7px; }
}

/* TABLET / MOBILE ≤768px — sidebar becomes overlay */
@media (max-width: 768px) {
  .page {
    display: block;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(88vw, 380px);
    z-index: 1200;
    transform: translateX(-110%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 8px 0 50px rgba(0,0,0,0.75);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .mobile-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(7, 11, 22, 0.78);
    backdrop-filter: blur(4px);
    z-index: 1100;
    cursor: pointer;
  }
  body.sidebar-open .mobile-overlay { display: block; }

  .workspace {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .topbar {
    flex: 0 0 50px;
    height: 50px;
    min-height: 50px;
    padding: 0 12px;
    gap: 8px;
    z-index: 10;
  }
  .mobile-actions { display: flex; flex: 0 0 auto; z-index: 10; }
  .mobile-only { display: flex; }
  .canvas-wrap {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    width: 100% !important;
    position: relative;
    overflow: hidden;
  }
  #activeModeLabel { font-size: 12px; padding: 5px 10px; }
  #stepHint { display: none; }
  .loupe { display: none !important; }
  .shortcut-help { display: none; }
  .grid-vis-toggle { grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .grid-vis-option { padding: 11px 4px; font-size: 12px; }
  .grid-vis-icon { font-size: 22px; }
}

/* PHONE ≤480px */
@media (max-width: 480px) {
  .sidebar { width: min(92vw, 340px); }
  .brand-name { font-size: 14px; }
  input[type="number"],
  input[type="file"] { font-size: 16px !important; }
  button { min-height: 44px; font-size: 13px; padding: 10px 12px; }
  .acc-header { min-height: 50px; font-size: 14px; padding: 14px 14px; }
  .grid2 { grid-template-columns: 1fr; gap: 8px; }
  .radio-row { flex-direction: column; gap: 8px; align-items: flex-start; }
  .toolrow { gap: 7px; }
  .toolrow > * { flex: 1 1 calc(50% - 4px); }
  .export-row button { flex: 1 1 100%; }
  .mobile-actions { padding: 8px 10px; gap: 6px; }
  .mobile-actions button { min-height: 42px; font-size: 12px; }
  .acc-body { padding: 4px 14px 16px; }
  .field { margin: 11px 0; }
}

@media (max-width: 360px) {
  .sidebar { width: 100vw; border-radius: 0; }
  .toolrow > * { flex: 1 1 100%; }
}

/* TOUCH DEVICES — bigger tap targets */
@media (hover: none) and (pointer: coarse) {
  button { min-height: 44px; }
  .acc-header { min-height: 50px; }
  input[type="number"],
  input[type="file"] { min-height: 44px; font-size: 16px; }
  .loupe { display: none !important; }
  .toggle-field { min-height: 44px; }
  .radio-row label { min-height: 36px; }
}

/* SAFE AREA */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar-inner { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .mobile-actions { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    padding-top: max(0px, env(safe-area-inset-top));
    height: calc(56px + env(safe-area-inset-top, 0px));
  }
}

/* ─────────────────────────────────────────────
   PORTRAIT WARNING (mobile)
   ───────────────────────────────────────────── */
#portraitWarning {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  font-family: var(--font);
  text-align: center;
  padding: 32px;
}
#portraitWarning .pw-icon {
  font-size: 64px;
  animation: rotate-hint 1.5s ease-in-out infinite alternate;
}
@keyframes rotate-hint {
  from { transform: rotate(0deg); }
  to   { transform: rotate(90deg); }
}
#portraitWarning h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--brand-hi);
  letter-spacing: -0.02em;
}
#portraitWarning p {
  font-size: 15px;
  color: var(--muted);
  max-width: 300px;
  line-height: 1.55;
}

@media (max-width: 768px) and (orientation: portrait) {
  #portraitWarning { display: flex; }
  .page { display: none !important; }
}
