:root {
  --fb-bg: #f4f5f8; --fb-card: #ffffff; --fb-text: #12161c; --fb-hint: #6b7280; --fb-line: #e6e8ee;
  --fb-accent: #2b7de9; --fb-accent-text: #ffffff;
  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-card)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --accent: var(--tg-theme-button-color, var(--fb-accent));
  --accent-text: var(--tg-theme-button-text-color, var(--fb-accent-text));
  --line: var(--fb-line);
  --ok: #1f9d55; --ok-bg: rgba(31,157,85,.12); --warn: #c98a00; --warn-bg: rgba(201,138,0,.14);
  --crit: #e03e45; --crit-bg: rgba(224,62,69,.12); --sim: #7357e8; --sim-bg: rgba(115,87,232,.12);
  --r: 16px; --r-sm: 11px;
  --font: -apple-system, "SF Arabic", "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --fb-bg: #0f1216; --fb-card: #181c22; --fb-text: #eef1f5; --fb-hint: #8b93a1; --fb-line: #262b33; --fb-accent: #4c95f5; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
.tiles > *, .secs > *, .hero > * { min-width: 0; }
.hero .d, .tile .s { overflow-wrap: anywhere; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }
body { overscroll-behavior-y: none; }
body { min-height: 100vh; padding-bottom: calc(76px + var(--safe-b)); }
button { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: 12px 16px 10px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid transparent; }
.top.scrolled { border-bottom-color: var(--line); }
.back { display: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--card); font-size: 18px; cursor: pointer; }
.back.on { display: grid; place-items: center; }
.ttl { flex: 1; min-width: 0; }
.ttl h1 { margin: 0; font-size: 17px; font-weight: 750; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ttl .sub { font-size: 12.5px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-btn { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 12px; min-height: 38px; font-size: 13px; cursor: pointer;
  max-width: 30vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-flex; gap: 6px; align-items: center; }
.chip-btn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.chip-btn.empty .dot { background: var(--hint); }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--card); cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(-360deg); } }

