/* ==========================================================================
   app.css — styling for index.html (Dynamic AR home screen + project wizard).
   Dark, modern, mobile-first. Other pages (viewer/preview) style themselves.
   ========================================================================== */

:root {
  --bg: #0b0f16;
  --surface: #121826;
  --surface-2: #1a2334;
  --surface-3: #212c42;
  --border: #26324a;
  --text: #e9eef8;
  --muted: #93a0b8;
  --accent: #4f8cff;
  --accent-strong: #6ea1ff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --danger: #ff5c6c;
  --danger-soft: rgba(255, 92, 108, 0.12);
  --ok: #3ddc97;
  --ok-soft: rgba(61, 220, 151, 0.12);
  --warn: #ffb454;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(79, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgba(61, 220, 151, 0.05), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open { overflow: hidden; }

.hidden { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
  white-space: nowrap;
}

/* --------------------------------------------------------------- header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 14px;
  background: rgba(11, 15, 22, 0.82);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, 0.35);
  flex: none;
}

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* --------------------------------------------------------------- layout */

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.section-head { margin-bottom: 18px; }

.section-head h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14.5px;
}

.app-footer {
  padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 22px);
  border-top: 1px solid var(--border);
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease,
              transform 0.06s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.985); }

.btn:focus-visible,
.icon-btn:focus-visible,
.text-input:focus-visible,
.select-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #fff;
  border-color: rgba(79, 140, 255, 0.6);
  box-shadow: 0 6px 18px rgba(79, 140, 255, 0.28);
}

.btn-primary:hover { filter: brightness(1.07); }

.btn-outline {
  background: transparent;
  border-color: var(--border);
}

.btn-outline:hover { background: var(--surface-2); border-color: var(--surface-3); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover { color: var(--text); background: var(--surface-2); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: rgba(255, 92, 108, 0.6);
}

.btn-danger:hover { filter: brightness(1.07); }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
}

.btn-danger-ghost:hover { background: var(--danger-soft); }

.btn-sm {
  min-height: 44px;
  padding: 10px 14px;
  font-size: 14px;
  flex: 1 1 auto;
}

.btn-lg { min-height: 54px; font-size: 16.5px; padding: 14px 26px; }

.btn-block { width: 100%; }

.btn:disabled,
.btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

.btn-plus { font-size: 19px; font-weight: 700; line-height: 1; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* --------------------------------------------------------------- empty state */

.empty-state {
  margin: 34px auto 0;
  max-width: 520px;
  padding: 34px 26px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin: 0 auto 16px;
  border-radius: 22px;
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.empty-state h2 { margin: 0 0 6px; font-size: 21px; }

.empty-state > p { margin: 0 0 14px; color: var(--muted); font-size: 15px; }

.empty-steps {
  margin: 0 0 24px;
  padding: 0 0 0 22px;
  text-align: left;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.55;
  display: grid;
  gap: 10px;
}

.empty-steps strong { color: var(--text); }

/* --------------------------------------------------------------- project grid */

.project-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card:hover { border-color: var(--surface-3); transform: translateY(-2px); }

.card-thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 10;
  background:
    linear-gradient(135deg, var(--surface-2) 25%, var(--surface) 25%, var(--surface) 50%,
                    var(--surface-2) 50%, var(--surface-2) 75%, var(--surface) 75%);
  background-size: 22px 22px;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease;
  background: #fff;
}

.card-thumb img.thumb-loaded { opacity: 1; }

.thumb-tag {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  background: rgba(11, 15, 22, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.card-body { padding: 14px 16px 6px; }

.card-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.card-meta {
  margin: 0 0 4px;
  font-size: 13.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.card-meta-dim { font-size: 12.5px; opacity: 0.8; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px 14px;
  margin-top: auto;
}

/* --------------------------------------------------------------- modals */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(4, 7, 12, 0.66);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 0;
}

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  max-height: 94dvh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  animation: modal-in 0.22s ease;
}

@keyframes modal-in {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.modal-body {
  padding: 4px 20px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-body > p { color: var(--muted); font-size: 15px; line-height: 1.5; margin: 0; }

.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px calc(env(safe-area-inset-bottom, 0px) + 16px);
  border-top: 1px solid var(--border);
}

.modal-foot .btn { flex: 1 1 auto; }

.modal-sm { max-width: 420px; }

/* --------------------------------------------------------------- wizard */

.wizard-step {
  padding: 18px 0;
  border-top: 1px solid var(--border);
}

.wizard-step:first-child { border-top: 0; padding-top: 8px; }

.step-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.step-num {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid rgba(79, 140, 255, 0.35);
  flex: none;
}

.step-head h3 {
  margin: 0;
  font-size: 16.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-req {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.step-hint {
  margin: 0 0 12px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

.text-input,
.select-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 16px; /* ≥16px prevents iOS zoom-on-focus */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease;
}

.text-input::placeholder { color: var(--muted); opacity: 0.7; }

.text-input:focus,
.select-input:focus { border-color: var(--accent); outline: none; }

.select-input {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 55%, calc(100% - 14px) 55%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 0;
}

.field-row label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  flex: none;
}

.field-row .select-input { flex: 1; }

.file-name {
  margin: 10px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.step-status {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--accent-strong);
}

.step-status::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  vertical-align: -1px;
  border-radius: 50%;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

.sheet-preview { margin: 14px 0; }

.sheet-preview-frame {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
  max-height: 300px;
  display: grid;
  place-items: center;
}

.sheet-canvas {
  display: block;
  max-width: 100%;
  max-height: 300px;
  width: auto;
  height: auto;
}

.sheet-dims {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: right;
}

/* progress bars */

.progress-wrap { margin: 14px 0 4px; }

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 12px rgba(79, 140, 255, 0.55);
  transition: width 0.2s ease;
}

.progress-label {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

/* success badge + stats */

.done-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 0;
  padding: 11px 14px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ok);
  background: var(--ok-soft);
  border: 1px solid rgba(61, 220, 151, 0.3);
  border-radius: var(--radius-sm);
}

.done-check {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ok);
  color: #06281a;
  font-size: 13px;
  font-weight: 800;
  flex: none;
}

.model-stats { margin-top: 4px; }

.stats-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  margin: 14px 0 0;
  padding: 14px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.stats-grid dt { color: var(--muted); font-weight: 600; }

.stats-grid dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.warnings {
  margin: 12px 0 0;
  padding: 12px 14px 12px 30px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--warn);
  background: rgba(255, 180, 84, 0.1);
  border: 1px solid rgba(255, 180, 84, 0.3);
  border-radius: var(--radius-sm);
}

.warnings li + li { margin-top: 6px; }

/* --------------------------------------------------------------- toasts */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 440px);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1.4;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: toast-in 0.22s ease;
  overflow-wrap: anywhere;
}

@keyframes toast-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.toast-out { opacity: 0; transform: translateY(8px); transition: all 0.25s ease; }

.toast-error   { border-color: rgba(255, 92, 108, 0.5);  background: #2b1620; }
.toast-success { border-color: rgba(61, 220, 151, 0.45); background: #10261e; }
.toast-info    { border-color: rgba(79, 140, 255, 0.45); background: #14203a; }

/* --------------------------------------------------------------- larger screens */

@media (min-width: 640px) {
  .app-header { padding-left: 26px; padding-right: 26px; }
  .app-main { padding: 30px 26px 56px; }

  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: 20px; max-height: 90dvh; }
  .modal-foot .btn { flex: 0 1 auto; min-width: 130px; }
  .btn-sm { flex: 0 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
