/* ==========================================================================
   Ender 3 V3 KE - Control Panel
   Design language: an instrument panel, not a SaaS marketing page. Two
   typefaces split the labor - Space Grotesk carries the human-facing UI
   (nav, labels, buttons), JetBrains Mono renders every live value (temps,
   coordinates, durations, gcode) the way a machine reports it.
   ========================================================================== */

:root {
  /* --- Color: graphite chassis + functional signal colors -------------- */
  --bg: #14181e;
  --bg-raised: #1a1f26;
  --panel: #1d232b;
  --panel-hover: #232a33;
  --border: #2c333d;
  --border-strong: #3a4350;

  --text: #e9ecf1;
  --text-muted: #97a1b0;
  --text-dim: #5c6572;

  --copper: #e8672e;      /* heat: nozzle / bed / active heating */
  --copper-dim: #6b3a24;
  --teal: #4fbf9f;         /* motion, success, connected */
  --teal-dim: #285147;
  --amber: #e8b339;        /* caution, auto-controlled, paused */
  --red: #e1503f;          /* stop, error, destructive */
  --red-dim: #4a231e;
  --blue: #5b8def;         /* informational accents, links */

  /* --- Type --------------------------------------------------------------*/
  --font-ui: "Space Grotesk", "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;

  /* --- Metrics ------------------------------------------------------------*/
  --radius: 5px;
  --radius-sm: 3px;
  --rail-w: 216px;
  --topbar-h: 60px;
  --gap: 18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--copper); color: #14181e; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

button, input, select, textarea { font-family: inherit; color: inherit; }

a { color: var(--blue); }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

p { margin: 0 0 8px; color: var(--text-muted); }

/* ==========================================================================
   App shell
   ========================================================================== */

#app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
}

.railnav {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 2px 8px 14px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
}

.conn-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex: none;
  box-shadow: 0 0 0 3px transparent;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.conn-dot.ok { background: var(--teal); box-shadow: 0 0 0 3px var(--teal-dim); }
.conn-dot.warn { background: var(--amber); box-shadow: 0 0 0 3px #4a3d1c; }
.conn-dot.err { background: var(--red); box-shadow: 0 0 0 3px var(--red-dim); }

.conn-text { color: var(--text-muted); }

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-btn svg { width: 16px; height: 16px; flex: none; opacity: 0.85; }

.nav-btn:hover { background: var(--panel-hover); color: var(--text); }

.nav-btn.active {
  background: var(--panel);
  border-color: var(--border-strong);
  color: var(--text);
}

.nav-btn.active::before { content: ""; }

a.nav-btn {
  text-decoration: none;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  border-radius: 0;
  padding-top: 14px;
}

a.nav-btn:hover { color: var(--copper); }

.rail-foot {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
  padding: 0 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ==========================================================================
   Main column
   ========================================================================== */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 20px;
  position: sticky;
  top: 0;
  background: rgba(20, 24, 30, 0.92);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.topbar h1 { font-size: 16px; }

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

.job-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--panel);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.job-pill .job-name { color: var(--text); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.job-pill .job-bar {
  width: 64px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  overflow: hidden;
}

.job-pill .job-bar > span {
  display: block;
  height: 100%;
  background: var(--teal);
}

.estop {
  background: var(--red);
  color: #1a0e0c;
  border: none;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.03em;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.05s ease;
}

.estop:hover { filter: brightness(1.1); }
.estop:active { transform: translateY(1px); }

#content {
  padding: 24px;
  flex: 1;
  min-width: 0;
}

.tab { display: none; }
.tab.active { display: block; }

/* ==========================================================================
   Grid / panel primitives
   ========================================================================== */

.grid {
  display: grid;
  gap: var(--gap);
}

.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-12 { grid-template-columns: repeat(12, 1fr); }

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

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.panel-hint {
  font-size: 11.5px;
  color: var(--text-dim);
}

.section-block + .section-block { margin-top: var(--gap); }

/* ==========================================================================
   Temp cards
   ========================================================================== */

.temp-card .temp-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.temp-label { font-size: 13px; font-weight: 600; }

.temp-state {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}

.temp-state.heating { color: var(--copper); border-color: var(--copper-dim); background: rgba(232, 103, 46, 0.08); }
.temp-state.idle { color: var(--text-dim); }

.temp-reading {
  font-family: var(--font-mono);
  font-size: 38px;
  font-weight: 500;
  margin: 10px 0 2px;
  color: var(--text);
  letter-spacing: -0.02em;
}

.temp-reading .unit { font-size: 20px; color: var(--text-muted); }

.temp-target {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.temp-target .val { color: var(--copper); }

.preset-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.custom-row { display: flex; gap: 8px; }

/* ==========================================================================
   Buttons & form controls
   ========================================================================== */

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}

.btn:hover { background: var(--panel-hover); border-color: var(--text-dim); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--copper); border-color: var(--copper); color: #1c0f08; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); background: var(--copper); }

.btn-teal { background: var(--teal); border-color: var(--teal); color: #0b1c17; font-weight: 600; }
.btn-teal:hover { filter: brightness(1.08); background: var(--teal); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }

.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(225, 80, 63, 0.1); }

.btn-sm { padding: 5px 10px; font-size: 11.5px; }
.btn-block { width: 100%; justify-content: center; display: inline-flex; }
.btn-icon { padding: 8px; display: inline-flex; align-items: center; justify-content: center; }

.field {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 8px 10px;
  width: 100%;
}

.field:focus { border-color: var(--blue); }

.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 5px;
  font-family: var(--font-ui);
}