main { padding: 6px 16px 24px; max-width: 720px; margin: 0 auto; }
.view { animation: in .18s ease-out; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

/* cards */
.card { background: var(--card); border-radius: var(--r); padding: 14px 16px; margin: 12px 0; }
.card h3 { margin: 0 0 8px; font-size: 13px; font-weight: 650; color: var(--hint); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; }
.row + .row { border-top: 1px solid var(--line); }
.row .k { color: var(--hint); font-size: 13.5px; }
.row .v { font-weight: 600; text-align: left; overflow-wrap: anywhere; max-width: 64%; }
.raw { display: block; font-size: 11px; font-weight: 400; color: var(--hint); direction: ltr; text-align: left; margin-top: 1px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; overflow-wrap: anywhere; }
.hero .raw { text-align: right; }
.hero { display: flex; gap: 14px; align-items: center; }
.hero .badge { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; flex: none; }
.hero .t { font-size: 17px; font-weight: 700; }
.hero .d { font-size: 13px; color: var(--hint); }
.ok .badge { background: var(--ok-bg); } .warn .badge { background: var(--warn-bg); } .crit .badge { background: var(--crit-bg); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.tile { background: var(--card); border-radius: var(--r); padding: 12px 14px; min-height: 86px; display: flex; flex-direction: column; gap: 4px; }
.tile .k { font-size: 12.5px; color: var(--hint); }
.tile .v { font-size: 17px; font-weight: 700; }
.tile .s { font-size: 12px; color: var(--hint); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg); } .pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.crit { color: var(--crit); background: var(--crit-bg); } .pill.sim { color: var(--sim); background: var(--sim-bg); }
.pill.mute { color: var(--hint); background: color-mix(in srgb, var(--hint) 14%, transparent); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.bar { height: 8px; background: color-mix(in srgb, var(--hint) 18%, transparent); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); }

/* sections grid */
.group-t { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 6px; }
.group-t h2 { font-size: 15px; margin: 0; font-weight: 700; }
.group-t span { font-size: 12px; color: var(--hint); }
.secs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sec { position: relative; text-align: right; border: 0; background: var(--card); border-radius: var(--r); padding: 12px 14px 12px; cursor: pointer;
  min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; transition: transform .08s; }
.sec:active { transform: scale(.98); }
.sec .n { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; font-weight: 750; font-size: 13.5px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.sec.simu .n { background: var(--sim-bg); color: var(--sim); }
.sec .t { font-weight: 680; font-size: 14.5px; margin-top: 10px; display: flex; align-items: center; gap: 7px; }
.sec .si { width: 18px; height: 18px; color: var(--hint); flex: none; display: inline-flex; }
.sec .si svg { width: 18px; height: 18px; }
.sec .pill { position: absolute; top: 12px; left: 12px; }

/* lists, forms */
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; }
.item + .item { border-top: 1px solid var(--line); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 640; }
.item .s { font-size: 12.5px; color: var(--hint); overflow-wrap: anywhere; }
.note { padding: 10px 0; }
.note + .note { border-top: 1px solid var(--line); }
.note .s { font-size: 12px; color: var(--hint); margin-top: 3px; }
.btn { border: 0; border-radius: var(--r-sm); padding: 10px 14px; font-weight: 650; cursor: pointer; background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.btn.red { background: var(--crit-bg); color: var(--crit); }
.btn.block { width: 100%; padding: 13px; font-size: 15.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 6px 14px; font-size: 13.5px; min-height: 36px; }
.btn:active, .chip-btn:active, .icon-btn:active { opacity: .7; }
label.f { display: block; font-size: 12.5px; color: var(--hint); margin: 10px 2px 5px; }
input.in, textarea.in { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: var(--r-sm);
  padding: 11px 12px; font: inherit; font-size: 16px; outline: none; }   /* 16px: iOS does not zoom on focus */
input.in:focus, textarea.in:focus { border-color: var(--accent); }
textarea.in { min-height: 92px; resize: vertical; }
input.ltr { direction: ltr; text-align: left; }
.hint { font-size: 12.5px; color: var(--hint); margin: 6px 2px 0; }
.banner { border-radius: var(--r); padding: 12px 14px; margin: 12px 0; font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.banner.sim { background: var(--sim-bg); color: var(--sim); }
.banner.crit { background: var(--crit-bg); color: var(--crit); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: color-mix(in srgb, var(--hint) 12%, transparent); color: var(--text); }
.banner.info b { color: var(--text); }
.banner b { display: block; margin-bottom: 2px; }
.models { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.model { background: var(--bg); border-radius: var(--r-sm); padding: 12px 8px; text-align: center; }
.model .m { font-weight: 700; font-size: 14px; }
.model .st { font-size: 12px; color: var(--hint); margin-top: 4px; }
.empty-s { text-align: center; color: var(--hint); padding: 22px 8px; font-size: 14px; }
.tag-sel { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.tag-sel::-webkit-scrollbar { display: none; }
.tag-sel button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; }
.tag-sel button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: right; color: var(--hint); font-weight: 600; padding: 6px 0; }
table.t td { padding: 7px 0; border-top: 1px solid var(--line); }

/* tab bar */
nav.tabs { position: fixed; inset-inline: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b)); }
nav.tabs button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  font-size: 11px; color: var(--hint); cursor: pointer; }
nav.tabs button svg { width: 23px; height: 23px; }
nav.tabs button.on { color: var(--accent); font-weight: 650; }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.38); z-index: 20; opacity: 0; pointer-events: none; transition: opacity .18s; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; inset-inline: 0; bottom: 0; z-index: 21; background: var(--card); border-radius: 20px 20px 0 0;
  padding: 10px 18px calc(18px + var(--safe-b)); transform: translateY(105%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
  max-width: 720px; margin: 0 auto; max-height: 86vh; overflow-y: auto; }
.sheet.on { transform: none; }
.sheet .grab { width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 6px; font-size: 18px; }
.sheet .lvl { margin-bottom: 10px; }
.sheet .sum { background: var(--bg); border-radius: var(--r-sm); padding: 12px; margin: 10px 0 14px; overflow-wrap: anywhere; }
.sheet .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sheet ul { margin: 6px 0 12px; padding-inline-start: 18px; }

.toast { position: fixed; inset-inline: 16px; bottom: calc(86px + var(--safe-b)); z-index: 30; background: #1f2329; color: #fff;
  border-radius: 12px; padding: 11px 14px; font-size: 14px; text-align: center; opacity: 0; transform: translateY(10px);
  transition: .2s; pointer-events: none; max-width: 520px; margin: 0 auto; }
.toast.on { opacity: 1; transform: none; }
.toast.err { background: var(--crit); }

.sk { background: linear-gradient(90deg, color-mix(in srgb, var(--hint) 10%, transparent) 25%, color-mix(in srgb, var(--hint) 20%, transparent) 50%,
  color-mix(in srgb, var(--hint) 10%, transparent) 75%); background-size: 200% 100%; animation: sh 1.1s infinite; border-radius: var(--r); }
@keyframes sh { to { background-position: -200% 0; } }
.locked { text-align: center; padding: 70px 24px; }
.locked .ic { font-size: 44px; }
.locked h2 { margin: 12px 0 6px; }
.locked p { color: var(--hint); margin: 0; }
@media (min-width: 560px) { .secs { grid-template-columns: repeat(3, 1fr); } .tiles { grid-template-columns: repeat(4, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
