/* ============================================
   HOME PWA - Clean Professional Design
   ============================================ */

:root {
  /* Neutral grays */
  --bg-base: #161616;
  --bg-elevated: #1e1e1e;
  --bg-surface: #262626;
  --bg-hover: #2e2e2e;
  --bg-active: #363636;

  /* Borders */
  --border: #3a3a3a;
  --border-subtle: #2a2a2a;

  /* Text */
  --text: #e5e5e5;
  --text-secondary: #a0a0a0;
  --text-muted: #666;

  /* Accent - system blue */
  --accent: #0a84ff;
  --accent-dim: rgba(10, 132, 255, 0.15);

  /* Status */
  --success: #30d158;
  --success-dim: rgba(48, 209, 88, 0.15);
  --danger: #ff453a;
  --danger-dim: rgba(255, 69, 58, 0.15);

  /* Sizing */
  --radius: 8px;
  --radius-lg: 12px;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

/* Reset */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  background: var(--bg-base);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.4;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100vh;
}

/* ============================================
   LOGIN
   ============================================ */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-container {
  width: 100%;
  max-width: 300px;
  text-align: center;
}

.login-container h1 {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 32px;
  color: var(--text);
}

.login-container input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

.login-container input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-container input::placeholder {
  color: var(--text-muted);
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text);
  width: 100%;
  margin-top: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: #555;
}

.btn:active {
  background: var(--bg-active);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: #409cff;
  border-color: #409cff;
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.icon-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: var(--text-secondary);
  display: block;
}

.mini-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.mini-btn:hover {
  background: #409cff;
}

.mini-btn.active {
  background: var(--success);
}

/* ============================================
   HEADER
   ============================================ */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

header::before {
  content: '';
  position: absolute;
  top: calc(-1 * var(--safe-top));
  left: 0;
  right: 0;
  height: var(--safe-top);
  background: var(--bg-base);
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.version-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  background: var(--bg-surface);
  border-radius: 4px;
  color: var(--text-muted);
}

/* ============================================
   NAVIGATION
   ============================================ */

