/* =========================================================================
   TeslaClaw — CSS Design System
   Tesla Model X optimized: dark theme, 64px+ touch targets, no build step
   Target: Chromium 109+
   ========================================================================= */

/* ---------------------------------------------------------------------------
   Custom Properties (Design Tokens)
   --------------------------------------------------------------------------- */

:root {
  /* Colors — background hierarchy */
  --bg: #050505;
  --surface: #141414;
  --surface-elevated: #1a1a1a;
  --border: #1a1a1a;
  --border-subtle: #0a0a0a;

  /* Colors — accent */
  --accent: #3b82f6;
  --accent-dim: #1d4ed8;
  --accent-faint: #0d1f40;

  /* Colors — text hierarchy */
  --text-bright: #fafafa;
  --text-primary: #e5e5e5;
  --text-secondary: #a3a3a3;
  --text-muted: #525252;
  --text-dim: #404040;
  --text-faint: #333333;

  /* Colors — semantic */
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;

  /* Colors — chat message */
  --user-msg-bg: #0d1520;
  --user-msg-border: #1e3a5f;
  --user-msg-text: #7db4f0;

  /* Typography */
  --font: -apple-system, system-ui, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'Cascadia Code', monospace;

  /* Geometry */
  --radius: 8px;
  --radius-sm: 4px;
  --radius-round: 12px;
}

/* ---------------------------------------------------------------------------
   Reset + Base
   --------------------------------------------------------------------------- */

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

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

button, input, textarea {
  font-family: var(--font);
  font-size: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
  cursor: pointer;
}

input, textarea {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}

/* ---------------------------------------------------------------------------
   Typography Scale
   --------------------------------------------------------------------------- */

.micro {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

.value {
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 300;
  line-height: 1.1;
}

.value .unit {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
}

.value-lg {
  color: var(--text-bright);
  font-size: 48px;
  font-weight: 200;
  line-height: 1;
  letter-spacing: -1px;
}

.value-lg .unit {
  color: var(--text-dim);
  font-size: 20px;
  font-weight: 300;
  letter-spacing: 0;
}

/* ---------------------------------------------------------------------------
   Top Bar
   --------------------------------------------------------------------------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 44px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-brand {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.3px;
}

/* ---------------------------------------------------------------------------
   Connection Health Dot
   --------------------------------------------------------------------------- */

.health-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: opacity 300ms ease;
}

.health-dot.healthy {
  background: var(--success);
}

.health-dot.degraded {
  background: var(--warning);
  animation: pulse-warning 2s ease-in-out infinite;
}

.health-dot.down {
  background: var(--error);
}

