/* Vazirmatn (SIL Open Font License, Vazirmatn-OFL.txt) is bundled: Google Fonts is often unreachable from Iran. */
@font-face { font-family: "Vazirmatn"; src: url("/static/Vazirmatn.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2f7d4f; --accent-soft: #e5f3ea; --danger: #c0392b; --danger-soft: #fbe9e7; --warn: #b7791f; --warn-soft: #fff4e0; --code: #f1f3f6;
  --radius: 12px; --shadow: 0 1px 3px rgba(20, 30, 50, .08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151b; --panel: #1b1f27; --text: #e6e9ef; --muted: #98a0b3; --line: #2b313d;
          --accent: #4fb57a; --accent-soft: #1f3328; --danger: #e5675a; --danger-soft: #3a2220; --warn: #e0a64a; --warn-soft: #3a2f1c; --code: #232834; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.7 Vazirmatn, Tahoma, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.4; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
code, pre, textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; direction: ltr; text-align: left; }
pre { background: var(--code); padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-word; max-height: 480px; }
.prose { white-space: pre-wrap; word-break: break-word; background: var(--code); padding: 12px; border-radius: 8px; max-height: 520px; overflow: auto; unicode-bidi: plaintext; }
.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }

.shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--panel); border-left: 1px solid var(--line); padding: 16px 10px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 18px; padding: 4px 10px 14px; }
nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; flex: 1; }
nav a { color: var(--text); padding: 8px 12px; border-radius: 8px; display: flex; align-items: center; gap: 6px; }
nav a:hover { background: var(--bg); }
nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 12px; padding: 0 7px; margin-inline-start: auto; }
.me { border-top: 1px solid var(--line); padding: 10px; font-size: 13px; color: var(--muted); }
main { padding: 24px; max-width: 1200px; width: 100%; min-width: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
textarea { min-height: 90px; resize: vertical; }
textarea.code { min-height: 380px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; }
th, td { unicode-bidi: plaintext; text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
th { color: var(--muted); font-weight: 500; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--bg); }

.pill { unicode-bidi: plaintext; display: inline-block; padding: 0 9px; border-radius: 20px; font-size: 12px; background: var(--code); color: var(--muted); white-space: nowrap; }
.pill.done, .pill.published { background: var(--accent-soft); color: var(--accent); }
.pill.failed, .pill.cancelled, .pill.stopped { background: var(--danger-soft); color: var(--danger); }
.pill.running, .pill.publishing, .pill.planning { background: var(--warn-soft); color: var(--warn); }

.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 48px); }
.msgs { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-start; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-end; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.composer { display: flex; gap: 8px; padding-top: 10px; align-items: flex-end; }
.composer textarea { min-height: 52px; max-height: 200px; }

.tree { list-style: none; padding-inline-start: 18px; margin: 4px 0; border-inline-start: 2px solid var(--line); }
.tree li { margin: 6px 0; }
details summary { cursor: pointer; }
.bar { height: 120px; display: flex; align-items: flex-end; gap: 3px; direction: ltr; }
.bar div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.toast { position: fixed; bottom: 18px; left: 18px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 10; max-width: 420px; }
.event { font-size: 13px; border-bottom: 1px dashed var(--line); padding: 5px 0; }
.event .ltr, span.ltr { overflow-wrap: anywhere; }

/* devices, schedules, security */
label.check { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; margin-inline-end: 12px; }
label.check input { width: auto; margin: 0; }
.pair-code { font-size: 34px; font-weight: 700; letter-spacing: 6px; padding: 14px 18px; margin: 12px 0; border-radius: 12px; background: var(--accent-soft); display: inline-block; }
.qr { background: #fff; display: inline-block; padding: 8px; border-radius: 10px; margin: 10px 0; }
.qr svg { display: block; width: 200px; height: 200px; }
pre.ltr { direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; }

/* ---------- app shell: navigation groups and the phone menu ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu-btn { display: none; font-size: 20px; line-height: 1; min-width: 44px; min-height: 44px; padding: 0; }
.nav-group { color: var(--muted); font-size: 12px; padding: 12px 12px 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; display: inline-block; text-align: center; }
a.btn { color: var(--text); }
a.btn.primary { color: #fff; }
.tw { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tw > table { min-width: 100%; }
pre, .prose, code { overflow-wrap: anywhere; }
img, svg, video { max-width: 100%; }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { margin-inline-start: auto; }
.ok { color: var(--accent); }
.warn { color: var(--warn); }
h2 .muted, h3 .muted { font-size: 13px; font-weight: 400; }
.page-head { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h2 { margin: 0; }
.intro { margin-top: 0; }
.pill.ok, .pill.on { background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.mid { background: var(--warn-soft); color: var(--warn); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); margin-inline-end: 6px; vertical-align: middle; }
.dot.ok { background: var(--accent); } .dot.bad { background: var(--danger); } .dot.mid { background: var(--warn); }

/* meters (server page) */
.meter { margin: 8px 0 14px; }
.meter .top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; flex-wrap: wrap; }
.meter .track { height: 10px; background: var(--code); border-radius: 6px; overflow: hidden; margin-top: 4px; direction: ltr; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width .4s; }
.meter.lv-mid .fill { background: var(--warn); }
.meter.lv-bad .fill { background: var(--danger); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--muted); }

