/* ==========================================================================
   Design System & Tokens
   Dark Blue Header/Footer, White Body, Vibrant Green Accent
   ========================================================================== */

:root {
  --color-dark-blue: #1471e3;
  --color-dark-blue-light: #0a3a75;
  --color-dark-blue-accent: #113f77;
  --color-white: #ffffff;
  --color-card-border: #e2e8f0;
  --color-text-main: #000000;
  --color-text-muted: #000000;
  --color-text-light: #f1f5f9;

  --color-primary: #2563eb;

  --header-height: 100px;
  --radius-sm: 6px;
  --radius-md: 12px;

  --shadow-sm: 0 2px 4px rgba(0,0,0,0.04);
  --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.08);
  --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--color-white);
  color: var(--color-text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Header Section (Dark Blue Top Bar)
   ========================================================================== */

.app-header {
  background-color: var(--color-white);
  color: var(--color-text-light);
  border-bottom: 2px solid var(--color-dark-blue-accent);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-slot-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-slot-top img {
  height: 42px;
  width: auto;
  object-fit: contain;
}

/* Desktop Navigation Menu */
.desktop-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-item {
  background: --color-dark-blue-light;
  color: #94a3b8;
  border: none;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.925rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition-fast);
  text-decoration: none;
}

.nav-item:hover {
  color: var(-color-dark-blue-light);
  background-color: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  color: var(--color-white);
  background-color: var(--color-dark-blue-light);
}

/* Hamburger Toggle Button */
.hamburger-btn {
  display: none;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--color-white);
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  transition: var(--transition-fast);
}

.hamburger-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background-color: var(--color-white);
  border-radius: 2px;
  transition: var(--transition-fast);
}

/* Mobile Dropdown Navigation Menu */
.mobile-nav {
  display: none;
  background-color: var(--color-dark-blue);
  border-bottom: 1px solid var(--color-dark-blue-light);
  padding: 0.75rem 1.5rem 1.25rem;
  flex-direction: column;
  gap: 0.5rem;
}

.mobile-nav.open {
  display: flex;
}

.mobile-nav .nav-item {
  width: 100%;
  justify-content: space-between;
  padding: 0.75rem 1rem;
}

/* ==========================================================================
   Main Content Area (White Background)
   ========================================================================== */

.main-content {
  flex: 1;
  background-color: var(--color-white);
  padding: 1.5rem 1.5rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page-section {
  display: none;
  animation: fadeIn 0.3s ease-out forwards;
}

.page-section.active {
  display: block;
}

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

.page-header {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-card-border);
}

.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--color-text-main);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.page-description {
  color: var(--color-text-muted);
  font-size: 0.95rem;
  margin-top: 0.4rem;
}

/* Expanded Unified Box for Subpage 1 Dual Images */
.unified-box-wide {
  max-width: 1050px;
  width: 100%;
}

/* Dual Slots Container for Upload/Camera (Initial State) */
.dual-slots-container {
  display: flex;
  gap: 1.5rem;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.slot-card {
  flex: 1;
  min-width: 300px;
  background-color: var(--color-white);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.slot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-card-border);
  padding-bottom: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.slot-title {
  color: #0f172a;
  letter-spacing: 0.5px;
}

.slot-input-zone {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.slot-preview-zone {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

/* "Change Front/Side Image" buttons inside a filled slot */
.slot-preview-zone .btn-secondary {
  margin-top: 0.5rem;
  width: 100%;
}

.slot-card[data-slot-state="loaded"] .slot-input-zone {
  display: none;
}

.slot-card[data-slot-state="loaded"] .slot-preview-zone {
  display: flex;
  animation: fadeIn 0.3s ease-out forwards;
}

.camera-target-label {
  color: #38bdf8;
  font-weight: 700;
  font-size: 0.9rem;
  text-align: center;
}

.view-initial-dual {
  max-width: 100% !important;
}

.box-view {
  display: none;
  width: 100%;
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.3s ease-out forwards;
}

/* State Visibility Rules */
.unified-box[data-state="initial"] .view-initial {
  display: flex;
}

/* view-initial-dual also shows in initial state (inline style removed; CSS handles it) */
.unified-box[data-state="initial"] .view-initial-dual {
  display: flex;
}

.unified-box[data-state="camera"] .view-camera {
  display: flex;
}

.unified-box[data-state="preview"] .view-preview {
  display: flex;
}

/* State 1: Initial Upload & Camera Launcher View */
.view-initial {
  gap: 1.25rem;
  width: 100%;
  max-width: 550px;
  margin: 0 auto;
}

.view-initial .dropzone {
  width: 100%;
  padding: 3rem 2rem;
  background-color: var(--color-white);
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  text-align: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.view-initial .dropzone:hover, .view-initial .dropzone.dragover {
  border-color: var(--color-primary);
  background-color: #eff6ff;
}

.dropzone-icon {
  width: 48px;
  height: 48px;
  color: var(--color-primary);
  margin-bottom: 0.75rem;
}

.dropzone-text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text-main);
}

.dropzone-subtext {
  font-size: 0.825rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.file-input {
  display: none;
}

.divider-text {
  display: flex;
  align-items: center;
  width: 100%;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.divider-text::before, .divider-text::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: #cbd5e1;
}

.divider-text span {
  padding: 0 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.925rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  border: none;
  text-align: center;
}

.view-initial .btn-camera {
  width: 100%;
  padding: 0.9rem 1.5rem;
  font-size: 1rem;
}

.btn-secondary {
  background-color: var(--color-white);
  color: var(--color-text-main);
  border: 1px solid var(--color-card-border);
}

.btn-secondary:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
}

.btn-camera {
  background-color: var(--color-dark-blue);
  color: var(--color-white);
}

.btn-camera:hover {
  background-color: var(--color-dark-blue-light);
}

.btn-green {
  background-color: #10b981;
  color: var(--color-white);
}

.btn-green:hover {
  background-color: #059669;
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* State 2: Camera View */
.view-camera {
  width: 100%;
}

.camera-stage {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* keep the stage clear of the sticky header when scrolled into view */
  scroll-margin-top: calc(var(--header-height) + 1rem);
}

.video-stream {
  /* ponytail: shrink with the viewport so "Take Image" stays on-screen on phones;
     tall screens keep the old 460px cap (260px = header + label + gaps + controls) */
  max-width: 100%;
  max-height: min(460px, calc(100vh - 260px));
  max-height: min(460px, calc(100dvh - 260px));
  /* auto size + max constraints = the element fits the stream's aspect ratio,
     so there are no black letterbox bars around the camera image */
  width: auto;
  height: auto;
  align-self: center;
  border-radius: var(--radius-sm);
  background-color: #050505;
}

.video-stream.mirrored {
  transform: scaleX(-1);
}

.camera-controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.btn-switch-cam {
  margin-right: auto;
  width: 46px;
  min-width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.8);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-switch-cam:active {
  transform: scale(0.94);
}

.btn-switch-cam[hidden] {
  display: none;
}

.camera-controls .btn-cancel-camera {
  margin-left: auto;
}

/* State 3: Processed Preview View */
.view-preview {
  width: 100%;
  gap: 1.25rem;
}

.action-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-card-border);
}

.canvas-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.output-canvas {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-card-border);
  background-color: #ffffff;
}