@keyframes pulse-warning {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------------------------------------------------------------------------
   Mode Switcher
   --------------------------------------------------------------------------- */

.mode-switcher {
  display: flex;
  gap: 2px;
  background: #0a0a0a;
  border-radius: 6px;
  padding: 2px;
  border: 1px solid var(--border);
}

.mode-pill {
  padding: 4px 14px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  position: relative;
  transition: opacity 200ms ease;
  min-width: 52px;
  text-align: center;
}

.mode-pill.active {
  background: var(--surface);
  color: var(--text-secondary);
}

.mode-pill.auto::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------------------------------------------------------------------------
   Layout Containers
   --------------------------------------------------------------------------- */

.mode-view {
  flex: 1;
  display: flex;
  overflow: hidden;
  animation: fade-in 200ms ease;
}

.panel {
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.panel-border {
  border-left: 1px solid var(--border);
  padding-left: 24px;
}

.divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Cards (HA Controls)
   --------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  border: 1px solid var(--border-subtle);
}

/* ---------------------------------------------------------------------------
   Toggle Switch
   --------------------------------------------------------------------------- */

.toggle {
  width: 44px;
  height: 24px;
  border-radius: var(--radius-round);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 200ms ease;
}

.toggle.on {
  background: var(--accent-dim);
  border: 1px solid var(--accent-dim);
}

.toggle.off {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

.toggle-knob {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  transition: transform 200ms ease;
}

.toggle.on .toggle-knob {
  transform: translateX(22px);
  background: var(--text-bright);
}

.toggle.off .toggle-knob {
  transform: translateX(2px);
  background: var(--text-muted);
}

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */

.btn {
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  touch-action: manipulation;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 150ms ease;
  white-space: nowrap;
}

.btn:active {
  opacity: 0.7;
}

.btn.active {
  border-color: var(--accent-dim);
  background: var(--user-msg-bg);
  color: var(--user-msg-text);
}

/* ---------------------------------------------------------------------------
   Temperature Controls
   --------------------------------------------------------------------------- */

.temp-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 150ms ease;
}

.temp-btn:active {
  opacity: 0.6;
}

.temp-val {
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 300;
  min-width: 60px;
  text-align: center;
}

.temp-unit {
  color: var(--text-dim);
  font-size: 14px;
}

/* ---------------------------------------------------------------------------
   Chat Panel
   --------------------------------------------------------------------------- */

.chat-msg {
  border-radius: 6px;
  padding: 10px 14px;
  max-width: 100%;
}

.chat-msg.assistant {
  background: var(--surface);
}

.chat-msg.assistant .chat-text {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.user {
  background: var(--user-msg-bg);
  border: 1px solid var(--user-msg-border);
}

.chat-msg.user .chat-text {
  color: var(--user-msg-text);
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg.system {
  background: transparent;
  border: 1px solid var(--border);
}

.chat-msg.system .chat-text {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
  font-style: italic;
}

.chat-time {
  color: var(--text-faint);
  font-size: 9px;
  margin-top: 4px;
  letter-spacing: 0.3px;
}

.chat-input-wrap {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  min-height: 44px;
  resize: none;
  user-select: text;
  -webkit-user-select: text;
}

.chat-input::placeholder {
  color: var(--text-faint);
}

.chat-send {
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: opacity 150ms ease;
}

.chat-send:active {
  opacity: 0.6;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-elevated) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--surface-elevated);
  border-radius: 2px;
}

/* ---------------------------------------------------------------------------
   Notifications
   --------------------------------------------------------------------------- */

.notif {
  padding: 8px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  border-left: 2px solid;
  cursor: pointer;
  transition: opacity 150ms ease;
}

.notif:active {
  opacity: 0.7;
}

.notif.error {
  border-color: var(--error);
  background: #140a0a;
}

.notif.warning {
  border-color: var(--warning);
  background: #14110a;
}

.notif.info {
  border-color: var(--accent);
  background: #0a0d14;
}

.notif-title {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.4;
}

.notif-body {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
  line-height: 1.3;
}

.notif-time {
  color: var(--text-faint);
  font-size: 9px;
  margin-top: 3px;
  letter-spacing: 0.3px;
}

/* ---------------------------------------------------------------------------
   Toast (Driving Mode — auto-dismissing)
   --------------------------------------------------------------------------- */

.toast {
  background: var(--surface);
  border-radius: 0 6px 6px 0;
  border-left: 2px solid;
  padding: 12px 16px;
  animation: toast-in 300ms ease forwards, toast-out 300ms ease 4700ms forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(20px); }
}

.toast-source {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.toast-body {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.4;
}

/* ---------------------------------------------------------------------------
   Stats Row
   --------------------------------------------------------------------------- */

.stats-row {
  display: flex;
  gap: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.stat {
  min-width: 80px;
}

/* ---------------------------------------------------------------------------
   PIN Pad
   --------------------------------------------------------------------------- */

.pin-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
}

.pin-brand {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.pin-dots {
  display: flex;
  gap: 12px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border);
  transition: background 150ms ease;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-error {
  color: var(--error);
  font-size: 13px;
  text-align: center;
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.pin-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  transition: opacity 150ms ease;
}

.pin-btn:active {
  opacity: 0.6;
}

.pin-btn.action {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

/* ---------------------------------------------------------------------------
   Battery Ring
   --------------------------------------------------------------------------- */

.battery-ring {
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Charge Chart
   --------------------------------------------------------------------------- */

.charge-chart-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------------------------------------------------------------------------
   Vehicle Summary
   --------------------------------------------------------------------------- */

.vehicle-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.vehicle-summary-row:last-child {
  border-bottom: none;
}

.vehicle-summary-label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.vehicle-summary-value {
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 400;
}

/* ---------------------------------------------------------------------------
   QR Auth Screen
   --------------------------------------------------------------------------- */

.qr-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.qr-code {
  padding: 16px;
  background: #fff;
  border-radius: var(--radius);
}

.qr-label {
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

.qr-switch {
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 8px 16px;
  min-height: 44px;
  display: flex;
  align-items: center;
}

/* ---------------------------------------------------------------------------
   Animations
   --------------------------------------------------------------------------- */

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------------------------------------------------------------------------
   HA Controls Grid
   --------------------------------------------------------------------------- */

.ha-controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ha-controls-grid > .card {
  min-width: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------------------
   Scrollable panels
   --------------------------------------------------------------------------- */

.scroll-y {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-elevated) transparent;
}

.scroll-y::-webkit-scrollbar {
  width: 4px;
}

.scroll-y::-webkit-scrollbar-thumb {
  background: var(--surface-elevated);
  border-radius: 2px;
}
