/* ============================================================
   RoofVision PWA — Dark app-native design
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a1a;
  --surface:   #12122a;
  --card:      #1a1a3a;
  --border:    #2a2a4a;
  --accent:    #e94560;
  --accent-dim:#e9456040;
  --blue:      #0f3460;
  --text:      #f0f0f5;
  --text-dim:  #8888aa;
  --radius:    14px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Header ─────────────────────────────────── */

.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 100;
  height: 56px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  display: flex; align-items: center; gap: 10px;
}

.header-title {
  font-size: 18px; font-weight: 700; letter-spacing: -0.3px;
}

.header-icon { flex-shrink: 0; }

.header-step {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ── Views ──────────────────────────────────── */

.view {
  display: none;
  flex-direction: column;
  flex: 1;
  padding-top: 56px;
  height: 100dvh;
  animation: viewIn 250ms ease-out;
}

.view.active { display: flex; }

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Camera View ────────────────────────────── */

.camera-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}

#camera-feed {
  width: 100%; height: 100%;
  object-fit: cover;
}

.camera-guide {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}

.guide-frame {
  width: 80%; height: 55%;
  position: relative;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 8px;
}

.guide-corner {
  position: absolute;
  width: 24px; height: 24px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
}
.guide-corner.tl { top:-1px; left:-1px; border-top-width:3px; border-left-width:3px; border-radius:8px 0 0 0; }
.guide-corner.tr { top:-1px; right:-1px; border-top-width:3px; border-right-width:3px; border-radius:0 8px 0 0; }
.guide-corner.bl { bottom:-1px; left:-1px; border-bottom-width:3px; border-left-width:3px; border-radius:0 0 0 8px; }
.guide-corner.br { bottom:-1px; right:-1px; border-bottom-width:3px; border-right-width:3px; border-radius:0 0 8px 0; }

.guide-text {
  position: absolute;
  bottom: 12%;
  text-align: center;
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  line-height: 1.8;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8), 0 0 2px rgba(0,0,0,0.6);
}