.inline-field { display: flex; flex-direction: column; gap: 0; }

/* segmented control (step size etc) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.segmented button {
  appearance: none;
  border: none;
  background: var(--bg-raised);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 12px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}

.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--copper); color: #1c0f08; font-weight: 600; }
.segmented button:hover:not(.active) { background: var(--panel-hover); color: var(--text); }

/* slider */
.slider-row { display: flex; align-items: center; gap: 12px; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid #0e1a16;
}

input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid #0e1a16;
}

.slider-val {
  font-family: var(--font-mono);
  font-size: 13px;
  width: 42px;
  text-align: right;
  color: var(--text);
}

/* ==========================================================================
   Dashboard specifics
   ========================================================================== */

.graph-panel canvas { width: 100%; height: 200px; display: block; }

.legend { display: flex; gap: 16px; margin-top: 10px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.legend-swatch { width: 10px; height: 2px; border-radius: 1px; }

.pos-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pos-axis { background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; text-align: center; }
.pos-axis .axis-name { font-size: 11px; color: var(--text-dim); letter-spacing: 0.04em; }
.pos-axis .axis-val { font-family: var(--font-mono); font-size: 19px; margin-top: 4px; }
.pos-axis.homed .axis-val { color: var(--teal); }
.pos-axis.unhomed .axis-val { color: var(--text-dim); }

.job-body { display: flex; gap: 16px; }

.job-thumb {
  position: relative;
  width: 108px;
  height: 108px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-raised);
}

.thumb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.thumb-img.loaded { display: block; }

/* Dimmed/grayscale base always visible once a thumbnail exists - the
   colored "reveal" layer is clipped to grow up from the bottom as the print
   progresses, echoing how an FDM print is actually built: layer by layer,
   bottom to top. */
.thumb-base { filter: grayscale(1) brightness(0.4); }
.thumb-reveal { transition: clip-path 0.6s ease; }

.thumb-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  padding: 8px;
}

.thumb-empty.hidden { display: none; }

.job-info { flex: 1; min-width: 0; }

.job-state-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.job-state-badge {  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  text-transform: lowercase;
}
.job-state-badge.printing { color: var(--teal); border-color: var(--teal-dim); background: rgba(79, 191, 159, 0.08); }
.job-state-badge.paused { color: var(--amber); border-color: #4a3d1c; background: rgba(232, 179, 57, 0.08); }
.job-state-badge.error { color: var(--red); border-color: var(--red-dim); background: rgba(225, 80, 63, 0.08); }

.job-filename { font-family: var(--font-mono); font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.job-progress-track { height: 6px; border-radius: 3px; background: var(--bg-raised); border: 1px solid var(--border); overflow: hidden; margin: 12px 0; }
.job-progress-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--blue)); }

.job-meta-row { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); margin-bottom: 14px; }

.job-actions { display: flex; gap: 8px; }

.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.preview3d-wrap {
  position: relative;
  height: 460px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-raised);
}

.preview3d-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.preview3d-wrap canvas:active { cursor: grabbing; }

.preview3d-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--bg-raised);
  text-align: center;
  padding: 20px;
  pointer-events: none;
}

.preview3d-empty.hidden { display: none; }

.empty-state {
  color: var(--text-dim);
  font-size: 12.5px;
  padding: 22px 10px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Control tab
   ========================================================================== */

.jog-wrap { display: flex; gap: 28px; flex-wrap: wrap; }

.jog-pad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 6px;
}

