/* ==========================================================
   ARABIC TOKEN COUNTER — style.css
   Premium Glassmorphism Dark Mode Design
   ========================================================== */

/* ─── CSS Variables ────────────────────────────────────── */
:root {
  --bg-primary: #0B0F19;
  --bg-secondary: #0F1420;
  --bg-card: #131929;
  --bg-elevated: #1A2235;
  --bg-hover: #1E2840;

  --accent-indigo: #6366F1;
  --accent-violet: #8B5CF6;
  --accent-purple: #A855F7;
  --accent-blue: #3B82F6;
  --accent-cyan: #06B6D4;
  --accent-emerald: #10B981;
  --accent-amber: #F59E0B;
  --accent-rose: #F43F5E;

  --border-subtle: rgba(99,102,241,0.12);
  --border-default: rgba(99,102,241,0.22);
  --border-strong: rgba(139,92,246,0.4);

  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #475569;

  --glow-indigo: 0 0 30px rgba(99,102,241,0.25);
  --glow-violet: 0 0 30px rgba(139,92,246,0.2);
  --glow-sm: 0 0 15px rgba(99,102,241,0.15);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Cairo', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Arabic RTL body override */
body[data-ui-lang="ar"] {
  font-family: 'Cairo', 'Inter', system-ui, sans-serif;
  direction: rtl;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.4); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-indigo); }

/* Selection */
::selection { background: rgba(99,102,241,0.35); color: #fff; }

/* ─── Background Orbs ───────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  top: -30%;
  left: -20%;
  width: 60vw;
  height: 60vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,0.07) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}
body::after {
  content: '';
  position: fixed;
  bottom: -20%;
  right: -10%;
  width: 50vw;
  height: 50vw;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(139,92,246,0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Header ────────────────────────────────────────────── */
#main-header {
  background: rgba(11,15,25,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-glass { position: relative; }

.logo-icon {
  width: 34px; height: 34px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(139,92,246,0.3));
  border: 1px solid var(--border-default);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--glow-sm);
}

.badge-penalty {
  background: rgba(244,63,94,0.08);
  border: 1px solid rgba(244,63,94,0.2);
  border-radius: 999px;
  padding: 4px 12px;
}

/* Language Toggle */
.lang-toggle {
  display: flex;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.lang-btn {
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--transition);
  letter-spacing: 0.05em;
}
.lang-btn.active {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-violet));
  color: #fff;
  box-shadow: var(--glow-sm);
}
.lang-btn:hover:not(.active) { color: var(--text-primary); background: rgba(255,255,255,0.08); }