/* Camera error overlay */
.camera-error {
  position: absolute; inset: 0;
  background: rgba(10,10,26,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
  z-index: 10;
}

.camera-error[hidden] { display: none; }

.camera-error p {
  font-size: 15px;
  color: var(--text-dim);
  max-width: 320px;
  line-height: 1.5;
}

/* ── Capture Button ─────────────────────────── */

.bottom-bar {
  background: var(--bg);
  padding: 16px 20px calc(16px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.bottom-hint {
  font-size: 12px;
  color: var(--text-dim);
}

.btn-capture {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: none;
  background: none;
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.capture-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 4px solid var(--accent);
}

.capture-dot {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 120ms ease;
}

.btn-capture:active .capture-dot {
  transform: scale(0.85);
}

/* ── Buttons ────────────────────────────────── */

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 14px 28px;
  font-size: 15px; font-weight: 600;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  min-height: 52px;
  cursor: pointer;
  transition: transform 100ms ease, opacity 100ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:active { transform: scale(0.97); opacity: 0.9; }

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 14px 28px;
  font-size: 15px; font-weight: 600;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  min-height: 52px;
  cursor: pointer;
  transition: transform 100ms ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary:active { transform: scale(0.97); }

.btn-sm {
  padding: 10px 20px;
  min-height: 42px;
  font-size: 14px;
}

.btn-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:active { background: var(--border); }

/* ── Editor View — sidebar layout ──────────── */

.editor-layout {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.editor-canvas-area {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
}

.polygon-canvas {
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
}

/* Right sidebar */
.editor-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-step {
  flex: 1;
  padding: 20px 16px;
  animation: viewIn 250ms ease-out;
}

.sidebar-step[hidden] { display: none; }

.panel-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 14px;
}

/* Step 1: material grid — vertical list */
.material-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.material-btn {
  width: 100%;
  padding: 14px 16px;
  font-size: 15px; font-weight: 500;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  min-height: 52px;
  cursor: pointer;
  text-align: left;
  transition: all 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.material-btn:active { transform: scale(0.97); }

.material-btn.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: #fff;
}

/* Step 2: color grid — centered circles with texture */
.color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  padding: 8px 0 16px;
}

.color-dot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.color-dot {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 150ms ease, transform 150ms ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  background-size: cover;
  background-position: center;
}

.color-dot:active { transform: scale(0.93); }

.color-dot.selected {
  border-color: var(--accent);
  transform: scale(1.12);
}

.color-dot-label {
  font-size: 11px;
  color: var(--text-dim);
}

.btn-back-step {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  font-size: 13px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.btn-back-step:active { color: var(--text); }

/* Sidebar bottom actions */
.sidebar-bottom {
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
}

.sidebar-bottom .btn-primary { flex: 1; }

/* ── Portrait: sidebar becomes bottom panel ─── */
@media (orientation: portrait) {
  .editor-layout {
    flex-direction: column;
  }
  .editor-canvas-area {
    flex: 1;
  }
  .editor-sidebar {
    width: 100%;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .material-grid {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .material-grid::-webkit-scrollbar { display: none; }
  .material-btn {
    flex-shrink: 0;
    width: auto;
    white-space: nowrap;
  }
  .color-grid {
    justify-content: flex-start;
  }
}

/* ── Preview View ───────────────────────────── */

.preview-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  overflow-y: auto;
}

.preview-slider {
  display: flex;
  gap: 12px;
  flex: 1;
}

.preview-half {
  flex: 1;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}

.preview-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

.preview-label {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  padding: 5px 14px;
  border-radius: 20px;
  z-index: 1;
}

.preview-bar {
  flex-direction: row;
  gap: 12px;
}

.preview-bar .btn-primary { flex: 1; }
.preview-bar .btn-secondary { flex-shrink: 0; }

/* ── Loading Overlay ────────────────────────── */

.loading-overlay {
  position: fixed; inset: 0;
  z-index: 200;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.loading-overlay[hidden] { display: none; }

.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 14px;
  color: var(--text-dim);
}

.btn-cancel-loading {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 24px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}

.btn-cancel-loading:active { color: var(--text); border-color: var(--text-dim); }

/* ── Modal ─────────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  z-index: 250;
  background: rgba(10,10,26,0.88);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px 24px;
  width: 100%;
  max-width: 380px;
  animation: viewIn 250ms ease-out;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: block;
  margin-bottom: 6px;
  margin-top: 14px;
}

.modal-label:first-of-type { margin-top: 0; }

.modal-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-input::placeholder {
  color: var(--text-dim);
  opacity: 0.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.modal-actions .btn-primary { flex: 1; }

/* ── Toast ──────────────────────────────────── */

.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 28px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 300;
  animation: toastIn 300ms ease-out;
  max-width: calc(100vw - 48px);
  text-align: center;
}

.toast[hidden] { display: none; }

.toast-error {
  border-color: var(--accent);
  background: #2a1020;
}

@keyframes toastIn {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

/* ── Onboarding ────────────────────────────── */

.onboarding-overlay {
  position: fixed; inset: 0;
  z-index: 400;
  background: rgba(10,10,26,0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.onboarding-overlay[hidden] { display: none; }

.onboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.onboard-step[hidden] { display: none; }

.onboard-icon {
  margin-bottom: 20px;
}

.onboard-card h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}

.onboard-card p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
}

.onboard-actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
}

.onboard-actions .btn-primary { flex: 1; }

/* ── Pulse feedback (haptic fallback) ──────── */

@keyframes pulse-anim {
  0%   { transform: scale(1); }
  50%  { transform: scale(0.95); opacity: 0.7; }
  100% { transform: scale(1); opacity: 1; }
}

.pulse-feedback {
  animation: pulse-anim 300ms ease-out;
}

/* ── Responsive ─────────────────────────────── */

@media (orientation: landscape) {
  .preview-slider { flex-direction: row; }
}

@media (orientation: portrait) {
  .preview-slider { flex-direction: column; }
  .preview-half { min-height: 35vh; }
}

@media (min-width: 768px) {
  .editor-panel {
    display: flex;
    gap: 32px;
    padding: 20px 28px 12px;
  }
  .material-section, .color-section { flex: 1; }
  .color-section { margin-top: 0; }
}
