/* ═══════════════════════════════════════════════════════════
   Arabic AI TTS — Design System & Styles
   ═══════════════════════════════════════════════════════════ */

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  --bg:           #0a0d14;
  --surface:      #111827;
  --surface-2:    #1a2235;
  --border:       #1e2d45;
  --border-light: #2a3f5f;
  --primary:      #6366f1;
  --primary-glow: rgba(99,102,241,0.35);
  --accent:       #22d3ee;
  --accent-glow:  rgba(34,211,238,0.2);
  --success:      #10b981;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --text-1:       #f1f5f9;
  --text-2:       #94a3b8;
  --text-3:       #4b6080;
  --radius:       16px;
  --radius-sm:    10px;
  --shadow:       0 25px 60px rgba(0,0,0,0.5);
  --font-ar:      'Cairo', sans-serif;
  --transition:   all 0.25s cubic-bezier(0.4,0,0.2,1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  overflow-x: hidden;
  padding: 24px 16px 60px;
}

/* ── Animated background orbs ───────────────────────────── */
.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.12;
  pointer-events: none;
  animation: float 12s ease-in-out infinite;
  z-index: 0;
}
.orb-1 { width: 500px; height: 500px; background: var(--primary); top: -150px; left: -150px; animation-delay: 0s; }
.orb-2 { width: 400px; height: 400px; background: var(--accent);  bottom: -100px; right: -100px; animation-delay: -4s; }
.orb-3 { width: 300px; height: 300px; background: #a855f7; top: 40%; left: 50%; animation-delay: -8s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(30px, -30px) scale(1.05); }
  66%       { transform: translate(-20px, 20px) scale(0.95); }
}

/* ── Layout ─────────────────────────────────────────────── */
.container {
  position: relative;
  z-index: 1;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Header ─────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  background: rgba(17,24,39,0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
}

.logo { display: flex; align-items: center; gap: 14px; }

.logo-icon {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  padding: 10px;
  box-shadow: 0 0 20px var(--primary-glow);
}
.logo-icon svg { color: #fff; width: 100%; height: 100%; }

.logo-text h1 { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.logo-text span { font-size: 0.78rem; color: var(--text-2); }

/* API status badge */
.api-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 30px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  background: var(--surface-2);
  transition: var(--transition);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  animation: pulse-dot 1.5s infinite;
}
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:0.4} }

.api-badge.online  .status-dot { background: var(--success); animation: none; }
.api-badge.offline .status-dot { background: var(--danger);  animation: none; }
.api-badge.online  { border-color: rgba(16,185,129,0.3); }
.api-badge.offline { border-color: rgba(239,68,68,0.3); }

/* ── Main Card ──────────────────────────────────────────── */
.card {
  background: rgba(17,24,39,0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Section Labels ─────────────────────────────────────── */
.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}
.label-icon { font-size: 1rem; }

/* ── Textarea ───────────────────────────────────────────── */
.textarea-wrapper { position: relative; }

textarea {
  width: 100%;
  min-height: 140px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-ar);
  font-size: 1rem;
  line-height: 1.8;
  padding: 16px;
  resize: vertical;
  transition: var(--transition);
  outline: none;
  direction: rtl;
}
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
textarea::placeholder { color: var(--text-3); }

.char-counter {
  position: absolute;
  bottom: 10px;
  left: 14px;
  font-size: 0.75rem;
  color: var(--text-3);
}

/* ── Controls Grid ──────────────────────────────────────── */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 640px) { .controls-grid { grid-template-columns: 1fr; } }

/* ── Voice Grid ─────────────────────────────────────────── */
.voice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}
.voice-grid::-webkit-scrollbar { width: 4px; }
.voice-grid::-webkit-scrollbar-track { background: var(--surface-2); border-radius: 2px; }
.voice-grid::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.voice-card {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-align: right;
  user-select: none;
}
.voice-card:hover { border-color: var(--primary); background: rgba(99,102,241,0.08); }
.voice-card.selected {
  border-color: var(--primary);
  background: rgba(99,102,241,0.15);
  box-shadow: 0 0 12px var(--primary-glow);
}
.voice-name { font-size: 0.9rem; font-weight: 700; color: var(--text-1); }
.voice-dialect { font-size: 0.72rem; color: var(--text-2); margin-top: 2px; }
.voice-gender { font-size: 0.65rem; color: var(--text-3); margin-top: 2px; }

