/* ═══════════════════════════════════════════════════════════════
   FitEstimate — Main Stylesheet
   Design: dark-first, high contrast, WCAG 2.1 AA compliant
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  /* Palette */
  --bg:            #090b12;
  --bg-card:       #111422;
  --bg-elevated:   #181c2e;
  --bg-input:      #1e2235;
  --border:        rgba(255,255,255,0.07);
  --border-accent: rgba(99,120,255,0.35);

  --text-primary:  #edeeff;
  --text-secondary:#8b90b8;
  --text-muted:    #565a78;

  --accent:        #6378ff;
  --accent-hover:  #7b8dff;
  --accent-glow:   rgba(99,120,255,0.18);

  --teal:          #00c9af;
  --teal-dim:      rgba(0,201,175,0.15);
  --green:         #27c77a;
  --green-dim:     rgba(39,199,122,0.15);
  --yellow:        #f0b429;
  --yellow-dim:    rgba(240,180,41,0.15);
  --red:           #e05252;
  --red-dim:       rgba(224,82,82,0.15);

  /* Sizes */
  --radius-xs:   6px;
  --radius-sm:   10px;
  --radius:      16px;
  --radius-lg:   24px;

  /* Motion */
  --ease:        cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --duration:    0.22s;

  /* Layout */
  --max-width:   1080px;
  --gap:         24px;
}

/* ── Base ─────────────────────────────────────────────────────── */
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

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

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Skip link (accessibility) ───────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 9999;
  text-decoration: none;
  transition: top var(--duration);
}
.skip-link:focus { top: 16px; }

/* ── Focus visible (global) ──────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
:focus:not(:focus-visible) { outline: none; }

/* ── Typography ──────────────────────────────────────────────── */
h1 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.1rem, 2.5vw, 1.35rem); font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }

/* ── Consent Modal ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,7,15,0.92);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.3s var(--ease);
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 32px 96px rgba(0,0,0,0.6), 0 0 0 1px rgba(99,120,255,0.08);
  animation: slideUp 0.35s var(--ease);
}

@media (max-width: 520px) {
  .modal-box { padding: 32px 24px; }
}

.modal-icon {
  width: 64px;
  height: 64px;
  background: var(--accent-glow);
  border: 1px solid var(--border-accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}

.modal-icon svg { color: var(--accent); }

.modal-box h1 {
  font-size: 1.6rem;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #edeeff, var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-box > p {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 1.05rem;
}

.privacy-list {
  list-style: none;
  margin-bottom: 36px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.privacy-list li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.privacy-list li::before {
  content: '';
  display: block;
  width: 20px;
  height: 20px;
  min-width: 20px;
  background: var(--green-dim);
  border: 1px solid var(--green);
  border-radius: 50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2327c77a'%3E%3Cpath fill-rule='evenodd' d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z' clip-rule='evenodd'/%3E%3C/svg%3E");
  background-size: 14px;
  background-repeat: no-repeat;
  background-position: center;
  margin-top: 2px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--duration), transform var(--duration), box-shadow var(--duration);
  text-decoration: none;
}

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.42;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px rgba(99,120,255,0.35);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(99,120,255,0.45);
}
.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-large {
  width: 100%;
  padding: 16px 24px;
  font-size: 1.05rem;
  border-radius: var(--radius-sm);
  margin-top: 28px;
}

/* ── Header ──────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: rgba(9,11,18,0.9);
  backdrop-filter: blur(12px);
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-glow);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-name {
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.brand-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.privacy-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--green-dim);
  border: 1px solid rgba(39,199,122,0.3);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--green);
  white-space: nowrap;
}

/* ── Model status bar ────────────────────────────────────────── */
.model-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  margin: 24px 0 0;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  transition: background var(--duration), border-color var(--duration);
}

.model-status.ready {
  background: var(--green-dim);
  border-color: rgba(39,199,122,0.3);
  color: var(--green);
}

.model-status.error {
  background: var(--red-dim);
  border-color: rgba(224,82,82,0.3);
  color: var(--red);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.loading {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
.status-dot.ready { background: var(--green); }
.status-dot.error { background: var(--red); }

/* ── Main content ─────────────────────────────────────────────── */
.main-content { padding: 8px 0 64px; }

.input-section { margin-top: 32px; }

.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top: 0;
}

@media (max-width: 680px) {
  .input-grid { grid-template-columns: 1fr; }
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.upload-card, .height-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.card-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ── Drop zone ───────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--duration), background var(--duration);
  position: relative;
  overflow: hidden;
}

.drop-zone:hover, .drop-zone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: scale(1.01);
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  pointer-events: none;
  text-align: center;
}

