/* Linkma Stylesheet - پشتیبانی از RTL/LTR و Dark/Light Mode */
:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 0.5rem;
  --gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

/* ===== Layout ===== */
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--bg-card); border-inline-start: 1px solid var(--border);
  padding: 1.5rem; transition: width 0.3s;
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.sidebar nav { flex: 1; }
.main-content {
  flex: 1 1 0%; padding: 2rem; max-width: 1400px; margin: 0 auto; width: 100%;
  min-width: 0; /* جلوگیری از سرریز grid در فرزندان */
}

/* ===== Header ===== */
.top-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem;
}
.logo {
  font-size: 1.5rem; font-weight: 800;
  background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem;
}
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.stat-value { font-size: 2rem; font-weight: 700; margin: 0.5rem 0; }
.stat-label { color: var(--text-secondary); font-size: 0.875rem; }
.stat-icon { font-size: 1.5rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem; background: var(--primary); color: white;
  border: none; border-radius: var(--radius); font-size: 0.875rem; font-weight: 600;
  cursor: pointer; transition: background 0.2s; font-family: inherit;
}
.btn:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-secondary); }
.btn-danger { background: #ef4444; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.75rem; }

/* ===== Inputs ===== */
.input, .select {
  width: 100%; padding: 0.625rem 0.875rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: inherit; font-size: 0.875rem; transition: border-color 0.2s;
}
.input:focus, .select:focus { outline: none; border-color: var(--primary); }
label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; font-weight: 500; }
.form-group { margin-bottom: 1rem; }

/* ===== Table ===== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 1rem; text-align: start; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; }
tr:hover { background: var(--bg-secondary); }

/* ===== Link Picker (search + select) ===== */
.link-picker { position: relative; width: 100%; max-width: 320px; }
.link-picker .input { width: 100%; }
.link-dropdown { position: absolute; inset-inline: 0; top: calc(100% + 0.25rem); z-index: 60; display: none; }
.link-dropdown.open { display: block; }
/* select به‌عنوان نگهدارندهٔ مقدار (state) به‌صورت دیداری پنهان اما قابل‌دسترس می‌ماند */
.link-dropdown .select {
  position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden;
  clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap;
}
.link-list {
  max-height: min(50vh, 280px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-card); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: var(--shadow-lg);
}
.link-item {
  padding: 0.625rem 0.875rem; cursor: pointer; font-size: 0.875rem;
  display: flex; justify-content: space-between; gap: 0.75rem; align-items: center;
  border-bottom: 1px solid var(--border);
}
.link-item:last-child { border-bottom: none; }
.link-item:hover, .link-item.active { background: var(--bg-secondary); }
.link-item .slug { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-item .meta { color: var(--text-secondary); font-size: 0.75rem; flex-shrink: 0; }
.link-item .url { color: var(--text-secondary); font-size: 0.7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.link-empty { padding: 1rem; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }

/* ===== Login ===== */
.login-container { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { width: 100%; max-width: 400px; }

/* ===== Charts ===== */
.chart-container { position: relative; height: 300px; margin-top: 1rem; }
.bar { transition: opacity 0.2s; }
.bar:hover { opacity: 0.8; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 2rem; inset-inline-end: 2rem; padding: 1rem 1.5rem;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 1000; animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { transform: translateY(1rem); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== Nav ===== */
.nav-link {
  display: block; padding: 0.75rem 1rem; color: var(--text-secondary);
  text-decoration: none; border-radius: var(--radius); margin-bottom: 0.25rem; font-size: 0.875rem;
  transition: background 0.2s, color 0.2s;
}
.nav-link:hover, .nav-link.active { background: var(--bg-secondary); color: var(--text); }

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-content { background: var(--bg-card); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; }

/* ===== Responsive ===== */

/* دسکتاپ بزرگ و تلویزیون */
@media (min-width: 1600px) {
  .main-content { padding: 2.5rem 3rem; }
  .stats-grid { grid-template-columns: repeat(4, minmax(220px, 1fr)); }
}

/* تبلت کوچک و موبایل بزرگ */
@media (max-width: 1024px) {
  .main-content { padding: 1.5rem; }
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* موبایل و تبلت کوچک */
@media (max-width: 768px) {
  /* سایدبار تبدیل به نوار پایین (bottom nav) */
  .sidebar {
    width: 100%; position: fixed; bottom: 0; inset-inline: 0; top: auto;
    height: auto; padding: 0.5rem 0.5rem calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 50; border-inline-start: none; border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgb(0 0 0 / 0.08);
  }
  .sidebar .logo { display: none; }
  .sidebar nav {
    flex: none; display: flex; align-items: stretch; justify-content: space-around; gap: 0.125rem;
  }
  .sidebar nav .nav-link {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.15rem;
    padding: 0.4rem 0.25rem; margin-bottom: 0; font-size: 0.65rem; text-align: center; flex: 1;
  }
  .sidebar nav .nav-link[style*="margin-top"] { margin-top: 0 !important; }
  #accountWidget { display: none; }

  .main-content { padding: 1rem; padding-bottom: calc(5rem + env(safe-area-inset-bottom)); max-width: 100%; }
  .top-header { flex-direction: column; align-items: stretch; gap: 0.875rem; }
  .top-header .btn { width: 100%; justify-content: center; }
  .stats-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: 0.75rem; }
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.5rem; }
  .card { padding: 1rem; }
  .modal { padding: 0.5rem; }
  .modal-content { padding: 1.25rem; max-height: 92vh; }
  .chart-container { height: 220px; }
}

/* موبایل کوچک */
@media (max-width: 420px) {
  .stats-grid { grid-template-columns: 1fr; }
  .sidebar nav .nav-link { font-size: 0.6rem; }
}

/* موبایل و تبلت کوچک — قوانین تکمیلی */
@media (max-width: 768px) {
  .link-picker { max-width: 100%; }
  .link-item { padding: 0.625rem 0.75rem; }
  .link-item .meta { display: none; }
}

/* کنتراست و حرکت ترجیحی کاربر */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