.voice-skeleton {
  height: 62px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Sliders ────────────────────────────────────────────── */
.sliders-group { display: flex; flex-direction: column; gap: 20px; }
.control-group { display: flex; flex-direction: column; }

.slider-value {
  margin-right: auto;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  font-family: 'Inter', monospace;
  min-width: 48px;
  text-align: center;
  background: rgba(34,211,238,0.1);
  padding: 2px 8px;
  border-radius: 20px;
}

.slider-track-wrapper { padding: 4px 0; }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to left,
    var(--primary) calc((var(--val,50) + 50) / 100 * 100%),
    var(--border)  calc((var(--val,50) + 50) / 100 * 100%)
  );
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 0 10px var(--primary-glow);
  cursor: pointer;
  transition: var(--transition);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.68rem;
  color: var(--text-3);
  margin-top: 6px;
}

/* ── Generate Button ────────────────────────────────────── */
.generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-ar);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 30px var(--primary-glow);
}
.generate-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s;
}
.generate-btn:hover::before { transform: translateX(100%); }
.generate-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 40px var(--primary-glow); }
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-icon svg { width: 22px; height: 22px; }
.btn-loader { display: none; }
.generate-btn.loading .btn-text { display: none; }
.generate-btn.loading .btn-loader { display: flex; }
.generate-btn.loading .btn-icon { display: none; }

.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Audio Section ──────────────────────────────────────── */
.audio-section {
  background: rgba(16,185,129,0.06);
  border: 1.5px solid rgba(16,185,129,0.25);
  border-radius: var(--radius-sm);
  padding: 20px;
  animation: slide-up 0.4s ease;
}
.audio-section.hidden { display: none; }

@keyframes slide-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.audio-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 14px;
}
.download-btn {
  margin-right: auto;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: rgba(16,185,129,0.15);
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: 20px;
  color: var(--success);
  font-family: var(--font-ar);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}
.download-btn:hover { background: rgba(16,185,129,0.25); }
.download-btn svg { width: 14px; height: 14px; }

.player-wrapper audio {
  width: 100%;
  border-radius: 8px;
  outline: none;
  filter: invert(0.9) hue-rotate(180deg);
}

.audio-meta { font-size: 0.75rem; color: var(--text-3); margin-top: 8px; text-align: center; }

/* ── Error Toast ────────────────────────────────────────── */
.error-toast {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.9rem;
  animation: slide-up 0.3s ease;
}
.error-toast.hidden { display: none; }

/* ── API Test Panel ─────────────────────────────────────── */
.api-panel {
  background: rgba(17,24,39,0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  overflow: hidden;
}
.api-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-2);
  transition: var(--transition);
  user-select: none;
}
.api-panel-header:hover { color: var(--text-1); background: rgba(255,255,255,0.02); }
.api-panel-header svg { width: 18px; height: 18px; transition: transform 0.3s; }
.api-panel-header.open svg { transform: rotate(180deg); }

.api-panel-body {
  display: none;
  padding: 0 24px 24px;
}
.api-panel-body.open { display: block; animation: slide-up 0.3s ease; }

.api-endpoints { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.endpoint-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}
.endpoint-card:hover { border-color: var(--primary); background: rgba(99,102,241,0.06); }

.method {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: 'Inter', monospace;
  letter-spacing: 0.5px;
}
.method.get  { background: rgba(34,211,238,0.15); color: var(--accent); }
.method.post { background: rgba(99,102,241,0.15); color: #a5b4fc; }

.endpoint-card code {
  font-family: 'Inter', monospace;
  font-size: 0.85rem;
  color: var(--text-1);
  direction: ltr;
  flex: 1;
}
.test-tag {
  margin-right: auto;
  font-size: 0.72rem;
  color: var(--text-3);
  padding: 2px 10px;
  border: 1px solid var(--border-light);
  border-radius: 20px;
}
.endpoint-card:hover .test-tag { color: var(--primary); border-color: var(--primary); }

.api-response {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  min-height: 80px;
  font-family: 'Inter', monospace;
  font-size: 0.8rem;
  direction: ltr;
  text-align: left;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-2);
}
.response-placeholder { color: var(--text-3); text-align: center; padding: 12px; direction: rtl; }
.response-loading { color: var(--accent); }
.response-ok   { color: #86efac; }
.response-error{ color: #fca5a5; }

/* ── Info Panel (replaces API test panel) ───────────────── */
.info-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  background: rgba(34,211,238,0.06);
  border: 1px solid rgba(34,211,238,0.2);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--text-2);
  backdrop-filter: blur(10px);
}
.info-icon { font-size: 1.1rem; flex-shrink: 0; }

