/* SteamAutoU panel — no external fonts/CDNs (works from Iran without filters). */
@font-face {
  font-family: "Qs Iranyekan";
  src: url("fonts/Qs_Iranyekan.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
:root {
  --bg: #0d1220;
  --panel: #151c2e;
  --panel-2: #1b2438;
  --hover: #222d45;
  --border: #283350;
  --text: #e7ebf3;
  --muted: #8d97ad;
  --faint: #5d6780;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, .14);
  --green: #2fbf71;   --green-soft: rgba(47, 191, 113, .14);
  --amber: #f0a537;   --amber-soft: rgba(240, 165, 55, .14);
  --red: #ef5b5b;     --red-soft: rgba(239, 91, 91, .14);
  --purple: #9b7bff;  --purple-soft: rgba(155, 123, 255, .14);
  --blue: #46a6ff;    --blue-soft: rgba(70, 166, 255, .14);
  --teal: #2cc6b8;    --teal-soft: rgba(44, 198, 184, .14);
  --gray: #8a93a6;    --gray-soft: rgba(138, 147, 166, .14);
  --shadow: 0 8px 24px rgba(0, 0, 0, .28);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Qs Iranyekan", "Vazirmatn", Tahoma, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5fa;
  --panel: #ffffff;
  --panel-2: #f6f8fc;
  --hover: #eef2f9;
  --border: #e1e6f0;
  --text: #1a2133;
  --muted: #5f6b82;
  --faint: #9aa4b8;
  --accent: #2f6fec;
  --accent-soft: rgba(47, 111, 236, .10);
  --shadow: 0 6px 18px rgba(25, 40, 80, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); direction: ltr; unicode-bidi: embed; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-inline-start: 0;
  border-inline-end: 1px solid var(--border);
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
}
.brand-name { font-weight: 800; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; user-select: none; border: 0; background: none; width: 100%; text-align: start;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.nav-item .count {
  margin-inline-start: auto; font-size: 11px; background: var(--panel-2); border: 1px solid var(--border);
  padding: 0 7px; border-radius: 99px; color: var(--muted);
}
.nav-icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 26px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 800; }
.menu-btn { display: none; }
.content { padding: 22px 26px 40px; max-width: 1400px; width: 100%; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: 260px; z-index: 30;
    transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 16px; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 25; }
}

/* ---------------------------------------------------------------- cards */
.grid { display: grid; gap: 14px; }
.grid-kpi { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-kpi { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 21px; }
  .card { padding: 13px 14px; }
  .hero-actions { margin-inline-start: 0; }
}

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; min-width: 0;
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 14px; margin: 0 0 12px;
}
.card-title .actions { margin-inline-start: auto; display: flex; gap: 6px; }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-value { font-size: 26px; font-weight: 800; line-height: 1.2; }
.kpi-sub { font-size: 12px; color: var(--faint); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: end; }

/* status hero */
.hero {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
}
.hero-state { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--gray); position: relative; flex: none; }
.pulse.on::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid currentColor; opacity: .5; animation: ping 1.6s ease-out infinite;
}
@keyframes ping { from { transform: scale(.6); opacity: .7; } to { transform: scale(1.5); opacity: 0; } }
.hero-title { font-size: 17px; font-weight: 800; }
.hero-sub { font-size: 12.5px; color: var(--muted); }
.hero-next { display: flex; gap: 22px; flex-wrap: wrap; }
.hero-next .item { display: flex; flex-direction: column; }
.hero-next .label { font-size: 12px; color: var(--muted); }
.hero-next .value { font-weight: 700; font-size: 15px; }
.hero-actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- buttons, inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border); cursor: pointer;
  font-weight: 600; font-size: 13px; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.btn.danger:hover { background: var(--red-soft); }
.btn.success { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, var(--border)); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.icon { padding: 7px 10px; }
.btn.ghost { background: none; border-color: transparent; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: 13px; }
.field .help { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--panel-2); border: 1px solid var(--border); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 90px; resize: vertical; font-family: var(--mono); direction: ltr; font-size: 12.5px; }
.input-wrap { position: relative; }
.input-suffix { position: absolute; inset-inline-end: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); font-size: 12px; pointer-events: none; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 18px; }