.jog-pad button {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.jog-pad button:hover { background: var(--panel-hover); border-color: var(--border-strong); }
.jog-pad button svg { width: 18px; height: 18px; }
.jog-pad .jog-home { color: var(--copper); font-family: var(--font-mono); font-size: 11px; font-weight: 700; }

.z-col { display: grid; grid-template-rows: repeat(3, 52px); gap: 6px; }
.z-col button {
  width: 52px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.z-col button:hover { background: var(--panel-hover); border-color: var(--border-strong); }
.z-col .z-label { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); display: flex; align-items: center; justify-content: center; }

.jog-controls-col { display: flex; flex-direction: column; gap: 14px; }

.fan-row { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.fan-row:last-child { border-bottom: none; }
.fan-row-head { display: flex; justify-content: space-between; align-items: center; }
.fan-name { font-size: 12.5px; font-weight: 600; }
.fan-auto-badge { font-family: var(--font-mono); font-size: 10px; color: var(--amber); border: 1px solid #4a3d1c; padding: 1px 7px; border-radius: 999px; }

/* ==========================================================================
   Files
   ========================================================================== */

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 26px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.dropzone.drag { border-color: var(--teal); background: rgba(79, 191, 159, 0.05); color: var(--text); }

.upload-progress { margin-top: 12px; display: none; }
.upload-progress.active { display: block; }
.upload-progress .job-progress-track { margin: 6px 0; }

table.file-table { width: 100%; border-collapse: collapse; }
table.file-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.file-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
table.file-table tr:last-child td { border-bottom: none; }
table.file-table td.mono, table.file-table th.mono { font-family: var(--font-mono); }
table.file-table tr.printing td { background: rgba(79, 191, 159, 0.05); }
table.file-table .file-name { display: flex; align-items: center; gap: 10px; }
table.file-table .file-thumb {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--bg-raised);
}
table.file-table .row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ==========================================================================
   Macros
   ========================================================================== */

.macro-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.macro-btn {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 12px;
  cursor: pointer;
}
.macro-btn:hover { border-color: var(--copper); color: var(--copper); }

.macro-params { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; margin-top: 14px; background: var(--bg-raised); }
.param-row { display: flex; gap: 8px; margin-bottom: 8px; }
.param-row .field { flex: 1; }

textarea.field { resize: vertical; min-height: 110px; font-size: 12.5px; line-height: 1.5; }

/* ==========================================================================
   Console
   ========================================================================== */

.console-log {
  background: #0f1318;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  height: 420px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.65;
}

.console-line { display: flex; gap: 10px; }
.console-line .t { color: var(--text-dim); flex: none; }
.console-line .m { color: var(--text-muted); word-break: break-word; }
.console-line.evt .m { color: var(--teal); }
.console-line.err .m { color: var(--red); }
.console-line.sent .m { color: var(--text); }
.console-line.sent .m::before { content: "\2192  "; color: var(--copper); }

.console-input-row { display: flex; gap: 8px; margin-top: 12px; }
.console-input-row .field { font-size: 13px; }

/* ==========================================================================
   System
   ========================================================================== */

.kv-table { width: 100%; border-collapse: collapse; }
.kv-table td { padding: 8px 4px; font-size: 12.5px; border-bottom: 1px solid var(--border); vertical-align: top; }
.kv-table tr:last-child td { border-bottom: none; }
.kv-table td:first-child { color: var(--text-dim); width: 40%; padding-right: 8px; font-weight: 500; }
.kv-table td:last-child { font-family: var(--font-mono); color: var(--text); word-break: break-word; overflow-wrap: anywhere; }

.device-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.device-row:last-child { border-bottom: none; }
.device-name { font-size: 12.5px; font-weight: 500; }
.device-status { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.device-status.on { color: var(--teal); }

.warn-banner {
  border: 1px solid #4a3d1c;
  background: rgba(232, 179, 57, 0.07);
  color: var(--amber);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 14px;
}

/* ==========================================================================
   Auth & API Keys Management Styles
   ========================================================================== */

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-hover);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-status.active {
  background: rgba(16, 185, 129, 0.12);
  color: var(--teal);
  border-color: rgba(16, 185, 129, 0.3);
}

.auth-key-section {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.auth-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.key-field-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.key-token-field {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--panel);
  color: var(--teal);
  cursor: text;
}

.field-hint {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 6px;
  line-height: 1.4;
}

.field-hint code {
  font-family: var(--font-mono);
  color: var(--orange);
  background: var(--panel);
  padding: 1px 4px;
  border-radius: 3px;
}

.add-key-card {
  background: var(--panel);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 10px;
}

.add-key-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-key-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.api-keys-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.api-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  gap: 8px;
}

.api-key-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.api-key-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.api-key-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.api-key-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.code-snippets-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.snippet-tabs {
  display: flex;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.snippet-tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11.5px;
  font-family: var(--font-mono);
  padding: 6px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.snippet-tab:hover {
  color: var(--text);
}

.snippet-tab.active {
  color: var(--orange);
  border-bottom-color: var(--orange);
  background: var(--panel);
}

.snippet-code-wrapper {
  position: relative;
  padding: 10px 12px;
}

.snippet-code-wrapper pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
}

.copy-snippet-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* ==========================================================================
   Toasts & modal
   ========================================================================== */

#toast-root {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--teal);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  min-width: 240px;
  max-width: 340px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.18s ease;
}

