/* ============================================================
   هوش مصنوعی قانونا — سیستم طراحی پایه
   ============================================================ */

:root {
  --font: 'Vazirmatn', 'Vazir', 'IRANSans', 'Segoe UI', Tahoma, sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 24px;
  --primary: #6366f1;
  --primary-2: #14b8a6;
  --accent: #f59e0b;
  --danger: #ef4444;
  --ok: #10b981;
  --grad: linear-gradient(135deg, #6366f1 0%, #14b8a6 100%);
  --grad-soft: linear-gradient(135deg, rgba(99,102,241,.14), rgba(20,184,166,.14));
  --shadow: 0 10px 40px rgba(2,6,23,.35);
  --shadow-sm: 0 4px 16px rgba(2,6,23,.22);
  --tr: .25s cubic-bezier(.4,0,.2,1);
}

html[data-theme="dark"] {
  --bg: #0a0f1e;
  --bg-2: #0d1428;
  --surface: #111a30;
  --surface-2: #16203a;
  --glass: rgba(17, 26, 48, .72);
  --border: rgba(148, 163, 184, .14);
  --border-2: rgba(148, 163, 184, .24);
  --text: #e8edf8;
  --muted: #93a1b8;
  --primary-text: #a5b4fc;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f2f5fb;
  --bg-2: #e9edf6;
  --surface: #ffffff;
  --surface-2: #f6f8fd;
  --glass: rgba(255, 255, 255, .82);
  --border: rgba(15, 23, 42, .09);
  --border-2: rgba(15, 23, 42, .16);
  --text: #101828;
  --muted: #5b6b83;
  --primary-text: #4f46e5;
  --shadow: 0 10px 40px rgba(15, 23, 42, .10);
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, .08);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* ویژگی hidden همیشه بر display اولویت داشته باشد (مودال‌ها، دراپ‌داون‌ها و ...) */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection { background: rgba(99, 102, 241, .35); }

/* ---------- اسکرول‌بار ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ---------- کانتینر ---------- */
.container { width: min(1160px, 92%); margin-inline: auto; }
.container.narrow { width: min(760px, 92%); }

/* ---------- دکمه‌ها ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: .92rem; font-weight: 600;
  padding: 10px 22px; border-radius: 12px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; color: var(--text);
  transition: transform .18s var(--tr), box-shadow .25s, background .25s, opacity .2s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--grad); color: #fff;
  box-shadow: 0 6px 20px rgba(99, 102, 241, .35);
}
.btn-primary:hover { box-shadow: 0 8px 28px rgba(99, 102, 241, .55); transform: translateY(-1px); }

.btn-ghost { background: transparent; border-color: var(--border-2); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--primary); }

.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary-text); }
.btn-outline:hover { background: var(--grad-soft); }

.btn-danger { background: rgba(239, 68, 68, .12); color: var(--danger); border-color: rgba(239, 68, 68, .3); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { padding: 6px 14px; font-size: .82rem; border-radius: 9px; }
.btn-lg { padding: 13px 30px; font-size: 1.02rem; border-radius: 14px; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 10px;
  background: transparent; border: none; color: var(--muted);
  font-size: 1rem; cursor: pointer; transition: var(--tr); flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- فرم‌ها ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select,
input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="number"], input[type="search"], textarea, select {
  width: 100%; font-family: inherit; font-size: .95rem;
  padding: 11px 14px; border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  border: 1.5px solid var(--border);
  outline: none; transition: var(--tr);
}
.field input:focus, .field textarea:focus, textarea:focus, input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, .14);
}
input:disabled { opacity: .55; cursor: not-allowed; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-error {
  margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: .86rem;
  background: rgba(239, 68, 68, .1); border: 1px solid rgba(239, 68, 68, .3); color: var(--danger);
}

/* ---------- کارت ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px;
  transition: transform .3s var(--tr), box-shadow .3s, border-color .3s;
}

/* ---------- آواتار ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--c, var(--grad)); color: #fff; font-weight: 700; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .3);
}

/* ---------- برند ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-logo { width: 38px; height: 38px; display: block; filter: drop-shadow(0 4px 10px rgba(99,102,241,.4)); }
.brand-logo img { width: 100%; height: 100%; }
.brand-name { font-size: 1.18rem; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- مودال ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4, 8, 20, .6); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
  animation: fadeIn .2s ease;
}
.modal {
  width: min(560px, 100%); max-height: 88vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-lg); padding: 26px;
  box-shadow: var(--shadow); animation: riseIn .3s cubic-bezier(.34,1.4,.64,1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { font-size: 1.08rem; }
.modal-desc { font-size: .86rem; color: var(--muted); margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- دراپ‌داون ---------- */
.dropdown {
  position: absolute; top: calc(100% + 8px); inset-inline-start: 0; z-index: 90;
  min-width: 300px; max-width: 92vw; max-height: 380px; overflow: auto;
  background: var(--glass); backdrop-filter: blur(18px);
  border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px;
  animation: riseIn .22s cubic-bezier(.34,1.3,.64,1);
}
.dropdown-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; border: none; border-radius: 12px;
  background: transparent; color: var(--text); font-family: inherit;
  cursor: pointer; text-align: start; transition: background .18s;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item.active { background: var(--grad-soft); }
.dd-icon { font-size: 1.2rem; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--surface-2); flex: none; }
.dd-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.4; }
.dd-text b { font-size: .9rem; }
.dd-text small { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-check { color: var(--primary-2); font-weight: 700; }
.dropdown-empty { padding: 16px; text-align: center; color: var(--muted); font-size: .85rem; }

/* ---------- توست ---------- */
#toastBox { position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: 500; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, 92vw); }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(16px);
  border: 1px solid var(--border-2); border-right: 4px solid var(--primary);
  border-radius: 14px; padding: 12px 16px; font-size: .88rem;
  box-shadow: var(--shadow); animation: toastIn .35s cubic-bezier(.34,1.3,.64,1);
}
.toast.success { border-right-color: var(--ok); }
.toast.error { border-right-color: var(--danger); }
.toast.warn { border-right-color: var(--accent); }
.toast.out { animation: toastOut .3s ease forwards; }

