/**
 * GE Low Voltage Switch Plate - Skeuomorphic UI
 *
 * Design goals:
 * - Replicate the look of classic GE despard-style switch plates
 * - Beige/ivory color scheme matching physical plates
 * - 3D rocker switches with realistic shadows
 * - Green highlight on top when ON, red highlight on bottom when OFF
 * - Two 2x4 plates side by side
 */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  /* Dark background to make the plates stand out, like a wall */
  background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* ============================================
   Connection Status Indicator
   ============================================ */

#status-indicator {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 100;
}

.status-dot {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transition: background-color 0.3s ease;
}

.status-connected .status-dot {
  background-color: #4ade80;
  box-shadow: 0 0 6px #4ade80;
}

.status-disconnected .status-dot {
  background-color: #f87171;
  box-shadow: 0 0 6px #f87171;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============================================
   View Toggle Button
   ============================================ */

#view-toggle {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease;
}

#view-toggle:hover {
  background: rgba(255, 255, 255, 0.2);
}

#view-toggle:active {
  background: rgba(255, 255, 255, 0.3);
}

.view-icon {
  font-size: 18px;
  color: #888;
}

/* ============================================
   Page Indicators (for tiled view)
   ============================================ */

#page-indicators {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 100;
}

#page-indicators.hidden {
  display: none;
}

.page-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
}

.page-dot:hover {
  background: rgba(255, 255, 255, 0.5);
}

.page-dot.active {
  background: rgba(255, 255, 255, 0.9);
  transform: scale(1.2);
}

/* ============================================
   Panel Container
   ============================================ */

#panel-container {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* Side-by-side view (default for larger screens) */
#panel-container.view-side-by-side {
  flex-direction: row;
  flex-wrap: nowrap;
  overflow: visible;
}

#panel-container.view-side-by-side .plate-content {
  padding: 0;
}

/* Tiled/swipeable view */
#panel-container.view-tiled {
  width: 100vw;
  height: 100%;
  padding: 0;
  gap: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: flex-start;
  overflow-x: scroll;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}

#panel-container.view-tiled::-webkit-scrollbar {
  display: none; /* Chrome, Safari */
}

#panel-container.view-tiled .switch-plate {
  flex: 0 0 100vw;
  width: 100vw;
  min-width: 100vw;
  max-width: 100vw;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  border-radius: 0;
  box-shadow: none;
  background: linear-gradient(180deg, #f5f0e6 0%, #e8e0d0 100%);
}

/* Keep screw holes visible in tiled view for config access */
#panel-container.view-tiled .switch-plate::before,
#panel-container.view-tiled .switch-plate::after {
  display: block;
}

/* Plate content wrapper */
.plate-content {
  display: flex;
  align-items: center;
  justify-content: center;
}

#panel-container.view-tiled .plate-content {
  padding: 40px;
}

/* Make switches larger in tiled view */
#panel-container.view-tiled .switch-button {
  width: 70px;
  height: 90px;
}

#panel-container.view-tiled .switch-label {
  font-size: 16px;
  font-weight: 500;
  max-width: 80px;
  margin-top: 12px;
  color: #444;
}

#panel-container.view-tiled .switch-grid {
  gap: 20px;
}

#panel-container.view-tiled .switch-rocker {
  padding: 4px;
}

.loading {
  color: #666;
  font-size: 18px;
}

/* ============================================
   Switch Plate (the beige backing)
   ============================================ */

.switch-plate {
  /* Classic GE ivory/beige color */
  background: linear-gradient(180deg, #f5f0e6 0%, #e8e0d0 100%);
  border-radius: 8px;
  padding: 16px;

  /* Plate shadow for 3D effect */
  box-shadow:
    0 4px 8px rgba(0, 0, 0, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);

  /* Subtle texture */
  position: relative;
}

/* Screw holes for authenticity */
.switch-plate::before,
.switch-plate::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: linear-gradient(135deg, #c0b8a8 0%, #d8d0c0 50%, #c0b8a8 100%);
  border-radius: 50%;
  border: 1px solid #b0a898;
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.3),
    0 1px 0 rgba(255, 255, 255, 0.3);
}

.switch-plate::before {
  top: 50%;
  left: 6px;
  transform: translateY(-50%);
}

.switch-plate::after {
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
}

/* ============================================
   Switch Grid
   ============================================ */

.switch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
  padding: 0 12px;
}

/* ============================================
   Individual Switch
   ============================================ */

.switch {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.switch-rocker {
  /* Dark bezel around the rocker */
  background: #3a3a4a;
  border-radius: 4px;
  padding: 3px;

  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.2);
}

.switch-button {
  /* The actual rocker switch */
  width: 44px;
  height: 56px;
  background: linear-gradient(180deg, #f0ebe0 0%, #e0d8c8 50%, #d8d0c0 100%);
  border-radius: 3px;
  position: relative;

  /* 3D effect */
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1),
    0 2px 4px rgba(0, 0, 0, 0.2);

  transition: all 0.15s ease;

  /* Divider line in the middle */
  display: flex;
  flex-direction: column;
}

.switch-button::before {
  /* Horizontal divider line */
  content: '';
  position: absolute;
  top: 50%;
  left: 4px;
  right: 4px;
  height: 1px;
  background: #c8c0b0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* Top half of rocker (ON indicator area) */
.switch-top {
  flex: 1;
  border-radius: 3px 3px 0 0;
  transition: all 0.15s ease;
}

/* Bottom half of rocker (OFF indicator area) */
.switch-bottom {
  flex: 1;
  border-radius: 0 0 3px 3px;
  transition: all 0.15s ease;
}

/* ============================================
   Switch States
   ============================================ */

/* ON state - solid green on top half, top pressed down */
.switch.state-on .switch-button {
  transform: perspective(100px) rotateX(5deg);
}

.switch.state-on .switch-top {
  background: rgba(74, 222, 128, 0.75);
}

/* OFF state - solid red on bottom half, bottom pressed down */
.switch.state-off .switch-button {
  transform: perspective(100px) rotateX(-5deg);
}

.switch.state-off .switch-bottom {
  background: rgba(248, 113, 113, 0.75);
}

/* Active/pressed state */
.switch:active .switch-button {
  transform: scale(0.98);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    inset 0 -1px 0 rgba(0, 0, 0, 0.05),
    0 1px 2px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Switch Label
   ============================================ */

.switch-label {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 500;
  color: #f0f0f0;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  max-width: 50px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   Responsive adjustments
   ============================================ */

/* Smaller screens - reduce sizes proportionally */
@media (max-width: 800px) {
  #panel-container {
    gap: 12px;
    padding: 10px;
  }

  .switch-plate {
    padding: 12px;
  }

  .switch-grid {
    gap: 6px;
    padding: 0 8px;
  }

  .switch-button {
    width: 36px;
    height: 46px;
  }

  .switch-label {
    font-size: 9px;
    max-width: 40px;
  }
}

/* Very small screens (phone) */
@media (max-width: 500px) {
  #panel-container {
    flex-direction: column;
    gap: 16px;
  }

  .switch-button {
    width: 32px;
    height: 40px;
  }
}

/* Larger screens - scale up */
@media (min-width: 1200px) {
  .switch-button {
    width: 52px;
    height: 66px;
  }

  .switch-label {
    font-size: 13px;
    max-width: 60px;
  }

  .switch-grid {
    gap: 10px;
  }
}
