:root {
  --bg: #ffffff;
  --sunken: #f5f6f8;
  --line: #e9ecf0;
  --ink: #0f1720;
  --on-ink: #ffffff;
  --muted: #6b7787;
  --accent: #0c7a86;
  --ok: #1d7a4b;
  --bad: #c0362c;
  --warn: #9a5b00;
  --radius: 10px;
  --font: Vazirmatn, "Segoe UI", Tahoma, "Noto Naskh Arabic", system-ui, sans-serif;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0b0f14;
    --sunken: #131a22;
    --line: #1f2933;
    --ink: #e9eef4;
    --on-ink: #0b0f14;
    --muted: #8896a6;
    --accent: #4cc0cb;
    --ok: #5fcf93;
    --bad: #ff8f85;
    --warn: #f0b95a;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f14;
    --sunken: #131a22;
    --line: #1f2933;
    --ink: #e9eef4;
    --on-ink: #0b0f14;
    --muted: #8896a6;
    --accent: #4cc0cb;
    --ok: #5fcf93;
    --bad: #ff8f85;
    --warn: #f0b95a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.75 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; font-weight: 500; line-height: 1.4; }
h2 { font-size: 18px; font-weight: 500; }
h3 { font-size: 15px; font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.noscript { padding: 24px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- چارچوب ---------- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 32px; }
.brand { font-weight: 500; font-size: 15px; color: inherit; text-decoration: none; }
.spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); }