/* ---------- سوییچ ---------- */
.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 99px; cursor: pointer;
  background: var(--border-2); transition: var(--tr);
}
.switch .track::after {
  content: ''; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  transition: var(--tr); box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(-20px); }
html[dir="rtl"] .switch input:checked + .track::after { transform: translateX(-20px); }

/* ---------- نشان‌ها ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 700;
}
.badge.ok { background: rgba(16,185,129,.14); color: var(--ok); }
.badge.warn { background: rgba(245,158,11,.14); color: var(--accent); }
.badge.err { background: rgba(239,68,68,.14); color: var(--danger); }
.badge.info { background: rgba(99,102,241,.14); color: var(--primary-text); }

/* ---------- انیمیشن‌ها ---------- */
@keyframes fadeIn { from { opacity: 0; } }
@keyframes riseIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@keyframes riseUp { from { opacity: 0; transform: translateY(22px); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px) scale(.95); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px) scale(.96); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { transform: scale(1.5); opacity: .4; } }
@keyframes shimmer { to { background-position: -400px 0; } }
@keyframes floaty { 50% { transform: translateY(-12px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes dots { 0%, 80%, 100% { transform: scale(.5); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

.rise-in { animation: riseUp .6s cubic-bezier(.22,1,.36,1) both; }

.caret-blink::after {
  content: '▍'; display: inline-block; margin-inline-start: 2px;
  color: var(--primary-2); animation: blink 1s steps(1) infinite;
}

/* ---------- تم ---------- */
html[data-theme="dark"] .theme-toggle::before,
html[data-theme="light"] .theme-toggle::before { content: '☀️'; }
html[data-theme="light"] .theme-toggle::before { content: '🌙'; }

/* ---------- ریسپانسیو ---------- */
@media (max-width: 640px) {
  .field-grid { grid-template-columns: 1fr; }
  .btn-lg { padding: 12px 22px; font-size: .95rem; }
}
