/* ============================================
   Somatic Therapy Tracker - PWA Stylesheet
   Apple dark aesthetic, mobile-first
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0a0a0a;
  color: #f0f0f0;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior: none;
}
a { color: #4ecdc4; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

/* --- Typography --- */
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1.05rem; font-weight: 600; }
.text-secondary { color: #999; }
.text-muted { color: #666; }
.text-accent { color: #4ecdc4; }
.text-center { text-align: center; }
small { font-size: 0.8rem; color: #999; }

/* --- Header --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid #2a2a2a;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.app-header h1 { font-size: 1.15rem; }
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-user img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.header-user span {
  font-size: 0.85rem;
  color: #999;
}

/* --- Auth --- */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  gap: 24px;
  text-align: center;
}
.auth-screen h1 { font-size: 1.75rem; margin-bottom: 4px; }
.auth-screen p { color: #999; font-size: 0.95rem; }
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  color: #333;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  min-height: 44px;
}
.btn-google:active { opacity: 0.85; }
.btn-google img { width: 20px; height: 20px; }

/* --- Bottom Tab Bar --- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: rgba(20, 20, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid #2a2a2a;
  display: flex;
  justify-content: space-around;
  padding: 6px 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  background: none;
  border: none;
  cursor: pointer;
  color: #666;
  font-size: 0.65rem;
  font-weight: 500;
  transition: color 0.2s;
}
.tab-item svg { width: 24px; height: 24px; }
.tab-item.active { color: #4ecdc4; }
.tab-item:active { opacity: 0.7; }

/* Content area: account for header + tab bar */
.main-content {
  padding-top: 8px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

/* --- Cards --- */
.card {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}
.card:active { border-color: #3a3a3a; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-subtitle { font-size: 0.8rem; color: #999; margin-top: 2px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-user-select: none;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; pointer-events: none; }
.btn-primary { background: #4ecdc4; color: #0a0a0a; }
.btn-danger { background: #ff6b6b; color: #fff; }
.btn-ghost {
  background: transparent;
  color: #4ecdc4;
  border: 1px solid #2a2a2a;
}
.btn-ghost:active { background: rgba(78, 205, 196, 0.08); }
.btn-sm { min-height: 36px; padding: 6px 14px; font-size: 0.85rem; border-radius: 8px; }
.btn-block { width: 100%; }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: #141414;
  color: #f0f0f0;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: #4ecdc4;
}
.form-input::placeholder, .form-textarea::placeholder { color: #666; }
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23999'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.form-textarea { min-height: 88px; resize: vertical; line-height: 1.5; }

/* Range slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: #2a2a2a;
  border-radius: 3px;
  outline: none;
  margin: 8px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  background: #4ecdc4;
  border-radius: 50%;
  cursor: pointer;
}

/* --- Body Map --- */
.body-map-container {
  width: 100%;
  aspect-ratio: 3 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}
.body-map-container svg { width: 100%; height: 100%; }
.body-region {
  cursor: pointer;
  transition: opacity 0.2s, r 0.15s;
  stroke: #2a2a2a;
  stroke-width: 1.5;
}
.body-region.default { fill: rgba(78, 205, 196, 0.15); }
.body-region.selected { fill: rgba(78, 205, 196, 0.5); stroke: #4ecdc4; stroke-width: 2; }
.body-region.connected { fill: rgba(78, 205, 196, 0.3); stroke: #4ecdc4; stroke-dasharray: 4 3; }

/* Tension intensity colors */
.tension-0, .tension-1, .tension-2 { fill: #4ecdc4; }
.tension-3, .tension-4 { fill: #a8e6a3; }
.tension-5, .tension-6 { fill: #ffd93d; }
.tension-7, .tension-8 { fill: #ff9f43; }
.tension-9, .tension-10 { fill: #ff6b6b; }

/* --- Info Panel (bottom sheet) --- */
.info-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.info-panel-overlay.active { opacity: 1; pointer-events: auto; }
.info-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 310;
  background: #1a1a1a;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  max-height: 60vh;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.info-panel.active { transform: translateY(0); }
.info-panel-handle {
  width: 36px;
  height: 5px;
  background: #3a3a3a;
  border-radius: 3px;
  margin: 10px auto 8px;
  flex-shrink: 0;
}
.info-panel-body {
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-overflow-scrolling: touch;
}

/* --- Library / Video Cards --- */
.video-card {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
}
.video-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #141414;
  object-fit: cover;
}
.video-card-body { padding: 12px; }
.video-card-title { font-weight: 600; font-size: 0.95rem; margin-bottom: 4px; }
.video-meta { font-size: 0.8rem; color: #666; margin-bottom: 8px; }
.rating-stars { color: #ffd93d; font-size: 0.9rem; letter-spacing: 2px; }
.rating-stars .empty { color: #2a2a2a; }

/* --- Tag Pills --- */
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.tag-modality { background: rgba(78, 205, 196, 0.15); color: #4ecdc4; }
.tag-region { background: rgba(255, 217, 61, 0.15); color: #ffd93d; }
.tag-segment { background: rgba(255, 107, 107, 0.15); color: #ff6b6b; }
.tag-general { background: rgba(153, 153, 153, 0.15); color: #999; }

/* --- Polyvagal State Badges --- */
.state-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.state-ventral_vagal { background: rgba(78, 205, 196, 0.15); color: #4ecdc4; }
.state-sympathetic { background: rgba(255, 159, 67, 0.15); color: #ff9f43; }
.state-dorsal_vagal { background: rgba(84, 160, 255, 0.15); color: #54a0ff; }
.state-blended { background: rgba(255, 217, 61, 0.12); color: #ffd93d; }
.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* --- Session Flow --- */
.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 0;
}
.step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2a2a2a;
  transition: background 0.25s, transform 0.25s;
}
.step-dot.active { background: #4ecdc4; transform: scale(1.3); }
.step-dot.done { background: #4ecdc4; opacity: 0.5; }
.section-header {
  font-size: 0.75rem;
  font-weight: 700;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 10px;
}
.sibam-card {
  background: #141414;
  border: 1px solid #2a2a2a;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}
.sibam-card.active { border-color: #4ecdc4; }
.sibam-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #4ecdc4;
  margin-bottom: 4px;
}

/* --- Loading --- */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #2a2a2a;
  border-top-color: #4ecdc4;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, #1a1a1a 25%, #242424 50%, #1a1a1a 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 8px;
}
.skeleton-line { height: 14px; margin-bottom: 10px; border-radius: 4px; }
.skeleton-line.short { width: 60%; }
.skeleton-card { height: 100px; margin-bottom: 12px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 0;
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom) + 8px);
  left: 16px;
  right: 16px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #f0f0f0;
  color: #0a0a0a;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.25s, transform 0.25s;
  max-width: 360px;
  text-align: center;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.success { background: #4ecdc4; color: #0a0a0a; }
.toast.error { background: #ff6b6b; color: #fff; }

/* --- Modal / Overlay --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 340px;
  transform: scale(0.95);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal-overlay.active .modal { transform: scale(1); }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.modal-body { color: #999; font-size: 0.9rem; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }

/* --- Empty States --- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #666;
}
.empty-state p { font-size: 0.95rem; margin-top: 8px; }
.empty-state .icon { font-size: 2rem; margin-bottom: 8px; opacity: 0.5; }

/* --- Utility --- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.p-16 { padding: 16px; }
.hidden { display: none !important; }
