:root {
  --bg: #f2f4f7; --card: #fff; --ink: #17212b; --muted: #687582; --line: #e2e7ec;
  --pri: #1e3a5f; --pri2: #2c5d8f; --priInk: #fff;
  --ok: #15803d; --okBg: #e9f7ee; --bad: #b42318; --badBg: #fdecea; --warn: #a15c07; --warnBg: #fff6e0;
  --term: #0f1720; --termInk: #d7e2ea;
  --r: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1319; --card: #161f27; --ink: #e7edf2; --muted: #93a0ab; --line: #26323c;
    --pri: #2c5d8f; --pri2: #4b84bd; --okBg: #12301f; --ok: #5fd48a; --badBg: #3a1712; --bad: #ff8a7a; --warnBg: #33270e; --warn: #f2c14e;
    --term: #070b0f; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.55 system-ui, "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
small { display: block; color: var(--muted); font-size: .84rem; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }
.ltr { direction: ltr; unicode-bidi: isolate; }

#app { max-width: 760px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--pri); color: var(--priInk); }
.top h1 { font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .ib { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 10px; width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer; flex: none; }
.top .ib svg { width: 20px; height: 20px; }

main { padding: 10px 14px; }
.h { margin: 18px 4px 8px; font-size: 1rem; color: var(--muted); font-weight: 600; }
.card { background: var(--card); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 10px; }
.card h3 { font-size: .95rem; margin-bottom: 10px; }
.note { background: var(--warnBg); color: var(--warn); border-color: transparent; }
.okbox { background: var(--okBg); color: var(--ok); border-color: transparent; }

.list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.row b { display: block; font-weight: 600; }
.row .chev { color: var(--muted); }
.st { width: 11px; height: 11px; border-radius: 50%; flex: none; background: #9aa5ae; }
.st.on { background: #22c55e; box-shadow: 0 0 0 3px color-mix(in srgb, #22c55e 25%, transparent); }
.st.off { background: #ef4444; }
.meters { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.meters span { font-size: .8rem; color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 11px; padding: 9px 14px; cursor: pointer; font-weight: 600; min-height: 42px; }
.btn.pri { background: var(--pri); color: #fff; border-color: var(--pri); }
.btn.bad { color: var(--bad); }
.btn.badfill { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.grid2 .btn { justify-content: flex-start; }

label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--pri2); }
.code-in { font-size: 1.5rem; letter-spacing: .3em; text-align: center; direction: ltr; }
.sw { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.sw input { width: 22px; height: 22px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.tabs button { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.tabs button.on { background: var(--pri); color: #fff; border-color: var(--pri); }

dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .9rem; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 4px 0 10px; }
.bar i { display: block; height: 100%; background: var(--pri2); border-radius: 99px; }
.bar i.hi { background: var(--bad); }

.term { background: var(--term); color: var(--termInk); border-radius: 12px; padding: 12px; font: 13px/1.5 Consolas, "Cascadia Mono", monospace;
  direction: ltr; text-align: left; white-space: pre; max-height: 60vh; overflow: auto; margin: 0; }
.term .cmd { color: #7dd3fc; }
.term .er { color: #fca5a5; }
.term .dim { color: #7b8b98; }
textarea.mono { font: 14px/1.5 Consolas, "Cascadia Mono", monospace; direction: ltr; text-align: left; min-height: 70px; resize: vertical; }

.files { display: flex; flex-direction: column; }
.files .fr { display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.files .fr:last-child { border-bottom: 0; }
.files .fr .nm { flex: 1; min-width: 0; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; unicode-bidi: plaintext; }
.files .fr svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
.files .fr.dir svg { color: var(--pri2); }
.path { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.path input { direction: ltr; text-align: left; }

table.procs { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.procs th, table.procs td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: start; }
table.procs th { color: var(--muted); font-weight: 600; cursor: pointer; }
table.procs td:nth-child(2) { white-space: nowrap; }
table.procs td.n { direction: ltr; text-align: left; overflow-wrap: anywhere; }

.log .it { padding: 9px 0; border-bottom: 1px solid var(--line); }
.log .it:last-child { border-bottom: 0; }
.pill { display: inline-block; font-size: .76rem; padding: 2px 8px; border-radius: 99px; background: var(--line); }
.pill.done { background: var(--okBg); color: var(--ok); }
.pill.error, .pill.expired { background: var(--badBg); color: var(--bad); }
.pill.sent, .pill.pending { background: var(--warnBg); color: var(--warn); }

.big-code { font: 700 2rem/1.2 Consolas, monospace; letter-spacing: .12em; text-align: center; direction: ltr; padding: 14px; background: var(--bg); border-radius: 12px; margin: 8px 0; user-select: all; }
.secret { font: 600 1rem Consolas, monospace; direction: ltr; text-align: center; word-break: break-all; background: var(--bg); padding: 10px; border-radius: 10px; user-select: all; }
ol.steps { padding-inline-start: 20px; margin: 6px 0; }
ol.steps li { margin-bottom: 6px; }

.center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.center .card { width: 100%; max-width: 420px; }
.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.logo img { width: 44px; height: 44px; border-radius: 12px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 20; padding: 18px; }
.modal { background: var(--card); border-radius: 16px; padding: 18px; width: 100%; max-width: 420px; max-height: 90vh; overflow: auto; }
.modal h3 { margin-bottom: 10px; }
.modal .btns { justify-content: flex-end; margin-top: 14px; }

#toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); inset-inline: 0; margin: auto; width: max-content; max-width: 90vw;
  background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; z-index: 30; }
#toast.on { opacity: 1; transform: none; }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
