@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #64748B;
  --faint: #94A3B8;
  --line: #E5E9F0;
  --line-2: #EEF1F6;
  --blue: #2563EB;
  --blue-600: #1D4ED8;
  --blue-50: #EFF4FF;
  --blue-100: #DBE6FE;
  --green: #059669;
  --green-50: #ECFDF5;
  --amber: #B45309;
  --amber-50: #FFFBEB;
  --red: #DC2626;
  --red-50: #FEF2F2;
  --violet: #7C3AED;
  --violet-50: #F5F3FF;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .14);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Vazirmatn', Tahoma, sans-serif;
  font-size: 14.5px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01";
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.ltr { direction: ltr; unicode-bidi: isolate; font-feature-settings: normal; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 1240px; margin: 0 auto; padding: 0 20px; height: 62px; display: flex; align-items: center; gap: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; color: var(--ink); white-space: nowrap; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 16px; font-weight: 800; }
.brand small { font-weight: 500; color: var(--muted); font-size: 12px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { white-space: nowrap; padding: 7px 14px; border-radius: 10px; color: var(--ink-2); font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--blue-50); color: var(--blue); }
.nav .badge { background: var(--blue); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 5px; line-height: 18px; min-width: 18px; display: inline-flex; align-items: center; justify-content: center; flex: none; box-sizing: border-box; }
/* QA #12: addresses / usernames / passwords keep Latin digits (ss01 would turn them Persian) */
pre.msg, .mono, .secret, .events .msg, a.ltr, .ltr { font-feature-settings: normal; }
.top-actions { display: flex; align-items: center; gap: 8px; }
main { max-width: 1240px; margin: 0 auto; padding: 24px 20px 64px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; font-weight: 800; letter-spacing: -.2px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h2 { font-size: 16px; margin: 0 0 4px; font-weight: 700; }
.card h2 + .hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- status strip ---------- */
.strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 12px; font-size: 12.5px; color: var(--ink-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--green); }
.dot.warn { background: #F59E0B; }
.dot.bad { background: var(--red); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 10px; padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13.5px;
  transition: background .15s, border-color .15s, box-shadow .15s; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--surface-2); border-color: #D5DBE5; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--blue-100); outline-offset: 1px; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-600); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--red); border-color: #F5C2C2; }
.btn.danger:hover { background: var(--red-50); }
.btn.danger.solid { background: var(--red); color: #fff; border-color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.lg { padding: 10px 22px; font-size: 15px; border-radius: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

/* ---------- forms ---------- */
label.f { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
label.f .help { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s; font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-100); outline: none; }
input.ltr, input.mono { text-align: left; }
textarea { resize: vertical; min-height: 80px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 7px 18px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--blue); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); }
.check:hover { border-color: #CBD5E1; }
.check input { margin-top: 5px; accent-color: var(--blue); width: 16px; height: 16px; flex: none; }
.check.locked { background: var(--surface-2); color: var(--faint); cursor: not-allowed; }
.check .t { font-weight: 600; font-size: 13.5px; }
.check .d { font-size: 12px; color: var(--muted); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: #CBD5E1; position: relative; cursor: pointer; transition: background .15s; flex: none; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: right .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked { background: var(--blue); }
.switch input:checked::after { right: 19px; }
.counter { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.counter button { border: 0; background: var(--surface-2); width: 32px; height: 34px; cursor: pointer; font-size: 16px; }
.counter button:hover { background: var(--blue-50); color: var(--blue); }
.counter span { min-width: 36px; text-align: center; font-weight: 700; }
.role-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.role-row:last-child { border-bottom: 0; }
.role-row .name { min-width: 120px; font-weight: 600; }
.role-row .users { flex: 1; color: var(--muted); font-size: 12.5px; }
.form-section { padding: 20px; border-bottom: 1px solid var(--line-2); }
.form-section:last-child { border-bottom: 0; }
.form-section h3 { margin: 0 0 2px; font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.form-section h3 .num { width: 22px; height: 22px; border-radius: 7px; background: var(--blue-50); color: var(--blue); font-size: 12px; display: grid; place-items: center; }
.form-section .hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.sticky-foot { position: sticky; bottom: 0; background: rgba(255, 255, 255, .95); backdrop-filter: blur(8px); border-top: 1px solid var(--line); box-shadow: 0 -6px 16px rgba(15, 23, 42, .06); padding: 14px 20px; display: flex; gap: 10px; align-items: center; border-radius: 0 0 var(--radius) var(--radius); }
.err { color: var(--red); font-size: 13px; }
.note { background: var(--blue-50); border: 1px solid var(--blue-100); color: #1E3A8A; border-radius: 12px; padding: 10px 14px; font-size: 13px; }
.note.warn { background: var(--amber-50); border-color: #FDE68A; color: #78350F; }
.note.bad { background: var(--red-50); border-color: #FECACA; color: #7F1D1D; }
.vw { display: grid; grid-template-columns: 24px minmax(0, 1fr) 110px 110px; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.vw:last-child { border-bottom: 0; }
.vw .title { font-weight: 600; font-size: 13.5px; }
.vw input[type=number] { text-align: center; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th { text-align: right; font-size: 12px; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
table.t th:first-child { border-top-right-radius: var(--radius); }
table.t th:last-child { border-top-left-radius: var(--radius); }
table.t td { padding: 13px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr { cursor: pointer; transition: background .12s; }
table.t tbody tr:hover { background: #FAFBFE; }
.client { font-weight: 700; }
.client small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 1px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.chip.trial { background: var(--blue-50); color: var(--blue); }
.chip.demo { background: var(--violet-50); color: var(--violet); }
.chip.both { background: linear-gradient(90deg, var(--blue-50), var(--violet-50)); color: var(--blue-600); }
.chip.running { background: var(--green-50); color: var(--green); }
.chip.creating { background: var(--blue-50); color: var(--blue); }
.chip.stopped { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.chip.expired { background: var(--amber-50); color: var(--amber); }
.chip.error { background: var(--red-50); color: var(--red); }
.chip.deleted { background: var(--surface-2); color: var(--faint); }
.chip.new { background: var(--blue); color: #fff; }
.chip .dot { width: 6px; height: 6px; background: currentColor; }
.spin { width: 12px; height: 12px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter .bar { width: 54px; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }
.meter .bar i.full { background: var(--amber); }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .ic { width: 52px; height: 52px; border-radius: 16px; background: var(--blue-50); color: var(--blue); display: grid; place-items: center; margin: 0 auto 12px; }

/* ---------- detail ---------- */
.detail-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.detail-head h1 { margin: 0; font-size: 22px; font-weight: 800; }
.kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line-2); border-radius: 12px; overflow: hidden; border: 1px solid var(--line-2); margin-top: 16px; }
.kv > div { background: var(--surface); padding: 12px 14px; }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v { font-weight: 700; margin-top: 2px; }
.acc { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.acc:last-child { border-bottom: 0; }
.secret { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 4px 2px 10px; }
pre.msg { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 0; font-family: inherit; font-size: 13.5px; line-height: 2; max-height: 380px; overflow: auto; }
pre.logs { white-space: pre-wrap; direction: ltr; text-align: left; background: #0B1220; color: #CBD5E1; border-radius: 12px; padding: 14px; font-size: 12px; max-height: 360px; overflow: auto; margin: 0; }
.events { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow: auto; }
.events li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 13px; }
.events li:last-child { border-bottom: 0; }
.events .when { color: var(--faint); white-space: nowrap; font-size: 12px; min-width: 92px; }
.events li.warn .msg { color: var(--amber); }
.events li.error .msg { color: var(--red); }
.events .msg { word-break: break-word; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-zone { border-color: #F8D4D4; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 80% -10%, #E3ECFF 0%, transparent 60%), var(--bg); }
.login { width: 100%; max-width: 400px; padding: 32px 28px; }
.login .mark { width: 48px; height: 48px; border-radius: 14px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; margin-bottom: 18px; }
.login h1 { font-size: 21px; margin: 0 0 4px; }
.login p { margin: 0 0 22px; color: var(--muted); }

/* ---------- toast + modal ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 100; box-shadow: var(--shadow-lg); max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--red); }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .38); display: grid; place-items: center; z-index: 90; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 460px; padding: 22px; box-shadow: var(--shadow-lg); }
.modal h3 { margin: 0 0 6px; font-size: 17px; }
.modal p { margin: 0 0 14px; color: var(--muted); }
@keyframes fade { from { opacity: 0; } }

/* ---------- requests ---------- */
.req { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.req:last-child { border-bottom: 0; }
.req .who { font-weight: 700; }
.req .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 12px; flex-wrap: wrap; }
.req .text { margin-top: 6px; color: var(--ink-2); font-size: 13.5px; white-space: pre-wrap; }
.req .actions { flex-wrap: wrap; justify-content: flex-end; align-content: flex-start; max-width: 360px; }
.calc-g .wide { grid-column: 1 / -1; }
.calc { margin-top: 10px; border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; max-width: 640px; }
.calc-h { font-size: 12.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.calc-g { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px 14px; }
.calc-g .k { display: block; font-size: 11.5px; color: var(--muted); }
.calc-g .v { display: block; font-size: 13px; font-weight: 600; color: var(--ink); }

/* ---------- mobile ---------- */
.mobile-list { display: none; }
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .acc { grid-template-columns: 1fr 1fr; }
  .acc > :first-child { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  main { padding: 16px 16px 48px; }
  .topbar-in { padding: 0 16px; gap: 10px; }
  .brand small { display: none; }
  .nav { overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .nav::-webkit-scrollbar { display: none; }
  .brand > span:not(.mark) { display: none; }
  .top-actions .btn { padding: 4px 8px; }
  .nav { gap: 0; }
  .nav a { padding: 6px 8px; gap: 4px; }
  .desktop-table { display: none; }
  .mobile-list { display: block; }
  .m-item { padding: 14px 16px; border-bottom: 1px solid var(--line-2); }
  .m-item:last-child { border-bottom: 0; }
  .m-item .r1 { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
  .m-item .r2 { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; margin-top: 6px; }
  .vw { grid-template-columns: 24px minmax(0, 1fr) 80px 80px; }
  .req { grid-template-columns: 1fr; }
  .top-actions .who { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Passwords/usernames must show Latin digits exactly as typed (ss01 turns them Persian). */
pre.msg, .secret, .secret *, .m-item .ltr, .mono { font-feature-settings: normal; }
.note .btn { margin-top: 8px; }

/* ---------- AI gateways + keys editor ---------- */
.flabel { font-weight: 600; font-size: 13px; color: var(--ink-2); display: block; margin-bottom: 6px; }
.flabel .help { font-weight: 400; color: var(--muted); font-size: 12px; margin-inline-start: 6px; }
.krow { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.krow .kn { width: 22px; height: 22px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--line); font-size: 11px; display: grid; place-items: center; color: var(--muted); }
.krow .kmask { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; text-align: left; }
.krow input { grid-column: span 2; }
.kres { margin-top: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); }
.kres-row { display: grid; grid-template-columns: 10px auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 4px 0; }
.gw { display: flex; gap: 16px; justify-content: space-between; align-items: flex-start; padding: 16px 20px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.gw.off { background: var(--surface-2); }
.gw-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 320px; }
.gw-name { font-weight: 700; font-size: 15px; }
.gw-check { margin-top: 4px; }
.gw-actions { justify-content: flex-end; max-width: 480px; }
table.t.plain tbody tr { cursor: default; }
.modal.wide { max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; }
a.pill { text-decoration: none; }
a.pill:hover { border-color: #CBD5E1; text-decoration: none; }
@media (max-width: 760px) {
  .gw { padding: 14px 16px; }
  .gw-actions { justify-content: flex-start; max-width: none; }
  .kres-row { grid-template-columns: 10px auto minmax(0, 1fr); }
  .kres-row > :last-child { grid-column: 2 / -1; }
}
