:root {
  --bg: #0b0e14;
  --bg-1: #11151f;
  --bg-2: #171c28;
  --bg-3: #1f2634;
  --line: #262e3d;
  --line-soft: #1c2331;
  --text: #e4e8f1;
  --dim: #97a1b5;
  --faint: #66708a;
  --accent: #6aa2ff;
  --accent-dim: #2a4270;
  --ok: #3ddc97;
  --warn: #f4bf50;
  --crit: #ff6b6b;
  --purple: #b98cff;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---------------------------------------------------------------- shell -- */

#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 650;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand .dot {
  width: 26px; height: 26px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center;
  font-size: 14px; font-weight: 800;
  color: #0b0e14;
}

.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--dim);
  font-weight: 500;
}
.nav a:hover { background: var(--bg-2); color: var(--text); text-decoration: none; }
.nav a.on { background: var(--accent-dim); color: #fff; }
.nav .count {
  font-size: 11px;
  background: var(--bg-3);
  color: var(--dim);
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.nav a.on .count { background: rgba(255,255,255,.18); color: #fff; }

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }
.topbar .sub { color: var(--faint); font-size: 13px; }
.topbar .spacer { flex: 1; }

.content { padding: 20px 24px 60px; }

/* ------------------------------------------------------------ elements -- */

.btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
  font-weight: 550;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: #35405400; border-color: #354054; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #08101f; }
.btn.primary:hover { background: #7fb0ff; }
.btn.danger { color: var(--crit); border-color: #4a2830; }
.btn.danger:hover { background: #2a1a1f; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }

input[type=text], input[type=password], input[type=search], select, textarea {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 76px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--dim); margin-bottom: 5px; }

.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.card > h3 {
  margin: 0;
  padding: 11px 15px;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--dim);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.card > h3 .when { text-transform: none; letter-spacing: 0; font-weight: 450; color: var(--faint); }
.card .body { padding: 13px 15px; }

.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--dim); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.small { font-size: 12.5px; }

/* Definition rows inside panels. Capped so a wide card does not strand the
   value half a screen away from its label. */
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 5px 12px; max-width: 620px; }
.kv dt { color: var(--faint); font-size: 12.5px; }
.kv dd { margin: 0; word-break: break-word; font-size: 13px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-3);
  color: var(--dim);
  white-space: nowrap;
}
.pill.ok { background: rgba(61,220,151,.13); color: var(--ok); }
.pill.warn { background: rgba(244,191,80,.13); color: var(--warn); }
.pill.crit { background: rgba(255,107,107,.14); color: var(--crit); }
.pill.info { background: rgba(106,162,255,.13); color: var(--accent); }

.dot-status {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--faint);
  flex: 0 0 8px;
}
.dot-status.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(61,220,151,.16); }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--faint);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg-1);
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: middle; }
tbody tr:hover { background: var(--bg-2); }
tbody tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }

.bar { height: 5px; background: var(--bg-3); border-radius: 3px; overflow: hidden; min-width: 54px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar > i.warn { background: var(--warn); }
.bar > i.crit { background: var(--crit); }

.empty { padding: 40px 20px; text-align: center; color: var(--faint); }

/* Wide content scrolls in its own box; the page itself never scrolls sideways. */
.scroll-x { overflow-x: auto; max-width: 100%; }
.scroll-x > table { min-width: 420px; }

/* ------------------------------------------------------------- machine -- */

.machine-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--co, var(--accent));
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.machine-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.machine-card.off { opacity: .62; }
.machine-card h4 { margin: 0 0 2px; font-size: 14.5px; font-weight: 620; }

.stat { display: flex; flex-direction: column; gap: 3px; }
.stat .n { font-size: 22px; font-weight: 660; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11.5px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }

/* -------------------------------------------------------------- remote -- */

.remote-wrap {
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 380px;
}
.remote-wrap canvas { display: block; max-width: 100%; max-height: calc(100vh - 230px); cursor: crosshair; }
.remote-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(11,14,20,.82);
  color: var(--dim);
  text-align: center;
  padding: 20px;
}

/* ------------------------------------------------------------ terminal -- */

.term {
  background: #05070c;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 58vh;
  overflow-y: auto;
}
.term .cmd { color: var(--accent); }
.term .err { color: var(--crit); }
.term .meta { color: var(--faint); }

/* -------------------------------------------------------------- ticket -- */

.ticket-row { cursor: pointer; }
.ticket-row td:first-child { font-family: var(--mono); color: var(--faint); font-size: 12px; }

.comment {
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 12px;
  margin-bottom: 12px;
}
.comment .who { font-size: 12px; color: var(--faint); margin-bottom: 3px; }

/* --------------------------------------------------------------- modal -- */

.modal-back {
  position: fixed; inset: 0;
  background: rgba(4,6,11,.72);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal h2 { margin: 0; padding: 16px 20px; font-size: 16px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 18px 20px; }
.modal .foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex; gap: 9px; justify-content: flex-end;
}

/* -------------------------------------------------------------- toasts -- */

#toasts {
  position: fixed; right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 9px;
  z-index: 200;
}
.toast {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  padding: 11px 15px;
  min-width: 250px;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,.42);
  animation: slidein .2s ease;
}
.toast.bad { border-left-color: var(--crit); }
.toast.good { border-left-color: var(--ok); }
@keyframes slidein { from { opacity: 0; transform: translateX(16px); } }

/* --------------------------------------------------------------- login -- */

.login-page {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(1100px 620px at 50% -8%, #16203a 0%, var(--bg) 60%);
}
.login-box {
  width: min(370px, 92vw);
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 30px;
  box-shadow: 0 24px 70px rgba(0,0,0,.5);
}
.login-box .brand { padding: 0 0 6px; font-size: 22px; }
.login-box p { margin: 0 0 22px; color: var(--faint); font-size: 13px; }
.login-box .err { color: var(--crit); font-size: 13px; min-height: 19px; margin-top: 10px; }

@media (max-width: 780px) {
  .sidebar { display: none; }
  .content { padding: 16px 14px 50px; }
  .topbar { padding: 14px 16px; }
  .kv { grid-template-columns: 1fr; gap: 1px 0; }
  .kv dd { margin-bottom: 8px; }
}