/* Prominent Large Predicted Age Banner Below Image Box (Scientific B&W Theme) */
.predicted-age-banner {
  width: 100%;
  margin-top: 1.25rem;
  background-color: var(--color-white);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  color: var(--color-text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.age-banner-header {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  margin-bottom: 0.3rem;
}

.age-banner-body {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  margin: 0.2rem 0;
}

.age-value-num {
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--color-text-main);
  line-height: 1;
  text-shadow: none;
}

.age-value-unit {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-main);
}

.age-banner-footer {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  font-weight: 600;
  font-family: monospace;
}

.age-confidence-val.error {
  color: #f87171;
}

/* Dual mugshot: age results as plain text lines, one under the other, same size */
.age-results-text {
  margin-top: 1.25rem;
  font-size: 1rem;
  line-height: 1.8;
}

.age-results-text p {
  margin: 0;
}

/* "ANALYZING…" loading line directly below the taken image(s) */
.analyzing-status {
  margin: 0.75rem 0 0;
  text-align: center;
  font-weight: 600;
  color: var(--color-text-muted);
}

.analyzing-status::before {
  content: "";
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-right: 0.5rem;
  vertical-align: -0.08em;
  border: 2px solid var(--color-card-border);
  border-top-color: var(--color-dark-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Result image panels (composite / cropped face) below the age banner */
.result-panel {
  width: 100%;
  margin-top: 1.25rem;
  background-color: var(--color-white);
  border: 1px solid var(--color-card-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  color: var(--color-text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.result-panel-label {
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.result-panel img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-card-border);
}

.result-image-row {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

.result-image-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.tile-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}

/* ==========================================================================
   Footer Section (Dark Blue Bottom Bar)
   ========================================================================== */

.app-footer {
  background-color: var(--color-dark-blue);
  color: var(--color-text-light);
  border-top: 2px solid var(--color-dark-blue-accent);
  margin-top: auto;
  padding: 1.5rem 0;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* Bottom logo strip (currently commented out in the templates) */
.logos-slot-bottom {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.logo-bottom-item {
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: var(--transition-fast);
}

.logo-bottom-item:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.logo-bottom-item img {
  height: 34px;
  width: auto;
  object-fit: contain;
}

.footer-divider {
  width: 100%;
  height: 1px;
  background-color: var(--color-dark-blue-light);
}

.footer-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 0.825rem;
  color: #94a3b8;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.footer-info .footer-link {
  color: #e2e8f0;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition-fast);
}

.footer-info .footer-link:hover {
  text-decoration: underline;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .desktop-nav {
    display: none;
  }

  .hamburger-btn {
    display: flex;
  }

  .header-container {
    padding: 0 1rem;
  }

  .main-content {
    padding: 1rem 1rem;
  }

  .logos-slot-bottom {
    gap: 1.25rem;
  }

  .footer-info {
    flex-direction: column;
    text-align: center;
  }
}

/* Small phone screens (< 480px) */
@media (max-width: 480px) {
  .page-title {
    font-size: 1.3rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .slot-card {
    min-width: 100%;
  }

  .age-value-num {
    font-size: 2.5rem;
  }

  .age-value-unit {
    font-size: 1rem;
  }

  .btn {
    font-size: 0.85rem;
    padding: 0.65rem 1rem;
  }
}

/* Developer floating button (bottom right) */
.dev-fab {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1100;                 /* above header's 1000 */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--color-dark-blue);
  color: var(--color-white);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0.55;
  transition: var(--transition-fast);
}
.dev-fab:hover { opacity: 1; transform: scale(1.05); }

/* Developer code modal */
.dev-modal {
  position: fixed; inset: 0;
  background: rgba(11, 25, 44, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1200;
}
.dev-modal[hidden] { display: none; }
.dev-card {
  background: var(--color-white);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  width: min(90vw, 340px);
  text-align: center;
}
.dev-card input {
  width: 100%; margin: 0.75rem 0; padding: 0.6rem;
  border: 1px solid var(--color-card-border); border-radius: var(--radius-sm);
}
.dev-actions { display: flex; gap: 0.5rem; justify-content: center; }
.dev-error { color: #dc2626; margin-top: 0.5rem; }

/* Respect users who opt out of animations (OS-level setting) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