nav {
  display: flex;
  justify-content: space-around;
  padding: 8px;
  padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.15s;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.nav-btn span {
  font-size: 10px;
  font-weight: 500;
}

.nav-btn.active {
  color: var(--accent);
}

/* ============================================
   MAIN CONTENT
   ============================================ */

main {
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

/* ============================================
   CARDS
   ============================================ */

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 12px;
}

.status-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-icon svg {
  width: 16px;
  height: 16px;
  fill: var(--accent);
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.card-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.card-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-card.wide {
  grid-column: span 2;
}

/* ============================================
   SECTIONS
   ============================================ */

.section {
  margin-bottom: 20px;
}

.section h2 {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* ============================================
   DEVICE LIST
   ============================================ */

.device-list, .control-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.device-item, .control-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.device-item.clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.device-item.clickable:active {
  background: var(--bg-hover);
}

.device-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.device-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-dot.on {
  background: var(--success);
}

/* ============================================
   TOGGLE BUTTON
   ============================================ */

.toggle-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.toggle-label {
  font-weight: 500;
  font-size: 14px;
}

.toggle-switch {
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: var(--bg-active);
  position: relative;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.toggle-btn.active .toggle-switch {
  background: var(--success);
}

.toggle-btn.active .toggle-switch::after {
  transform: translateX(16px);
}

/* ============================================
   FAN CONTROL
   ============================================ */

.fan-control {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.fan-power {
  margin-bottom: 16px;
}

.fan-speed {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.speed-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.speed-btn:hover {
  background: var(--bg-hover);
}

.speed-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.fan-timer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fan-timer > span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.timer-btns {
  display: flex;
  gap: 6px;
}

.timer-btn {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.timer-btn:hover {
  background: var(--bg-hover);
}

.timer-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================================
   ELEVATOR CONTROL
   ============================================ */

.elevator-control {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  text-align: center;
}

.elevator-status {
  margin-bottom: 16px;
}

.elevator-status .floor {
  font-size: 40px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.elevator-status .direction {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

.elevator-btns {
  display: flex;
  gap: 8px;
}

.ev-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.ev-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.ev-btn:active {
  background: var(--bg-active);
}

.ev-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.ev-btn.active {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

/* ============================================
   ELEVATOR PANEL - 4 ELEVATORS GRID
   ============================================ */

.elevator-panel {
  grid-column: span 2;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
}

.elevator-panel.single {
  grid-column: span 1;
  grid-template-columns: 1fr;
}

.elevator-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.elevator-cell::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--accent-dim), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.elevator-cell.active::before {
  opacity: 1;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.6; }
}

.elevator-car-number {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

.elevator-cell.active .elevator-car-number {
  color: var(--accent);
}

.elevator-floor-display {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.elevator-floor-display .floor-number {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  transition: transform 0.3s ease;
}

.elevator-cell.moving .floor-number {
  animation: floor-change 0.5s ease-in-out;
}

@keyframes floor-change {
  0% { transform: translateY(0); opacity: 1; }
  50% { transform: translateY(-8px); opacity: 0.3; }
  100% { transform: translateY(0); opacity: 1; }
}

.elevator-floor-display .floor-arrow {
  font-size: 16px;
  line-height: 1;
  color: var(--accent);
  min-width: 16px;
  text-align: center;
}

.elevator-cell.moving.up .floor-arrow::before {
  content: '▲';
  animation: arrow-up 1s ease-in-out infinite;
}

.elevator-cell.moving.down .floor-arrow::before {
  content: '▼';
  animation: arrow-down 1s ease-in-out infinite;
}

@keyframes arrow-up {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-3px); opacity: 1; }
}

@keyframes arrow-down {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(3px); opacity: 1; }
}

.elevator-dest {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  min-height: 14px;
  text-align: center;
  margin-bottom: 6px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.elevator-cell.moving .elevator-dest {
  opacity: 1;
}

.elevator-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.3;
  transition: all 0.3s ease;
}

.elevator-cell.active .elevator-indicator {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 8px var(--accent);
}

/* ============================================
   LOBBY BUTTONS
   ============================================ */

.lobby-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.lobby-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  min-width: 32px;
  transition: all 0.15s;
}

.lobby-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.lobby-btn:active {
  background: var(--bg-active);
}

.lobby-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ============================================
   GAS CONTROL
   ============================================ */

.gas-control {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#gas-control-status {
  font-size: 16px;
  font-weight: 600;
}

.gas-control .btn {
  width: auto;
  margin: 0;
  padding: 10px 16px;
}

/* ============================================
   CAMERA
   ============================================ */

.camera-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.camera-view {
  aspect-ratio: 4/3;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

#camera-video,
#wallpad-camera-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.camera-placeholder svg {
  width: 48px;
  height: 48px;
  fill: currentColor;
  margin-bottom: 10px;
  opacity: 0.4;
}

.camera-placeholder p {
  font-weight: 500;
  font-size: 13px;
}

.camera-controls {
  display: flex;
  gap: 8px;
}

.camera-controls .btn {
  flex: 1;
  margin: 0;
}

.camera-note {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* Wallpad Camera */
.wallpad-camera {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
}

.wallpad-camera h3 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.wallpad-ip-input {
  margin-bottom: 12px;
}

.wallpad-ip-input input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 14px;
}

.wallpad-ip-input input::placeholder {
  color: var(--text-muted);
}

/* ============================================
   ENERGY
   ============================================ */

.energy-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.energy-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 14px;
}

.energy-card .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.energy-card .value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

.energy-card .unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ============================================
   CHARGER
   ============================================ */

.charger-section h2 {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.charger-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.charger-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.charger-name {
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.charger-status {
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
  margin-left: 8px;
}

.charger-status.available {
  background: var(--success-dim);
  color: var(--success);
}

.charger-status.unavailable {
  background: var(--danger-dim);
  color: var(--danger);
}

.charger-notify-btn {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  font-size: 16px;
  opacity: 0.3;
  flex-shrink: 0;
}

.charger-notify-btn:hover {
  opacity: 0.6;
}

.charger-notify-btn.active {
  opacity: 1;
}

/* ============================================
   BOILER CONTROL
   ============================================ */

.boiler-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.temp-display {
  font-size: 18px;
  font-weight: 700;
  min-width: 44px;
  text-align: center;
  color: var(--accent);
}

.temp-btns {
  display: flex;
  gap: 4px;
}

.temp-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.temp-btn:hover {
  background: var(--bg-hover);
}

.temp-btn:active {
  background: var(--bg-active);
}

/* ============================================
   MODAL
   ============================================ */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-content {
  width: 100%;
  max-width: 300px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.modal-content h2 {
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.setting-item:last-of-type {
  border-bottom: none;
}

.setting-item span {
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 14px;
}

.setting-item span:first-child {
  color: var(--text);
}

/* ============================================
   TOAST
   ============================================ */

.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================
   UTILITIES
   ============================================ */

.loading {
  opacity: 0.5;
}

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 2px;
}

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
  }
}

::selection {
  background: var(--accent-dim);
  color: var(--text);
}
