/* ═══════════════════════════════════════════════════════════════
   tath.ai — Main Stylesheet
   Dark-first, RTL, Vazirmatn, Persian-first design system
   ═══════════════════════════════════════════════════════════════ */

/* ─── Design Tokens ──────────────────────────────────────────── */
:root {
  /* Brand */
  --brand-1: #6366f1;
  --brand-2: #8b5cf6;
  --brand-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);

  /* Dark theme (default) */
  --bg-base:    #0d0d12;
  --bg-surface: #13131c;
  --bg-card:    #1a1a27;
  --bg-hover:   #21213a;
  --bg-input:   #1e1e2e;

  --border-subtle: rgba(255,255,255,.07);
  --border-normal: rgba(255,255,255,.12);
  --border-focus:  var(--brand-1);

  --text-primary:   #f0f0f8;
  --text-secondary: #9a9ab8;
  --text-muted:     #5a5a78;
  --text-inverse:   #0d0d12;

  --success: #22c55e;
  --warning: #f59e0b;
  --danger:  #ef4444;
  --info:    #3b82f6;

  /* 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;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
  --shadow-brand: 0 4px 24px rgba(99,102,241,.35);

  /* Typography */
  --font-sans: 'Vazirmatn', system-ui, sans-serif;
  --font-mono: 'Fira Code', 'Consolas', monospace;
  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 15px;
  --text-lg:   17px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  30px;
  --text-4xl:  38px;

  /* Transitions */
  --trans-fast: .12s ease;
  --trans-base: .2s ease;
  --trans-slow: .35s cubic-bezier(.4,0,.2,1);

  /* Sidebar */
  --sidebar-w: 260px;
  --topbar-h:  58px;
}

/* Light Mode overrides */
[data-theme="light"] {
  --bg-base:    #f5f5fa;
  --bg-surface: #ffffff;
  --bg-card:    #ffffff;
  --bg-hover:   #eeeef8;
  --bg-input:   #f0f0f8;
  --border-subtle: rgba(0,0,0,.06);
  --border-normal: rgba(0,0,0,.12);
  --text-primary:   #0d0d1a;
  --text-secondary: #4a4a6a;
  --text-muted:     #8a8aaa;
  --text-inverse:   #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.15);
}

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

html {
  font-size: var(--text-base);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  direction: rtl;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-1); text-decoration: none; transition: color var(--trans-fast); }
a:hover { color: var(--brand-2); }

img, video { max-width: 100%; display: block; }
button { cursor: pointer; font-family: var(--font-sans); }
input, textarea, select { font-family: var(--font-sans); }

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-normal); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Utility ────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--text-sm); }
.text-center { text-align: center; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  border: none;
  transition: all var(--trans-base);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand-gradient);
  color: white;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 28px rgba(99,102,241,.45); color: white; }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-normal);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-normal);
}
.btn-outline:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-sm { padding: 7px var(--space-4); font-size: var(--text-xs); }
.btn-lg { padding: 13px var(--space-8); font-size: var(--text-base); }
.btn-full { width: 100%; }
.btn-icon { padding: 9px; border-radius: var(--radius-md); }

/* Loading state */
.btn.loading { pointer-events: none; }
.btn.loading::after {
  content: '';
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  position: absolute;
}

/* ─── Form Elements ──────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.label-link { font-weight: 400; font-size: var(--text-xs); color: var(--brand-1); }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
textarea,
select {
  background: var(--bg-input);
  border: 1px solid var(--border-normal);
  color: var(--text-primary);
  padding: 10px var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

input::placeholder { color: var(--text-muted); }

.input-password {
  position: relative;
}
.input-password input { padding-left: 44px; }
.toggle-password {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--text-muted);
  padding: 4px;
  transition: color var(--trans-fast);
}
.toggle-password:hover { color: var(--text-primary); }

/* ─── Alerts ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 12px var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid;
}
.alert-error   { background: rgba(239,68,68,.1);  border-color: rgba(239,68,68,.3);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.1);  border-color: rgba(34,197,94,.3);  color: #86efac; }
.alert-warning { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.3); color: #fcd34d; }
.alert-info    { background: rgba(59,130,246,.1); border-color: rgba(59,130,246,.3); color: #93c5fd; }

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card-hover {
  transition: transform var(--trans-base), box-shadow var(--trans-base), border-color var(--trans-base);
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-normal);
}

/* ─── Badge ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}
.badge-primary { background: rgba(99,102,241,.2); color: #a5b4fc; }
.badge-success { background: rgba(34,197,94,.2);  color: #86efac; }
.badge-warning { background: rgba(245,158,11,.2); color: #fcd34d; }
.badge-danger  { background: rgba(239,68,68,.2);  color: #fca5a5; }
.badge-free    { background: rgba(100,116,139,.2); color: #94a3b8; }
.badge-pro     { background: rgba(99,102,241,.2); color: #a5b4fc; }
.badge-enterprise { background: rgba(245,158,11,.2); color: #fcd34d; }

/* ─── App Layout ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  z-index: 100;
  transition: transform var(--trans-slow);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  text-decoration: none;
  color: var(--text-primary);
}
.sidebar-logo span { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.5px; }

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 9px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: all var(--trans-fast);
  text-decoration: none;
  position: relative;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: rgba(99,102,241,.12);
  color: var(--brand-1);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  right: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--brand-gradient);
  border-radius: 2px 0 0 2px;
}
.nav-item svg { flex-shrink: 0; opacity: .8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: var(--space-4) var(--space-3);
  border-top: 1px solid var(--border-subtle);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  transition: background var(--trans-fast);
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
}
.sidebar-user:hover { background: var(--bg-hover); color: var(--text-primary); }
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--brand-gradient);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-sm);
  color: white; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: var(--text-sm); font-weight: 600; }
.user-plan { font-size: var(--text-xs); color: var(--text-muted); }

/* Main content */
.main-content {
  margin-right: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  position: sticky; top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}