.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 15, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 22px;
  width: 360px;
  max-width: calc(100vw - 40px);
}

.modal-box h3 { font-size: 14.5px; margin-bottom: 8px; }
.modal-box p { font-size: 12.5px; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 980px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .jog-wrap { justify-content: center; }
}

@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  .railnav {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 12px;
  }
  .brand, .rail-foot { display: none; }
  .nav-list { flex-direction: row; }
  .conn-row { flex: none; }
  #content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .job-pill .job-name { max-width: 100px; }
}

/* ==========================================================================
   Docs page
   ========================================================================== */

.docs-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 760px);
  gap: 48px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 24px 80px;
  align-items: start;
}

.docs-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.btn-agent-docs {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #e8672e 0%, #d34a10 100%);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 14px rgba(232, 103, 46, 0.35);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-decoration: none;
}

.btn-agent-docs:hover {
  background: linear-gradient(135deg, #ff7b42 0%, #e8672e 100%);
  box-shadow: 0 6px 20px rgba(232, 103, 46, 0.5);
  transform: translateY(-1px);
}

.btn-agent-docs:active {
  transform: translateY(0);
}

.btn-agent-docs svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.docs-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  text-decoration: none;
  margin-bottom: 18px;
}
.docs-back:hover { color: var(--copper); }

.docs-toc {
  position: sticky;
  top: 24px;
  border-right: 1px solid var(--border);
  padding-right: 20px;
}

.docs-toc .brand-mark { font-size: 14px; margin-bottom: 2px; }
.docs-toc .brand-sub { margin-bottom: 18px; }

.docs-toc nav { display: flex; flex-direction: column; gap: 2px; }
.docs-toc a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12.5px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
}
.docs-toc a:hover { color: var(--text); background: var(--panel-hover); }

.docs-toc .toc-group-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 14px 0 4px 8px;
}
.docs-toc .toc-group-label:first-child { margin-top: 0; }

.docs-main h1 {
  font-size: 26px;
  margin-bottom: 8px;
}

.docs-lede {
  color: var(--text-muted);
  font-size: 13.5px;
  max-width: 62ch;
  margin-bottom: 28px;
}

.docs-notice {
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--blue);
  background: var(--panel);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.doc-group {
  margin-bottom: 44px;
  scroll-margin-top: 24px;
}

.doc-group > h2 {
  font-size: 17px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.doc-group > p.group-desc {
  font-size: 12.5px;
  margin-bottom: 18px;
  max-width: 62ch;
}

.endpoint {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 16px 18px;
  margin-bottom: 14px;
  scroll-margin-top: 24px;
}

.endpoint-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.method-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.02em;
}
.method-badge.get { color: var(--teal); background: rgba(79, 191, 159, 0.1); border: 1px solid var(--teal-dim); }
.method-badge.post { color: var(--copper); background: rgba(232, 103, 46, 0.1); border: 1px solid var(--copper-dim); }
.method-badge.delete { color: var(--red); background: rgba(225, 80, 63, 0.1); border: 1px solid var(--red-dim); }
.method-badge.all { color: var(--blue); background: rgba(91, 141, 239, 0.1); border: 1px solid #2c3f63; }

.endpoint-path {
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--text);
}

.endpoint-desc { font-size: 12.5px; margin-bottom: 12px; }

.endpoint h4 {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 14px 0 6px;
  font-weight: 600;
}
.endpoint h4:first-of-type { margin-top: 0; }

