/* ═══════════════════════════════════════════════════════════
   base.css — Design system: tokens, reset, layout, utilities
   InsightFlow · Luxury Dark Theme
   ═══════════════════════════════════════════════════════════ */

/* ─── Arabic typography ───────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Alexandria:wght@300;400;500;600;700&display=swap');

/* ─── Design Tokens ───────────────────────────────────────── */
:root {
  /* Colors */
  --color-bg:             #0b090d;
  --color-bg-2:           #151117;
  --color-surface:        rgba(255, 250, 242, 0.055);
  --color-surface-up:     rgba(255, 250, 242, 0.09);
  --color-surface-hover:  rgba(255, 250, 242, 0.125);

  --color-gold:           #cfb476;
  --color-gold-light:     #f0dda9;
  --color-gold-dim:       rgba(207, 180, 118, 0.11);
  --color-gold-glow:      rgba(207, 180, 118, 0.12);
  --color-gold-border:    rgba(207, 180, 118, 0.36);
  --color-gold-grad:      linear-gradient(135deg, #c7a766 0%, #f0dda9 100%);

  --color-text:           #f6f1e9;
  --color-text-2:         #ddd5c8;
  --color-muted:          #b8afa2;

  --color-border:         rgba(246, 241, 233, 0.14);
  --color-border-gold:    rgba(207, 180, 118, 0.30);

  --color-error:          #ff9b9b;
  --color-error-bg:       rgba(255, 126, 126, 0.13);
  --color-success:        #8addac;
  --color-success-bg:     rgba(111, 211, 157, 0.13);
  --color-info-bg:        rgba(100, 150, 240, 0.12);

  /* Shadows */
  --shadow-card:          0 18px 60px rgba(0, 0, 0, 0.28), 0 1px 0 rgba(255,255,255,0.045);
  --shadow-glow-gold:     0 14px 46px rgba(207, 180, 118, 0.10);
  --shadow-glow-sm:       0 0 18px rgba(207, 180, 118, 0.09);
  --shadow-modal:         0 30px 90px rgba(0, 0, 0, 0.58);
  --shadow-elevated:      0 8px 32px rgba(0, 0, 0, 0.4);

  /* Radii */
  --radius-sm:    6px;
  --radius:       12px;
  --radius-card:  22px;
  --radius-lg:    28px;
  --radius-pill:  999px;

  /* Typography */
  --font:         'Alexandria', 'Noto Sans Arabic', 'Tahoma', sans-serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', monospace;

  --text-xs:      0.7rem;
  --text-sm:      0.875rem;
  --text-base:    1rem;
  --text-md:      1.125rem;
  --text-lg:      1.375rem;
  --text-xl:      1.75rem;
  --text-2xl:     2.25rem;
  --text-3xl:     2.75rem;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Layout */
  --nav-height:   78px;
  --footer-height: 48px;
  --sidebar-w:    340px;

  /* Transitions */
  --ease:         cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring:  cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast:     150ms;
  --dur:          340ms;
  --dur-slow:     520ms;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  color-scheme: dark;
}

body {
  font-family: var(--font);
  font-variant-numeric: lining-nums;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  text-align: start;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* Background texture */
  background-image:
    radial-gradient(ellipse 70% 55% at 75% -10%, rgba(207,180,118,0.07) 0%, transparent 65%),
    radial-gradient(ellipse 70% 70% at 5% 105%, rgba(84,70,92,0.09) 0%, transparent 65%);
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select {
  font: inherit;
  font-variant-numeric: lining-nums;
  color: inherit;
}
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

::selection {
  background: rgba(207, 180, 118, 0.28);
  color: var(--color-text);
}

/* ─── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar            { width: 6px; height: 6px; }
::-webkit-scrollbar-track      { background: transparent; }
::-webkit-scrollbar-thumb      { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover{ background: rgba(201,168,76,0.3); }

/* ─── App Layout ───────────────────────────────────────────── */
#app-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-height);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 clamp(18px, 4vw, 56px);
  background: rgba(11, 9, 13, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--color-border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-shrink: 0;
  min-width: 0;
  margin-inline-end: var(--space-5);
}

.nav-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(207, 180, 118, 0.16));
}

