/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --border:    #2a2d3a;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --accent:    #3b82f6;

  --ok:        #22c55e;
  --warn:      #f59e0b;
  --error:     #ef4444;
  --info:      #6366f1;

  --state-idle:  #475569;
  --state-prod:  #22c55e;
  --state-prep:  #a78bfa;
  --state-wait:  #f59e0b;
  --state-alert: #fb923c;
  --state-hold:  #ef4444;
  --state-boot:  #334155;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

header h1 span {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
  margin-left: 8px;
}

/* ── Connection badge ───────────────────────────────────────────────────────── */
#conn-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

#conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--error);
  transition: background 0.3s;
}

#conn-dot.connected  { background: var(--ok); }
#conn-dot.connecting { background: var(--warn); animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.card-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  letter-spacing: 0.02em;
  text-decoration: none;
  display: inline-block;
}

.btn:active  { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2563eb; }

.btn-success { background: var(--ok); color: #052e16; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

.btn-warn    { background: var(--warn); color: #451a03; }
.btn-warn:hover:not(:disabled) { background: #d97706; }

.btn-danger  { background: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text); }

.btn-sm   { padding: 5px 10px; font-size: 11px; }
.btn-icon { padding: 4px 8px; font-size: 13px; line-height: 1; }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-row { margin-bottom: 12px; }

.form-row label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.form-row input,
.form-row select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.form-row input:focus,
.form-row select:focus { border-color: var(--accent); }

.form-row select option { background: var(--surface); }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

@media (max-width: 480px) {
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr 1fr; }
}

.form-section {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ── Modal ──────────────────────────────────────────────────────────────────── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

#modal-overlay.open { display: flex; }

#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  margin: 16px;
}

#modal h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: flex-end;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  transition: transform 0.25s ease;
  z-index: 300;
}

#toast.show { transform: translateX(-50%) translateY(0); }
#toast.ok   { border-color: var(--ok);   color: var(--ok); }
#toast.warn { border-color: var(--warn); color: var(--warn); }

/* ── Sensor grid ────────────────────────────────────────────────────────────── */
.sensors-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 640px) {
  .sensors-grid { grid-template-columns: repeat(2, 1fr); }
}

.sensor-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.sensor-label {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.sensor-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.sensor-unit {
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
}

.sensor-stale { opacity: 0.35; }

/* ── Bar ────────────────────────────────────────────────────────────────────── */
.bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  background: var(--accent);
}

.bar-fill.low { background: var(--error); }

/* ── Utilities ──────────────────────────────────────────────────────────────── */
.hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

.empty-state {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 20px 0;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 14px;
}
