@font-face {
  font-family: "Mikhak";
  src: url("/static/fonts/Mikhak.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #0a0a0c;
  --bg-soft: #0f0f13;
  --surface: #141418;
  --surface-2: #1a1a21;
  --surface-3: #1f1f27;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f3ff;
  --muted: #9a94ab;
  --muted-2: #c9c4d8;
  --accent: #b79cff;
  --accent-solid: #6025bf;
  --accent-2: #7c3aed;
  --accent-soft: rgba(167, 139, 250, 0.14);
  --accent-strong: rgba(167, 139, 250, 0.28);
  --up: #34d399;
  --down: #fb7185;
  --warn: #fbbf24;
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 10px;
  --gap: 18px;
  --font: "Mikhak", "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --shadow: 0 24px 60px -36px rgba(0, 0, 0, 0.9);
  --shadow-accent: 0 18px 40px -20px rgba(96, 37, 191, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1100px 560px at 88% -12%, rgba(124, 58, 237, 0.20), transparent 62%),
    radial-gradient(900px 520px at 0% 100%, rgba(34, 211, 238, 0.055), transparent 58%),
    var(--bg);
  background-attachment: fixed;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.02em; }
h1 { font-size: clamp(1.6rem, 2.4vw, 2.15rem); line-height: 1.35; }
h2 { font-size: 1rem; line-height: 1.5; }
p { margin: 0; }
a { color: var(--accent); }
code {
  font-family: var(--mono);
  font-size: 0.82em;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(183, 156, 255, 0.16);
  border-radius: 6px;
  padding: 1px 6px;
}
.num, .kpi__value, td.num, .chart-meta { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--down); font-size: 13.5px; }
.disclaimer { margin-top: 10px; }
.up { color: var(--up); }
.down { color: var(--down); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 7px;
}

* { scrollbar-width: thin; scrollbar-color: rgba(183, 156, 255, 0.28) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(183, 156, 255, 0.24);
  border: 2px solid var(--bg);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(183, 156, 255, 0.4); }

/* ── Header ─────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 10, 12, 0.78);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--border);
}
.app-header__inner {
  max-width: 1440px;
  margin: 0 auto;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 10px 28px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #8b5cf6 0%, #6025bf 70%, #4c1d95 100%);
  color: #fff;
  font-weight: 900;
  font-size: 17px;
  box-shadow: var(--shadow-accent), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}
.brand__text { font-size: 18px; letter-spacing: -0.02em; }
.brand__text strong { color: var(--accent); }
.brand--lg { justify-content: center; font-size: 22px; }
.brand--lg .brand__mark { width: 48px; height: 48px; border-radius: 15px; font-size: 21px; }

.nav { display: flex; align-items: center; gap: 4px; min-width: 0; }
.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s;
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.045); }
.nav a[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(183, 156, 255, 0.18);
}
.app-header__status {
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot--ok { background: var(--up); box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.12); }
.dot--bad { background: var(--down); box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.12); }
.dot--warn { background: var(--warn); box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.12); }

.link {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 4px;
  font: inherit;
  font-weight: 700;
}
.link:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────── */
.app { min-height: 100dvh; }
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 30px 28px 64px;
  min-width: 0;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-head__copy { min-width: 0; }
