:root {
  --bg: #0d1117;
  --panel: #161b22;
  --border: #2d333b;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #76b900;
  --accent-dim: #4e7a00;
  --warn: #e3b341;
  --err: #f85149;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Ubuntu", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 9px; }
img.logo { width: 24px; height: 24px; }
header .who { color: var(--muted); font-size: 13px; }
header button {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 12px;
  margin-left: 12px;
  cursor: pointer;
  font-size: 13px;
}
header button:hover { color: var(--text); border-color: var(--muted); }

main { max-width: 1080px; margin: 0 auto; padding: 22px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.card .value { font-size: 30px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.bar { height: 6px; background: var(--border); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; width: 0; transition: width 0.6s; }
.bar.hot i { background: var(--warn); }

canvas.spark { width: 100%; height: 42px; margin-top: 10px; }

h2 { font-size: 14px; color: var(--muted); margin: 26px 0 12px; text-transform: uppercase; letter-spacing: 0.06em; }

.svc-wrap { margin-bottom: 10px; }

.service {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
}

.service .controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
  max-width: 100%;
  min-width: 0;
}

.svc-wrap:has(.logs.open) .service { border-radius: 10px 10px 0 0; }

select.model {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  flex: 1 1 200px;
  min-width: 0;
  max-width: 340px;
  cursor: pointer;
}
select.model:disabled { opacity: 0.45; cursor: wait; }

.opts { display: flex; gap: 8px; flex-shrink: 0; }
.opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.opt input { margin: 0; accent-color: var(--accent); cursor: pointer; }
.opt input:disabled { cursor: wait; }
.opt:has(input:disabled) { opacity: 0.6; }
.opt .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); }
.opt .dot.running { background: var(--accent); }
.opt .dot.starting { background: var(--warn); }
.opt .dot.unhealthy { background: var(--err); }

.logbtn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.logbtn:hover { color: var(--text); border-color: var(--muted); }

.logs {
  display: none;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  max-height: 320px;
  overflow-y: auto;
  padding: 10px 14px;
  font: 11px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #9da7b3;
}
.logs.open { display: block; }
.logs div { white-space: pre-wrap; word-break: break-all; }

.service .info { flex: 1 1 180px; min-width: 0; }
.service .name { font-weight: 600; font-size: 15px; }
.service .desc { color: var(--muted); font-size: 12px; margin-top: 2px; overflow-wrap: anywhere; }
.service .err { color: var(--err); font-size: 12px; margin-top: 4px; white-space: pre-wrap; }

.badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.badge.running { color: var(--accent); border-color: var(--accent-dim); }
.badge.starting, .badge.stopping { color: var(--warn); border-color: var(--warn); }
.badge.unhealthy { color: var(--err); border-color: var(--err); }

.toggle {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 13px;
  background: var(--border);
  border: none;
  cursor: pointer;
  transition: background 0.25s;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.25s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(20px); }
.toggle:disabled { opacity: 0.45; cursor: wait; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num { font-variant-numeric: tabular-nums; }

.offline {
  display: none;
  background: var(--err);
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: 13px;
}

/* phones: stack the service row, controls get their own full-width line */
@media (max-width: 640px) {
  header { padding: 12px 14px; }
  header h1 { font-size: 15px; }
  header button { padding: 5px 10px; margin-left: 8px; }
  main { padding: 12px; }
  h2 { font-size: 12px; margin: 20px 0 10px; }
  /* stat cards: 2-up instead of a tall single column */
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { padding: 12px; }
  .card .value { font-size: 22px; margin-top: 4px; }
  .card .sub { font-size: 11px; }
  canvas.spark { height: 34px; margin-top: 8px; }
  .bar { margin-top: 8px; }
  /* service rows: info on top, controls on their own full-width line */
  .service { padding: 12px 14px; }
  .service .info { flex-basis: 100%; }
  .service .controls { margin-left: 0; width: 100%; }
  select.model { flex-basis: 100%; max-width: 100%; }
  .logs { max-height: 260px; padding: 8px 10px; font-size: 10.5px; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }
}

/* login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 34px;
  width: 340px;
}
.login h1 { font-size: 19px; margin-bottom: 4px; display: flex; align-items: center; gap: 9px; }
.login .logo { width: 26px; height: 26px; }
.login p { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 5px; }
.login input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button {
  width: 100%;
  margin-top: 22px;
  background: var(--accent);
  color: #0b0e04;
  font-weight: 650;
  border: none;
  border-radius: 7px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
}
.login button:hover { background: #85cc0a; }
.login .msg { color: var(--err); font-size: 13px; margin-top: 12px; min-height: 17px; }
