:root {
  color-scheme: light;
  --page: #f6f7f9;
  --surface: #ffffff;
  --text: #191919;
  --text-2: #666666;
  --border: rgba(11, 11, 11, 0.1);
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --series-1: #257de0;
  --series-2: #f47230;
  --good: #006c10;
  --bad: #c62f30;
  --warn-bg: #fff6e0;
  --err-bg: #fdecec;
  --ok-bg: #e8f6ea;
  --accent: #2370cd;
  --accent-ink: #ffffff;
  --radius: 12px;
  --series-3: #00b894;
  --series-4: #f2a600;
  --series-5: #ee7fac;
  --st-good: #0aac23;
  --st-warn: #fbb315;
  --st-bad: #dc3c3d;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --text: #efefef;
    --text-2: #9c9c9c;
    --border: rgba(255, 255, 255, 0.1);
    --grid: #303030;
    --axis: #474747;
    --series-1: #338ced;
    --series-2: #e76624;
    --good: #53c556;
    --bad: #eb6263;
    --warn-bg: #3a2e10;
    --err-bg: #3b1717;
    --ok-bg: #14301a;
    --accent: #338ced;
    --series-3: #00a888;
    --series-4: #d28e05;
    --series-5: #e24d8b;
  }
}

/* فرم‌های یک‌خطی */
.row { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }
.row input, .row select, select.inline {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .7rem;
}
.row input { flex: 1 1 260px; }
select.inline { padding: .2rem .5rem; font-size: .85rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.btn.mini { padding: .1rem .55rem; font-size: .78rem; border-radius: 7px; }

/* CrUX */
.cwv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; }
.cwv .value { font-size: 1.45rem; font-weight: 700; }
.dist { display: flex; gap: 2px; height: 8px; margin: .5rem 0 .25rem; }
.dist span { border-radius: 2px; min-width: 2px; }
.dist .g { background: var(--st-good); }
.dist .n { background: var(--st-warn); }
.dist .p { background: var(--st-bad); }
.dist-legend { font-size: .75rem; color: var(--text-2); display: flex; gap: .6rem; flex-wrap: wrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: .25rem; }
.dot.g { background: var(--st-good); } .dot.n { background: var(--st-warn); } .dot.p { background: var(--st-bad); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Vazirmatn, system-ui, "Segoe UI", Tahoma, sans-serif;
  background: var(--page);
  color: var(--text);
  line-height: 1.8;
  font-size: 15px;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.4; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }

.btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: .5rem 1.1rem; border-radius: 10px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: .5rem; white-space: nowrap;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.big { padding: .75rem 1.6rem; font-size: 1.05rem; }
.btn:disabled { opacity: .6; cursor: wait; }

/* ورود */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 2.5rem 2rem; max-width: 460px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-card .logo { font-size: 3rem; }
.login-card h1 { margin: .25rem 0 .75rem; font-size: 1.5rem; }
.login-card .btn { margin: 1rem 0 .5rem; }

/* بالای صفحه */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; }
.user { display: flex; align-items: center; gap: .6rem; }
.user img { width: 32px; height: 32px; border-radius: 50%; }
.user span { color: var(--text-2); font-size: .9rem; direction: ltr; }

main { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem;
}

.filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; margin-bottom: 1rem; }
.filters label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--text-2); flex: 1 1 220px; }
.filters select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .6rem; min-width: 0;
}

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button {
  font: inherit; background: none; border: none; color: var(--text-2); padding: .6rem 1rem; cursor: pointer;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.empty { text-align: center; padding: 3rem 1rem; }
.period { margin: 0 0 1rem; font-size: .85rem; color: var(--text-2); }

/* کارت‌های عدد */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; }
.kpi .label { color: var(--text-2); font-size: .85rem; }
.kpi .value { font-size: 1.7rem; font-weight: 700; line-height: 1.3; }
.kpi .delta { font-size: .8rem; color: var(--text-2); }
.kpi .delta.good { color: var(--good); }
.kpi .delta.bad { color: var(--bad); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.chart-box { position: relative; height: 260px; }
.section { margin-bottom: 1rem; }

/* جدول */
.table-wrap { overflow: auto; max-height: 520px; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .45rem .6rem; text-align: right; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 600; cursor: pointer; user-select: none; }
td.num, th.num { text-align: left; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.url { direction: ltr; text-align: left; word-break: break-all; max-width: 420px; }
tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.badge { display: inline-block; padding: 0 .5rem; border-radius: 99px; font-size: .78rem; }
.badge.ok { background: var(--ok-bg); color: var(--good); }
.badge.bad { background: var(--err-bg); color: var(--bad); }
.badge.mid { background: var(--warn-bg); }

.alert { border-radius: 10px; padding: .7rem 1rem; margin-bottom: 1rem; border: 1px solid var(--border); }
.alert.warn { background: var(--warn-bg); }
.alert.error { background: var(--err-bg); }

/* هوش مصنوعی */
.ai-intro { text-align: center; margin-bottom: 1rem; }
.ai-intro p { max-width: 720px; margin: .5rem auto 1rem; }
.scores { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: .75rem; }
.score { text-align: center; min-width: 110px; }
.score .value { font-size: 1.6rem; font-weight: 700; }
.report { line-height: 2; }
.report h1, .report h2, .report h3 { margin-top: 1.5rem; }
.report table { margin: .75rem 0; }
.report code { direction: ltr; unicode-bidi: embed; background: color-mix(in srgb, var(--text) 8%, transparent); padding: 0 .3rem; border-radius: 4px; }
.report pre { direction: ltr; overflow: auto; background: color-mix(in srgb, var(--text) 6%, transparent); padding: .75rem; border-radius: 8px; }
.report li:has(> input[type="checkbox"]) { list-style: none; }
.report li > input[type="checkbox"] { margin-left: .4rem; }
.chat { margin-top: 1rem; }
.chat .msg { padding: .75rem 1rem; border-radius: 10px; margin-bottom: .5rem; }
.chat .msg.user { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chat form { display: flex; gap: .5rem; margin-top: .5rem; }
.chat textarea {
  flex: 1; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: .5rem .75rem; resize: vertical; min-height: 48px;
}

.spinner {
  width: 22px; height: 22px; border: 3px solid var(--grid); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; display: inline-block; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { text-align: center; padding: 2.5rem 1rem; color: var(--text-2); }
.loading .spinner { margin-left: .5rem; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--surface); padding: .6rem 1.2rem; border-radius: 10px; max-width: 90vw;
}