.page-head__kicker {
  display: inline-block;
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.page-head h1 { margin-top: 4px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

/* ── Cards and grids ────────────────────────────────────────────── */
.card {
  position: relative;
  min-width: 0;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.028), transparent 42%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card__head h2 { color: var(--text); }
.grid { display: grid; gap: var(--gap); }
.grid--kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: var(--gap); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--form, .grid--lab { grid-template-columns: minmax(310px, 390px) minmax(0, 1fr); align-items: start; }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.dashboard-lists { margin-top: var(--gap); }
.results { display: grid; gap: var(--gap); min-width: 0; grid-template-columns: minmax(0, 1fr); }
.results > * { min-width: 0; }
.results .grid--kpi { margin-bottom: 0; }

.kpi {
  position: relative;
  display: grid;
  align-content: center;
  gap: 5px;
  min-height: 126px;
  overflow: hidden;
  background:
    radial-gradient(220px 150px at 100% 0%, rgba(124, 58, 237, 0.16), transparent 70%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 50%),
    var(--surface);
}
.kpi::after {
  content: "";
  position: absolute;
  width: 150px;
  height: 150px;
  inset-block-start: -80px;
  inset-inline-start: -55px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(183, 156, 255, 0.18), transparent 68%);
  pointer-events: none;
}
.kpi__label { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi__value { font-size: clamp(1.45rem, 2.3vw, 1.95rem); font-weight: 800; line-height: 1.35; }
.kpi__value.up { color: var(--up); }
.kpi__value.down { color: var(--down); }

.empty {
  text-align: center;
  padding: 64px 24px;
  border-style: dashed;
  background: rgba(255, 255, 255, 0.015);
}
.empty h2 { margin-bottom: 8px; }

/* ── Forms ──────────────────────────────────────────────────────── */
.form { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; min-width: 0; }
.field > span { color: var(--muted); font-size: 12.5px; font-weight: 600; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
input, select {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
input::placeholder { color: var(--muted); opacity: 0.7; }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px rgba(183, 156, 255, 0.14);
}
select option { background: var(--surface-2); color: var(--text); }
input[type="date"] { color-scheme: dark; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 36px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, 0.05); }
.chip[aria-pressed="true"] {
  color: var(--accent);
  border-color: rgba(183, 156, 255, 0.4);
  background: var(--accent-soft);
}
.advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.015);
}
.advanced summary {
  cursor: pointer;
  min-height: 46px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 600;
}
.advanced[open] summary { color: var(--text); }
.params { display: grid; gap: 12px; padding: 4px 0 16px; }
.params .field-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.check { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 4px; }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent-solid); }
.check span { color: var(--muted-2); font-size: 13px; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0) scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn--primary {
  border-color: transparent;
  background: linear-gradient(135deg, #7c3aed 0%, #6025bf 100%);
  color: #fff;
  box-shadow: 0 14px 30px -18px rgba(124, 58, 237, 0.85);
}
.btn--primary:hover { filter: brightness(1.08); box-shadow: 0 18px 42px -18px rgba(124, 58, 237, 0.95); }
.btn--danger { color: var(--down); border-color: rgba(251, 113, 133, 0.35); background: rgba(251, 113, 133, 0.08); }
.btn--danger:hover { background: rgba(251, 113, 133, 0.14); }
.btn--block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }

/* ── Tables ─────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-inline: -4px;
  border-radius: var(--radius-sm);
}
.table {
  width: 100%;
  min-width: 640px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.table th, .table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: start;
  white-space: nowrap;
}
.table th {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: var(--surface-2);
}
.table th:first-child { border-start-start-radius: var(--radius-sm); }
.table th:last-child { border-start-end-radius: var(--radius-sm); }
.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover { background: rgba(183, 156, 255, 0.055); }
.table tbody tr[data-clickable] { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.up { color: var(--up); }
.table td.down { color: var(--down); }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
}
.pill--long { color: var(--up); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); }
.pill--short { color: var(--down); border-color: rgba(251, 113, 133, 0.35); background: rgba(251, 113, 133, 0.08); }

/* ── Charts ─────────────────────────────────────────────────────── */
.chart {
  display: block;
  width: 100%;
  height: 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent),
    var(--surface-2);
}
.chart--equity { height: 240px; }
.chart-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
}

/* ── Gate ───────────────────────────────────────────────────────── */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(800px 500px at 70% 0%, rgba(124, 58, 237, 0.22), transparent 65%),
    radial-gradient(700px 500px at 10% 100%, rgba(34, 211, 238, 0.06), transparent 60%);
}
.gate__card {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 34px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent 46%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(183, 156, 255, 0.06);
}
.gate__kicker {
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.gate__card h1 { font-size: 1.55rem; }
.gate__card .field { text-align: start; }
.gate__card .btn { width: 100%; }
.gate__hint { color: var(--muted); font-size: 12px; }

/* ── Toast ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(520px, 92vw);
  padding: 13px 20px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--surface-3);
  box-shadow: var(--shadow);
  animation: rise 0.25s ease;
}

.page { animation: pageIn 0.35s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .grid--form, .grid--lab { grid-template-columns: minmax(0, 1fr); }
  .grid--2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app-header__inner {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }
  .nav {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    gap: 2px;
    overflow-x: visible;
  }
  .nav a { min-height: 44px; padding: 8px 12px; }
  .app-header__status { margin-inline-start: auto; }
  .main { padding: 22px 16px 48px; }
  .page-head { align-items: flex-start; }
  .grid--kpi { grid-template-columns: minmax(0, 1fr); }
  .chart { height: 250px; }
}
@media (max-width: 560px) {
  body { font-size: 14px; }
  .field-row, .params .field-row { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 18px; }
  .kpi { min-height: 112px; }
  .kpi__value { font-size: 1.55rem; }
  .chart, .chart--equity { height: 230px; }
  .page-head { flex-direction: column; gap: 10px; }
  .page-head h1 { font-size: 1.5rem; }
  .gate__card { padding: 26px 20px; }
  .brand__text { font-size: 16px; }
  .status-pill { padding: 5px 10px; }
}
