*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f1419;
  color: #e4e8ee;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: #5aa9e6; text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: #1f6feb;
  color: #fff;
  padding: 9px 16px;
  border-radius: 6px;
  font-weight: 500;
  transition: background 120ms;
}
button:hover { background: #2a7cf0; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; color: #9aa5b5; border: 1px solid #2d3644; }
button.ghost:hover { background: #1b2129; color: #e4e8ee; }
button.danger { background: #c93c3c; }
button.danger:hover { background: #dc4545; }
input, select, textarea {
  font: inherit;
  background: #0b0f14;
  color: #e4e8ee;
  border: 1px solid #2d3644;
  border-radius: 6px;
  padding: 9px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #1f6feb; outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 12px; color: #9aa5b5; margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 14px; }
.card {
  background: #171c24;
  border: 1px solid #232a35;
  border-radius: 10px;
  padding: 22px;
}
.muted { color: #9aa5b5; }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.pill.green { background: rgba(46, 160, 67, 0.15); color: #5ed67a; }
.pill.red { background: rgba(201, 60, 60, 0.15); color: #ff7878; }
.pill.gray { background: rgba(154, 165, 181, 0.12); color: #9aa5b5; }
.pill.blue { background: rgba(31, 111, 235, 0.15); color: #6caeff; }

/* ────── LOGIN ────── */
.login-root {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f1419 0%, #11212f 100%);
}
.login-box {
  width: 380px;
  max-width: 92vw;
  padding: 32px;
  background: #171c24;
  border: 1px solid #232a35;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.login-box h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
}
.login-box .sub { color: #9aa5b5; margin-bottom: 22px; font-size: 13px; }
.login-box button { width: 100%; padding: 11px; margin-top: 6px; }
.logo {
  width: 46px; height: 46px; border-radius: 10px;
  background: linear-gradient(135deg, #1f6feb, #5aa9e6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 20px;
  margin-bottom: 14px;
}
.error {
  background: rgba(201, 60, 60, 0.1);
  border: 1px solid rgba(201, 60, 60, 0.3);
  color: #ff7878;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}
.success {
  background: rgba(46, 160, 67, 0.1);
  border: 1px solid rgba(46, 160, 67, 0.3);
  color: #5ed67a;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ────── LAYOUT ────── */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: #0b0f14;
  border-right: 1px solid #1a1f28;
  padding: 18px 0;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  padding: 0 20px 20px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #1a1f28;
  margin-bottom: 12px;
}
.sidebar .brand .logo { width: 32px; height: 32px; font-size: 14px; margin: 0; }
.sidebar .brand .name { font-weight: 600; font-size: 14px; }
.sidebar nav a {
  display: block;
  color: #9aa5b5;
  padding: 9px 20px;
  font-size: 14px;
  border-left: 2px solid transparent;
  transition: all 100ms;
}
.sidebar nav a:hover { background: #11151c; color: #e4e8ee; text-decoration: none; }
.sidebar nav a.active {
  background: #11151c;
  color: #fff;
  border-left-color: #1f6feb;
  font-weight: 500;
}
.sidebar .footer {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid #1a1f28;
  font-size: 12px;
  color: #9aa5b5;
}
.sidebar .footer .me { color: #e4e8ee; font-weight: 500; margin-bottom: 4px; font-size: 13px; word-break: break-all; }
.sidebar .footer a { display: block; color: #9aa5b5; padding: 4px 0; }

.main { padding: 28px 32px; max-width: 1400px; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h2 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.3px; }

/* ────── TABLE ────── */
table { width: 100%; border-collapse: collapse; }
table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9aa5b5;
  padding: 10px 14px;
  border-bottom: 1px solid #232a35;
  background: #11151c;
}
table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #1a1f28;
  vertical-align: middle;
}
table tbody tr:hover { background: #11151c; }
table tbody tr.clickable { cursor: pointer; }

/* ────── MACHINES GRID ────── */
.machines-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.machine-card {
  background: #171c24;
  border: 1px solid #232a35;
  border-radius: 10px;
  padding: 16px;
  transition: border-color 120ms;
  cursor: pointer;
}
.machine-card:hover { border-color: #2d3644; }
.machine-card .mc-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 10px;
}
.machine-card .mc-name { font-weight: 600; font-size: 15px; margin-bottom: 2px; }
.machine-card .mc-pc { font-size: 12px; color: #9aa5b5; font-family: ui-monospace, Menlo, monospace; }
.machine-card .mc-meta { font-size: 12px; color: #9aa5b5; margin-top: 8px; }
.machine-card .mc-meta span { margin-right: 10px; }

/* ────── MODAL ────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: #171c24;
  border: 1px solid #232a35;
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ────── VIEWER ────── */
.viewer-root {
  position: fixed; inset: 0;
  background: #000;
  display: flex; flex-direction: column;
  z-index: 200;
}
.viewer-header {
  background: #0b0f14;
  border-bottom: 1px solid #1a1f28;
  padding: 8px 14px;
  display: flex; align-items: center; justify-content: space-between;
  color: #e4e8ee;
  gap: 10px;
  flex-wrap: wrap;
}
.viewer-header .vh-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.viewer-header .vh-title { font-weight: 600; }
.viewer-header .vh-status { font-size: 12px; color: #9aa5b5; }
.viewer-header .vh-ctrls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.viewer-header .vh-sel, .viewer-header .vh-fps {
  background: #0b0f14; color: #e4e8ee; border: 1px solid #2d3644; border-radius: 4px;
  font-size: 12px; padding: 4px 6px;
}
.viewer-header .vh-fps { width: 60px; }
.viewer-header button.small { font-size: 12px; padding: 4px 10px; }
.viewer-header button.pulse { animation: vhpulse 1s infinite; }
@keyframes vhpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(60,160,255,.8); } 50% { box-shadow: 0 0 0 6px rgba(60,160,255,0); } }

.viewer-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
  min-height: 0;
}
.vh-stage {
  flex: 1;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  overflow: hidden;
}
.vh-canvas {
  display: block;
  max-width: 100%; max-height: 100%;
  outline: none;
  cursor: crosshair;
  image-rendering: pixelated;
}
.vh-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #9aa5b5; background: rgba(0,0,0,.5); font-size: 14px;
  pointer-events: none;
}
.vh-stats {
  position: absolute; right: 8px; top: 8px;
  background: rgba(11,15,20,.8);
  color: #9aa5b5;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  pointer-events: none;
}
.vh-side {
  width: 340px;
  background: #0b0f14;
  border-left: 1px solid #1a1f28;
  display: flex; flex-direction: column;
  color: #e4e8ee;
}
.vh-side-header { padding: 10px 14px; border-bottom: 1px solid #1a1f28; font-weight: 600; }
.vh-file-nav { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid #1a1f28; }
.vh-file-nav .vh-file-path {
  flex: 1; background: #0b0f14; color: #e4e8ee; border: 1px solid #2d3644;
  border-radius: 4px; padding: 4px 6px; font-size: 12px;
}
.vh-file-list { flex: 1; overflow: auto; font-size: 13px; }
.vh-file-row { padding: 4px 10px; display: flex; justify-content: space-between; cursor: default; border-bottom: 1px solid #11161e; }
.vh-file-row.dir { cursor: pointer; color: #9ec5ff; }
.vh-file-row:hover { background: #131a24; }
.vh-chat-log { flex: 1; overflow: auto; padding: 8px 12px; font-size: 13px; }
.vh-chat-me { color: #9ec5ff; margin: 4px 0; }
.vh-chat-them { color: #e4e8ee; margin: 4px 0; }
.vh-chat-input {
  margin: 8px; background: #0b0f14; color: #e4e8ee; border: 1px solid #2d3644;
  border-radius: 4px; padding: 6px 8px; font-size: 13px;
}

.kbd {
  display: inline-block;
  background: #0b0f14;
  border: 1px solid #2d3644;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}
pre {
  background: #0b0f14;
  border: 1px solid #232a35;
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 12px;
  user-select: all;
}
