/* ═══════════════════════════════════════════════════════════════════════════════
   PostureAssess — Mobile-First Stylesheet
   Clinical palette, state-machine visibility, smooth transitions
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── Custom Properties ─────────────────────────────────────────────────────── */
:root {
  --color-primary:       #0077B6;
  --color-primary-dark:  #005F92;
  --color-primary-light: #00B4D8;
  --color-teal:          #48CAE4;
  --color-teal-light:    #ADE8F4;
  --color-good:          #2DC653;
  --color-good-bg:       #F0FBF4;
  --color-warning:       #F77F00;
  --color-warning-bg:    #FFF7EE;
  --color-error:         #D62828;
  --color-error-bg:      #FFF0F0;
  --color-surface:       #F8FAFC;
  --color-card:          #FFFFFF;
  --color-text:          #1A1A2E;
  --color-text-secondary:#4A5568;
  --color-text-muted:    #94A3B8;
  --color-border:        #E2E8F0;
  --color-overlay:       rgba(0, 0, 0, 0.55);

  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   20px;
  --radius-full: 9999px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 10px 30px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);

  --transition: 200ms ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden; /* Prevents scroll bounce on iOS while in states */
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-primary);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

svg { display: block; }

/* ── App Container ──────────────────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0;
  /* Safe area insets for notched/Dynamic-Island iPhones */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── State Section Visibility ──────────────────────────────────────────────── */
.state-section {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.state-section.active {
  opacity: 1;
  pointer-events: auto;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   IDLE STATE
   ═══════════════════════════════════════════════════════════════════════════════ */
#state-idle {
  background: linear-gradient(160deg, #0096C7 0%, #0077B6 45%, #005F92 100%);
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.idle-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  max-width: 340px;
  width: 100%;
}

.app-logo {
  width: 96px;
  height: 96px;
  background: rgba(255,255,255,0.15);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255,255,255,0.25);
}

.app-logo svg {
  width: 100%;
  height: 100%;
}

.app-name {
  font-size: 28px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: -0.5px;
}

.app-tagline {
  font-size: 15px;
  color: rgba(255,255,255,0.80);
  max-width: 260px;
  line-height: 1.4;
}

.idle-hint {
  font-size: 13px;
  color: rgba(255,255,255,0.55);
  margin-top: 4px;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   VIEWFINDER STATE
   ═══════════════════════════════════════════════════════════════════════════════ */
#state-viewfinder {
  background: #000;
}

.viewfinder-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.camera-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
}

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

.silhouette-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 15%;
  pointer-events: none;
}

.silhouette-svg {
  height: 85%;
  width: auto;
  max-width: 55%;
  opacity: 0.7;
}

.instruction-strip {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
  padding: 20px 20px 12px;
  color: rgba(255,255,255,0.90);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.01em;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 40px 24px;
  background: #0A0A0A;
}

/* Capture button — classic camera shutter style */
.capture-btn {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-full);
  background: transparent;
  border: 3px solid #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  transition: transform var(--transition), opacity var(--transition);
}

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

.capture-btn-inner {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  background: #FFFFFF;
  transition: background var(--transition);
}

.capture-btn:active .capture-btn-inner {
  background: #CCECFF;
}

.btn-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.12);
  border: 1.5px solid rgba(255,255,255,0.20);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 11px;
  transition: background var(--transition), transform var(--transition);
}

.btn-icon svg {
  width: 100%;
  height: 100%;
}

.btn-icon:active {
  background: rgba(255,255,255,0.22);
  transform: scale(0.93);
}

.btn-icon-spacer {
  width: 48px;
  height: 48px;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   PREVIEW STATE
   ═══════════════════════════════════════════════════════════════════════════════ */
#state-preview {
  background: #000;
}

.preview-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.preview-canvas-wrapper {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#capture-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  background: #0A0A0A;
  padding: 10px 16px;
  text-align: center;
}

.privacy-note svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  opacity: 0.7;
}

.preview-actions {
  display: flex;
  gap: 12px;
  padding: 16px 24px 24px;
  background: #0A0A0A;
}

.preview-actions .btn {
  flex: 1;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   ANALYZING STATE
   ═══════════════════════════════════════════════════════════════════════════════ */
#state-analyzing {
  background: var(--color-card);
  align-items: center;
  justify-content: center;
}

.analyzing-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.spinner-ring {
  width: 80px;
  height: 80px;
}

.spinner-ring svg {
  width: 100%;
  height: 100%;
}

.spinner-arc {
  transform-origin: 50% 50%;
  animation: spin 1.1s linear infinite;
}

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

.analyzing-status {
  font-size: 17px;
  font-weight: 500;
  color: var(--color-text);
  text-align: center;
  min-height: 1.5em;
  transition: opacity 0.3s ease;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   RESULTS STATE
   ═══════════════════════════════════════════════════════════════════════════════ */
#state-results {
  background: var(--color-surface);
  overflow: hidden;
}

