:root {
  --bg: #080a0f;
  --bg-2: #0d1118;
  --panel: rgba(18, 23, 32, 0.86);
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.12);
  --txt: #e8edf5;
  --muted: #7d8798;
  --ok: #38e8a8;
  --warn: #ffc24b;
  --err: #ff5f6d;
  --crit: #ff3b6b;
  --off: #5b6577;
  --accent: #5aa9ff;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Apple SD Gothic Neo",
    "Malgun Gothic", system-ui, sans-serif;
  --r: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(680px 420px at 12% -8%, rgba(56, 232, 168, 0.09), transparent 62%),
    radial-gradient(720px 460px at 92% 4%, rgba(90, 169, 255, 0.08), transparent 64%),
    linear-gradient(180deg, #080a0f, #06080c 60%, #05070a);
  z-index: -1;
}

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; line-height: 1.6; }

/* ------------------------------------------------------------ splash */
.splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 18px;
  justify-items: center;
  background: var(--bg);
  z-index: 60;
  transition: opacity 0.4s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash p { color: var(--muted); font-size: 13px; letter-spacing: 0.08em; }
.splash-ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(56, 232, 168, 0.18);
  border-top-color: var(--ok);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ shell */
.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 22px 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: linear-gradient(180deg, rgba(22, 28, 38, 0.9), rgba(13, 17, 24, 0.86));
  backdrop-filter: blur(10px);
  position: sticky;
  top: 12px;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(56, 232, 168, 0.1);
  border: 1px solid rgba(56, 232, 168, 0.28);
  color: var(--ok);
  font-size: 19px;
}
.brand h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.16em;
  font-weight: 700;
  font-family: var(--mono);
}
.brand-sub { margin: 2px 0 0; font-size: 11px; color: var(--muted); letter-spacing: 0.02em; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.03);
  font-size: 12px;
  font-family: var(--mono);
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.pill.ghost { color: var(--muted); }
.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--off);
  box-shadow: 0 0 0 0 transparent;
}
.pill[data-state="live"] { color: var(--ok); border-color: rgba(56, 232, 168, 0.35); }
.pill[data-state="live"] .dot {
  background: var(--ok);
  animation: pulse 1.8s ease-out infinite;
}
.pill[data-state="stale"] { color: var(--warn); border-color: rgba(255, 194, 75, 0.35); }
.pill[data-state="stale"] .dot { background: var(--warn); }
.pill[data-state="down"] { color: var(--err); border-color: rgba(255, 95, 109, 0.35); }
.pill[data-state="down"] .dot { background: var(--err); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(56, 232, 168, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(56, 232, 168, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 232, 168, 0); }
}

/* ------------------------------------------------------------ buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.05);
  color: var(--txt);
  font: inherit;
  font-size: 12.5px;
  padding: 8px 13px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.22); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--txt); }
.btn.full { width: 100%; margin-top: 10px; }
.btn.danger { color: var(--err); border-color: rgba(255, 95, 109, 0.3); }
.btn.danger:hover { background: rgba(255, 95, 109, 0.12); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ------------------------------------------------------------ hero */
.main { display: grid; gap: 16px; margin-top: 16px; }

.hero {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 22px;
  padding: 26px 26px 22px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background:
    radial-gradient(560px 260px at 0% 0%, rgba(56, 232, 168, 0.07), transparent 70%),
    linear-gradient(180deg, rgba(20, 26, 35, 0.9), rgba(12, 16, 22, 0.92));
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.014) 0 1px,
    transparent 1px 3px
  );
  pointer-events: none;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px 7px 11px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  border: 1px solid var(--line-2);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}
