:root {
  color-scheme: light dark; /* the page themes itself, so mobile browsers must not auto-darken it */
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f1f4f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #e8efff;
  --success: #15803d;
  --success-soft: #e3f6ea;
  --warn: #b45309;
  --warn-soft: #fff4dc;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .06);
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2e;
    --surface-2: #17223a;
    --text: #e6ebf5;
    --muted: #92a0b8;
    --border: #243049;
    --primary: #5b8cff;
    --primary-hover: #7ba0ff;
    --primary-soft: #1a2a52;
    --success: #4ade80;
    --success-soft: #12301f;
    --warn: #fbbf24;
    --warn-soft: #33270c;
    --danger: #f87171;
    --danger-soft: #3a1a1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 14px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .9rem;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  background: var(--primary); color: #fff; transition: background .15s, box-shadow .15s, opacity .15s;
}
.btn:hover { background: var(--primary-hover); }
.btn:focus-visible, .input:focus-visible, select:focus-visible { outline: 3px solid var(--primary-soft); outline-offset: 1px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.danger.outline { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger.outline:hover { background: var(--danger-soft); }
.btn.success { background: var(--success); }
.btn.sm { padding: 6px 11px; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }

/* ---------- forms ---------- */
label.field { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); }
label.field > span { display: block; margin-bottom: 5px; }
.input, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 12px;
}
.input::placeholder { color: var(--muted); opacity: .7; }
/* password field with a show/hide eye button inside it */
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 44px; }
.pw-toggle { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); width: 36px; height: 36px;
  display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.pw-toggle:focus-visible { outline: 3px solid var(--primary-soft); }
select { padding-right: 28px; }

.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(18px); }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 0 20px; height: 62px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #2563eb, #7c3aed); display: grid; place-items: center; color: #fff; }
.logo svg { width: 18px; height: 18px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--muted); font-weight: 600; font-size: .9rem; padding: 8px 12px; border-radius: 8px; display: inline-flex; gap: 8px; align-items: center; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.count { background: var(--danger); color: #fff; border-radius: 99px; font-size: .72rem; padding: 1px 7px; font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.avatar.sm { width: 28px; height: 28px; font-size: .75rem; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live-dot.on::before { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.page { max-width: 1080px; margin: 0 auto; padding: 28px 20px 64px; }
.page-head { margin-bottom: 22px; }
.page-head p { margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card.flat { box-shadow: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.host { background: var(--primary-soft); color: var(--primary); }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.live { background: var(--danger-soft); color: var(--danger); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- group card ---------- */
.group-card { display: flex; flex-direction: column; gap: 14px; }
.group-card .desc { min-height: 1.4em; }
.group-meta { display: flex; gap: 14px; color: var(--muted); font-size: .84rem; }
.status-box { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }
.status-box.live { background: var(--danger-soft); }
.group-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- tabs / tables ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab { background: none; border: 0; font: inherit; font-weight: 600; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 8px; align-items: center; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-color: var(--primary); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person .name { font-weight: 600; }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .icon { width: 46px; height: 46px; margin: 0 auto 12px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.host-picker { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.host-picker-side { flex: 0 1 260px; min-width: 200px; }
.host-picker-main { flex: 1 1 420px; min-width: 0; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(900px 400px at 15% -10%, rgba(37, 99, 235, .14), transparent),
  radial-gradient(700px 400px at 100% 0%, rgba(124, 58, 237, .12), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .brand { justify-content: center; margin-bottom: 20px; font-size: 1.25rem; }
.auth-card .logo { width: 38px; height: 38px; border-radius: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.seg button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 8px; border-radius: 8px; cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.error { background: var(--danger-soft); color: var(--danger); border-radius: 9px; padding: 9px 12px; font-size: .88rem; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 12px 14px; font-size: .9rem; }
.notice.info { background: var(--primary-soft); color: var(--primary); }
.center-card { max-width: 480px; margin: 12vh auto 0; text-align: center; }
.center-card .icon { width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px); z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal { width: 100%; max-width: 420px; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); padding: 24px; }
.modal h2 { margin-bottom: 6px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.countdown { width: 84px; height: 84px; margin: 14px auto; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; font-weight: 700; color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 6px var(--primary-soft); }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 36px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 10px; box-shadow: var(--shadow); padding: 12px 14px; display: flex; gap: 12px; align-items: center; animation: slide .2s ease-out; }
.toast.success { border-left-color: #22c55e; }
.toast.error { border-left-color: var(--danger); }
.toast .grow { font-size: .9rem; }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--radius); margin-bottom: 18px; background: var(--danger-soft); border: 1px solid transparent; }
.banner.info { background: var(--primary-soft); }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.big { width: 34px; height: 34px; border-width: 3px; border-color: var(--primary-soft); border-top-color: var(--primary); }
.loading-card { background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); padding: 28px 34px; display: flex; flex-direction: column; align-items: center; gap: 14px; font-weight: 600; }

@media (max-width: 720px) {
  .topbar-inner { gap: 10px; padding: 0 12px; height: auto; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .nav { order: 3; width: 100%; flex: none; overflow-x: auto; }
  .user-name { display: none; }
  .page { padding: 20px 14px 56px; }
  .grid { grid-template-columns: 1fr; }
}