/* ── Waveform Animation (audio playing) ─────────────────── */
.waveform-anim {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 48px;
  margin: 10px 0 6px;
}
.waveform-anim span {
  display: inline-block;
  width: 5px;
  background: linear-gradient(180deg, var(--accent), var(--primary));
  border-radius: 3px;
  animation: wave 1.2s ease-in-out infinite;
}
.waveform-anim span:nth-child(1)  { animation-delay: 0.00s; }
.waveform-anim span:nth-child(2)  { animation-delay: 0.10s; }
.waveform-anim span:nth-child(3)  { animation-delay: 0.20s; }
.waveform-anim span:nth-child(4)  { animation-delay: 0.30s; }
.waveform-anim span:nth-child(5)  { animation-delay: 0.40s; }
.waveform-anim span:nth-child(6)  { animation-delay: 0.30s; }
.waveform-anim span:nth-child(7)  { animation-delay: 0.20s; }
.waveform-anim span:nth-child(8)  { animation-delay: 0.10s; }
.waveform-anim span:nth-child(9)  { animation-delay: 0.00s; }
.waveform-anim span:nth-child(10) { animation-delay: 0.15s; }

@keyframes wave {
  0%, 100% { height: 8px;  opacity: 0.5; }
  50%       { height: 40px; opacity: 1;   }
}

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-3);
  direction: ltr;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
  background: rgba(17,24,39,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
}
.footer-top { color: var(--text-3); }
.footer-copy { color: var(--text-2); font-size: 0.78rem; display: flex; flex-direction: column; gap: 4px; }
.footer-copy strong { color: var(--accent); }
.footer-copy a { color: var(--primary); text-decoration: none; transition: var(--transition); }
.footer-copy a:hover { color: var(--accent); text-decoration: underline; }
.footer-links { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }

/* ── Cookie Banner ──────────────────────────────────────── */
.cookie-banner {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(17,24,39,0.95);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  padding: 16px 22px;
  max-width: 560px;
  width: calc(100% - 32px);
  align-items: center;
  gap: 14px;
  animation: slide-up 0.4s ease;
  direction: rtl;
  font-size: 0.82rem;
  color: var(--text-2);
}
.cookie-banner.visible { display: flex; }
.cookie-banner.dismissed { animation: fade-out 0.3s ease forwards; }

@keyframes fade-out {
  to { opacity: 0; transform: translateX(-50%) translateY(20px); }
}

.cookie-icon { font-size: 1.4rem; flex-shrink: 0; }
.cookie-banner p { flex: 1; margin: 0; line-height: 1.6; }
.cookie-link { color: var(--primary); text-decoration: none; }
.cookie-link:hover { text-decoration: underline; }

.cookie-accept-btn {
  flex-shrink: 0;
  padding: 8px 18px;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  border: none;
  border-radius: 30px;
  color: #fff;
  font-family: var(--font-ar);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.cookie-accept-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px var(--primary-glow); }

/* ── Privacy Section ────────────────────────────────────── */
.privacy-section {
  background: rgba(17,24,39,0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.privacy-summary {
  padding: 14px 22px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
  list-style: none;
  transition: var(--transition);
  user-select: none;
}
.privacy-summary::-webkit-details-marker { display: none; }
.privacy-summary:hover { color: var(--text-1); background: rgba(255,255,255,0.02); }

.privacy-content {
  padding: 0 22px 18px;
  font-size: 0.8rem;
  color: var(--text-2);
  line-height: 1.8;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.privacy-content a { color: var(--primary); text-decoration: none; }
.privacy-content a:hover { text-decoration: underline; }
