:root {
  --bg: #0f1115; --panel: #181b22; --panel2: #20242e; --line: #2a2f3a;
  --text: #e9ecf2; --muted: #9aa3b2; --accent: #5865f2; --accent2: #4752c4;
  --ok: #2dd471; --bad: #ed4245; --warn: #faa61a;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; min-width: 0; }
html { overflow-x: hidden; }
body {
  margin: 0; max-width: 100%; overflow-x: hidden;
  background: radial-gradient(1200px 600px at 50% -10%, #161a23 0%, var(--bg) 55%);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; }
h1, h2, h3 { margin: 0 0 6px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: 0 2px 10px rgba(0,0,0,.22); }
.stack > * + * { margin-top: 16px; }

input, textarea, select, button {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 11px; padding: 13px 14px; width: 100%;
}
textarea { resize: vertical; min-height: 90px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='%239aa3b2'%3E%3Cpath d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
button { background: linear-gradient(180deg, var(--accent), var(--accent2)); border: none; cursor: pointer; font-weight: 650; transition: filter .12s, transform .05s; }
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: var(--bad); }
button.small { width: auto; padding: 9px 14px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); text-align: center; }
.login input, .login button { margin-top: 14px; }

/* header */
header {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(180deg, rgba(24,27,34,.97), rgba(15,17,21,.9));
  backdrop-filter: blur(10px);
}
.topbar { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; }
.brand { font-size: 17px; white-space: nowrap; }
.inst-pick { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-left: auto; }
.inst-pick select { width: auto; padding: 8px 30px 8px 10px; }
#logout { flex: none; }
header nav { display: flex; gap: 8px; flex-wrap: wrap; }
.tab { background: var(--panel2); border: 1px solid var(--line); padding: 11px 14px; font-size: 15px; font-weight: 600; flex: 1 1 auto; min-width: max-content; border-radius: 11px; white-space: nowrap; }
.tab.active { background: linear-gradient(180deg, var(--accent), var(--accent2)); border-color: var(--accent); box-shadow: 0 4px 16px rgba(88,101,242,.4); }
.tab-pane { padding: 18px 16px 64px; max-width: 760px; margin: 0 auto; }

/* status */
.statusline { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.dot.up { background: var(--ok); box-shadow: 0 0 0 4px rgba(45,212,113,.15); }
.dot.down { background: var(--bad); box-shadow: 0 0 0 4px rgba(237,66,69,.15); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-top: 14px; }
.metric { background: linear-gradient(180deg, #232834, #1b1f29); border: 1px solid var(--line); border-radius: 12px; padding: 14px 12px; text-align: center; }
.metric b { display: block; font-size: 24px; letter-spacing: -.02em; }
.metric span { font-size: 12px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 650; background: var(--panel2); }
.badge.on { background: rgba(45,212,113,.16); color: var(--ok); }
.badge.off { background: rgba(154,163,178,.16); color: var(--muted); }

details.logs { margin-top: 18px; }
details.logs summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
pre.log { background: #0b0d11; border: 1px solid var(--line); border-radius: 11px; padding: 12px; overflow: auto; max-height: 45vh; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }

/* settings */
.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }
.seg { display: flex; gap: 8px; }
.seg button { background: var(--panel2); border: 1px solid var(--line); font-weight: 600; }
.seg button.sel { background: var(--accent); border-color: var(--accent); }
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { display: none; }
.switch .track { width: 52px; height: 30px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { left: 25px; }

/* actions */
.cat { margin-bottom: 14px; }
.cat h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 10px; }
.act-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.act { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; font-weight: 600; transition: transform .08s, border-color .12s, box-shadow .12s; }
.act:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.28); }
.act .warn { color: var(--warn); font-size: 12px; display: block; font-weight: 500; margin-top: 4px; }
.back { background: transparent; border: none; color: var(--accent); width: auto; padding: 6px 0; font-weight: 600; }
.form-head { margin-bottom: 4px; }
.result { margin-top: 16px; border-radius: 11px; padding: 14px; }
.result.ok { background: rgba(45,212,113,.1); border: 1px solid rgba(45,212,113,.3); }
.result.err { background: rgba(237,66,69,.1); border: 1px solid rgba(237,66,69,.3); }
.result pre { margin: 8px 0 0; white-space: pre-wrap; word-break: break-word; font-size: 13px; color: var(--muted); }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 20px; z-index: 20; }
.modal-card { width: min(420px, 100%); }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; padding: 13px 18px; z-index: 30; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.ok { border-color: rgba(45,212,113,.5); }
.toast.err { border-color: rgba(237,66,69,.5); }

@media (min-width: 620px) {
  .tab { flex: none; padding: 11px 22px; }
}