table.params-table { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
table.params-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
}
table.params-table td {
  padding: 6px 8px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.params-table tr:last-child td { border-bottom: none; }
table.params-table td.pname { font-family: var(--font-mono); color: var(--copper); white-space: nowrap; }
table.params-table td.ptype { font-family: var(--font-mono); color: var(--text-dim); white-space: nowrap; }

.code-block {
  background: #0f1318;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre;
  margin-bottom: 4px;
}
.code-block .k { color: var(--blue); }
.code-block .s { color: var(--teal); }

@media (max-width: 860px) {
  .docs-shell { grid-template-columns: 1fr; }
  .docs-toc { position: static; border-right: none; padding-right: 0; border-bottom: 1px solid var(--border); padding-bottom: 18px; }
}

/* ==========================================================================
   2FA Lock Screen Overlay
   ========================================================================== */

.auth-lockscreen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 20, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 24px;
  opacity: 1;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.auth-lockscreen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-card {
  background: rgba(22, 28, 38, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 40px 32px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.85), 0 0 1px rgba(255, 255, 255, 0.2) inset;
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.auth-lockscreen.hidden .auth-card {
  transform: translateY(16px);
}

.auth-icon-wrapper {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(232, 103, 46, 0.12);
  border: 1px solid rgba(232, 103, 46, 0.35);
  border-radius: 50%;
  color: var(--copper);
}

.auth-icon {
  width: 32px;
  height: 32px;
}

.auth-icon-pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(232, 103, 46, 0.4);
  animation: authPulse 2.2s infinite ease-out;
}

@keyframes authPulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  70% { transform: scale(1.35); opacity: 0; }
  100% { transform: scale(1.35); opacity: 0; }
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  color: var(--text-bright);
}

.auth-sub {
  color: var(--text-muted);
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 24px;
}

.auth-waiting {
  background: rgba(14, 18, 25, 0.8);
  border: 1px solid rgba(232, 103, 46, 0.25);
  border-radius: var(--radius-md);
  padding: 18px 16px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
}

.auth-waiting.hidden { display: none; }

.auth-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(232, 103, 46, 0.2);
  border-top-color: var(--copper);
  border-radius: 50%;
  animation: authSpin 0.9s linear infinite;
  flex: none;
}

@keyframes authSpin {
  to { transform: rotate(360deg); }
}

.auth-waiting-text strong {
  display: block;
  font-size: 13.5px;
  color: var(--text-bright);
  margin-bottom: 2px;
}

.auth-waiting-text p {
  margin: 0 0 4px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.auth-countdown {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--copper);
  font-weight: 600;
}

.auth-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.btn-lg {
  padding: 13px 20px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}

.auth-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  font-size: 11px;
  color: var(--text-dim);
}

/* ==========================================================================
   Mobile & Tablet Responsiveness (<= 840px)
   ========================================================================== */