.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--border); cursor: pointer; transition: background .15s;
}
.switch span::before {
  content: ""; position: absolute; width: 18px; height: 18px; top: 3px; inset-inline-start: 3px;
  border-radius: 50%; background: #fff; transition: inset-inline-start .15s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { inset-inline-start: 21px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel-2); }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--gray-soft); color: var(--gray);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.purple { background: var(--purple-soft); color: var(--purple); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.teal { background: var(--teal-soft); color: var(--teal); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 14px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--panel-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: 0; }
.items-cell { max-width: 340px; color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- bars / chart */
.bar { height: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.warn > i { background: var(--amber); }
.bar.danger > i { background: var(--red); }
.breakdown { display: flex; flex-direction: column; gap: 9px; }
.breakdown-row { display: grid; grid-template-columns: 150px 1fr 46px; align-items: center; gap: 10px; font-size: 13px; }
.breakdown-row .num { text-align: end; font-weight: 700; }
.chart { width: 100%; height: 190px; display: block; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--faint); font-size: 10px; font-family: var(--font); }
.chart .b-all { fill: var(--accent); opacity: .35; }
.chart .b-final { fill: var(--green); }
.chart .b-retry { fill: var(--amber); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 5px; vertical-align: -1px; }

/* ---------------------------------------------------------------- feed / logs */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 10px; padding: 9px 2px; border-bottom: 1px dashed var(--border); font-size: 13px; align-items: flex-start; }
.feed-item:last-child { border-bottom: 0; }
.feed-time { color: var(--faint); font-size: 12px; white-space: nowrap; min-width: 92px; }
.feed-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--gray); }
.feed-dot.warn { background: var(--amber); }
.feed-dot.error { background: var(--red); }
.feed-dot.info { background: var(--accent); }
.feed-msg { direction: ltr; text-align: left; flex: 1; word-break: break-word; }

.log-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.log-box {
  background: #0a0e18; color: #cfd6e4; border: 1px solid var(--border); border-radius: var(--radius);
  height: calc(100vh - 230px); min-height: 360px; overflow: auto; padding: 10px 0;
  font-family: var(--mono); font-size: 12.5px; direction: ltr; text-align: left;
}
:root[data-theme="light"] .log-box { background: #0f1525; }
.log-line { padding: 1px 14px; white-space: pre-wrap; word-break: break-word; }
.log-line:hover { background: rgba(255, 255, 255, .04); }
.log-line .ts { color: #6b7690; margin-inline-end: 10px; }
.log-line.error { color: #ff8b8b; }
.log-line.warn { color: #ffcf7a; }
.log-line.ok { color: #79e2a6; }
.log-line.head { color: #8fb6ff; }

/* ---------------------------------------------------------------- proxies */
.proxy-card { display: flex; flex-direction: column; gap: 10px; }
.proxy-head { display: flex; align-items: center; gap: 10px; }
.proxy-name { font-weight: 800; font-size: 15px; }
.proxy-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.proxy-host { font-family: var(--mono); direction: ltr; text-align: left; font-size: 12.5px; color: var(--muted); word-break: break-all; }
.proxy-test { font-size: 12.5px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--panel-2); border: 1px solid var(--border); }
.proxy-test.ok { border-color: color-mix(in srgb, var(--green) 45%, var(--border)); }
.proxy-test.fail { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }

.routes { display: flex; flex-direction: column; gap: 8px; }
.route-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--panel-2); }
.route-row.off { opacity: .55; }
.route-name { font-weight: 700; font-size: 13px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.route-sub { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; font-size: 11.5px; color: var(--muted); }
.route-sub .bar { flex: 1; height: 6px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented button {
  display: flex; flex-direction: column; gap: 3px; text-align: start; padding: 10px 12px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.segmented button span { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.segmented button:hover { background: var(--hover); }
.segmented button.active { border-color: var(--accent); background: var(--accent-soft); }
.segmented button.active b { color: var(--accent); }
@media (max-width: 760px) { .segmented { grid-template-columns: 1fr; } }

.stat-line { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.stat-line b { color: var(--text); font-weight: 700; }

/* ---------------------------------------------------------------- alerts, toasts, modal */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-2); font-size: 13px;
}
.alert.warn { border-color: color-mix(in srgb, var(--amber) 50%, var(--border)); background: var(--amber-soft); }
.alert.info { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: var(--accent-soft); }
.alert.error { border-color: color-mix(in srgb, var(--red) 50%, var(--border)); background: var(--red-soft); }
.alert .grow { min-width: 0; }

.toasts { position: fixed; bottom: 18px; inset-inline-start: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-inline-start: 4px solid var(--accent);
  box-shadow: var(--shadow); padding: 10px 14px; border-radius: var(--radius-sm); min-width: 240px; max-width: 380px; font-size: 13px;
  animation: slide .2s ease;
}
.toast.ok { border-inline-start-color: var(--green); }
.toast.error { border-inline-start-color: var(--red); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-bg { position: fixed; inset: 0; background: rgba(5, 8, 16, .6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); width: min(520px, 100%); padding: 20px; }
.modal h3 { margin: 0 0 10px; font-size: 16px; }
.modal .row { justify-content: flex-end; margin-top: 18px; }

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; padding: 28px; }
.login-card .brand { padding: 0; justify-content: center; }
.login-error { color: var(--red); font-size: 13px; min-height: 20px; }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 6px 0 -4px; }
.page { display: flex; flex-direction: column; gap: 14px; }
