/* ═══════════════════════════════════════════
   WAGON LIGHT CONTROLLER — INDUSTRIAL LIGHT UI
   ═══════════════════════════════════════════ */

:root {
  --bg:          #f0f2f5;
  --bg-card:     #ffffff;
  --bg-surface:  #e8eaed;
  --border:      #c8cdd8;
  --text:        #1a1c23;
  --text-muted:  #5a6278;
  --accent:      #2563eb;
  --radius:      10px;
  --font-body:   'DM Sans', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ── HEADER ── */
header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

header h1 {
  font-family: var(--font-mono);
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text);
}

.subtitle {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-top: 0.3rem;
}

/* ── MAIN LAYOUT ── */
main {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

/* ── LABEL INPUT BAR ── */
.label-input-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.label-input-bar input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.45rem 0.75rem;
  outline: none;
}

.label-input-bar input:focus {
  border-color: var(--accent);
}

.label-input-bar button {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  white-space: nowrap;
}

.label-input-bar button:hover {
  filter: brightness(1.15);
}

.label-input-bar input.input-error {
  border-color: #ff4444;
}

.wagon-input-error {
  color: #ff6666;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  margin: -0.25rem 0 0.75rem;
}

.wagon-input-error code {
  background: var(--bg-surface);
  border-radius: 3px;
  padding: 0 0.25rem;
}

/* ── WAGON LABEL OVERLAY ── */
.wagon-viewport {
  position: relative;
}

.wagon-info-row {
  display: block;
  align-items: center;
  justify-content: left;
  padding: 0 0.25rem;
  margin-bottom: 0.25rem;
  min-height: 1.4rem;
}

.wagon-label {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.wagon-last-updated {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: left;
}

/* ── WAGON SVG VIEWPORT ── */
.wagon-viewport {
  width: 100%;
  background:
    radial-gradient(ellipse 80% 60% at 50% 50%, rgba(224,228,236,1) 0%, var(--bg) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem 0.5rem 0.5rem;
  margin-bottom: 1rem;
  overflow: hidden;
}

#wagon-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Lamp visibility is controlled by the JS render loop via inline opacity */
.lamp-group {
  transition: none; /* no CSS transitions — JS drives opacity directly */
}

/* ── CONTROLS SECTION ── */
.controls {
  margin-top: 1rem;
}

.controls h2 {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── LAMP CARD ── */
.lamp-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  transition: border-color 0.3s;
}

.lamp-card:hover {
  border-color: var(--accent);
}

.lamp-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.lamp-indicator {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: 0 0 8px currentColor;
  transition: background 0.4s, box-shadow 0.4s;
}

.lamp-label {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: #ccc;
}

/* ── PRESET BUTTONS ── */
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.7rem;
}

.preset-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 2px solid transparent;
  background: var(--bg-surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
}

.preset-btn:hover {
  border-color: var(--btn-color);
  transform: scale(1.12);
}

.preset-btn:active {
  transform: scale(0.95);
}

.preset-btn .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--btn-color);
  box-shadow: 0 0 6px var(--btn-color);
}

/* ── CUSTOM COLOR PICKER ── */
.custom-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.custom-row label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.color-picker {
  -webkit-appearance: none;
  appearance: none;
  width: 40px;
  height: 28px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  cursor: pointer;
  padding: 0;
}

.color-picker::-webkit-color-swatch-wrapper { padding: 2px; }
.color-picker::-webkit-color-swatch { border-radius: 3px; border: none; }
.color-picker::-moz-color-swatch { border-radius: 3px; border: none; }

/* ── BOTH LAMPS SECTION ── */
.both-section {
  margin-top: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.both-section h3 {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.7rem;
}

.preset-row--wide {
  gap: 0.5rem;
}

.preset-btn--both {
  width: auto;
  height: 36px;
  padding: 0 0.65rem;
  gap: 0.4rem;
}

.btn-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: capitalize;
}

.preset-btn--both .dot {
  width: 12px;
  height: 12px;
}

/* ── FOOTER ── */
footer {
  text-align: center;
  padding: 1.5rem 1rem;
  border-top: 1px solid var(--border);
}

footer p {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

/* ── POLL PAUSED BANNER ── */
.poll-paused-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: #fefce8;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #92400e;
}

.poll-paused-banner button {
  flex-shrink: 0;
  background: #f59e0b;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  white-space: nowrap;
}

.poll-paused-banner button:hover {
  filter: brightness(1.1);
}

/* ── HELP SECTION ── */
.help-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: hidden;
  margin-bottom: 2rem;
}

.help-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.help-summary::-webkit-details-marker { display: none; }

.help-summary:hover { background: var(--bg-surface); }

.help-title {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.help-chevron {
  font-size: 0.65rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.help-section[open] .help-chevron { transform: rotate(180deg); }

.help-body {
  padding: 1rem 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.help-modes {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.help-mode {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.help-dot {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-top: 0.2rem;
}

.help-mode strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.help-mode p, .help-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.help-note {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

/* ═══════════════════════════
   RESPONSIVE — MOBILE FIRST
   ═══════════════════════════ */

@media (max-width: 640px) {
  header { padding: 1.2rem 0.75rem 0.6rem; }

  header h1 {
    font-size: clamp(1.5rem, 6vw, 2rem);
  }

  .subtitle {
    font-size: 0.9rem;
  }

  /* Stack input and button vertically */
  .label-input-bar {
    flex-direction: column;
  }

  .label-input-bar input {
    font-size: 1rem;
    padding: 0.65rem 0.9rem;
  }

  .label-input-bar button {
    font-size: 1rem;
    padding: 0.65rem 1rem;
    width: 100%;
  }

  .wagon-input-error {
    font-size: 0.88rem;
  }

  .wagon-viewport {
    padding: 0.5rem 0.25rem 0.25rem;
    border-radius: 8px;
    margin-bottom: 1.2rem;
  }

  .control-grid {
    grid-template-columns: 1fr;
    gap: 0.8rem;
  }

  .lamp-card { padding: 0.8rem; }

  .preset-btn { width: 36px; height: 36px; }
  .preset-btn .dot { width: 18px; height: 18px; }

  .preset-btn--both { height: 40px; padding: 0 0.8rem; }

  .both-section { padding: 0.8rem; }

  /* Help section */
  .help-title { font-size: 1rem; }
  .help-mode strong { font-size: 1rem; }
  .help-mode p, .help-note { font-size: 0.92rem; }
  .help-dot { width: 18px; height: 18px; }

  /* Poll banner */
  .poll-paused-banner {
    font-size: 0.9rem;
    flex-direction: column;
    align-items: flex-start;
  }

  .poll-paused-banner button {
    font-size: 0.9rem;
    padding: 0.45rem 1rem;
    width: 100%;
  }

  /* Wagon info row */
  .wagon-label,
  .wagon-last-updated {
    font-size: 1rem;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .control-grid {
    gap: 0.8rem;
  }
}