.topbar-title { font-size: var(--text-lg); font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.page-content {
  flex: 1;
  padding: var(--space-8) var(--space-6);
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ─── Stats Grid ─────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.purple { background: rgba(99,102,241,.15); color: var(--brand-1); }
.stat-icon.green  { background: rgba(34,197,94,.15);  color: var(--success); }
.stat-icon.yellow { background: rgba(245,158,11,.15); color: var(--warning); }
.stat-icon.blue   { background: rgba(59,130,246,.15); color: var(--info); }

.stat-label { font-size: var(--text-xs); color: var(--text-muted); margin-bottom: 4px; }
.stat-value { font-size: var(--text-2xl); font-weight: 700; line-height: 1; }
.stat-change { font-size: var(--text-xs); color: var(--text-muted); margin-top: 4px; }
.stat-change.up   { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ─── Templates Grid ─────────────────────────────────────────── */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.template-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--trans-base);
  position: relative;
}
.template-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand-1);
}
.template-thumb {
  aspect-ratio: 3/4;
  background: var(--bg-hover);
  position: relative;
  overflow: hidden;
}
.template-thumb img { width: 100%; height: 100%; object-fit: cover; }
.template-thumb-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg-hover) 0%, var(--bg-input) 100%);
  color: var(--text-muted);
}
.template-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  opacity: 0;
  transition: opacity var(--trans-base);
}
.template-card:hover .template-overlay { opacity: 1; }
.template-info { padding: var(--space-3) var(--space-4); }
.template-name { font-size: var(--text-sm); font-weight: 600; margin-bottom: 4px; }
.template-meta { font-size: var(--text-xs); color: var(--text-muted); }

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  opacity: 0; pointer-events: none;
  transition: opacity var(--trans-base);
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-normal);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  width: 100%; max-width: 540px;
  max-height: 90vh; overflow-y: auto;
  transform: scale(.95) translateY(8px);
  transition: transform var(--trans-base);
  box-shadow: var(--shadow-lg);
}
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-6);
}
.modal-title { font-size: var(--text-xl); font-weight: 700; }

/* ─── Loading / Skeleton ─────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-card) 50%, var(--bg-hover) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-md);
}

/* ─── Animations ─────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

.animate-fade-in { animation: fadeIn .3s ease forwards; }

/* ─── Theme Toggle ───────────────────────────────────────────── */
.theme-toggle {
  width: 36px; height: 20px;
  background: var(--border-normal);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  border: none;
  transition: background var(--trans-base);
}
.theme-toggle.on { background: var(--brand-1); }
.theme-toggle::after {
  content: '';
  position: absolute;
  top: 2px; right: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: white;
  transition: transform var(--trans-base);
  box-shadow: var(--shadow-sm);
}
.theme-toggle.on::after { transform: translateX(-16px); }

/* ─── Responsive ─────────────────────────────────────────────── */
.mobile-menu-btn {
  display: none;
  padding: var(--space-2);
  background: none; border: none;
  color: var(--text-primary);
}

@media (max-width: 1024px) {
  :root { --sidebar-w: 240px; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
  }
  .sidebar-overlay.open { display: block; }

  .main-content { margin-right: 0; }
  .mobile-menu-btn { display: flex; }
  .page-content { padding: var(--space-5) var(--space-4); }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .templates-grid { grid-template-columns: repeat(2, 1fr); }
}
