/* ==========================================================================
   أطلس العمود الفقري ثلاثي الأبعاد — تنسيقات الواجهة (RTL)
   Arabic Spine Atlas — Modern Anatomical 3D UI Stylesheet
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&display=swap');

:root {
  --bg-main: #070a12;
  --bg-surface: rgba(15, 23, 42, 0.88);
  --bg-surface-elevated: rgba(30, 41, 59, 0.92);
  --bg-card: rgba(30, 41, 59, 0.65);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(56, 189, 248, 0.5);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --color-cervical: #38bdf8;
  --color-thoracic: #22c55e;
  --color-lumbar: #f97316;
  --color-sacrum: #ef4444;
  --color-coccyx: #a855f7;
  --color-discs: #94a3b8;

  --accent-gold: #fbbf24;
  --accent-danger: #f43f5e;
  --accent-success: #10b981;
  
  --shadow-panel: 0 20px 40px -15px rgba(0, 0, 0, 0.7);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-main);
  color: var(--text-primary);
  font-family: 'Cairo', 'Noto Kufi Arabic', system-ui, -apple-system, sans-serif;
  direction: rtl;
  text-align: right;
  line-height: 1.6;
}

/* ==================== Canvas Layer ==================== */
#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#canvas-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ==================== Loading Screen ==================== */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: radial-gradient(circle at center, #0f172a 0%, #030712 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 54px;
  height: 54px;
  border: 4px solid rgba(56, 189, 248, 0.15);
  border-top-color: var(--color-cervical);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.loading-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.loading-subtext {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

/* ==================== App Header ==================== */
.app-header {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  left: 1.25rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.header-brand {
  pointer-events: auto;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f8fafc 30%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.header-badges {
  display: flex;
  gap: 0.5rem;
  pointer-events: auto;
}

.badge-tag {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border-subtle);
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* ==================== Region Selector Bar ==================== */
.region-bar-container {
  position: absolute;
  top: 5rem;
  right: 1.25rem;
  z-index: 10;
  max-width: calc(100vw - 2.5rem);
}

.region-bar {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.4rem;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  scrollbar-width: none;
}

.region-bar::-webkit-scrollbar {
  display: none;
}

.region-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.region-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.region-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--border-focus);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.color-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.dot-all { background: #94a3b8; }
.dot-cervical { background: var(--color-cervical); }
.dot-thoracic { background: var(--color-thoracic); }
.dot-lumbar { background: var(--color-lumbar); }
.dot-sacrum { background: var(--color-sacrum); }
.dot-coccyx { background: var(--color-coccyx); }
.dot-discs { background: var(--color-discs); }

/* ==================== Quick View Controls ==================== */
.view-controls {
  position: absolute;
  bottom: 4rem;
  right: 1.25rem;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.icon-btn {
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.icon-btn:hover {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* ==================== Side / Bottom Info Panel ==================== */
.inspector-panel {
  position: absolute;
  top: 5rem;
  left: 1.25rem;
  width: 380px;
  max-width: calc(100vw - 2.5rem);
  max-height: calc(100vh - 10rem);
  z-index: 15;
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.panel-header {
  padding: 1.1rem 1.25rem 0.8rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.panel-title-group {
  flex: 1;
}

.structure-badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  background: rgba(56, 189, 248, 0.15);
  color: var(--color-cervical);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.structure-arabic-name {
  font-size: 1.22rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.35;
}

.structure-english-name {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: system-ui, sans-serif;
  direction: ltr;
  text-align: right;
  margin-top: 0.1rem;
}

.panel-content {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}

/* Info Cards */
.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
}

.info-card-title {
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card-teacher .info-card-title {
  color: #38bdf8;
}

.card-teacher .info-card-body {
  font-size: 0.88rem;
  color: #e2e8f0;
  line-height: 1.65;
}

.card-effect {
  border-color: rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.08);
}

.card-effect .info-card-title {
  color: #fb7185;
}

.card-effect .info-card-body {
  font-size: 0.85rem;
  color: #fecdd3;
  line-height: 1.6;
}

/* Action Buttons */
.actions-container {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-remove {
  background: rgba(244, 63, 94, 0.2);
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.4);
}

.btn-remove:hover {
  background: rgba(244, 63, 94, 0.35);
  color: #fff;
  border-color: #f43f5e;
}

.btn-play {
  background: rgba(168, 85, 247, 0.2);
  color: #d8b4fe;
  border-color: rgba(168, 85, 247, 0.4);
}

.btn-play:hover {
  background: rgba(168, 85, 247, 0.35);
  color: #fff;
  border-color: #a855f7;
}

.btn-reset {
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
  grid-column: span 2;
}

.btn-reset:hover {
  background: rgba(51, 65, 85, 0.9);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* Voice Scenario Simulation Box */
.voice-scenario-box {
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(168, 85, 247, 0.4);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  animation: fadeIn 0.3s ease;
}

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

.scenario-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.4rem;
}

.scenario-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: #c084fc;
}

.scenario-subtag {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.voice-bubble {
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  line-height: 1.6;
}

.bubble-pain {
  background: rgba(239, 68, 68, 0.15);
  border-right: 3px solid #ef4444;
  color: #fca5a5;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.15);
}

.bubble-pain.pulse {
  animation: pulseBorder 1s infinite alternate;
}

@keyframes pulseBorder {
  from { border-color: #ef4444; box-shadow: 0 0 10px rgba(239, 68, 68, 0.2); }
  to { border-color: #f87171; box-shadow: 0 0 25px rgba(239, 68, 68, 0.5); }
}

.bubble-teacher {
  background: rgba(56, 189, 248, 0.12);
  border-right: 3px solid #38bdf8;
  color: #bae6fd;
}

.bubble-speaker {
  font-size: 0.75rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
  display: block;
}

/* ==================== Footer & Attributions ==================== */
.app-footer {
  position: absolute;
  bottom: 0.8rem;
  left: 1.25rem;
  right: 1.25rem;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.footer-content {
  pointer-events: auto;
  background: var(--bg-surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.footer-content a {
  color: var(--color-cervical);
  text-decoration: none;
  transition: color 0.2s ease;
}

.footer-content a:hover {
  text-decoration: underline;
  color: #7dd3fc;
}

.license-pill {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ==================== Mobile Responsiveness ==================== */
@media (max-width: 768px) {
  .app-header {
    top: 0.6rem;
    right: 0.8rem;
    left: 0.8rem;
  }
  
  .header-brand {
    padding: 0.5rem 0.9rem;
  }
  
  .brand-title {
    font-size: 1.05rem;
  }
  
  .region-bar-container {
    top: 4.2rem;
    right: 0.8rem;
    left: 0.8rem;
  }
  
  .region-btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.78rem;
  }

  .view-controls {
    bottom: calc(52vh + 1rem);
    right: 0.8rem;
    flex-direction: row;
  }
  
  .inspector-panel {
    top: auto;
    bottom: 2.2rem;
    left: 0.8rem;
    right: 0.8rem;
    width: auto;
    max-width: none;
    max-height: 50vh;
    border-radius: var(--radius-md);
  }

  .app-footer {
    bottom: 0.4rem;
    left: 0.8rem;
    right: 0.8rem;
    font-size: 0.68rem;
  }
}
