/* ==========================================================================
   زروان فاند — سیستم طراحی (Design System)
   فونت وزیرمتن self-host، تم تیره/روشن، موبایل-اول، RTL
   ========================================================================== */

@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400; font-display: swap; font-style: normal;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500; font-display: swap; font-style: normal;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700; font-display: swap; font-style: normal;
}

/* ---------- توکن‌های طراحی ---------- */
:root {
  --bg-0: #0a0e17;
  --bg-1: #0e1422;
  --surface: #151d2e;
  --surface-2: #1b2538;
  --surface-3: #222e44;
  --glass: rgba(21, 29, 46, 0.72);
  --text: #e8edf5;
  --text-2: #aab4c5;
  --muted: #76839a;
  --border: rgba(255, 255, 255, 0.07);
  --border-2: rgba(255, 255, 255, 0.12);
  --green: #16c784;
  --green-dim: rgba(22, 199, 132, 0.14);
  --red: #ea3943;
  --red-dim: rgba(234, 57, 67, 0.14);
  --gold: #f0b90b;
  --accent: #4f8cff;
  --accent-2: #6366f1;
  --accent-grad: linear-gradient(135deg, #4f8cff 0%, #6366f1 100%);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --header-h: 62px;
  --maxw: 1440px;
}

[data-theme='light'] {
  --bg-0: #eef1f7;
  --bg-1: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f8;
  --glass: rgba(255, 255, 255, 0.82);
  --text: #16203a;
  --text-2: #44516a;
  --muted: #7a869c;
  --border: rgba(15, 25, 50, 0.09);
  --border-2: rgba(15, 25, 50, 0.16);
  --green: #00a06b;
  --green-dim: rgba(0, 160, 107, 0.12);
  --red: #d4313c;
  --red-dim: rgba(212, 49, 60, 0.10);
  --shadow: 0 8px 28px rgba(40, 60, 110, 0.12);
  --shadow-sm: 0 2px 10px rgba(40, 60, 110, 0.08);
}

/* ---------- پایه ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Vazirmatn', Tahoma, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(79, 140, 255, 0.10), transparent 60%),
    radial-gradient(900px 500px at 0% 0%, rgba(99, 102, 241, 0.08), transparent 55%),
    var(--bg-0);
  color: var(--text);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num { font-variant-numeric: tabular-nums; letter-spacing: 0; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--muted); }
.center { text-align: center; }
.hide { display: none !important; }

/* ---------- نوار پیشرفت بالای صفحه ---------- */
#progress {
  position: fixed; top: 0; right: 0; height: 3px; width: 0;
  background: var(--accent-grad); z-index: 100;
  box-shadow: 0 0 10px var(--accent); transition: width .2s ease, opacity .3s;
  border-radius: 0 0 0 3px;
}

/* ---------- هدر ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  height: var(--header-h); padding: 0 clamp(14px, 3vw, 28px);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; white-space: nowrap; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px; flex: 0 0 auto;
  background: var(--accent-grad); display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(79, 140, 255, 0.4);
}
.brand .logo svg { width: 18px; height: 18px; }
.brand b { background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand small { color: var(--muted); font-size: 11px; font-weight: 500; display: block; line-height: 1; margin-top: 2px; }

.nav-desktop { display: flex; gap: 4px; margin-inline-start: 8px; }
.nav-desktop a {
  padding: 8px 14px; border-radius: var(--radius-xs); color: var(--text-2);
  font-weight: 500; font-size: 13.5px; transition: all .15s; white-space: nowrap;
}
.nav-desktop a:hover { background: var(--surface-2); color: var(--text); }
.nav-desktop a.active { background: var(--accent-grad); color: #fff; box-shadow: var(--shadow-sm); }

.topbar .spacer { margin-inline-start: auto; }

/* جست‌وجو */
.search-box { position: relative; }
.search-box input {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 38px 9px 14px; border-radius: 999px; width: clamp(180px, 22vw, 280px);
  font-family: inherit; font-size: 13.5px; transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.15); outline: none; }
