/* CSS Variables */
:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --text-primary: #ffffff;
  --text-secondary: #a0a0a0;
  --accent: #e94560;
  --accent-light: #ff6b6b;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #ef4444;
  --border-radius: 12px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.screen {
  min-height: 100vh;
}

/* Login Screen */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-container {
  width: 100%;
  max-width: 320px;
  text-align: center;
}

.login-container h1 {
  font-size: 2.5rem;
  margin-bottom: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-container input {
  width: 100%;
  padding: 16px;
  margin-bottom: 16px;
  border: none;
  border-radius: var(--border-radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
}

.login-container input::placeholder {
  color: var(--text-secondary);
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 10px;
}

/* Buttons */
.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--border-radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-secondary);
  color: var(--text-primary);
  width: 100%;
  margin-top: 8px;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
}

.btn.danger {
  background: var(--danger);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.icon-btn {
  background: transparent;
  border: none;
  padding: 8px;
  cursor: pointer;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: var(--text-primary);
}

.mini-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.mini-btn.active {
  background: var(--success);
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  padding-top: calc(16px + var(--safe-top));
  background: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

/* Navigation */
nav {
  display: flex;
  justify-content: space-around;
  padding: 12px 8px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--bg-secondary);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
}

.nav-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.nav-btn span {
  font-size: 11px;
}

.nav-btn.active {
  color: var(--accent);
}

/* Main Content */
main {
  padding: 20px;
  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: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 16px;
}

.status-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon svg {
  width: 24px;
  height: 24px;
  fill: var(--text-primary);
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.card-value {
  font-size: 16px;
  font-weight: 600;
}

/* Sections */
.section {
  margin-bottom: 24px;
}

.section h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

/* Device List */
.device-list, .control-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-item, .control-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--border-radius);
}

.device-item.clickable {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.device-item.clickable:active {
  opacity: 0.7;
}

.device-name {
  font-weight: 500;
}

.device-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.status-dot.on {
  background: var(--success);
}

/* Toggle Button */
.toggle-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
}

.toggle-switch {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: var(--bg-secondary);
  position: relative;
  transition: background 0.2s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s;
}

.toggle-btn.active .toggle-switch {
  background: var(--success);
}

.toggle-btn.active .toggle-switch::after {
  transform: translateX(20px);
}

/* Fan Control */
.fan-control {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 16px;
}

.fan-power {
  margin-bottom: 16px;
}

.fan-speed {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.speed-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--bg-secondary);
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
}

.speed-btn.active {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.2);
}

.fan-timer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fan-timer span {
  font-size: 14px;
  color: var(--text-secondary);
}

.timer-btns {
  display: flex;
  gap: 8px;
}

.timer-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
}

.timer-btn.active {
  background: var(--accent);
}

/* Elevator Control */
.elevator-control {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  text-align: center;
}

.elevator-status {
  margin-bottom: 20px;
}

.elevator-status .floor {
  font-size: 48px;
  font-weight: 700;
}

.elevator-status .direction {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
}

.elevator-btns {
  display: flex;
  gap: 12px;
}

.ev-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border: none;
  border-radius: var(--border-radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
}

.ev-btn svg {
  width: 32px;
  height: 32px;
  fill: currentColor;
}

.ev-btn.active {
  background: var(--success);
}

/* Lobby Buttons */
.lobby-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.lobby-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 12px;
  cursor: pointer;
  min-width: 32px;
}

.lobby-btn:active {
  background: var(--accent);
}

/* Wide card for lobby */
.status-card.wide {
  grid-column: span 2;
}

/* Gas Control */
.gas-control {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#gas-control-status {
  font-size: 18px;
  font-weight: 500;
}

.gas-control .btn {
  width: auto;
  margin: 0;
}

/* Camera */
.camera-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.camera-view {
  aspect-ratio: 4/3;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  overflow: hidden;
  position: relative;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.camera-placeholder svg {
  width: 64px;
  height: 64px;
  fill: currentColor;
  margin-bottom: 12px;
}

.camera-controls {
  display: flex;
  gap: 8px;
}

.camera-controls .btn {
  flex: 1;
  margin: 0;
}

.camera-note {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
}

/* Energy */
.energy-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.energy-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 16px;
}

.energy-card .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.energy-card .value {
  font-size: 24px;
  font-weight: 700;
}

.energy-card .unit {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Charger */
.charger-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.charger-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--border-radius);
}

.charger-name {
  font-weight: 500;
}

.charger-status {
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
}

.charger-status.available {
  background: rgba(74, 222, 128, 0.2);
  color: var(--success);
}

.charger-status.unavailable {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.charger-notify-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.charger-notify-btn:hover {
  opacity: 0.8;
}

.charger-notify-btn.active {
  opacity: 1;
}

/* Boiler Control */
.boiler-control {
  display: flex;
  align-items: center;
  gap: 16px;
}

.temp-display {
  font-size: 24px;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.temp-btns {
  display: flex;
  gap: 8px;
}

.temp-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
}

/* 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: 320px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 24px;
}

.modal-content h2 {
  margin-bottom: 20px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--bg-card);
}

/* Loading Animation */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.loading {
  animation: pulse 1.5s infinite;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background: var(--bg-card);
  border-radius: 24px;
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show {
  opacity: 1;
}
