/* ── RESET & BASE ── */
:root {
  --bg:            #f5f5f0;
  --surface:       #ffffff;
  --border:        #e8e8e2;
  --border-strong: #d0d0c8;
  --text-1:        #1a1a18;
  --text-2:        #6b6b60;
  --text-3:        #a0a095;
  --blue:          #1a5fb4;
  --blue-bg:       #eef4fd;
  --blue-border:   #b6d0f5;
  --green:         #2d7a4f;
  --green-bg:      #edf7f1;
  --green-border:  #b8dfc9;
  --orange:        #c47d0e;
  --orange-bg:     #fef8ed;
  --orange-border: #f5d89a;
  --red:           #c0392b;
  --red-bg:        #fdf2f0;
  --red-border:    #f0c4be;
  --radius:        12px;
  --shadow:        0 1px 4px rgba(0,0,0,0.07);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  padding: 0 0 80px;
}

/* ── HEADER ── */
.header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(245,245,240,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.logo {
  font-size: 18px; font-weight: 700; letter-spacing: -0.4px; color: var(--text-1);
}
.logo span { color: var(--blue); }
.header-sub { font-size: 10px; color: var(--text-3); font-family: 'DM Mono', monospace; margin-top: 2px; }
.header-right { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.conn-badge {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 5px 12px;
  font-size: 11px; font-weight: 600; color: var(--text-2);
  white-space: nowrap;
}
.badge-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-strong);
  transition: background 0.3s, box-shadow 0.3s;
}
.badge-dot.online  { background: var(--green);  box-shadow: 0 0 0 3px var(--green-bg); animation: pulse-dot 1.5s infinite; }
.badge-dot.offline { background: var(--red);    box-shadow: 0 0 0 3px var(--red-bg); }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:0.5} }
.last-sync { font-size: 10px; color: var(--text-3); font-family: 'DM Mono', monospace; }

/* ── CONTAINER ── */
.container { max-width: 980px; margin: 0 auto; padding: 18px 16px; }

/* ── FIREBASE CONFIG BAR ── */
.config-bar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow);
}
.config-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.config-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text-3);
  white-space: nowrap; min-width: 80px;
}
.config-input {
  flex: 1; min-width: 200px; border: 1px solid var(--border);
  background: var(--bg); border-radius: 8px; padding: 9px 12px;
  font-size: 13px; font-family: 'DM Mono', monospace;
  color: var(--text-1); outline: none; transition: border-color 0.2s;
}
.config-input:focus { border-color: var(--blue); }
.btn-connect {
  background: var(--text-1); color: #fff; border: none;
  border-radius: 8px; padding: 9px 20px; font-size: 13px;
  font-weight: 600; cursor: pointer; font-family: 'DM Sans', sans-serif;
  transition: opacity 0.2s; white-space: nowrap; min-height: 40px;
}
.btn-connect:active { opacity: 0.75; }
.btn-connect.connected { background: var(--green); }
.config-hint { font-size: 11px; color: var(--text-3); }

/* ── EMERGENCY STOP ── */
.btn-emergency {
  width: 100%; padding: 18px; border-radius: var(--radius);
  font-size: 15px; font-weight: 700; cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  background: var(--red); color: #fff; border: none;
  margin-bottom: 12px; display: flex; align-items: center;
  justify-content: center; gap: 10px; letter-spacing: 0.5px;
  transition: opacity 0.15s, transform 0.1s;
  box-shadow: 0 3px 12px rgba(192,57,43,0.3);
}
.btn-emergency:active { opacity: 0.85; transform: scale(0.99); }
.emergency-icon { font-size: 18px; }