.search-box .s-icon { position: absolute; top: 50%; right: 13px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0; width: min(340px, 90vw); max-height: 60vh;
  overflow-y: auto; background: var(--surface); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); display: none; z-index: 60; padding: 6px;
}
.search-results.show { display: block; animation: pop .15s ease; }
.search-results a.item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-xs); color: var(--text); text-decoration: none;
}
.search-results a.item:hover { background: var(--surface-2); }
.search-results .item small { color: var(--muted); font-size: 12px; }

/* دکمه‌های آیکونی هدر */
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  border-radius: 10px; cursor: pointer; transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-2); }
.hamburger { display: none; }

/* بَج زنده */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--green-dim); color: var(--green); }
.badge.ok::before { animation: pulse 1.6s infinite; }
.badge.off { background: var(--red-dim); color: var(--red); }

/* ---------- نوار خلاصه بازار (ticker) ---------- */
.ticker {
  position: sticky; top: var(--header-h); z-index: 30;
  display: flex; gap: 0; overflow: hidden; white-space: nowrap;
  background: var(--surface); border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.ticker .track { display: inline-flex; gap: 26px; padding: 9px 20px; animation: marquee 38s linear infinite; }
.ticker:hover .track { animation-play-state: paused; }
.ticker .t-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; }
.ticker .t-item b { font-weight: 700; }
.ticker .t-item .num { color: var(--text-2); }

/* ---------- چیدمان اصلی ---------- */
main { padding: clamp(14px, 2.5vw, 22px); max-width: var(--maxw); margin: 0 auto; }
.section-title {
  display: flex; align-items: center; gap: 10px; margin: 22px 2px 12px; font-size: 15px; font-weight: 700;
}
.section-title:first-child { margin-top: 6px; }
.section-title .bar { width: 4px; height: 16px; border-radius: 3px; background: var(--accent-grad); }

/* کارت‌های آماری */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; }
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px; overflow: hidden;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--border-2); box-shadow: var(--shadow-sm); }
.card .label { color: var(--muted); font-size: 12.5px; margin-bottom: 7px; display: flex; align-items: center; gap: 6px; }
.card .value { font-size: 22px; font-weight: 700; letter-spacing: -.2px; }
.card .delta { font-size: 12.5px; margin-top: 5px; font-weight: 500; display: inline-flex; align-items: center; gap: 3px; }
.card.accent::after {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--accent-grad);
}
.card.flash-up { animation: flashUp .8s ease; }
.card.flash-down { animation: flashDown .8s ease; }

/* پنل‌ها */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.panel-head .actions { display: flex; gap: 6px; }
.chart { width: 100%; height: 290px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); transition: all .15s;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent-grad); color: #fff; border-color: transparent; }

/* جدول‌ها */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  position: sticky; top: 0; color: var(--muted); font-weight: 500; text-align: right;
  padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface); cursor: default; user-select: none;
}
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--text); }
thead th.sortable::after { content: '⇅'; opacity: .35; margin-inline-start: 4px; font-size: 11px; }
thead th.sort-asc::after { content: '↑'; opacity: 1; color: var(--accent); }
thead th.sort-desc::after { content: '↓'; opacity: 1; color: var(--accent); }
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td .sym-link { font-weight: 600; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 7px; font-size: 12px; font-weight: 600; }
.pill.pos { background: var(--green-dim); color: var(--green); }
.pill.neg { background: var(--red-dim); color: var(--red); }

/* وضعیت خالی و اسکلت */
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 13.5px; }
.empty .ico { font-size: 28px; opacity: .5; display: block; margin-bottom: 8px; }
.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--radius); }
.skeleton::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
  animation: shimmer 1.3s infinite;
}
.sk-card { height: 92px; }
.sk-chart { height: 290px; }
.sk-row { height: 38px; margin-bottom: 8px; }