@media (max-width: 840px) {
  #app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
  }

  /* --- Mobile Bottom Navigation Bar --- */
  .railnav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    height: auto;
    width: 100%;
    flex-direction: row;
    background: rgba(18, 22, 28, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 0;
    z-index: 1000;
    justify-content: space-around;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.5);
  }

  .railnav .brand,
  .railnav .conn-row,
  .railnav #docs-link,
  .railnav .rail-foot {
    display: none !important;
  }

  .nav-list {
    flex-direction: row;
    width: 100%;
    justify-content: space-around;
    gap: 2px;
  }

  .nav-list li {
    flex: 1;
    display: flex;
  }

  .nav-btn {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    font-size: 10px;
    gap: 4px;
    border-radius: var(--radius-sm);
    text-align: center;
    min-height: 48px;
    border: none;
    background: transparent;
  }

  .nav-btn svg {
    width: 18px;
    height: 18px;
  }

  .nav-btn.active {
    background: rgba(232, 103, 46, 0.15);
    color: var(--copper);
    border-color: transparent;
  }

  /* --- Mobile Topbar --- */
  .topbar {
    height: auto;
    min-height: 52px;
    padding: 10px 14px;
    gap: 8px;
    background: rgba(18, 22, 28, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .topbar h1 {
    font-size: 15px;
    white-space: nowrap;
  }

  .topbar-right {
    gap: 8px;
  }

  .estop {
    padding: 7px 11px;
    font-size: 11px;
    font-weight: 700;
  }

  .job-pill {
    padding: 3px 8px;
    font-size: 10.5px;
    gap: 6px;
  }

  .job-pill .job-name {
    max-width: 80px;
  }

  .job-pill .job-bar {
    width: 32px;
  }

  /* --- Main Content Area --- */
  #content {
    padding: 14px 12px;
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 12px));
    overflow-x: hidden;
  }

  /* --- Grid System Collapse --- */
  .grid-2,
  .grid-3,
  .grid-12 {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .panel {
    padding: 14px 12px;
  }

  /* --- Temperature Cards --- */
  .temp-reading {
    font-size: 32px;
  }

  .preset-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .preset-row .btn {
    flex: 1 1 calc(33.33% - 6px);
    text-align: center;
    padding: 7px 4px;
    font-size: 11px;
  }

  .custom-row {
    display: flex;
    gap: 6px;
    width: 100%;
  }

  .custom-row .field {
    flex: 1;
  }

  .pos-grid {
    gap: 6px;
  }

  .pos-axis {
    padding: 8px 4px;
  }

  .pos-axis .axis-val {
    font-size: 16px;
  }

  /* --- Job Status Card --- */
  .job-body {
    flex-direction: column;
    gap: 12px;
  }

  .job-thumb {
    width: 100%;
    height: 140px;
    margin: 0 auto;
  }

  .job-actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
  }

  .job-actions .btn {
    flex: 1 1 calc(50% - 8px);
    padding: 10px;
    font-size: 13px;
  }

  /* --- 3D Preview Canvas --- */
  .preview3d-wrap {
    height: 300px;
  }

  /* --- Jog Pad & Motion Controls --- */
  .jog-wrap {
    justify-content: center;
    gap: 16px;
  }

  .jog-pad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(3, 56px);
    gap: 6px;
  }

  .jog-pad button {
    min-width: 56px;
    min-height: 56px;
  }

  .z-col {
    grid-template-rows: repeat(3, 56px);
    gap: 6px;
  }

  .z-col button {
    width: 56px;
    min-height: 56px;
  }

  .jog-controls-col {
    width: 100%;
    align-items: center;
  }

  .segmented {
    width: 100%;
    display: flex;
  }

  .segmented button {
    flex: 1;
    padding: 9px 2px;
    font-size: 12px;
  }

  .quick-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .quick-actions .btn {
    flex: 1 1 calc(50% - 8px);
    padding: 10px 8px;
    font-size: 12px;
    text-align: center;
  }

  /* --- File Manager Table --- */
  #files-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }

  table.file-table {
    min-width: 480px;
  }

  table.file-table th,
  table.file-table td {
    padding: 8px 6px;
    font-size: 11.5px;
  }

  /* --- Macros Grid --- */
  .macro-grid .macro-btn {
    flex: 1 1 calc(50% - 8px);
    padding: 10px 8px;
    text-align: center;
  }

  /* --- Console --- */
  .console-log {
    height: 280px;
    font-size: 11.5px;
  }

  /* --- Toast Notifications --- */
  #toast-root {
    bottom: calc(72px + env(safe-area-inset-bottom, 10px));
    right: 12px;
    left: 12px;
    align-items: center;
  }

  .toast {
    min-width: 0;
    width: 100%;
    max-width: 400px;
  }

  /* --- 2FA Lock Screen --- */
  .auth-card {
    padding: 30px 20px;
    margin: 12px;
    width: calc(100% - 24px);
  }

  .auth-icon-wrapper {
    width: 60px;
    height: 60px;
    margin-bottom: 16px;
  }

  .auth-title {
    font-size: 20px;
  }

  .auth-sub {
    font-size: 13px;
    margin-bottom: 20px;
  }

  /* --- System Info Table Stacking on Mobile --- */
  .kv-table,
  .kv-table tbody,
  .kv-table tr,
  .kv-table td {
    display: block;
    width: 100%;
  }

  .kv-table tr {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }

  .kv-table tr:last-child {
    border-bottom: none;
  }

  .kv-table td {
    padding: 2px 0;
    border-bottom: none;
  }

  .kv-table td:first-child {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    margin-bottom: 2px;
  }

  .kv-table td:last-child {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .key-field-row {
    flex-direction: column;
    align-items: stretch;
  }

  .api-key-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .api-key-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 4px;
  }

  /* --- Modal Box --- */
  .modal-box {
    width: calc(100% - 32px);
    max-width: 360px;
    padding: 20px;
  }
}

@media (max-width: 480px) {
  .job-actions .btn {
    flex: 1 1 100%;
  }

  .quick-actions .btn {
    flex: 1 1 100%;
  }

  .macro-grid .macro-btn {
    flex: 1 1 100%;
  }

  .preview3d-wrap {
    height: 260px;
  }
}

