/* Ops dashboard. Standalone: no framework, no external assets, no build step.
   Palette matches the Django admin theme (packages/svc_common ... edu_theme.css). */
:root {
  color-scheme: light dark;
  --bg: #f4f6fc;
  --card: #ffffff;
  --fg: #1f2340;
  --muted: #6b7090;
  --line: #e6e9f4;
  --soft: #eef2fc;
  --brand: #5672c4;
  --brand-2: #7c5cff;
  --up: #12a150;
  --down: #d63b3b;
  --off: #8b92a8;
  --pending: #c77700;
  --shadow: 0 1px 2px rgba(27, 31, 59, .05), 0 10px 30px rgba(27, 31, 59, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f18; --card: #161a27; --fg: #e8eaf3; --muted: #9aa0b8; --line: #252b3f; --soft: #1c2236;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f18; --card: #161a27; --fg: #e8eaf3; --muted: #9aa0b8; --line: #252b3f; --soft: #1c2236; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg); min-height: 100vh;
}
h1, h2, h3 { margin: 0; }
button { font: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px;
  padding: 14px 28px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; box-shadow: 0 4px 20px rgba(86, 114, 196, .25);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .18); border: 1px solid rgba(255, 255, 255, .28);
}
.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: .01em; }
.brand .sub { margin: 1px 0 0; font-size: 12px; color: rgba(255, 255, 255, .82); }
.top-actions { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px; border-radius: 999px;
  font-weight: 700; font-size: 13px; background: rgba(255, 255, 255, .18); color: #fff; white-space: nowrap;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #7ef0ae; box-shadow: 0 0 0 3px rgba(126, 240, 174, .25); }
.pill.bad::before { background: #ffb4b4; box-shadow: 0 0 0 3px rgba(255, 180, 180, .25); }

.btn {
  font-weight: 600; font-size: 13px; padding: 7px 14px; border-radius: 10px; border: 1px solid transparent;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn.ghost { color: #fff; background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .3); }
.btn.ghost:hover { background: rgba(255, 255, 255, .24); }

/* ---------- layout ---------- */
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 28px 56px; }
.stale-note { color: var(--down); font-weight: 600; font-size: 13px; margin: 0 0 16px; }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; position: relative; overflow: hidden;
}
.stat::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--muted); opacity: .5; }
.stat.up::after { background: var(--up); opacity: 1; }
.stat.down::after { background: var(--down); opacity: 1; }
.stat.off::after { background: var(--off); opacity: 1; }
.stat-num { font-size: 30px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.stat.up .stat-num { color: var(--up); }
.stat.down .stat-num { color: var(--down); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 600; }

/* ---------- alerts ---------- */
.alert {
  border: 1px solid color-mix(in srgb, var(--down) 40%, transparent);
  background: color-mix(in srgb, var(--down) 8%, var(--card));
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 22px; box-shadow: var(--shadow);
}
.alert-title { color: var(--down); font-weight: 700; margin-bottom: 6px; }
.alert ul { margin: 0; padding-left: 18px; }
.alert li { margin: 2px 0; }
.err { color: var(--down); font-weight: 600; }

/* ---------- sections and service cards ---------- */
.group { margin-top: 28px; }
.group-title {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.group-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; min-width: 0;
  border-left: 4px solid var(--pending);
}
.card.up { border-left-color: var(--up); }
.card.down { border-left-color: var(--down); background: color-mix(in srgb, var(--down) 6%, var(--card)); }
.card.off { border-left-color: var(--off); opacity: .72; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.optional { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 4px; }
.state {
  font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap;
  color: var(--pending); background: color-mix(in srgb, var(--pending) 14%, transparent);
}
.state.up { color: var(--up); background: color-mix(in srgb, var(--up) 14%, transparent); }
.state.down { color: var(--down); background: color-mix(in srgb, var(--down) 14%, transparent); }
.state.off { color: var(--muted); background: var(--soft); }
.detail { color: var(--muted); font-size: 12.5px; word-break: break-word; }
.card-foot {
  color: var(--muted); font-size: 11.5px; display: flex; justify-content: space-between; gap: 8px;
  font-variant-numeric: tabular-nums; margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--line);
}

/* ---------- history table ---------- */
.panel { margin-top: 32px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--soft); }
.panel-head h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 18px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--brand) 5%, transparent); }
th { color: var(--muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
td.time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.empty { color: var(--muted); padding: 22px 18px; text-align: center; }

/* ---------- sign-in ---------- */
body.login {
  display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--brand), var(--brand-2));
}
.login-card {
  width: min(390px, 100%); background: var(--card); color: var(--fg); border-radius: 22px; padding: 34px 30px 26px;
  box-shadow: 0 30px 70px rgba(10, 12, 40, .35);
}
.login-mark {
  width: 54px; height: 54px; border-radius: 17px; display: grid; place-items: center; color: #fff; margin-bottom: 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 10px 24px rgba(86, 114, 196, .4);
}
.login-card h1 { font-size: 21px; margin-bottom: 4px; }
.login-card > p { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 11px 13px; outline: none; transition: border-color .12s, box-shadow .12s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
.submit {
  width: 100%; font: inherit; font-weight: 700; color: #fff; border: 0; border-radius: 12px; padding: 12px; margin-top: 6px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 8px 20px color-mix(in srgb, var(--brand) 35%, transparent);
}
.submit:hover { filter: brightness(1.06); }
.login-error {
  background: color-mix(in srgb, var(--down) 12%, transparent); color: var(--down);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 600; margin-bottom: 14px;
}
.login-foot { color: var(--muted); font-size: 11.5px; margin-top: 18px; text-align: center; }

/* ---------- filter, empty note, check-now button ---------- */
.filter { display: inline-flex; align-items: center; gap: 8px; margin: 18px 0 0; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.filter input { width: 16px; height: 16px; margin: 0; accent-color: var(--brand); }
.empty-note { margin-top: 28px; padding: 22px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.btn:disabled { opacity: .6; cursor: progress; }

/* ---------- queue backlog warning ---------- */
.card.warn { border-left-color: var(--pending); }
.state.warn { color: var(--pending); background: color-mix(in srgb, var(--pending) 14%, transparent); }

/* ---------- expandable details on each card ---------- */
.more { margin-top: 2px; border-top: 1px dashed var(--line); padding-top: 6px; font-size: 12.5px; }
.more summary { cursor: pointer; color: var(--brand); font-weight: 700; user-select: none; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0; }
.facts dt { color: var(--muted); font-weight: 600; white-space: nowrap; }
.facts dd { margin: 0; word-break: break-all; font-variant-numeric: tabular-nums; }
.bars-label { color: var(--muted); font-size: 11.5px; margin-bottom: 6px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 28px; margin-bottom: 10px; }
.bar { flex: 1 1 0; min-width: 3px; max-width: 12px; height: 100%; border-radius: 3px; background: var(--off); opacity: .45; }
.bar.up { background: var(--up); opacity: .85; }
.bar.down { background: var(--down); opacity: 1; }
.bar.off { background: var(--off); }
.bar.pending { background: var(--pending); }
.muted { color: var(--muted); }
.btn-sm {
  font: inherit; font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 8px;
  color: var(--fg); background: var(--soft); border: 1px solid var(--line);
}
.btn-sm:hover { border-color: var(--brand); }

/* ---------- live logs: clickable cards and the side drawer ---------- */
.card.has-logs { cursor: pointer; transition: border-color .12s, box-shadow .12s, transform .12s; }
.card.has-logs:hover { box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 35%, transparent), var(--shadow); }
.card.selected { box-shadow: 0 0 0 2px var(--brand), var(--shadow); }
.card-more { position: relative; }
.card-more .log-btn { position: absolute; top: 6px; right: 0; }
.log-btn {
  font-size: 11.5px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  color: var(--brand); background: transparent; border: 1px solid color-mix(in srgb, var(--brand) 40%, transparent);
}
.log-btn:hover, .log-btn:focus-visible { background: color-mix(in srgb, var(--brand) 12%, transparent); outline: none; }

body.drawer-open { overflow: hidden; }
[hidden] { display: none !important; }
.drawer-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(13, 15, 30, .35); }
.drawer {
  --log-bg: #0f1220; --log-fg: #d7dbea; --log-muted: #7c84a3; --log-warn: #f0b44c; --log-err: #ff7b7b;
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(880px, 100%);
  display: flex; flex-direction: column; background: var(--card); border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(13, 15, 30, .25); animation: drawer-in .16s ease-out;
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
}
.drawer-title { display: flex; align-items: center; gap: 12px; min-width: 0; flex-wrap: wrap; }
.drawer-title h2 { font-size: 16px; font-weight: 700; }
.live { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 7px; color: rgba(255, 255, 255, .9); }
.live::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #c9cde0; }
.live.on::before { background: #7ef0ae; box-shadow: 0 0 0 3px rgba(126, 240, 174, .25); animation: pulse 1.6s infinite; }
.live.wait::before { background: #ffd27a; }
.live.off::before { background: #ffb4b4; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(126, 240, 174, 0); } }
@media (prefers-reduced-motion: reduce) { .live.on::before { animation: none; } }
.icon-btn {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; color: #fff;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .3);
}
.icon-btn:hover { background: rgba(255, 255, 255, .24); }
.drawer-tools {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 18px;
  border-bottom: 1px solid var(--line); background: var(--soft);
}
.drawer-tools input, .drawer-tools select {
  font: inherit; font-size: 12.5px; color: var(--fg); background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 9px; outline: none;
}
.drawer-tools input { flex: 1 1 130px; min-width: 0; }
.drawer-tools input:focus, .drawer-tools select:focus { border-color: var(--brand); }
.btn-sm[aria-pressed="true"] { color: #fff; background: var(--pending); border-color: var(--pending); }
.log-view {
  flex: 1; overflow: auto; padding: 8px 0; background: var(--log-bg); color: var(--log-fg); outline: none;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
.ln { display: flex; gap: 12px; padding: 0 18px; white-space: pre-wrap; word-break: break-word; }
.ln:hover { background: rgba(255, 255, 255, .04); }
.ln .ts { flex: none; color: var(--log-muted); font-variant-numeric: tabular-nums; user-select: none; }
.ln .msg { min-width: 0; }
.ln.warn .msg { color: var(--log-warn); }
.ln.err { background: rgba(255, 90, 90, .08); }
.ln.err .msg { color: var(--log-err); }
.ln.sys { color: var(--log-muted); font-style: italic; justify-content: center; padding: 6px 18px; }
.jump {
  position: absolute; right: 26px; bottom: 52px; font: inherit; font-size: 12.5px; font-weight: 700;
  padding: 7px 14px; border-radius: 999px; border: 0; color: #fff; background: var(--brand);
  box-shadow: 0 6px 18px rgba(13, 15, 30, .35);
}
.drawer-foot { padding: 8px 18px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .topbar { padding: 14px 16px; }
  .wrap { padding: 18px 14px 44px; }
  .stat-num { font-size: 26px; }
  .drawer-head, .drawer-tools { padding-left: 16px; padding-right: 16px; }
  .ln { padding: 0 16px; gap: 8px; }
  .ln .ts { display: none; }
}