/* دکمه‌ها و فرم‌ها */
.btn {
  background: var(--accent-grad); color: #fff; border: none; padding: 10px 18px;
  border-radius: var(--radius-xs); cursor: pointer; font-family: inherit; font-size: 13.5px;
  font-weight: 600; transition: transform .12s, box-shadow .15s; box-shadow: var(--shadow-sm);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(79,140,255,.35); }
.btn:active { transform: translateY(0); }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn.ghost:hover { border-color: var(--border-2); box-shadow: none; }
.btn-x {
  background: var(--red-dim); color: var(--red); border: none;
  width: 30px; height: 30px; border-radius: var(--radius-xs); cursor: pointer; font-size: 16px; line-height: 1;
}
.btn-x:hover { background: rgba(234,57,67,.25); }
input, select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 13px; border-radius: var(--radius-xs); font-family: inherit; font-size: 13.5px; transition: border-color .15s;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(79,140,255,.12); }
label { font-size: 12.5px; color: var(--text-2); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* فیلترساز */
.cond-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.cond-row select, .cond-row input { min-width: 0; }
.cond-row .f-field { flex: 2 1 140px; }
.cond-row .f-op { flex: 1 1 70px; }
.cond-row .f-val { flex: 1 1 90px; }
.preset-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* صفحه نماد */
.sym-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.sym-head .t { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sym-head h2 { margin: 0; font-size: 20px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 12px; }
.tab { padding: 8px 16px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-2); cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-grad); color: #fff; border-color: transparent; }
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: pop .2s ease; }
.gauge-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

/* پنل ادمین */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.stat-row:last-child { border-bottom: none; }
.login-card { max-width: 400px; margin: 8vh auto; }
.login-card .panel { padding: 28px; }
.login-card h3 { margin: 0 0 4px; font-size: 18px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card input { width: 100%; margin-bottom: 12px; }

/* footer */
footer { text-align: center; color: var(--muted); padding: 26px 16px 40px; font-size: 12.5px; }

/* toast */
#toast-wrap { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-2); padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13px; animation: pop .2s ease; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }

/* ناوبری پایین موبایل */
.bottom-nav { display: none; }

/* ---------- انیمیشن‌ها ---------- */
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(22,199,132,.5); } 70% { box-shadow: 0 0 0 6px rgba(22,199,132,0); } }
@keyframes marquee { from { transform: translateX(-0%); } to { transform: translateX(calc(-50% - 13px)); } }
@keyframes shimmer { 100% { transform: translateX(-100%); } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.99); } to { opacity: 1; transform: none; } }
@keyframes flashUp { 0% { background: var(--green-dim); } 100% { background: var(--surface); } }
@keyframes flashDown { 0% { background: var(--red-dim); } 100% { background: var(--surface); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- واکنش‌گرا (موبایل-اول) ---------- */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .nav-desktop { display: none; }
  .hamburger { display: grid; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .search-box input { width: 150px; }
  .ticker { display: none; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; right: 0; left: 0; z-index: 50;
    background: var(--glass); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--muted); font-size: 10.5px; font-weight: 500; padding: 5px 10px; border-radius: 12px; flex: 1; text-align: center;
  }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav a svg { width: 21px; height: 21px; }
  body { padding-bottom: 64px; }
  main { padding-bottom: 8px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .card .value { font-size: 19px; }
  .chart { height: 240px; }

  /* جدول‌های واکنش‌گرا → کارتی */
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr {
    background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 9px; padding: 6px 12px;
  }
  table.responsive tr:hover { background: var(--surface-2); }
  table.responsive td {
    display: flex; justify-content: space-between; align-items: center;
    border: none; border-bottom: 1px dashed var(--border); padding: 7px 0; white-space: normal; text-align: left;
  }
  table.responsive td:last-child { border-bottom: none; }
  table.responsive td::before {
    content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 500; text-align: right;
  }
}
@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .brand small { display: none; }
}

/* اسکرول‌بار */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 2px solid var(--bg-0); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