/* ── STATUS BAR ── */
.status-bar {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; transition: all 0.3s;
  box-shadow: var(--shadow);
}
.status-bar.running   { background: var(--green-bg);  border-color: var(--green-border); }
.status-bar.autoramp  { background: var(--orange-bg); border-color: var(--orange-border); }
.status-bar.emergency { background: var(--red-bg);    border-color: var(--red-border); }
.status-dot-wrap { display: flex; align-items: center; gap: 8px; }
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--border-strong); transition: all 0.3s;
}
.running   .status-dot { background: var(--green);  box-shadow: 0 0 0 3px var(--green-bg); animation: pulse-dot 1.5s infinite; }
.autoramp  .status-dot { background: var(--orange); box-shadow: 0 0 0 3px var(--orange-bg); animation: pulse-dot 1s infinite; }
.emergency .status-dot { background: var(--red);    box-shadow: 0 0 0 3px var(--red-bg); }
.status-label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.running   .status-label { color: var(--green); }
.autoramp  .status-label { color: var(--orange); }
.emergency .status-label { color: var(--red); }
.status-meta { font-size: 11px; color: var(--text-3); font-family: 'DM Mono', monospace; }

/* ── STATS GRID ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px; margin-bottom: 10px;
}
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); transition: border-color 0.3s, background 0.3s;
}
.stat-card.warn   { border-color: var(--orange-border); background: var(--orange-bg); }
.stat-card.danger { border-color: var(--red-border);    background: var(--red-bg); }
.stat-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-label {
  font-size: 10px; font-weight: 600; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text-3);
}
.stat-badge {
  font-size: 9px; font-weight: 700; letter-spacing: 1px;
  padding: 2px 7px; border-radius: 4px;
  background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border);
}
.stat-badge.warn   { background: var(--orange-bg); color: var(--orange); border-color: var(--orange-border); }
.stat-badge.danger { background: var(--red-bg);    color: var(--red);    border-color: var(--red-border); }
.stat-value {
  font-family: 'DM Mono', monospace;
  font-size: clamp(24px, 4.5vw, 32px);
  font-weight: 500; color: var(--text-1); line-height: 1;
  letter-spacing: -1px; margin-bottom: 3px;
}
.stat-unit { font-size: 10px; color: var(--text-3); font-family: 'DM Mono', monospace; margin-bottom: 10px; }
.bar-track { background: var(--bg); border-radius: 4px; height: 4px; overflow: hidden; border: 1px solid var(--border); }
.bar { height: 100%; border-radius: 4px; width: 0%; transition: width 0.5s cubic-bezier(0.4,0,0.2,1), background 0.3s; }
.bar-blue   { background: var(--blue); }
.bar-green  { background: var(--green); }
.bar-orange { background: var(--orange); }
.bar-red    { background: var(--red); }
.stat-foot { font-size: 10px; color: var(--text-3); margin-top: 5px; }
.reset-btn {
  font-size: 11px; font-weight: 600; color: var(--text-3);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 9px; cursor: pointer;
  font-family: 'DM Sans', sans-serif; transition: all 0.15s;
}
.reset-btn:hover { border-color: var(--blue); color: var(--blue); }
.reset-btn:active { transform: scale(0.95); }

/* ── TEMPERATURE ROW ── */
.temp-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 10px;
}
@media (min-width: 700px) { .temp-row { grid-template-columns: 1fr 1fr 1fr; } }

.temp-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; box-shadow: var(--shadow);
  transition: border-color 0.3s, background 0.3s;
}
.temp-card.warm   { border-color: var(--orange-border); background: var(--orange-bg); }
.temp-card.hot    { border-color: var(--red-border);    background: var(--red-bg); }
.temp-value {
  font-family: 'DM Mono', monospace;
  font-size: clamp(22px, 4vw, 28px); font-weight: 500;
  color: var(--text-1); letter-spacing: -1px; line-height: 1; margin: 4px 0;
}
.temp-unit { font-size: 14px; color: var(--text-3); }
.temp-health { font-size: 10px; color: var(--green); font-weight: 600; letter-spacing: 1px; margin-top: 3px; }
.temp-health.warm { color: var(--orange); }
.temp-health.hot  { color: var(--red); }
.temp-gauge-wrap { flex-shrink: 0; }
.temp-gauge { width: 72px; height: 72px; }

