:root {
  --teal: #156b68; --teal-2: #1a8a86; --soft: #f0f9f8; --gold: #caa453; --ink: #1f2a2a;
  --bg: #f0f9f8; --card: #ffffff; --text: #1f2a2a; --muted: #5d6e6d; --line: #d9e9e7;
  --track: #e3efed; --head: #156b68; --head-2: #12585a; --head-text: #ffffff;
  --ok: #1f8a4c; --ok-bg: #e5f5ec; --warn: #a8761a; --warn-bg: #fbf1dc; --err: #c0392b; --err-bg: #fbe7e4;
  --info: #1a8a86; --info-bg: #e4f3f2; --run: #1a8a86; --grey: #8a9998; --grey-bg: #eef2f2;
  --shadow: 0 1px 2px rgba(21, 107, 104, .06), 0 4px 16px rgba(21, 107, 104, .07);
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1a1a; --card: #132625; --text: #e4efee; --muted: #9db3b1; --line: #23403e;
    --track: #1e3836; --head: #0f2524; --head-2: #12302f; --head-text: #eaf6f5;
    --ok: #4cc37f; --ok-bg: #12301f; --warn: #e0b45a; --warn-bg: #33280f; --err: #f0766a; --err-bg: #3a1714;
    --info: #4fc1bb; --info-bg: #11302e; --run: #4fc1bb; --grey: #7f9593; --grey-bg: #1a302f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  --bg: #0c1a1a; --card: #132625; --text: #e4efee; --muted: #9db3b1; --line: #23403e;
  --track: #1e3836; --head: #0f2524; --head-2: #12302f; --head-text: #eaf6f5;
  --ok: #4cc37f; --ok-bg: #12301f; --warn: #e0b45a; --warn-bg: #33280f; --err: #f0766a; --err-bg: #3a1714;
  --info: #4fc1bb; --info-bg: #11302e; --run: #4fc1bb; --grey: #7f9593; --grey-bg: #1a302f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: 'Almarai', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 17px; line-height: 1.6; overflow-x: hidden;
}
h1, h2 { margin: 0; font-weight: 800; }
h2 { font-size: 1.12rem; color: var(--text); }
button { font: inherit; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

/* header ------------------------------------------------------------------ */
.top {
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(160deg, var(--head), var(--head-2));
  color: var(--head-text); border-bottom: 3px solid var(--gold);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.top-in { display: flex; align-items: center; gap: 12px; max-width: 1280px; margin: 0 auto; }
.top-logo { width: 52px; height: auto; background: #fff; border-radius: 12px; padding: 4px 5px; flex: none; }
.top-title { flex: 1; min-width: 0; }
.top h1 { font-size: 1.15rem; line-height: 1.3; }
.top-sub { margin: 0; font-size: .78rem; opacity: .85; }
.conn {
  display: flex; align-items: center; gap: 6px; flex: none;
  background: rgba(255, 255, 255, .12); border-radius: 999px; padding: 4px 10px; font-size: .78rem;
}
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: #f0b429; box-shadow: 0 0 0 3px rgba(240, 180, 41, .25); }
.conn.live .conn-dot { background: #3ddc84; box-shadow: 0 0 0 3px rgba(61, 220, 132, .25); animation: pulse 2s infinite; }
.conn.off .conn-dot { background: #ff6b5e; box-shadow: 0 0 0 3px rgba(255, 107, 94, .25); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(61, 220, 132, 0); } }
.clocks { display: flex; gap: 8px; max-width: 1280px; margin: 8px auto 0; }
.clock {
  flex: 1; display: flex; justify-content: space-between; align-items: baseline;
  background: rgba(255, 255, 255, .1); border-radius: 10px; padding: 4px 10px;
}
.clock-l { font-size: .8rem; opacity: .85; }
.clock-v { font-size: 1.12rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .5px; }

/* layout ------------------------------------------------------------------ */
.wrap { max-width: 1280px; margin: 0 auto; padding: 14px 16px 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.col { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; min-width: 0; }
@media (min-width: 980px) {
  .wrap { grid-template-columns: minmax(340px, 420px) minmax(0, 1fr); align-items: start; padding-top: 20px; }
  .col-side { position: sticky; top: 132px; }
  body { font-size: 16px; }
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.stamp { font-size: .8rem; color: var(--muted); }

/* status ------------------------------------------------------------------ */
.switch { display: flex; align-items: center; gap: 14px; border-radius: 14px; padding: 12px 14px; background: var(--grey-bg); }
.switch-ico { width: 18px; height: 18px; border-radius: 50%; background: var(--grey); flex: none; }
.switch-l { font-size: .85rem; color: var(--muted); }
.switch-v { font-size: 1.45rem; font-weight: 800; line-height: 1.3; }
.switch.on { background: var(--warn-bg); }
.switch.on .switch-ico { background: var(--gold); box-shadow: 0 0 0 5px rgba(202, 164, 83, .28); animation: pulseg 2s infinite; }
.switch.on .switch-v { color: var(--warn); }
.switch.off { background: var(--ok-bg); }
.switch.off .switch-ico { background: var(--ok); }
.switch.off .switch-v { color: var(--ok); }
@keyframes pulseg { 50% { box-shadow: 0 0 0 9px rgba(202, 164, 83, 0); } }
.flags { margin: 8px 2px 0; font-size: .85rem; color: var(--muted); }
.win { margin-top: 16px; }
.win-row { display: flex; justify-content: space-between; align-items: baseline; }
.win-l { font-weight: 700; }
.win-pct { font-size: 1.5rem; font-weight: 800; color: var(--teal-2); font-variant-numeric: tabular-nums; }
.bar { height: 12px; border-radius: 999px; background: var(--track); overflow: hidden; margin: 6px 0; }
.bar > span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--teal-2)); transition: width .6s; }
.win-times { display: flex; justify-content: space-between; gap: 6px; font-size: .8rem; color: var(--muted); }
.win-state { text-align: center; color: var(--text); font-weight: 700; }
.phase-now { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.phase-now-l { display: block; font-size: .82rem; color: var(--muted); }
.phase-now-v { display: block; font-size: 1.15rem; font-weight: 800; color: var(--teal-2); }

/* push -------------------------------------------------------------------- */
.push h2 { margin-bottom: 8px; }
.guide { background: var(--info-bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: .95rem; }
.guide p { margin: 0 0 6px; }
.guide p:last-child { margin: 0; font-size: .85rem; }
.share-ico {
  display: inline-block; width: 15px; height: 18px; vertical-align: -3px; margin: 0 2px;
  border: 2px solid currentColor; border-top: 0; border-radius: 0 0 3px 3px; position: relative;
}
.share-ico::before { content: ''; position: absolute; left: 50%; top: -6px; width: 2px; height: 12px; background: currentColor; transform: translateX(-50%); }
.push-msg { margin: 0 0 10px; color: var(--muted); font-size: .92rem; }
.push-msg:empty { display: none; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 12px 18px; min-height: 48px;
  background: var(--teal); color: #fff; font-weight: 700; font-size: 1rem; cursor: pointer; flex: 1 1 auto;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-2 { background: var(--gold); color: #1f2a2a; }
.btn-ghost { background: transparent; color: var(--teal-2); border: 1px solid var(--line); }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 4px; }

/* health ------------------------------------------------------------------ */
.health { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hc { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.hc-l { font-size: .8rem; color: var(--muted); }
.hc-v { font-size: 1.3rem; font-weight: 800; line-height: 1.3; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hc-s { font-size: .78rem; color: var(--muted); overflow-wrap: anywhere; }
.hc .bar { height: 6px; margin: 6px 0 2px; }
.hc .bar > span { background: var(--teal-2); }
.hc.warn { border-color: var(--warn); background: var(--warn-bg); }
.hc.warn .bar > span { background: var(--warn); }
.hc.crit { border-color: var(--err); background: var(--err-bg); }
.hc.crit .bar > span { background: var(--err); }
.hc.crit .hc-v { color: var(--err); }
.hc.good .hc-v { color: var(--ok); }
.problems { margin-top: 10px; background: var(--err-bg); border-radius: 12px; padding: 10px 12px; font-size: .88rem; }
.problems strong { color: var(--err); }
.problems ul { margin: 4px 0 0; padding: 0; list-style-position: inside; }
.problems li { overflow-wrap: anywhere; }
.stale { color: var(--err); font-weight: 700; }

/* systems ----------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  border-radius: 999px; padding: 4px 10px; font-size: .82rem; line-height: 1.5;
  background: var(--grey-bg); color: var(--muted); border: 1px solid transparent;
}
.chip > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--grey); flex: none; }
.chip.ok { background: var(--ok-bg); color: var(--text); }
.chip.ok .chip-dot { background: var(--ok); }
.chip.regression { background: var(--err-bg); color: var(--err); border-color: var(--err); font-weight: 700; }
.chip.regression .chip-dot { background: var(--err); }
.legend-i { white-space: nowrap; }

/* timeline ---------------------------------------------------------------- */
.tl { list-style: none; margin: 0; padding: 0; }
.tl-i { position: relative; padding: 0 34px 16px 0; }
.tl-i::before { content: ''; position: absolute; right: 11px; top: 26px; bottom: -2px; width: 2px; background: var(--line); }
.tl-i:last-child { padding-bottom: 0; }
.tl-i:last-child::before { display: none; }
.tl-dot {
  position: absolute; right: 2px; top: 4px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--grey);
}
.tl-i.done .tl-dot { background: var(--ok); border-color: var(--ok); }
.tl-i.done::before { background: var(--ok); }
.tl-i.running .tl-dot { border-color: var(--run); background: var(--run); box-shadow: 0 0 0 5px rgba(26, 138, 134, .25); animation: pulset 1.6s infinite; }
.tl-i.failed .tl-dot { background: var(--err); border-color: var(--err); }
.tl-i.rolled_back .tl-dot { background: var(--warn); border-color: var(--warn); }
.tl-i.skipped .tl-dot { border-style: dashed; }
@keyframes pulset { 50% { box-shadow: 0 0 0 9px rgba(26, 138, 134, 0); } }
.tl-box { border-radius: 12px; padding: 8px 12px; background: transparent; }
.tl-i.running .tl-box { background: var(--info-bg); }
.tl-i.failed .tl-box { background: var(--err-bg); }
.tl-i.rolled_back .tl-box { background: var(--warn-bg); }
.tl-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px; }
.tl-title { font-weight: 800; font-size: 1.02rem; }
.tl-i.skipped .tl-title, .tl-i.pending .tl-title { color: var(--muted); }
.tl-i.pending .tl-title { color: var(--text); font-weight: 700; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; border-radius: 999px; padding: 1px 9px; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.badge.running { background: var(--run); color: #fff; }
.badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.failed { background: var(--err); color: #fff; }
.badge.rolled_back { background: var(--warn); color: #fff; }
.tl-meta { font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 12px; font-variant-numeric: tabular-nums; }
.tl-detail { margin: 4px 0 0; font-size: .9rem; overflow-wrap: anywhere; }

/* feed -------------------------------------------------------------------- */
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ev { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; border-radius: 12px; padding: 10px 12px; border-inline-start: 4px solid var(--info); background: var(--info-bg); }
.ev.success { border-color: var(--ok); background: var(--ok-bg); }
.ev.warning { border-color: var(--warn); background: var(--warn-bg); }
.ev.error { border-color: var(--err); background: var(--err-bg); }
.ev-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .9rem; color: var(--muted); padding-top: 1px; }
.ev-body { min-width: 0; }
.ev-title { font-weight: 800; overflow-wrap: anywhere; }
.ev.error .ev-title { color: var(--err); }
.ev-detail { font-size: .88rem; color: var(--muted); overflow-wrap: anywhere; margin-top: 2px; }
.ev-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag { font-size: .72rem; border-radius: 6px; padding: 0 7px; background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.tag.lvl-success { color: var(--ok); }
.tag.lvl-warning { color: var(--warn); }
.tag.lvl-error { color: var(--err); }
.ev.new { animation: flash 1.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--gold); } to { box-shadow: 0 0 0 0 transparent; } }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }
.more { width: 100%; margin-top: 10px; }

/* messages ---------------------------------------------------------------- */
.msgs { border-top: 4px solid var(--gold); }
@media (min-width: 980px) { .msgs { grid-column: 1 / -1; } }
.q-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.q { border-radius: 12px; padding: 12px; border: 1px solid var(--line); }
.q.open { border: 2px solid var(--gold); background: var(--warn-bg); }
.q-meta { font-size: .78rem; color: var(--muted); }
.q-text { font-weight: 800; font-size: 1.08rem; margin: 2px 0 8px; overflow-wrap: anywhere; white-space: pre-wrap; }
.q-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.q-opts .btn { flex: 1 1 auto; min-width: 96px; }
.q-free { display: flex; gap: 8px; }
.q-free input { flex: 1; min-width: 0; font: inherit; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.q-free .btn { flex: none; }
.q-ans { margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: var(--ok-bg); font-size: .95rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.q-ans b { color: var(--ok); }
.q-done-wrap { margin-top: 10px; }
.q-done-wrap summary { cursor: pointer; color: var(--teal-2); font-weight: 700; padding: 4px 0; }
.q-done-wrap .q-list { margin-top: 8px; }
.gen { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.gen-l { display: block; font-weight: 700; margin-bottom: 6px; }
.gen-row { display: flex; gap: 8px; align-items: stretch; }
.gen-row textarea { flex: 1; min-width: 0; font: inherit; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); resize: vertical; }
.gen-row .btn { flex: none; }
.gen-sent { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; font-size: .88rem; }
.gen-sent li { color: var(--muted); overflow-wrap: anywhere; white-space: pre-wrap; }
.gen-sent li b { color: var(--ok); font-weight: 700; }
.q-free input:focus, .gen-row textarea:focus { outline: 3px solid rgba(26, 138, 134, .35); border-color: var(--teal-2); }

/* footer / toast ---------------------------------------------------------- */
.foot { max-width: 1280px; margin: 0 auto; padding: 8px 16px calc(env(safe-area-inset-bottom) + 18px); display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); }
.logout { margin: 0; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); z-index: 10;
  max-width: 480px; margin: 0 auto; background: var(--ink); color: #fff; border-radius: 12px; padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); text-align: center;
}

/* login ------------------------------------------------------------------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: linear-gradient(180deg, var(--bg), var(--card)); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--gold); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 22px; text-align: center; }
.login-logo { width: 120px; height: auto; background: #fff; border-radius: 14px; padding: 6px; }
.login-card h1 { font-size: 1.4rem; color: var(--teal-2); margin-top: 12px; }
.login-sub { margin: 2px 0 20px; color: var(--muted); font-size: .9rem; }
.login-card form { text-align: right; display: grid; gap: 8px; }
.login-card label { font-weight: 700; }
.login-card input[type=password] {
  font: inherit; font-size: 1.15rem; letter-spacing: 1px; text-align: center; width: 100%;
  padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
.login-card input:focus { outline: 3px solid rgba(26, 138, 134, .35); border-color: var(--teal-2); }
.login-card button { appearance: none; border: 0; border-radius: 12px; min-height: 50px; background: var(--teal); color: #fff; font-weight: 800; font-size: 1.05rem; cursor: pointer; margin-top: 6px; }
.login-err { margin: 0; color: var(--err); background: var(--err-bg); border-radius: 10px; padding: 8px 10px; font-size: .92rem; }
.login-note { margin: 16px 0 0; font-size: .8rem; color: var(--muted); }