.layout { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 56px; max-width: 980px; margin: 0 auto; padding: 24px 32px 120px; }
.layout.single { grid-template-columns: minmax(0, 1fr); max-width: 680px; }
.side { position: sticky; top: 24px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.side .back { color: var(--muted); text-decoration: none; font-size: 13px; padding: 0 0 14px; display: block; }
.side a.nav { display: block; padding: 5px 14px; color: var(--muted); text-decoration: none; border-inline-start: 2px solid transparent; }
.side a.nav:hover { color: var(--ink); }
.side a.nav[aria-current="page"] { color: var(--ink); font-weight: 500; border-inline-start-color: var(--accent); }
.main { display: flex; flex-direction: column; gap: 36px; min-width: 0; }
.page-head { display: flex; flex-direction: column; gap: 2px; }

/* ---------- بخش‌ها و ردیف‌ها ---------- */
.group { border-top: 1px solid var(--line); }
.group > .row, .group > .list-row { border-bottom: 1px solid var(--line); }
.group-title { padding: 18px 0 4px; color: var(--muted); font-size: 13px; font-weight: 500; }
.group > .dep { border-bottom: 1px solid var(--line); }
.dep > .row { padding-bottom: 12px; }
.subs { margin: 0 0 16px; margin-inline-start: 12px; padding-inline-start: 18px; border-inline-start: 2px solid var(--accent); transition: opacity .15s; }
.subs > .row { padding: 12px 0; }
.subs > .row + .row { border-top: 1px dashed var(--line); }
.subs.off { opacity: .5; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 18px 0; }
.row.stack { flex-direction: column; align-items: stretch; gap: 12px; }
.row .text { min-width: 0; }
.row .label { font-weight: 500; }
.row .desc { font-size: 13px; color: var(--muted); margin-top: 1px; }
.row .control { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
a.row { color: inherit; text-decoration: none; }
a.row:hover .label { color: var(--accent); }
.chev { color: var(--muted); }

/* ---------- کنترل‌ها ---------- */
.switch { position: relative; width: 40px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.switch .track { position: absolute; inset: 0; border-radius: 12px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(-16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled { cursor: wait; }

.stepper { display: inline-flex; align-items: center; background: var(--sunken); border-radius: 8px; }
.stepper button { width: 32px; height: 32px; border: 0; background: transparent; cursor: pointer; font-size: 17px; line-height: 1; color: var(--muted); border-radius: 8px; }
.stepper button:hover { color: var(--ink); background: var(--line); }
.stepper input { width: 56px; height: 32px; border: 0; text-align: center; background: transparent; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit { font-size: 13px; color: var(--muted); }

.seg { display: inline-flex; background: var(--sunken); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 14px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--ink); font-weight: 500; box-shadow: 0 0 0 1px var(--line); }

input[type="text"], input[type="search"], input[type="number"], select, textarea {
  background: var(--sunken); border: 1px solid transparent; border-radius: 8px; padding: 9px 12px; width: 100%;
}
input[type="text"]:focus, input[type="search"]:focus, input[type="number"]:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; background: var(--bg); }
textarea { min-height: 110px; resize: vertical; }
select { width: auto; }
.btn { border: 0; background: var(--sunken); padding: 8px 16px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--line); }
.btn.primary { background: var(--ink); color: var(--on-ink); font-weight: 500; }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--bad); background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.btn.danger:hover { background: var(--sunken); }
.btn[disabled] { opacity: .5; cursor: wait; }
.btn.sm { padding: 3px 12px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- سلامت ربات ---------- */
.group.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 4px 32px; border-top: 0; padding: 0; }
.health .item { display: flex; gap: 10px; padding: 8px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 11px; flex-shrink: 0; background: var(--line); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.hint { font-size: 13px; color: var(--muted); }
.banner { padding: 0 14px; border-inline-start: 2px solid var(--warn); color: var(--warn); }
.banner.bad { border-inline-start-color: var(--bad); color: var(--bad); }

/* ---------- لیست‌ها ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--sunken); border-radius: 999px; padding: 3px 4px 3px 14px; }
.chip button { border: 0; background: transparent; color: var(--muted); border-radius: 50%; width: 22px; height: 22px; cursor: pointer; line-height: 1; }
.chip button:hover { background: var(--line); color: var(--bad); }
.empty { padding: 36px 0; text-align: center; color: var(--muted); }
.locks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; padding: 16px 0; }
.lock { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border: 0; border-radius: 8px; cursor: pointer; background: var(--sunken); }
.lock[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); font-weight: 500; }
.lock[aria-pressed="true"] .unit { color: inherit; opacity: .7; }

.group.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 24px; border-top: 0; }
.stat .num { font-size: 34px; font-weight: 500; line-height: 1.3; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 14px 12px 14px 0; border-top: 1px solid var(--line); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 400; border-top: 0; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 0 10px; border-radius: 999px; background: var(--sunken); font-size: 13px; }
.badge.warn { color: var(--warn); }
.uid { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); direction: ltr; unicode-bidi: embed; }
.ltr { direction: ltr; unicode-bidi: embed; }
.toolbar { display: flex; gap: 12px; padding: 14px 0; flex-wrap: wrap; align-items: center; }
.toolbar input { flex: 1; min-width: 180px; width: auto; }
.result { padding: 12px 14px; background: var(--sunken); border-radius: 8px; white-space: pre-line; }

/* ---------- ورود ---------- */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 32px; }
.login-card { width: min(440px, 100%); display: flex; flex-direction: column; gap: 18px; }
.steps { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 6px; }
code, .code { background: var(--sunken); padding: 1px 6px; border-radius: 5px; direction: ltr; unicode-bidi: embed; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* ---------- اعلان ---------- */
#toasts { position: fixed; inset-inline: 0; bottom: 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 50; }
.toast { background: var(--ink); color: var(--on-ink); padding: 9px 18px; border-radius: 999px; animation: pop .18s ease-out; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .switch .track, .switch .track::after { transition: none; } }

[hidden] { display: none !important; }
.mins { width: 84px; }
.widget { min-height: 44px; }
.pair { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; padding: 16px 0; border-top: 1px solid var(--line); }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; }
.list-row.row { padding: 18px 0; }

/* ---------- موبایل ---------- */
@media (max-width: 800px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 8px 18px 100px; }
  .side { position: static; flex-direction: row; overflow-x: auto; gap: 4px; }
  .side .back { padding: 6px 10px 6px 14px; white-space: nowrap; }
  .side a.nav { white-space: nowrap; border-inline-start: 0; border-bottom: 2px solid transparent; padding: 6px 10px; }
  .side a.nav[aria-current="page"] { border-bottom-color: var(--accent); }
  .row { flex-wrap: wrap; gap: 12px; }
  .pair { grid-template-columns: 1fr; }
  .topbar { padding: 12px 18px; }
  .who { display: none; }
  h1 { font-size: 24px; }
}
