/* =============================================================================
   ESP32 Relay Cloud — design tokens
   Theme: dark control panel, LED-style status indicators, etched nameplate type
   ============================================================================= */
:root {
  /* color */
  --bg: #14171A;
  --panel: #1B1F23;
  --panel-raised: #22272C;
  --border: #2C3238;
  --border-soft: #23282D;
  --text: #ECEDEE;
  --text-dim: #9099A1;
  --text-faint: #5F676E;

  --led-on: #3DDC84;
  --led-on-glow: rgba(61, 220, 132, 0.35);
  --led-off: #5A6168;
  --led-pending: #F2B23C;
  --led-pending-glow: rgba(242, 178, 60, 0.35);
  --led-fault: #FF5C5C;
  --led-fault-glow: rgba(255, 92, 92, 0.35);
  --brand: #4FA8FF;
  --brand-glow: rgba(79, 168, 255, 0.3);

  /* type */
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', monospace;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* layout */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --gap: 16px;
  --header-h: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

body {
  background-image:
    radial-gradient(circle at 20% 0%, rgba(79,168,255,0.04), transparent 40%),
    radial-gradient(circle at 80% 100%, rgba(61,220,132,0.03), transparent 40%);
  min-height: 100vh;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--brand); text-decoration: none; }

button {
  font-family: var(--font-sans);
  cursor: pointer;
}

::selection { background: var(--brand-glow); }

/* reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
}
.btn:hover { border-color: #3A4148; background: #262C32; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #0B1B2B; font-weight: 600; }
.btn-primary:hover { background: #6BB6FF; border-color: #6BB6FF; }
.btn-danger { background: transparent; border-color: var(--led-fault); color: var(--led-fault); }
.btn-danger:hover { background: rgba(255,92,92,0.1); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--panel-raised); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--text-dim); font-weight: 500; }
.field input, .field select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font-sans);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.field input, .field select { max-width: 100%; box-sizing: border-box; }
.hint { font-size: 12px; color: var(--text-faint); margin-top: -8px; margin-bottom: 14px; }

/* ---------------------------------------------------------------------------
   App shell
   --------------------------------------------------------------------------- */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(20,23,26,0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: 0.02em;
}
.brand .mark {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.brand .mark .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--led-on); box-shadow: 0 0 6px var(--led-on-glow); }

.conn-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); }
.conn-status .led { width: 7px; height: 7px; border-radius: 50%; background: var(--led-off); }
.conn-status.live .led { background: var(--led-on); box-shadow: 0 0 6px var(--led-on-glow); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.role-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 9px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }

main.view { flex: 1; padding: 20px; max-width: 1180px; width: 100%; margin: 0 auto; }

.view-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.view-header h1 { font-size: 17px; font-weight: 600; margin: 0; }
.view-header .sub { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }

/* ---------------------------------------------------------------------------
   Cards / panels
   --------------------------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 16px;
}
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.device-card { display: flex; flex-direction: column; gap: 12px; }
.device-card .dc-head { display: flex; align-items: flex-start; justify-content: space-between; }
.device-card .dc-name { font-weight: 600; font-size: 14.5px; }
.device-card .dc-loc { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.device-card .dc-status { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.device-card .dc-status .led { width: 7px; height: 7px; border-radius: 50%; background: var(--led-off); }
.device-card .dc-status.online .led { background: var(--led-on); box-shadow: 0 0 6px var(--led-on-glow); }

.channel-strip { display: flex; flex-direction: column; gap: 8px; border-top: 1px dashed var(--border); padding-top: 12px; }
.channel-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.channel-row:has(.channel-meta) { align-items: flex-start; }
.channel-label { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.channel-label .idx { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; flex-shrink: 0; }
.channel-label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* Groups page: responsive auto-fit tile grid. An expanded tile spans the full
   row so its channels lay out comfortably while collapsed tiles keep their shape. */
.group-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; align-items: start; }
.group-tile { display: flex; flex-direction: column; gap: 10px; }
.group-tile.expanded { grid-column: 1 / -1; }
.group-tile .ag-caret { display: inline-block; transition: transform 0.15s ease; }
.group-tile.expanded .ag-caret { transform: rotate(90deg); }
@media (max-width: 560px) { .group-grid { grid-template-columns: 1fr; } }

/* Map view: a fixed-size viewport containing a transformable "world" (image +
   pins). Zoom/pan apply a CSS transform to the world; pins are positioned in
   percentages so they track the image at any zoom. */