.nav-brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding-block: 2px;
}

.nav-title {
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--color-gold-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0;
  line-height: 1.55;
  white-space: nowrap;
}

.nav-subtitle {
  font-size: 0.64rem;
  font-weight: 400;
  color: var(--color-text-2);
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.6;
  white-space: nowrap;
}

.nav-tabs {
  display: flex;
  gap: var(--space-1);
  padding: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 9px 21px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-muted);
  transition: all var(--dur) var(--ease);
  position: relative;
}

.nav-tab-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.nav-tab:hover {
  color: var(--color-text-2);
  background: var(--color-surface-up);
}

.nav-tab.active {
  background: var(--color-gold-dim);
  color: var(--color-gold-light);
  border: 1px solid var(--color-gold-border);
  box-shadow: var(--shadow-glow-sm);
}

.nav-meta {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
}

.save-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-muted);
  transition: background var(--dur) var(--ease);
}

.save-dot--saving { background: var(--color-gold); animation: pulse-dot 1s ease infinite; }
.save-dot--saved  { background: var(--color-success); }
.save-dot--error  { background: var(--color-error); }

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

.save-text {
  font-size: var(--text-xs);
  color: var(--color-text-2);
  letter-spacing: 0;
}

/* ─── Panels ───────────────────────────────────────────────── */
.panel {
  position: absolute;
  top: var(--nav-height);
  left: 0; right: 0; bottom: var(--footer-height);
  overflow-y: auto;
  overflow-x: hidden;
}

.panel.hidden { display: none; }

/* ─── Glass Utility ─────────────────────────────────────────── */
.glass {
  background: linear-gradient(145deg, rgba(255,250,242,0.065), rgba(255,250,242,0.035));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--color-border-gold);
  box-shadow: var(--shadow-card);
}

/* ─── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 11px 24px;
  min-height: 44px;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all var(--dur) var(--ease);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.btn:hover::after  { opacity: 0.04; }
.btn:active::after { opacity: 0.08; }
.btn:disabled, .btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-gold-grad);
  color: #1a1200;
  font-weight: 600;
  box-shadow: 0 2px 16px rgba(201,168,76,0.25), 0 1px 0 rgba(255,255,255,0.1) inset;
}
.btn-primary:hover {
  box-shadow: 0 4px 24px rgba(201,168,76,0.4), 0 1px 0 rgba(255,255,255,0.1) inset;
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--color-surface-up);
  color: var(--color-text-2);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover {
  border-color: var(--color-gold-border);
  color: var(--color-text);
}

.btn-ghost {
  color: var(--color-muted);
  padding: 8px 16px;
}
.btn-ghost:hover {
  background: var(--color-surface-up);
  color: var(--color-text-2);
}

.btn-danger {
  background: var(--color-error-bg);
  color: var(--color-error);
  border: 1px solid rgba(224, 82, 82, 0.25);
}
.btn-danger:hover { background: rgba(224, 82, 82, 0.2); }

.btn-sm  { padding: 6px 14px; font-size: var(--text-xs); }
.btn-lg  { padding: 14px 32px; font-size: var(--text-base); }
.btn-arrow { transition: transform var(--dur) var(--ease-spring); }
.btn:hover .btn-arrow { transform: translateX(-4px); }

/* ─── Form Inputs ──────────────────────────────────────────── */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="tel"],
textarea,
select {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  background: rgba(255, 250, 242, 0.065);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: var(--text-base);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  text-align: start;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--color-gold-border);
  box-shadow: 0 0 0 3px var(--color-gold-glow);
}

input.input-error, textarea.input-error {
  border-color: var(--color-error);
  box-shadow: 0 0 0 3px var(--color-error-bg);
}

textarea { resize: vertical; line-height: 1.6; }

input::placeholder,
textarea::placeholder {
  color: #a9a094;
  opacity: 1;
}