.upload-icon {
  width: 56px;
  height: 56px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.upload-primary {
  font-weight: 600;
  color: var(--text-primary);
}
.upload-secondary {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.photo-preview {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-preview img {
  max-height: 280px;
  max-width: 100%;
  object-fit: contain;
  border-radius: var(--radius-xs);
  display: block;
}

.remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  background: var(--red);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  transition: background var(--duration), transform var(--duration);
}
.remove-btn:hover { background: #c0392b; transform: scale(1.1); }

.upload-tips {
  margin-top: 14px;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.upload-tips li {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-left: 16px;
  position: relative;
}
.upload-tips li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--accent);
}

/* ── Height input ────────────────────────────────────────────── */
.height-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 4px;
}

.height-input-wrap input {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 56px 14px 18px;
  color: var(--text-primary);
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: border-color var(--duration);
  -moz-appearance: textfield;
}
.height-input-wrap input::-webkit-inner-spin-button,
.height-input-wrap input::-webkit-outer-spin-button { -webkit-appearance: none; }
.height-input-wrap input:focus {
  outline: none;
  border-color: var(--accent);
}
.height-input-wrap input::placeholder { color: var(--text-muted); }

.height-unit {
  position: absolute;
  right: 18px;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  pointer-events: none;
}

.input-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.privacy-reminder {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.privacy-reminder svg { color: var(--green); flex-shrink: 0; }

/* ── Error box ───────────────────────────────────────────────── */
.error-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  background: var(--red-dim);
  border: 1px solid rgba(224,82,82,0.3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 0.875rem;
  margin-top: 12px;
}

/* ── Processing spinner ──────────────────────────────────────── */
.processing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 0;
  gap: 20px;
}

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

.processing-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  text-align: center;
}

/* ── Results ─────────────────────────────────────────────────── */
.results-section {
  margin-top: 40px;
  animation: fadeIn 0.4s var(--ease);
}

.results-section h2 {
  margin-bottom: 8px;
}

.results-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

/* ── Measurement cards ───────────────────────────────────────── */
.measurements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

@media (max-width: 560px) {
  .measurements-grid { grid-template-columns: 1fr 1fr; }
}

.measure-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  transition: border-color var(--duration), transform var(--duration);
}

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

.measure-name {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.measure-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1;
}

.measure-unit {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 2px;
}

.measure-type-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 2px 7px;
  border-radius: 999px;
  margin-top: 4px;
  margin-bottom: 10px;
}

.measure-range {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.measure-range-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  margin-top: 8px;
  position: relative;
}

.measure-range-fill {
  position: absolute;
  top: 0;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.6;
}

.measure-range-dot {
  position: absolute;
  top: -3px;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: 2px solid var(--bg-card);
  border-radius: 50%;
  transform: translateX(-50%);
}

/* ── Size recommendation ─────────────────────────────────────── */
.size-card {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  padding: 32px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.size-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--teal));
}

.size-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.size-display {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.size-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.size-value {
  font-size: 5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.confidence-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
}

.confidence-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.confidence-bar-outer {
  height: 8px;
  background: var(--bg-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.confidence-bar-inner {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--teal));
  transition: width 0.8s var(--ease);
}

.confidence-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
}

.confidence-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ── Size probability bars ───────────────────────────────────── */
.size-probs-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.size-probs {
  margin-bottom: 28px;
}

.prob-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.prob-size-label {
  font-size: 0.85rem;
  font-weight: 600;
  width: 40px;
  text-align: right;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.prob-size-label.highlighted { color: var(--text-primary); }

.prob-bar-outer {
  flex: 1;
  height: 20px;
  background: var(--bg-elevated);
  border-radius: var(--radius-xs);
  overflow: hidden;
  position: relative;
}

.prob-bar-fill {
  height: 100%;
  border-radius: var(--radius-xs);
  background: var(--bg-elevated);
  transition: width 0.7s var(--ease);
  display: flex;
  align-items: center;
  padding-left: 8px;
}

.prob-bar-fill.active {
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
}

.prob-bar-fill.near {
  background: var(--bg-input);
  border: 1px solid var(--border-accent);
}

.prob-pct {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
}

.prob-pct-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 42px;
  text-align: right;
  flex-shrink: 0;
}

/* ── Explanation ─────────────────────────────────────────────── */
.explanation {
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.explanation h3 {
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.explanation-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.65;
}

.adjustment-note {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--teal-dim);
  border: 1px solid rgba(0,201,175,0.25);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--teal);
  font-weight: 500;
  margin-top: 10px;
}

/* ── Feedback card ───────────────────────────────────────────── */
.feedback-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
}

.feedback-card h3 {
  margin-bottom: 4px;
}
.feedback-card > p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.feedback-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.feedback-btn {
  flex: 1;
  min-width: 100px;
  padding: 10px 16px;
  background: var(--bg-elevated);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration);
}

.feedback-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--accent-glow);
}

.feedback-btn--fit {
  border-color: rgba(39,199,122,0.4);
  color: var(--green);
}
.feedback-btn--fit:hover {
  border-color: var(--green);
  background: var(--green-dim);
}

.feedback-btn.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text-primary);
}

.feedback-thanks {
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Learning stats ──────────────────────────────────────────── */
.learning-card {
  background: var(--teal-dim);
  border: 1px solid rgba(0,201,175,0.2);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 20px;
  font-size: 0.875rem;
  color: var(--teal);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Footer ──────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: 64px;
}

.site-footer p {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

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

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  .size-main { flex-direction: column; align-items: flex-start; }
  .size-value { font-size: 3.5rem; }
  .confidence-block { width: 100%; }
  .measurements-grid { grid-template-columns: 1fr; }
}

/* ── Print (no special handling needed, just hide UI chrome) ── */
@media print {
  .site-header, .site-footer, .feedback-card, .btn { display: none; }
  body { background: white; color: black; }
}