.map-viewport { position: relative; width: 100%; height: 480px; background: #0d0f12; border: 1px solid var(--border-soft); border-radius: 10px; overflow: hidden; touch-action: none; cursor: grab; }

/* Map tiles: responsive grid; expanded tile spans the full row so the rest reflow below it. */
.map-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.map-tile { border: 1px solid var(--border-soft); border-radius: 12px; background: var(--panel, #14181d); overflow: hidden; transition: border-color .15s ease; }
.map-tile:hover { border-color: var(--accent, #38bdf8); }
.map-tile.expanded { grid-column: 1 / -1; border-color: var(--accent, #38bdf8); }
.map-tile-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; cursor: pointer; font-weight: 600; }
.map-tile-head .ag-caret { color: var(--text-dim); }
.map-tile-name { flex: 1; }
.map-tile-body { padding: 0 16px 16px; }
.map-tile:not(.expanded) .map-tile-body { padding: 0; }

/* All On / All Off buttons (maps + groups). Green = on, red = off. */
.btn.map-allon, .btn.grp-allon { background: rgba(34,197,94,.16); color: #22c55e; border-color: rgba(34,197,94,.4); }
.btn.map-allon:hover:not(:disabled), .btn.grp-allon:hover:not(:disabled) { background: rgba(34,197,94,.28); }
.btn.map-alloff, .btn.grp-alloff { background: rgba(239,68,68,.16); color: #ef4444; border-color: rgba(239,68,68,.4); }
.btn.map-alloff:hover:not(:disabled), .btn.grp-alloff:hover:not(:disabled) { background: rgba(239,68,68,.28); }
.btn.map-allon:disabled, .btn.map-alloff:disabled, .btn.grp-allon:disabled, .btn.grp-alloff:disabled { opacity: .4; cursor: not-allowed; }

/* Slide switch (block sync toggle). */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; cursor: pointer; inset: 0; background: #3a3f47; border-radius: 24px; transition: .2s; }
.switch-slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .switch-slider { background: #22c55e; }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }
.map-viewport:active { cursor: grabbing; }
.map-world { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.map-world img { display: block; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.map-pin-layer { position: absolute; inset: 0; }
.map-pin { position: absolute; display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 14px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; border: 1.5px solid; background: #1b1f24; box-shadow: 0 1px 5px rgba(0,0,0,.5); }
.map-pin.on { background: rgba(45,212,167,.2); border-color: #2dd4a7; color: #2dd4a7; }
.map-pin.off { background: rgba(120,130,140,.2); border-color: #6b7580; color: #c2cad1; }
.map-pin.offline { opacity: .5; }
.map-pin.esp { border-style: dashed; }
.map-pin.selected { outline: 2px solid #38bdf8; outline-offset: 2px; }
.map-pin .pin-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.map-pin .pin-body { display: inline-flex; align-items: center; gap: 5px; transform-origin: center center; transition: transform 0.12s ease; }

/* Load icons (predefined-load logos). Inherit text colour via currentColor. */
.load-ico { display: inline-flex; align-items: center; justify-content: center; }
.load-ico svg { width: 1em; height: 1em; display: block; }
.badge.load-badge { display: inline-flex; align-items: center; gap: 4px; }
.badge.load-badge .load-ico svg { width: 13px; height: 13px; }
.map-pin .load-ico svg { width: 22px; height: 22px; }
.map-pin.icon-only { padding: 8px; border-radius: 50%; background: #11151a; box-shadow: 0 2px 8px rgba(0,0,0,.6); border-width: 2px; }
.map-pin.icon-only.on { background: #0f2b22; }
.map-pin.icon-only .pin-text { display: none; }
.map-pin .pin-dot { width: 12px; height: 12px; }

/* Icon picker grid (super-admin default loads). */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.icon-opt { display: flex; align-items: center; justify-content: center; height: 46px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer; font-size: 22px; }
.icon-opt .load-ico svg { width: 22px; height: 22px; }
.icon-opt:hover { border-color: var(--accent); }
.icon-opt.active { border-color: var(--accent); background: rgba(56,189,248,.12); color: #38bdf8; }
.map-pin.editing { cursor: grab; }
.map-pin.editing:active { cursor: grabbing; }
.map-pin .pin-rot { all: unset; cursor: pointer; margin-left: 4px; padding: 0 4px; border-radius: 6px; background: #38bdf8; color: #fff; font-size: 12px; line-height: 1.4; }
.map-zoom-controls { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.map-zoom-controls .btn { width: 36px; padding: 6px 0; }

/* Crop / rotate editor used in the plan upload flow. */
.crop-wrap { display: flex; flex-direction: column; gap: 12px; }
.crop-canvas-box { position: relative; background: #0d0f12; border: 1px solid var(--border-soft); border-radius: 8px; overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 240px; max-height: 52vh; touch-action: none; }
.crop-canvas-box canvas { display: block; max-width: 100%; max-height: 52vh; cursor: crosshair; }
.crop-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.crop-toolbar .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.crop-toolbar .seg button { border: none; border-radius: 0; padding: 6px 10px; font-size: 12px; background: var(--bg); }
.crop-toolbar .seg button.active { background: var(--accent); color: #fff; }
.crop-straighten { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.crop-straighten input[type=range] { flex: 1; }

/* Rocker switch — the signature control element */
.rocker {
  position: relative;
  width: 46px;
  height: 24px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s ease;
}
.rocker .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--led-off);
  transition: transform 0.18s cubic-bezier(.4,0,.2,1), background 0.18s ease, box-shadow 0.18s ease;
}
.rocker.on { border-color: rgba(61,220,132,0.4); }
.rocker.on .knob { transform: translateX(22px); background: var(--led-on); box-shadow: 0 0 8px var(--led-on-glow); }
.rocker.fb-mismatch .knob { background: var(--led-fault); box-shadow: 0 0 8px var(--led-fault-glow); }
.rocker:disabled, .rocker.disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover { background: rgba(255,255,255,0.015); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-family: var(--font-mono); padding: 2px 8px; border-radius: 10px; border: 1px solid var(--border); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.badge .led { width: 6px; height: 6px; border-radius: 50%; }
.badge.ok { color: var(--led-on); border-color: rgba(61,220,132,0.3); }
.badge.ok .led { background: var(--led-on); }
.badge.pending { color: var(--led-pending); border-color: rgba(242,178,60,0.3); }
.badge.pending .led { background: var(--led-pending); }
.badge.fault { color: var(--led-fault); border-color: rgba(255,92,92,0.3); }
.badge.fault .led { background: var(--led-fault); }

/* ---------------------------------------------------------------------------
   Modal
   --------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(8,10,12,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: 100%; max-width: 420px;
  max-height: 86vh;
  overflow-y: auto;
}
.modal h2 { font-size: 15px; margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------------------------------------------------------------------------
   Toast
   --------------------------------------------------------------------------- */
#toast-host { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--panel-raised); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 16px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.18s ease;
}
.toast.error { border-color: rgba(255,92,92,0.4); color: #FFB3B3; }
.toast.success { border-color: rgba(61,220,132,0.4); color: #B7F2D2; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------------------------------------------------------------------------
   Login
   --------------------------------------------------------------------------- */
.login-wrap { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 20px; overflow-y: auto; min-height: 0; }
.login-card { width: 100%; max-width: 360px; margin: auto; }
.login-card .brand { justify-content: center; font-size: 16px; margin-bottom: 4px; }
.login-card .tagline { text-align: center; color: var(--text-dim); font-size: 12.5px; margin-bottom: 24px; }
.role-select { display: flex; gap: 6px; margin-bottom: 18px; }
.role-pill {
  flex: 1; text-align: center; padding: 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--panel-raised); color: var(--text-dim);
  font-size: 12.5px; font-weight: 500;
}
.role-pill.active { color: var(--text); border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.login-card .btn-primary { width: 100%; margin-top: 6px; }
.login-foot { text-align: center; margin-top: 16px; font-size: 12.5px; color: var(--text-dim); }

/* ---------------------------------------------------------------------------
   Empty state
   --------------------------------------------------------------------------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-dim); }
.empty .glyph { width: 40px; height: 40px; margin: 0 auto 14px; border-radius: 50%; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; }
.empty h3 { font-size: 14px; color: var(--text); margin: 0 0 6px; }
.empty p { font-size: 12.5px; margin: 0; }

/* utility */
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.muted { color: var(--text-dim); }
.mono { font-family: var(--font-mono); }
.w-full { width: 100%; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin: 24px 0 10px; font-weight: 600; }
.section-title:first-child { margin-top: 0; }

@media (max-width: 640px) {
  main.view { padding: 14px; }
  .field-row { flex-direction: column; gap: 0; }
}

/* Make native date-picker calendar icons visible on the dark theme.
   color-scheme: dark already renders the icon light — do NOT also invert it
   (invert + dark scheme cancel out and make the icon black/invisible). */
:root { color-scheme: dark; }
input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"] { color-scheme: dark; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: 0.85;
  cursor: pointer;
  padding: 2px;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover,
input[type="month"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* ---- Custom type-or-pick combo box ---- */
.combo-wrap { position: relative; }
.combo-input { width: 100%; box-sizing: border-box; padding-right: 30px; }
.combo-caret {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--text-dim, #8b9095); font-size: 11px;
}
.combo-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50;
  display: none; max-height: 264px; overflow-y: auto;
  background: var(--panel, #14161c); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 12px 28px rgba(0,0,0,.45);
  padding: 4px;
}
.combo-panel.show { display: block; }
.combo-opt {
  padding: 9px 11px; border-radius: 6px; cursor: pointer; color: var(--text);
  font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.combo-opt:hover { background: var(--hover, rgba(255,255,255,.06)); }
.combo-empty { padding: 10px 11px; color: var(--text-dim, #8b9095); font-size: 13px; }
/* Scrollbar styling for the panel */
.combo-panel::-webkit-scrollbar { width: 9px; }
.combo-panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 6px; }
.combo-panel::-webkit-scrollbar-track { background: transparent; }


/* =============================================================================
   Polish pass — alignment + subtle, sober motion
   ============================================================================= */

/* Channel rows: consistent height, label truncates, controls right-aligned. */
.channel-row { min-height: 46px; }
.channel-row .channel-label { flex: 1; min-width: 0; }
.channel-row .channel-label .name,
.channel-row .channel-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* Speed control: fixed footprint so every rocker lines up vertically. */
.speed-wrap { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none; }
.speed-range { width: 84px; accent-color: var(--brand, #3ddc84); cursor: pointer; }
.speed-val { font-size: 11px; color: var(--text-dim); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.speed-sel { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; width: 58px; cursor: pointer; transition: border-color .15s ease; }
.speed-sel:hover { border-color: #3A4148; }

/* Device cards: equal-height columns; action row pinned to the bottom. */
.device-card { display: flex; flex-direction: column; transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease; }
.device-card:hover { border-color: #39414a; box-shadow: 0 6px 18px rgba(0,0,0,.28); }
.device-card > .flex:last-child { margin-top: auto; padding-top: 10px; }

/* Buttons: subtle lift on hover, gentle press. Sober — no bounce. */
.btn { transition: background .15s ease, border-color .15s ease, transform .12s ease, box-shadow .15s ease; will-change: transform; }
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.btn:active:not(:disabled) { transform: translateY(0) scale(0.97); box-shadow: none; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

/* Rocker: smoother knob travel + soft glow ramp. */
.rocker { transition: border-color .2s ease, background .2s ease; }
.rocker .knob { transition: transform .22s cubic-bezier(.4, 0, .2, 1), background .2s ease, box-shadow .25s ease; }
.rocker:hover:not(:disabled) { border-color: #3A4148; }
.rocker:active:not(:disabled) .knob { transform: scale(0.92); }
.rocker.on:active:not(:disabled) .knob { transform: translateX(22px) scale(0.92); }

/* Nav: smooth underline/color shifts. */
.nav a, .nav button, .tabs a, [data-nav] { transition: color .15s ease, border-color .15s ease, background .15s ease; }
.role-pill { transition: background .15s ease, color .15s ease, border-color .15s ease; }

/* Tiles (maps/blocks) share the card motion. */
.map-tile { transition: border-color .18s ease, box-shadow .18s ease; }
.map-tile:hover { border-color: #39414a; box-shadow: 0 4px 14px rgba(0,0,0,.22); }

/* Modals + toasts: gentle fade/slide in. */
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.modal-card, .login-card { animation: fadeUp .18s ease-out; }
.toast { animation: fadeUp .16s ease-out; }

/* Inputs: focus ring consistency. */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid rgba(61,220,132,.45); outline-offset: 1px; border-color: rgba(61,220,132,.5); }

/* Badges align vertically with text around them. */
.badge { vertical-align: middle; }

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .btn, .rocker .knob, .device-card, .map-tile, .modal-card, .login-card, .toast { transition: none !important; animation: none !important; }
}