/* provider cards */
.prov { display: flex; flex-direction: column; gap: 8px; margin-bottom: 0; }
.prov h3 { margin: 0; }
.prov .note { margin: 0; font-size: 14px; }
.prov .iran { font-size: 13px; background: var(--code); border-radius: 8px; padding: 6px 10px; margin: 0; }
.prov .facts { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.prov form { display: flex; flex-direction: column; gap: 8px; }
.prov .result { font-size: 13px; }
.policy label.choice { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.policy label.choice input { width: auto; margin-top: 6px; }
.policy label.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choices { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }

/* forms in cards */
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); align-items: end; }
.form-grid .full { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
td .actions { flex-wrap: nowrap; }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { width: 20px; height: 20px; margin: 0; }
.logbox { max-height: 420px; font-size: 12px; }
.reveal { margin-top: 10px; }
.empty { color: var(--muted); padding: 10px 0; }
.recording { background: var(--danger) !important; border-color: var(--danger) !important; color: #fff !important; }

/* ---------- tablets and phones ---------- */
@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: auto; z-index: 5; padding: 8px 12px; border-left: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 4px; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .side nav, .side .me { display: none; }
  .side.open nav { display: flex; max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px); }
  .side.open .me { display: block; }
  nav a { padding: 10px 12px; min-height: 44px; }
  main { padding: 14px 16px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.wide { grid-template-columns: minmax(0, 1fr); }
  .msg { max-width: 95%; }
  .chat { height: calc(100vh - 110px); height: calc(100dvh - 110px); }
  button, .btn, input, select { min-height: 42px; }
  button.link { min-height: 40px; padding: 0 6px; }
  label.check { min-height: 40px; }
  .row > input, .row > select, .row > textarea { max-width: none !important; flex: 1 1 100%; }
  .row > label:not(.check) { flex: 1 1 100%; }
  .row > label:not(.check) input, .row > label:not(.check) select { max-width: none !important; }
  .toast { left: 12px; right: 12px; max-width: none; }
  .stat .n { font-size: 22px; }
  textarea.code { min-height: 260px; }
}
@media (max-width: 420px) {
  .grid:not(.wide) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 14px; }
  .pair-code { font-size: 26px; letter-spacing: 3px; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv > :nth-child(even) { margin-bottom: 6px; }
}
@media (pointer: coarse) {
  button, .btn { min-height: 42px; }
}
.grid > * { min-width: 0; }
.prov label.check, .policy label.check, .stack label.check, label.check.wrap { white-space: normal; align-items: flex-start; }
.prov label.check input, .stack label.check input, label.check.wrap input { margin-top: 5px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.kv > .ltr { text-align: right; }
.grid.wide { align-items: start; }
.composer textarea { flex: 1 1 auto; min-width: 0; }
@media (max-width: 480px) {
  .composer { flex-wrap: wrap; }
  .composer textarea { flex-basis: 100%; }
  .composer .primary { flex: 1; }
}
fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
/* first-run checklist, settings form, project secrets */
.card.setup { border-inline-start: 4px solid var(--accent); }
.checklist { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.checklist li.done { color: var(--muted); }
.pre-line { white-space: pre-line; }
#general h4 { margin: 14px 0 4px; }
#general h4:first-child { margin-top: 0; }
.channel .form-grid label .small, #keys label .small { display: block; }
#sec-form label { position: relative; }
#sec-form .sec-del { margin-top: 4px; align-self: flex-start; }
pre.copyable { user-select: all; white-space: pre-wrap; word-break: break-all; }