.results-header {
  padding: 16px 20px 12px;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.results-header h2 {
  font-size: 19px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.3px;
}

.results-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Score Card ─────────────────────────────────────────────────────────────── */
.score-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.score-ring-wrapper {
  flex-shrink: 0;
  width: 96px;
  height: 96px;
  position: relative;
}

.score-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-ring-bg {
  fill: none;
  stroke: var(--color-border);
  stroke-width: 6;
}

.score-ring-fill {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 263.9; /* 2π × 42 */
  stroke-dashoffset: 263.9;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.34, 1.0, 0.64, 1),
              stroke 0.4s ease;
}

.score-number-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-number {
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  color: var(--color-text);
}

.score-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.score-info {
  flex: 1;
  min-width: 0;
}

.score-assessment {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
  margin-bottom: 8px;
}

.severity-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  text-transform: capitalize;
}

.severity-badge.good {
  background: var(--color-good-bg);
  color: #1A8C3A;
}

.severity-badge.mild {
  background: #EEF9FE;
  color: #0077B6;
}

.severity-badge.moderate {
  background: var(--color-warning-bg);
  color: #B35A00;
}

.severity-badge.severe {
  background: var(--color-error-bg);
  color: var(--color-error);
}

/* ── Section Headings ───────────────────────────────────────────────────────── */
.results-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--color-text-secondary);
  padding: 4px 4px 0;
}

/* ── Finding Cards ──────────────────────────────────────────────────────────── */
.finding-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border-left: 4px solid transparent;
}

.finding-card[data-status="good"] {
  border-left-color: var(--color-good);
  background: var(--color-good-bg);
}

.finding-card[data-status="warning"] {
  border-left-color: var(--color-warning);
  background: var(--color-warning-bg);
}

.finding-card[data-status="error"] {
  border-left-color: var(--color-error);
  background: var(--color-error-bg);
}

.finding-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  margin-top: 1px;
}

.finding-card[data-status="good"]    .finding-icon { background: var(--color-good);    color: #fff; }
.finding-card[data-status="warning"] .finding-icon { background: var(--color-warning); color: #fff; }
.finding-card[data-status="error"]   .finding-icon { background: var(--color-error);   color: #fff; }

.finding-body {
  flex: 1;
  min-width: 0;
}

.finding-area {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 3px;
}

.finding-description {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.45;
}

/* ── Recommendations Card ───────────────────────────────────────────────────── */
.recommendations-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.recommendations-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.recommendations-title::before {
  content: '';
  display: block;
  width: 4px;
  height: 16px;
  background: var(--color-primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.recommendations-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recommendations-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.45;
}

.recommendations-list li::before {
  content: '→';
  color: var(--color-primary);
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 0px;
}

.results-footer {
  padding: 12px 20px 20px;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   ERROR STATE
   ═══════════════════════════════════════════════════════════════════════════════ */
#state-error {
  background: var(--color-card);
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
}

.error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  max-width: 320px;
  width: 100%;
}

.error-icon svg {
  width: 64px;
  height: 64px;
}

.error-card h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
}

.error-message {
  font-size: 15px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}


/* ═══════════════════════════════════════════════════════════════════════════════
   SHARED BUTTONS
   ═══════════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 24px;
  transition: transform var(--transition), opacity var(--transition),
              box-shadow var(--transition);
  letter-spacing: 0.01em;
  -webkit-user-select: none;
  user-select: none;
}

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

.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(0, 119, 182, 0.35);
}

.btn-primary:active {
  background: var(--color-primary-dark);
  box-shadow: 0 2px 6px rgba(0, 119, 182, 0.25);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}

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

.btn-lg {
  padding: 16px 32px;
  font-size: 17px;
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 280px;
}

/* Dark-background button variant (for PREVIEW dark bg) */
.btn-secondary-dark {
  background: rgba(255,255,255,0.12);
  color: #FFFFFF;
  border: 1.5px solid rgba(255,255,255,0.25);
}


/* ═══════════════════════════════════════════════════════════════════════════════
   TABLET / DESKTOP FALLBACK  (≥ 768px)
   ═══════════════════════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
  #state-idle {
    background: linear-gradient(160deg, #0096C7 0%, #0077B6 100%);
  }

  .idle-card {
    gap: 20px;
  }

  .app-logo {
    width: 112px;
    height: 112px;
  }

  .app-name {
    font-size: 34px;
  }

  .viewfinder-layout {
    max-width: 480px;
    margin: 0 auto;
  }

  .results-container {
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
  }

  .results-header,
  .results-footer {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   HIGH CONTRAST MODE
   ═══════════════════════════════════════════════════════════════════════════════ */
@media (prefers-contrast: high) {
  .finding-card {
    border-left-width: 6px;
    border: 2px solid;
  }

  .finding-card[data-status="good"]    { border-color: var(--color-good); }
  .finding-card[data-status="warning"] { border-color: var(--color-warning); }
  .finding-card[data-status="error"]   { border-color: var(--color-error); }

  .silhouette-overlay { opacity: 0.9; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .spinner-arc {
    animation: none;
    stroke-dasharray: 80 118;
  }

  .score-ring-fill {
    transition: none;
  }

  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
