/* ---- APP LAYOUT ---- */
.app-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 60px);
  overflow: hidden;
}

/* ---- LEFT PANEL: FACE CANVAS ---- */
.face-panel {
  position: relative;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.face-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 40px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  margin: 24px;
  width: calc(100% - 48px);
  height: calc(100% - 48px);
}

.face-empty-icon {
  width: 64px;
  height: 64px;
  color: var(--text-faint);
  opacity: 0.5;
}

.face-empty h3 {
  font-size: 16px;
  color: var(--text-muted);
}

.face-empty p {
  font-size: 13px;
  color: var(--text-faint);
}

.face-empty-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.face-loading {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(13, 13, 15, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: left;
}

.face-loading-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(245, 240, 243, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.9s linear infinite;
}

.face-loading strong,
.face-loading span {
  display: block;
}

.face-loading strong {
  color: var(--text);
  font-size: 14px;
  line-height: 1.2;
}

.face-loading span {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 3px;
}

#face-canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

#face-canvas.active {
  display: block;
}

#face-video {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
}

.canvas-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(13, 13, 15, 0.8));
  padding: 32px 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}

.canvas-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 150ms;
  font-family: 'Inter', sans-serif;
}

.canvas-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

.toggle-pill {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  display: flex;
  overflow: hidden;
}

.toggle-pill button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 150ms;
}

.toggle-pill button.active {
  background: var(--accent);
  color: var(--bg);
}

.skin-type-chip {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(13, 13, 15, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
}

.cam-status {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(13, 13, 15, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(224, 112, 112, 0.4);
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--warning);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

.cam-dot {
  width: 8px;
  height: 8px;
  background: var(--warning);
  border-radius: 50%;
  animation: pulse-dot 1.4s ease infinite;
}

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

/* ---- RIGHT PANEL: PRODUCT ---- */
.product-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg);
}

.product-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 8px;
}

.product-empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.product-empty h3 {
  font-size: 16px;
}

.product-empty p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.scan-input-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 280px;
  margin-top: 8px;
}

.scan-input-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 16px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Inter', sans-serif;
  transition: all 150ms;
  width: 100%;
}

.scan-input-btn:hover {
  border-color: var(--border-hover);
  background: var(--surface2);
}

/* ---- TEXT SEARCH ---- */
.text-search-area {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: none;
}

.text-search-area.visible {
  display: block;
}

.text-search-row {
  display: flex;
  gap: 8px;
}

.text-search-row input {
  flex: 1;
}

/* ---- APPLIED PRODUCTS ---- */
.applied-stack {
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.025);
}

.applied-stack-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.applied-stack-head span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.look-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.look-action-btn {
  background: var(--surface2);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-pill);
  color: var(--text);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 12px;
  white-space: nowrap;
  transition: all 150ms;
}

.look-action-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--bg);
}

.look-action-btn:hover {
  border-color: rgba(212, 168, 184, 0.5);
  color: var(--accent);
}

.look-action-primary:hover {
  background: var(--accent-dark);
  color: var(--bg);
}

.applied-products-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.applied-product {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px;
  transition: all 150ms;
}

.applied-product:hover,
.applied-product.active {
  background: var(--surface2);
  border-color: rgba(212, 168, 184, 0.36);
}

.applied-product button {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  padding: 5px 8px;
  transition: all 150ms;
}

.applied-product button:hover {
  border-color: rgba(224, 112, 112, 0.4);
  color: var(--warning);
}

.applied-color {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.applied-product-info {
  min-width: 0;
}

.applied-product-info div {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.applied-product-info span {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- PRODUCT LOADED STATE ---- */
.product-content {
  padding: 16px;
  flex: 1;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.product-card-top {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.product-card-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.product-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 24px;
}

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

.product-name {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.product-brand-shade {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.product-shop-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--accent);
  margin-top: 6px;
}

.product-swatches,
.product-examples {
  margin-top: 14px;
}

.product-swatches .label,
.product-examples .label {
  margin-bottom: 8px;
}

.product-swatches-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.product-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  padding: 0;
}

.product-swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px rgba(212, 168, 184, 0.22);
}

.product-examples-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.product-examples-list img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border);
}

.allergen-warning {
  margin-top: 12px;
}

.review-summary {
  margin-top: 12px;
}

.review-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

.review-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  padding: 0;
  margin-top: 4px;
}