.badge-led { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-badge[data-sev="ok"] { color: var(--ok); border-color: rgba(56, 232, 168, 0.4); background: rgba(56, 232, 168, 0.09); }
.status-badge[data-sev="warn"] { color: var(--warn); border-color: rgba(255, 194, 75, 0.4); background: rgba(255, 194, 75, 0.09); }
.status-badge[data-sev="error"] { color: var(--err); border-color: rgba(255, 95, 109, 0.42); background: rgba(255, 95, 109, 0.1); }
.status-badge[data-sev="critical"] { color: var(--crit); border-color: rgba(255, 59, 107, 0.5); background: rgba(255, 59, 107, 0.12); }
.status-badge[data-sev="offline"] { color: var(--off); border-color: rgba(91, 101, 119, 0.5); background: rgba(91, 101, 119, 0.12); }
.status-badge[data-sev="error"] .badge-led,
.status-badge[data-sev="critical"] .badge-led { animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

.hero h2 {
  margin: 14px 0 6px;
  font-size: 27px;
  letter-spacing: -0.01em;
  font-weight: 650;
  line-height: 1.22;
}
.hero-desc, #hero-desc { margin: 0; font-size: 13px; color: var(--muted); max-width: 46ch; line-height: 1.6; }

.hero-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
  max-width: 470px;
}
.fact {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 12px;
  background: rgba(0, 0, 0, 0.22);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.fact-k { font-size: 10.5px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }
.fact-v {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--txt);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hero-right { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px; }
.gauge-wrap { position: relative; width: 100%; max-width: 240px; }
.gauge { width: 100%; display: block; overflow: visible; }
.gauge-track, .gauge-fill {
  fill: none;
  stroke-width: 12;
  stroke-linecap: round;
}
.gauge-track { stroke: rgba(255, 255, 255, 0.07); }
.gauge-fill {
  stroke: var(--ok);
  stroke-dasharray: 264;
  stroke-dashoffset: 264;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.2, 0.8, 0.2, 1), stroke 0.4s;
  filter: drop-shadow(0 0 7px rgba(56, 232, 168, 0.45));
}
.gauge-label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  pointer-events: none;
}
.gauge-label strong { display: block; font-size: 25px; font-family: var(--mono); letter-spacing: -0.02em; }
.gauge-label span { font-size: 10.5px; color: var(--muted); letter-spacing: 0.1em; }

.gauge-stats {
  display: flex;
  gap: 22px;
  justify-content: center;
  width: 100%;
}
.gauge-stats > div { text-align: center; }
.gauge-stats b { display: block; font-family: var(--mono); font-size: 16px; }
.gauge-stats span { font-size: 10.5px; color: var(--muted); }

/* ------------------------------------------------------------ cards */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  backdrop-filter: blur(8px);
  padding: 18px 18px 16px;
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.card-actions { display: flex; align-items: center; gap: 10px; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  overflow: hidden;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-family: var(--mono);
  padding: 5px 10px;
  cursor: pointer;
}
.seg button.on { background: rgba(56, 232, 168, 0.14); color: var(--ok); }
.seg button:hover:not(.on) { color: var(--txt); }