input:placeholder-shown,
textarea:placeholder-shown {
  direction: rtl;
  text-align: right;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23c9a84c'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-inline-end: 16px;
  padding-inline-start: 40px;
  cursor: pointer;
}

select option,
select optgroup {
  background: #f6f1e9;
  color: #17131a;
}

/* ─── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 4, 10, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.modal-overlay.hidden { display: none; }

.modal-container {
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius-lg);
  border-color: var(--color-gold-border);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}

.modal-inner { display: flex; flex-direction: column; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.modal-title {
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: 0;
  background: var(--color-gold-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  font-size: var(--text-sm);
  transition: all var(--dur-fast) var(--ease);
}
.modal-close:hover { background: var(--color-surface-up); color: var(--color-text); }

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  max-height: 70vh;
}

.modal-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-4) var(--space-6) var(--space-5);
  border-top: 1px solid var(--color-border);
}

/* ─── Toast ────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  inset-inline-end: var(--space-6);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--color-bg-2);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-elevated);
  font-size: var(--text-sm);
  pointer-events: all;
  transform: translateX(calc(-100% - 24px));
  opacity: 0;
  transition: all var(--dur) var(--ease);
}

.toast.toast-visible {
  transform: translateX(0);
  opacity: 1;
}

[dir="ltr"] .toast {
  transform: translateX(calc(100% + 24px));
}

[dir="ltr"] .toast.toast-visible {
  transform: translateX(0);
}

[dir="ltr"] .btn:hover .btn-arrow {
  transform: translateX(4px);
}

.toast-success { border-color: rgba(82,192,122,0.3); }
.toast-error   { border-color: rgba(224,82,82,0.3); }
.toast-info    { border-color: var(--color-border-gold); }

.toast-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  flex-shrink: 0;
}
.toast-success .toast-icon { background: var(--color-success-bg); color: var(--color-success); }
.toast-error .toast-icon   { background: var(--color-error-bg);   color: var(--color-error); }
.toast-info .toast-icon    { background: var(--color-gold-dim);   color: var(--color-gold); }

.toast-message { color: var(--color-text-2); }

/* ─── Brand Footer ──────────────────────────────────────────── */
.app-footer {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 110;
  height: var(--footer-height);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 9, 13, 0.92);
  border-top: 1px solid var(--color-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.app-footer__link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding-inline: var(--space-4);
  color: var(--color-gold-light);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.app-footer__link:hover {
  color: var(--color-text);
  transform: translateY(-1px);
}

.app-footer__arrow {
  color: var(--color-gold);
  font-size: var(--text-base);
}

/* ─── Animations ───────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position:  200% center; }
}

.fade-in  { animation: fadeIn  var(--dur) var(--ease) both; }
.slide-in { animation: slideIn var(--dur) var(--ease) both; }
.scale-in { animation: scaleIn var(--dur) var(--ease) both; }

/* ─── Drag & Drop ──────────────────────────────────────────── */
.dragging        { opacity: 0.4 !important; }
.drag-placeholder {
  background: var(--color-gold-dim);
  border: 1.5px dashed var(--color-gold-border);
  border-radius: var(--radius);
  margin: var(--space-2) 0;
  transition: height var(--dur-fast) var(--ease);
}

/* ─── Utilities ────────────────────────────────────────────── */
.hidden          { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.gold-text {
  background: var(--color-gold-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ─── Accessibility ─────────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--color-gold-light);
  outline-offset: 3px;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(240, 221, 169, 0.9);
  outline-offset: 3px;
}

.cms-icon-btn,
.modal-close {
  min-width: 44px;
  min-height: 44px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root {
    --nav-height: 68px;
    --footer-height: 46px;
    --sidebar-w:  100%;
  }

  .nav-subtitle { display: none; }
  .nav-brand-text { display: none; }
  .nav-logo { width: 42px; height: 42px; }
  .nav-tab { padding: 8px 12px; font-size: var(--text-xs); }
  .save-text { display: none; }
}