/* ---- RECOMMENDATIONS ---- */
.recommendations {
  margin-top: 16px;
}

.recommendations h4 {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.reco-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.reco-card:last-child {
  border-bottom: none;
}

.reco-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

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

.reco-name {
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.reco-brand {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.reco-reason {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}

.reco-view {
  font-size: 12px;
  color: var(--accent);
  margin-top: 4px;
  display: inline-block;
}

/* ---- SKELETON LOADING ---- */
.skeleton-product {
  padding: 16px;
}

.skel-line {
  height: 14px;
  margin-bottom: 8px;
  background: var(--surface2);
  border-radius: 4px;
  animation: skeleton-pulse 1.2s ease infinite;
}

.skel-line.w-60 { width: 60%; }
.skel-line.w-40 { width: 40%; }
.skel-line.w-80 { width: 80%; }
.skel-line.w-100 { width: 100%; }

.skel-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  animation: skeleton-pulse 1.2s ease infinite;
  flex-shrink: 0;
}

/* ---- HEADER ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(13, 13, 15, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.app-header-logo {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  flex: 1;
  text-decoration: none;
}

.app-header-logo span { color: var(--accent); }

.avatar-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  transition: border-color 150ms;
}

.avatar-btn:hover {
  border-color: var(--border-hover);
}

.avatar-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Dropdown */
.dropdown-wrapper {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  min-width: 200px;
  z-index: 200;
  display: none;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-item {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 150ms;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: 'Inter', sans-serif;
}

.dropdown-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.dropdown-email {
  padding: 8px 12px 4px;
  font-size: 12px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  word-break: break-all;
}

/* ---- BARCODE SCANNER ---- */
.barcode-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.barcode-viewport {
  width: 100%;
  max-width: 500px;
  position: relative;
}

#barcode-video {
  width: 100%;
  border-radius: var(--radius);
}

.barcode-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 42vh) auto;
    grid-template-rows: minmax(300px, 42dvh) auto;
    height: auto;
    min-height: calc(100vh - 56px);
    min-height: calc(100dvh - 56px);
    overflow: visible;
  }

  .face-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    height: auto;
    min-height: 300px;
  }

  .face-empty {
    gap: 10px;
    margin: 12px;
    min-height: calc(100% - 24px);
    height: auto;
    width: calc(100% - 24px);
    padding: 18px 14px;
    overflow-y: auto;
  }

  .face-empty-icon {
    width: 48px;
    height: 48px;
  }

  .face-empty h3 {
    font-size: 15px;
  }

  .face-empty p {
    font-size: 12px;
    max-width: 280px;
  }

  .face-empty-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
  }

  .face-empty-actions .btn {
    width: 100%;
    min-width: 0;
    padding: 9px 8px;
    font-size: 12px;
    line-height: 1.2;
    white-space: normal;
  }

  .face-loading {
    padding: 18px;
  }

  .canvas-controls {
    gap: 8px;
    padding: 28px 10px max(12px, env(safe-area-inset-bottom));
  }

  .canvas-btn {
    min-width: 72px;
    justify-content: center;
    padding: 9px 10px;
  }

  .toggle-pill {
    flex: 1;
    max-width: 160px;
  }

  .toggle-pill button {
    flex: 1;
    padding: 8px 10px;
  }

  .product-panel {
    min-height: auto;
    overflow: visible;
    scroll-margin-top: 64px;
  }

  .product-empty {
    align-items: stretch;
    justify-content: flex-start;
    padding: 18px 16px 24px;
  }

  .scan-input-buttons {
    max-width: none;
  }

  .scan-input-btn {
    justify-content: center;
    min-height: 48px;
    text-align: center;
  }

  .text-search-area {
    padding: 12px;
  }

  .text-search-row {
    flex-direction: column;
  }

  .text-search-row .btn {
    width: 100%;
  }

  .product-content {
    padding: 12px;
  }

  .applied-stack {
    padding: 12px;
  }

  .applied-stack-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .look-actions {
    width: 100%;
    justify-content: stretch;
  }

  .look-action-btn {
    flex: 1;
    white-space: normal;
  }

  .product-examples-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .toast-container {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .toast {
    min-width: 0;
  }
}

@media (max-width: 380px) {
  .face-empty-actions {
    grid-template-columns: 1fr;
  }
}