/* ── HEALTH CARD ── */
.health-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
  grid-column: 1 / -1;
}
@media (min-width: 700px) { .health-card { grid-column: auto; } }
.health-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.health-row:last-child { border-bottom: none; }
.health-icon { width: 18px; text-align: center; font-size: 12px; }
.health-name { flex: 1; color: var(--text-2); font-weight: 500; }
.health-status {
  font-size: 10px; font-weight: 700; letter-spacing: 1px;
  padding: 2px 8px; border-radius: 4px;
  background: var(--bg); color: var(--text-3); border: 1px solid var(--border);
}
.health-status.ok   { background: var(--green-bg);  color: var(--green);  border-color: var(--green-border); }
.health-status.warn { background: var(--orange-bg); color: var(--orange); border-color: var(--orange-border); }
.health-status.bad  { background: var(--red-bg);    color: var(--red);    border-color: var(--red-border); }

/* ── CHART ── */
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.chart-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.chart-legend { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-3); flex: 1; }
.legend-dot { width: 10px; height: 4px; border-radius: 2px; }
.legend-dot.blue { background: var(--blue); }
canvas#rpmChart { width: 100% !important; display: block; }
.chart-foot {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 10px; font-family: 'DM Mono', monospace; color: var(--text-3);
}

/* ── CONTROL GRID ── */
.control-grid {
  display: grid; grid-template-columns: 1fr;
  gap: 10px;
}
@media (min-width: 640px) { .control-grid { grid-template-columns: 1fr 1fr; } }

.control-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow);
}

/* ── THROTTLE ── */
.throttle-row {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 14px;
}
.throttle-big {
  font-family: 'DM Mono', monospace;
  font-size: clamp(36px, 8vw, 48px); font-weight: 500;
  line-height: 1; letter-spacing: -2px; color: var(--text-1);
}
.pct-sym { font-size: 22px; color: var(--text-3); }
.pwm-label { font-size: 10px; color: var(--text-3); letter-spacing: 1px; text-transform: uppercase; }
.pwm-val { font-family: 'DM Mono', monospace; font-size: 13px; color: var(--blue); font-weight: 500; }

input[type=range] {
  width: 100%; -webkit-appearance: none; height: 6px;
  border-radius: 4px; background: var(--bg);
  border: 1px solid var(--border); outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px;
  border-radius: 50%; background: var(--text-1);
  cursor: pointer; border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  transition: transform 0.1s;
}
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.15); }
input[type=range]::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--text-1); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2); cursor: pointer;
}
.range-ticks {
  display: flex; justify-content: space-between;
  margin-top: 7px; font-size: 10px; color: var(--text-3);
  font-family: 'DM Mono', monospace;
}

/* ── CONTROL BUTTONS ── */
.btn-row { display: flex; gap: 8px; margin-bottom: 10px; }
.btn {
  flex: 1; padding: 13px 10px; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: 'DM Sans', sans-serif; border: 1px solid transparent;
  transition: all 0.15s; min-height: 46px; text-align: center;
}
.btn:active { transform: scale(0.97); }
.btn-start { background: var(--green-bg); color: var(--green); border-color: var(--green-border); }
.btn-stop  { background: var(--red-bg);   color: var(--red);   border-color: var(--red-border); }
.btn-auto  {
  width: 100%; padding: 13px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  background: var(--orange-bg); color: var(--orange);
  border: 1px solid var(--orange-border);
  transition: all 0.15s; min-height: 46px;
}
.btn-auto:active { transform: scale(0.97); }

/* ── WARNING BOX ── */
.warn-box {
  margin-top: 10px; padding: 10px 12px;
  background: var(--red-bg); border: 1px solid var(--red-border);
  border-radius: 8px; font-size: 12px; color: var(--red);
  font-weight: 500; line-height: 1.5;
}

/* ── SAFE AREA (iPhone home bar) ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}
