/* vesc_panel.css — Saltybot VESC Motor Dashboard (Issue #653) */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg0:    #050510;
  --bg1:    #070712;
  --bg2:    #0a0a1a;
  --bd:     #0c2a3a;
  --bd2:    #1e3a5f;
  --dim:    #374151;
  --mid:    #6b7280;
  --base:   #9ca3af;
  --hi:     #d1d5db;
  --cyan:   #06b6d4;
  --green:  #22c55e;
  --amber:  #f59e0b;
  --red:    #ef4444;
  --orange: #f97316;
  --purple: #a855f7;
}

body {
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  background: var(--bg0);
  color: var(--base);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
#header {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  background: var(--bg1);
  border-bottom: 1px solid var(--bd);
  flex-shrink: 0;
  gap: 10px;
  flex-wrap: wrap;
}
.logo { color: var(--orange); font-weight: bold; letter-spacing: 0.15em; font-size: 13px; flex-shrink: 0; }
#conn-bar { display: flex; align-items: center; gap: 6px; }
#header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.meta-label { font-size: 10px; color: var(--mid); }

#conn-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--dim); flex-shrink: 0; transition: background 0.3s;
}
#conn-dot.connected { background: var(--green); }
#conn-dot.error     { background: var(--red); animation: blink 1s infinite; }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

#ws-input {
  background: var(--bg2); border: 1px solid var(--bd2); border-radius: 4px;
  color: #67e8f9; padding: 2px 8px; font-family: monospace; font-size: 11px; width: 200px;
}
#ws-input:focus { outline: none; border-color: var(--cyan); }

.hdr-btn {
  padding: 3px 10px; border-radius: 4px; border: 1px solid var(--bd2);
  background: var(--bg2); color: #67e8f9; font-family: monospace;
  font-size: 10px; font-weight: bold; cursor: pointer; transition: background 0.15s;
  white-space: nowrap;
}
.hdr-btn:hover { background: #0e4f69; }

/* ── Status bar ── */
#status-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 4px 16px; background: var(--bg1);
  border-bottom: 1px solid var(--bd); font-size: 10px; flex-wrap: wrap;
}
.sys-badge {
  padding: 2px 8px; border-radius: 3px; font-weight: bold;
  border: 1px solid; letter-spacing: 0.05em; font-size: 10px; white-space: nowrap;
}
.badge-ok    { background: #052e16; border-color: #166534; color: #4ade80; }
.badge-warn  { background: #451a03; border-color: #92400e; color: #fcd34d; }
.badge-error { background: #450a0a; border-color: #991b1b; color: #f87171; animation: blink 1s infinite; }
.badge-stale { background: #111827; border-color: #374151; color: #6b7280; }

/* E-stop button */
.estop-btn {
  margin-left: auto;
  padding: 4px 18px;
  border-radius: 5px;
  border: 2px solid #991b1b;
  background: #450a0a;
  color: #f87171;
  font-family: monospace;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: background 0.15s, transform 0.1s;
}
.estop-btn:hover  { background: #7f1d1d; border-color: var(--red); }
.estop-btn:active { transform: scale(0.96); }
.estop-btn.fired  {
  background: var(--red); color: #fff;
  border-color: #fca5a5; animation: blink 0.5s 3;
}

/* ── Dashboard grid ── */
#dashboard {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr) 1.1fr;
  gap: 12px;
  padding: 12px;
  align-content: start;
  overflow-y: auto;
}
@media (max-width: 1100px) { #dashboard { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { #dashboard { grid-template-columns: 1fr; } }

/* ── Card ── */
.card {
  background: var(--bg1);
  border: 1px solid var(--bd);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.state-offline { border-color: #374151; opacity: 0.65; }
.card.state-warn    { border-color: #92400e; }
.card.state-fault   { border-color: #991b1b; }

.card-title {
  font-size: 9px; font-weight: bold; letter-spacing: 0.15em;
  color: #0891b2; text-transform: uppercase;
  display: flex; align-items: center; justify-content: space-between;
}

/* Fault badge */
.fault-badge {
  padding: 1px 8px; border-radius: 3px; font-size: 9px; font-weight: bold;
  letter-spacing: 0.08em; border: 1px solid;
  background: #052e16; border-color: #166534; color: #4ade80;
}
.fault-badge.warn    { background: #451a03; border-color: #92400e; color: #fcd34d; }
.fault-badge.fault   { background: #450a0a; border-color: #991b1b; color: #f87171; animation: blink 1s infinite; }
.fault-badge.offline { background: #111827; border-color: #374151; color: #6b7280; }

/* ── Arc gauge wrap ── */
.gauge-row-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.arc-wrap {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.arc-wrap canvas { display: block; }
.arc-dir {
  font-size: 9px; font-weight: bold; letter-spacing: 0.1em;
  color: var(--mid); text-align: center; margin-top: 2px;
}

/* ── Motor stats (right of arc) ── */
.motor-stats {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.stat-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 9px; margin-bottom: 2px;
}
.stat-label { color: var(--mid); }
.stat-val   { font-family: monospace; font-size: 11px; color: var(--hi); }

/* ── Bar gauge ── */
.bar-track {
  width: 100%; height: 6px;
  background: var(--bg2); border-radius: 3px;
  overflow: hidden; border: 1px solid var(--bd2);
}
.bar-track.mini { height: 4px; margin-top: 3px; }
.bar-fill {
  height: 100%; width: 0%; border-radius: 3px;
  background: var(--green);
  transition: width 0.4s ease, background 0.4s ease;
}

/* ── Temperature boxes ── */
.temp-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.temp-box {
  background: var(--bg2); border: 1px solid var(--bd2);
  border-radius: 6px; padding: 6px 8px; text-align: center;
}
.temp-box.warn  { border-color: #92400e; }
.temp-box.crit  { border-color: #991b1b; }
.temp-label { font-size: 8px; color: var(--mid); margin-bottom: 2px; letter-spacing: 0.08em; }
.temp-val   { font-size: 18px; font-weight: bold; font-family: monospace; color: var(--hi); }

/* ── Sparklines ── */
.spark-section { display: flex; flex-direction: column; gap: 2px; }
.spark-label   { font-size: 8px; color: var(--dim); letter-spacing: 0.05em; }
.sparkline {
  width: 100%; display: block; border-radius: 3px;
  border: 1px solid var(--bd2); background: var(--bg2);
}

/* ── Battery card ── */
.batt-row {
  display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end;
}
.batt-metric { display: flex; flex-direction: column; align-items: flex-start; }
.batt-metric-label { font-size: 8px; color: var(--mid); letter-spacing: 0.08em; margin-bottom: 2px; }
.big-num { font-size: 28px; font-weight: bold; font-family: monospace; color: var(--green); }
.batt-unit { font-size: 10px; color: var(--mid); }

/* ── Footer ── */
#footer {
  background: var(--bg1); border-top: 1px solid var(--bd);
  padding: 3px 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; font-size: 10px; color: var(--dim);
  flex-wrap: wrap; gap: 6px;
}

/* ── Mobile tweaks ── */
@media (max-width: 640px) {
  .gauge-row-top { flex-direction: column; align-items: center; }
  .arc-wrap canvas { width: 120px; height: 86px; }
  .motor-stats { width: 100%; }
  .batt-row { gap: 10px; }
  .big-num { font-size: 22px; }
  #footer { flex-direction: column; align-items: flex-start; }
}
