:root {
  color-scheme: dark;
  --bg: #0d1015;
  --panel: #151920;
  --panel-2: #1d222c;
  --border: #29313d;
  --text: #eef1f5;
  --muted: #9099a9;
  --accent: #00b849;
  --blue: #3989ff;
  --danger: #ed4c56;
  --warning: #f7ad2f;
  --radius: 13px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at 50% -20%, #172330 0, var(--bg) 42%);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
}
button, input, select { font: inherit; }
button, select, input {
  border: 1px solid var(--border);
  border-radius: 9px;
}
button, select {
  min-height: 40px;
  padding: 8px 15px;
  background: var(--panel-2);
  color: var(--text);
}
button { cursor: pointer; transition: filter .15s, transform .15s, opacity .15s; }
button:hover:not(:disabled) { filter: brightness(1.14); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #78adff;
  outline-offset: 2px;
}
button:disabled, select:disabled { cursor: not-allowed; opacity: .38; }
a { color: #9bc2ff; text-decoration: none; }
a:hover { text-decoration: underline; }
.primary { background: var(--blue); border-color: var(--blue); }
.warning { background: var(--warning); border-color: var(--warning); color: #211600; }
.danger { background: var(--danger); border-color: var(--danger); }
.ghost { background: transparent; }
.compact { min-height: 34px; padding: 5px 11px; }
.wide { width: 100%; margin-top: 8px; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 62px;
  padding: 10px 24px;
  background: rgba(21, 25, 32, .94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand h1 { margin: 0; font-size: 18px; line-height: 1.1; }
.brand span:last-child { color: var(--muted); font-size: 12px; }
.status-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--danger); }
.status-dot.online { background: var(--accent); box-shadow: 0 0 9px rgba(0, 184, 73, .8); }
.topbar nav { display: flex; align-items: center; gap: 12px; }

main {
  display: grid;
  grid-template-columns: minmax(420px, 1.35fr) minmax(360px, 1fr);
  gap: 16px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px 24px 30px;
}
.panel {
  overflow: hidden;
  background: rgba(21, 25, 32, .96);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-heading h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.panel-content { padding: 15px 16px 17px; }
.channel-status { color: var(--muted); font-size: 12px; }
.camera-wrap { position: relative; background: #000; }
#camera { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: contain; }
.state-badge {
  position: absolute;
  top: 11px;
  left: 11px;
  padding: 5px 10px;
  background: rgba(0, 0, 0, .68);
  border-radius: 7px;
  font-size: 12px;
  font-weight: 700;
}
.camera-light { position: absolute; top: 11px; right: 11px; }
.camera-light.active { background: var(--warning); border-color: var(--warning); color: #1d1500; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(105px, 1fr)); gap: 9px; }
.stat { min-width: 0; padding: 10px 11px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.stat > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.stat strong { display: block; overflow: hidden; font-size: 18px; white-space: nowrap; text-overflow: ellipsis; }
.stat b, .stat i { font-style: normal; }
.stat small { color: var(--muted); font-size: 11px; font-weight: 400; }
.progress-block { margin-top: 13px; }
.progress-track { height: 10px; overflow: hidden; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; }
#progress-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--blue), var(--accent)); transition: width .5s; }
.progress-meta { display: flex; justify-content: space-between; margin-top: 5px; color: var(--muted); font-size: 11px; }
.job-name { min-height: 20px; margin: 8px 0 0; overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-top: 13px; }
.button-row.flush { margin-top: 0; }
.diagnostic { margin-top: 12px; padding: 10px; background: rgba(237, 76, 86, .1); border: 1px solid rgba(237, 76, 86, .35); border-radius: 9px; color: #ffb4ba; font-size: 12px; }

.controls-panel, .history-panel { grid-column: 1 / -1; }
.controls-grid { display: grid; grid-template-columns: 260px 1fr; gap: 28px; align-items: start; }
.control-title { margin: 0 0 9px; color: var(--muted); font-size: 12px; }
.dpad { display: grid; grid-template-columns: repeat(3, 58px); grid-template-rows: repeat(3, 44px); gap: 6px; }
.dpad button { padding: 0; font-size: 16px; }
.presets { padding-top: 0; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 11px; }

.chart-legend { display: flex; gap: 20px; color: var(--muted); font-size: 12px; }
.chart-legend span::before { display: inline-block; width: 16px; height: 3px; margin: 0 6px 3px 0; border-radius: 2px; content: ""; }
.nozzle-line::before { background: #ff626b; }
.bed-line::before { background: #4f96ff; }
.chamber-line::before { background: #54d584; }
#temperature-chart { display: block; width: 100%; min-height: 180px; margin-top: 8px; background: #11151b; border-radius: 9px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
td { font-size: 12px; }
.audit-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.audit-list li { display: grid; grid-template-columns: 145px 1fr auto; gap: 10px; padding-bottom: 7px; border-bottom: 1px solid var(--border); font-size: 12px; }
.audit-list time { color: var(--muted); }
.audit-ok { color: #65dd8e; }
.audit-failed { color: #ff777f; }

.toast {
  position: fixed;
  z-index: 50;
  bottom: 22px;
  left: 50%;
  max-width: min(520px, calc(100% - 32px));
  padding: 11px 17px;
  transform: translate(-50%, 80px);
  opacity: 0;
  background: #252c36;
  border: 1px solid #3a4553;
  border-radius: 10px;
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45);
  transition: .25s;
  pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

.auth-page { display: grid; place-items: center; padding: 22px; }
.auth-page > main.auth-card { display: block; grid-template-columns: none; width: min(410px, 100%); margin: 0; padding: 30px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 22px 80px rgba(0, 0, 0, .35); }
.auth-logo { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 15px; background: var(--accent); border-radius: 13px; color: #fff; font-size: 24px; font-weight: 800; }
.auth-card h1 { margin: 0; text-align: center; font-size: 25px; }
.auth-subtitle { margin: 6px 0 22px; color: var(--muted); text-align: center; }
.auth-card label { display: block; margin: 13px 0 6px; color: var(--muted); font-size: 12px; }
.auth-card input { width: 100%; height: 44px; padding: 9px 12px; background: var(--panel-2); color: var(--text); }
.form-message { min-height: 21px; margin: 0 0 6px; color: #ff8e95; text-align: center; font-size: 12px; }
.account-card h1 { margin-top: 15px; }
.back-link { font-size: 12px; }

@media (max-width: 940px) {
  main { grid-template-columns: 1fr; }
  .controls-panel, .history-panel { grid-column: auto; }
}
@media (max-width: 620px) {
  .topbar { padding-inline: 16px; }
  .topbar nav a { display: none; }
  main { padding: 14px 14px 26px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(100px, 1fr)); }
  .controls-grid { grid-template-columns: 1fr; }
  .dpad { margin: 0 auto; }
  .audit-list li { grid-template-columns: 1fr auto; }
  .audit-list time { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