/* ─── Glass Cards ───────────────────────────────────────── */
.glass-card {
  background: rgba(19,25,41,0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
  transition: border-color var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}
.glass-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(99,102,241,0.3), transparent);
}
.glass-card:hover {
  border-color: var(--border-default);
  box-shadow: 0 4px 32px rgba(0,0,0,0.45), var(--glow-sm), inset 0 1px 0 rgba(255,255,255,0.06);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.card-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ─── Hero Section ──────────────────────────────────────── */
.hero-intro {
  max-width: 800px;
}

.hero-heading {
  font-size: clamp(1.5rem, 3.5vw, 2.2rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
}

.gradient-text {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-violet), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  max-width: 680px;
}

/* ─── Pill Badges ───────────────────────────────────────── */
.pill-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.pill-violet { background: rgba(139,92,246,0.15); color: #C4B5FD; border: 1px solid rgba(139,92,246,0.3); }
.pill-blue   { background: rgba(59,130,246,0.15); color: #93C5FD; border: 1px solid rgba(59,130,246,0.3); }
.pill-rose   { background: rgba(244,63,94,0.12); color: #FDA4AF; border: 1px solid rgba(244,63,94,0.25); }
.pill-emerald{ background: rgba(16,185,129,0.12); color: #6EE7B7; border: 1px solid rgba(16,185,129,0.25); }
.pill-amber  { background: rgba(245,158,11,0.12); color: #FCD34D; border: 1px solid rgba(245,158,11,0.25); }

/* ─── Textarea ──────────────────────────────────────────── */
.main-textarea {
  width: 100%;
  min-height: 220px;
  background: rgba(11,15,25,0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px 44px 36px 14px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.main-textarea::placeholder { color: var(--text-muted); }
.main-textarea:focus {
  border-color: var(--border-strong);
  box-shadow: var(--glow-sm), 0 0 0 1px rgba(99,102,241,0.2);
}
body[data-ui-lang="ar"] .main-textarea { direction: rtl; text-align: right; }

.textarea-stats {
  position: absolute;
  bottom: 8px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
}
body[data-ui-lang="ar"] .textarea-stats { left: auto; right: 12px; }

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.copy-btn:hover { background: rgba(99,102,241,0.2); border-color: var(--border-default); color: #fff; }
body[data-ui-lang="ar"] .copy-btn { right: auto; left: 10px; }

/* ─── Quick Stats Strip ─────────────────────────────────── */
.stat-mini {
  background: rgba(11,15,25,0.5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all var(--transition);
}
.stat-mini:hover { border-color: var(--border-default); background: rgba(99,102,241,0.06); }
.stat-mini-label { font-size: 10px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-mini-value { font-size: 18px; font-weight: 700; font-family: 'JetBrains Mono', monospace; transition: all 0.15s; }

/* ─── Token Visualizer ──────────────────────────────────── */
.visualizer-box {
  background: rgba(11,15,25,0.5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px;
  min-height: 120px;
  max-height: 280px;
  overflow-y: auto;
  line-height: 2.2;
  font-size: 14px;
  word-break: break-word;
}
body[data-ui-lang="ar"] .visualizer-box { direction: rtl; text-align: right; }

.viz-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

/* Token highlight colors */
.tok {
  display: inline;
  padding: 1px 0;
  border-radius: 3px;
  cursor: default;
  transition: filter 0.15s;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}
.tok:hover { filter: brightness(1.3); }

.tok-0 { background: rgba(99,102,241,0.25);  border-bottom: 2px solid rgba(99,102,241,0.6);  color: #C7D2FE; }
.tok-1 { background: rgba(139,92,246,0.25);  border-bottom: 2px solid rgba(139,92,246,0.6);  color: #DDD6FE; }
.tok-2 { background: rgba(6,182,212,0.2);    border-bottom: 2px solid rgba(6,182,212,0.5);   color: #A5F3FC; }
.tok-3 { background: rgba(16,185,129,0.2);   border-bottom: 2px solid rgba(16,185,129,0.5);  color: #A7F3D0; }
.tok-4 { background: rgba(245,158,11,0.18);  border-bottom: 2px solid rgba(245,158,11,0.45); color: #FDE68A; }
.tok-5 { background: rgba(244,63,94,0.18);   border-bottom: 2px solid rgba(244,63,94,0.4);   color: #FECDD3; }

.tok-sep { color: rgba(255,255,255,0.08); font-size: 10px; user-select: none; }

.legend-dot {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  border: 1px solid;
  opacity: 0.9;
  color: #fff;
}

/* Penalty info box */
.penalty-info {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(245,158,11,0.06);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.penalty-info-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ─── Sliders ───────────────────────────────────────────── */
.slider-custom {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--accent-indigo), var(--accent-violet));
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  transition: all var(--transition);
}
.slider-custom::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent-indigo);
  box-shadow: 0 0 10px rgba(99,102,241,0.5);
  cursor: pointer;
  transition: all var(--transition);
}
.slider-custom::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 0 16px rgba(99,102,241,0.7);
}
.slider-custom::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent-indigo);
  cursor: pointer;
}

/* ─── Cost Matrix Table ─────────────────────────────────── */
.matrix-head { background: rgba(255,255,255,0.03); }

#matrix-tbody tr {
  border-top: 1px solid var(--border-subtle);
  transition: background var(--transition);
}
#matrix-tbody tr:hover { background: rgba(99,102,241,0.06); }

.matrix-model-name {
  display: flex;
  align-items: center;
  gap: 8px;
}
.matrix-model-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.matrix-model-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.matrix-model-sub {
  font-size: 10px;
  color: var(--text-muted);
}
.matrix-cell {
  padding: 10px 12px;
  text-align: right;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-secondary);
}
.matrix-cell-model { padding: 10px 12px; text-align: left; }
body[data-ui-lang="ar"] .matrix-cell-model { text-align: right; }
body[data-ui-lang="ar"] .matrix-cell { text-align: left; }

.matrix-badge-cheapest {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  font-weight: 700;
  background: rgba(16,185,129,0.2);
  color: #6EE7B7;
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: 999px;
  padding: 1px 6px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ─── Monthly Bill ──────────────────────────────────────── */
.monthly-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: rgba(11,15,25,0.4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  transition: all var(--transition);
}
.monthly-item:hover { border-color: var(--border-default); background: rgba(99,102,241,0.05); }
.monthly-item-left { display: flex; align-items: center; gap: 8px; }
.monthly-item-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.monthly-item-name { font-size: 12px; font-weight: 600; color: var(--text-primary); }
.monthly-item-cost { font-size: 15px; font-weight: 700; font-family: 'JetBrains Mono', monospace; }

.savings-box {
  background: linear-gradient(135deg, rgba(16,185,129,0.08), rgba(6,182,212,0.08));
  border: 1px solid rgba(16,185,129,0.2);
  border-radius: var(--radius);
  padding: 16px;
}

/* ─── Insight Items ─────────────────────────────────────── */
.insight-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  background: rgba(11,15,25,0.4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  transition: all var(--transition);
}
.insight-item:hover { border-color: var(--border-default); background: rgba(99,102,241,0.05); }
.insight-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

/* ─── Buttons ───────────────────────────────────────────── */
.btn-ghost {
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--border-default); background: rgba(255,255,255,0.05); color: var(--text-primary); }
.btn-ghost:active { transform: scale(0.97); }

/* ─── Ad Slots ──────────────────────────────────────────── */
.ad-placeholder {
  background: rgba(19,25,41,0.5);
  border: 1px dashed rgba(99,102,241,0.2);
  border-radius: var(--radius-lg);
  overflow: hidden;
  width: 100%;
}
.ad-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: inherit;
  padding: 20px;
  gap: 6px;
  text-align: center;
}
.ad-label {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 6px;
}
.ad-promo-text {
  font-size: 12px;
  color: rgba(99,102,241,0.7);
  font-weight: 600;
}
.ad-promo-sub { font-size: 11px; color: var(--text-muted); }
.ad-promo-sub code { background: rgba(99,102,241,0.15); padding: 1px 5px; border-radius: 3px; font-size: 10px; }

/* ─── Footer ────────────────────────────────────────────── */
#main-footer {
  background: rgba(9,12,21,0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  position: relative;
  z-index: 1;
}

.footer-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.footer-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.75;
}
.footer-text strong { color: var(--text-secondary); -webkit-text-fill-color: var(--text-secondary); }

/* ─── Global Tooltip ────────────────────────────────────── */
.global-tooltip {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  max-width: 240px;
  transition: opacity 0.15s;
  font-family: 'JetBrains Mono', monospace;
}
.global-tooltip.hidden { opacity: 0; }

/* ─── Number Animation ──────────────────────────────────── */
.num-flash {
  animation: numFlash 0.25s ease-out;
}
@keyframes numFlash {
  0%   { color: #A5B4FC; transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .hero-heading { font-size: 1.4rem; }
  .main-textarea { min-height: 160px; }
  .card-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 1280px) {
  #main-layout { grid-template-columns: 1fr; }
}

/* ─── RTL Specific Overrides ─────────────────────────────── */
body[data-ui-lang="ar"] .textarea-stats { left: auto; right: 12px; }
body[data-ui-lang="ar"] #main-header { direction: rtl; }
body[data-ui-lang="ar"] .card-header { flex-direction: row-reverse; }
body[data-ui-lang="ar"] .insight-item { flex-direction: row-reverse; }
body[data-ui-lang="ar"] .monthly-item { flex-direction: row-reverse; }
body[data-ui-lang="ar"] .monthly-item-left { flex-direction: row-reverse; }
body[data-ui-lang="ar"] .penalty-info { flex-direction: row-reverse; }
body[data-ui-lang="ar"] .stat-mini { text-align: right; }
body[data-ui-lang="ar"] .matrix-cell-model { text-align: right; }
body[data-ui-lang="ar"] .matrix-cell { text-align: left; }
body[data-ui-lang="ar"] .footer-heading { direction: rtl; text-align: right; }
body[data-ui-lang="ar"] .footer-text { direction: rtl; text-align: right; }

/* ─── Micro-animations ──────────────────────────────────── */
.glass-card { animation: slideUp 0.4s ease-out both; }
.glass-card:nth-child(1) { animation-delay: 0ms; }
.glass-card:nth-child(2) { animation-delay: 60ms; }
.glass-card:nth-child(3) { animation-delay: 120ms; }

@keyframes slideUp {
  0%  { opacity: 0; transform: translateY(10px); }
  100%{ opacity: 1; transform: translateY(0); }
}

/* Glow pulse on new token count */
.glow-pulse {
  animation: glowPulse 0.3s ease-out;
}
@keyframes glowPulse {
  0%  { box-shadow: 0 0 20px rgba(99,102,241,0.5); }
  100%{ box-shadow: none; }
}