.chart-host { position: relative; height: 190px; }
.chart-host canvas { width: 100%; height: 190px; display: block; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.chart-empty[hidden] { display: none; }

/* ------------------------------------------------------------ supplies */
.supply-list { display: grid; gap: 9px; }
.supply {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
}
.supply-name { font-size: 12.5px; }
.supply-val { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.supply-bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.supply-bar i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--ok), #7cf0c6);
  transition: width 0.6s ease;
}
.supply-bar[data-level="low"] i { background: linear-gradient(90deg, var(--warn), #ffd98a); }
.supply-bar[data-level="empty"] i { background: linear-gradient(90deg, var(--err), #ff9aa4); }

/* ------------------------------------------------------------ rules */
.rule-list, .job-list, .timeline { list-style: none; margin: 0; padding: 0; }
.rule-list { display: grid; gap: 9px; max-height: 330px; overflow-y: auto; }
.rule-item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.18);
  display: grid;
  gap: 6px;
}
.rule-top { display: flex; align-items: center; gap: 9px; justify-content: space-between; }
.rule-name { font-size: 12.5px; font-weight: 600; }
.rule-trigger {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rule-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(90, 169, 255, 0.1);
  border: 1px solid rgba(90, 169, 255, 0.2);
  color: #9cc9ff;
}
.chip.fire { background: rgba(255, 194, 75, 0.1); border-color: rgba(255, 194, 75, 0.25); color: #ffd98a; }

.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.switch input { accent-color: var(--ok); width: 14px; height: 14px; }

.toggle {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.2s;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #9aa4b4;
  transition: transform 0.2s, background 0.2s;
}
.toggle[aria-checked="true"] { background: rgba(56, 232, 168, 0.35); }
.toggle[aria-checked="true"]::after { transform: translateX(14px); background: var(--ok); }

/* ------------------------------------------------------------ jobs */
.job-list { display: grid; gap: 6px; max-height: 250px; overflow-y: auto; }
.job {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
}
.job-code { font-family: var(--mono); font-size: 11.5px; }
.job-time { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.st {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 5px;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.st[data-s="queued"] { color: var(--muted); border-color: var(--line-2); }
.st[data-s="running"] { color: var(--accent); border-color: rgba(90, 169, 255, 0.35); background: rgba(90, 169, 255, 0.1); }
.st[data-s="ok"] { color: var(--ok); border-color: rgba(56, 232, 168, 0.3); background: rgba(56, 232, 168, 0.08); }
.st[data-s="fail"] { color: var(--err); border-color: rgba(255, 95, 109, 0.3); background: rgba(255, 95, 109, 0.08); }
.st[data-s="skip"] { color: var(--off); border-color: rgba(91, 101, 119, 0.35); }

.cmd-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }

/* ------------------------------------------------------------ admin token */
.token-row {
  display: flex;
  gap: 7px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.input {
  flex: 1 1 220px;
  min-width: 0;
  font: inherit;
  font-size: 12.5px;
  font-family: var(--mono);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: rgba(0, 0, 0, 0.32);
  color: var(--txt);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.input::placeholder { color: var(--off); }
.input:focus {
  border-color: rgba(56, 232, 168, 0.5);
  background: rgba(0, 0, 0, 0.45);
}
#admin-status[data-state="ok"] { color: var(--ok); border-color: rgba(56, 232, 168, 0.35); }
#admin-status[data-state="bad"] { color: var(--err); border-color: rgba(255, 95, 109, 0.35); }

/* ------------------------------------------------------------ timeline */
.timeline { display: grid; gap: 0; max-height: 420px; overflow-y: auto; padding-left: 4px; }
.ev {
  display: grid;
  grid-template-columns: 88px 12px 1fr;
  gap: 10px;
  padding: 8px 0;
  align-items: start;
  position: relative;
}
.ev-time { font-family: var(--mono); font-size: 10.5px; color: var(--muted); padding-top: 2px; }
.ev-rail { position: relative; height: 100%; display: flex; justify-content: center; }
.ev-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  background: var(--off);
  z-index: 1;
  box-shadow: 0 0 0 3px var(--bg-2);
}
.ev-rail::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: -8px;
  width: 1px;
  background: var(--line-2);
}
.ev:last-child .ev-rail::before { display: none; }
.ev[data-sev="info"] .ev-dot { background: var(--accent); }
.ev[data-sev="warn"] .ev-dot { background: var(--warn); }
.ev[data-sev="error"] .ev-dot { background: var(--err); }
.ev[data-sev="critical"] .ev-dot { background: var(--crit); box-shadow: 0 0 0 3px var(--bg-2), 0 0 10px var(--crit); }
.ev[data-sev="ok"] .ev-dot, .ev[data-kind="recovery"] .ev-dot { background: var(--ok); }
.ev-body { display: grid; gap: 2px; min-width: 0; }
.ev-msg { font-size: 12.5px; line-height: 1.45; word-break: break-word; }
.ev-meta { font-family: var(--mono); font-size: 10px; color: var(--muted); letter-spacing: 0.03em; }
.ev.unacked .ev-msg { font-weight: 600; }
.ev.unacked .ev-msg::after {
  content: "NEW";
  font-family: var(--mono);
  font-size: 8.5px;
  color: var(--ok);
  border: 1px solid rgba(56, 232, 168, 0.4);
  border-radius: 4px;
  padding: 1px 4px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* ------------------------------------------------------------ code */
.code {
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.7;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 12px 0 0;
  color: #b8c6d9;
}

/* ------------------------------------------------------------ footer */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  flex-wrap: wrap;
}

/* ------------------------------------------------------------ toast */
.toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: grid;
  gap: 8px;
  z-index: 80;
  max-width: min(360px, calc(100vw - 40px));
}
.toast {
  padding: 11px 14px;
  border-radius: 11px;
  border: 1px solid var(--line-2);
  background: rgba(20, 26, 35, 0.96);
  backdrop-filter: blur(10px);
  font-size: 12.5px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s ease;
  border-left: 3px solid var(--accent);
}
.toast[data-k="ok"] { border-left-color: var(--ok); }
.toast[data-k="err"] { border-left-color: var(--err); }
.toast[data-k="warn"] { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------ scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* ------------------------------------------------------------ responsive */
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; }
  .hero-right { flex-direction: row; justify-content: space-between; align-items: center; }
  .gauge-wrap { max-width: 180px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .shell { padding: 12px 12px 40px; }
  .topbar { flex-wrap: wrap; top: 6px; }
  .brand-sub { display: none; }
  .hero { padding: 20px 18px 18px; }
  .hero h2 { font-size: 22px; }
  .hero-right { flex-direction: column; }
  .ev { grid-template-columns: 62px 12px 1fr; gap: 8px; }
  .hero-facts { grid-template-columns: 1fr 1fr; }
}
