/* Global styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  color-scheme: light dark;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',
    'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  background: #f5f5f5;
  color: #222;
  line-height: 1.6;
  padding: 2rem;
}

/* Header */
header {
  margin-bottom: 2rem;
}

header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  color: #0891b2;
}

header p {
  color: #6b7280;
  font-size: 1rem;
}

/* Breadcrumb navigation */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.breadcrumb-link {
  color: #0891b2;
  text-decoration: none;
}

.breadcrumb-link:hover {
  text-decoration: underline;
}

.breadcrumb-separator {
  color: #6b7280;
}

.breadcrumb-current {
  color: #6b7280;
}

/* Main content */
main {
  max-width: 1400px;
  margin: 0 auto;
}

section {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

section h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: #222;
}

/* Overview grid */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.overview-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.overview-item .label {
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 500;
}

.overview-item .value {
  font-size: 2rem;
  font-weight: 700;
  color: #0891b2;
}

/* Group controls */
.group-controls {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.group-btn {
  padding: 0.75rem 1.5rem;
  border: 1px solid #0891b2;
  background: #0891b2;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.group-btn:hover {
  background: #0e7490;
  border-color: #0e7490;
}

.group-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.group-btn.loading {
  position: relative;
  color: transparent;
}

.group-btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: button-spin 0.6s linear infinite;
  color: white;
}

@keyframes button-spin {
  to {
    transform: rotate(360deg);
  }
}

.group-btn.secondary {
  background: white;
  color: #0891b2;
}

.group-btn.secondary:hover {
  background: #f0f9ff;
}

/* Devices list */
.devices-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
}

.device-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1.5rem;
  transition: all 0.2s ease;
}

.device-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.device-card.loading {
  opacity: 0.7;
  pointer-events: none;
  position: relative;
}

.device-card.loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(8, 145, 178, 0.1);
  border-radius: 8px;
  z-index: 1;
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #e5e5e5;
}

.device-name {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #222;
}

.device-model {
  font-size: 0.85rem;
  color: #6b7280;
}

.status-indicator {
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-indicator.on {
  background: rgba(8, 145, 178, 0.15);
  color: #0891b2;
}

.status-indicator.off {
  background: rgba(107, 114, 128, 0.15);
  color: #6b7280;
}

.status-indicator.unknown {
  background: rgba(251, 146, 60, 0.15);
  color: #ea580c;
}

/* Device controls */
.device-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.power-btn {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #0891b2;
  background: #0891b2;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.2s ease;
}

.power-btn:hover {
  background: #0e7490;
  border-color: #0e7490;
}

.power-btn.off {
  background: white;
  color: #0891b2;
}

.power-btn.off:hover {
  background: #f0f9ff;
}

.power-btn.unknown {
  background: white;
  color: #ea580c;
  border-color: #ea580c;
}

.power-btn.unknown:hover {
  background: #fff7ed;
}

.power-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Brightness control */
.brightness-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.brightness-control label {
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 500;
}

/* Mode tabs */
.mode-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 0.5rem;
}

.mode-tab {
  flex: 1;
  padding: 0.5rem 1rem;
  border: 1px solid #e5e5e5;
  background: white;
  color: #6b7280;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.mode-tab:hover {
  background: #f9f9f9;
}

.mode-tab.active {
  background: #0891b2;
  color: white;
  border-color: #0891b2;
}

/* Color controls */
.color-controls,
.temp-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.color-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.color-control label {
  font-size: 0.9rem;
  color: #6b7280;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.temp-label-left,
.temp-label-right {
  font-size: 0.8rem;
  color: #9ca3af;
}

/* Range input styling */
input[type='range'] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #e5e5e5;
  outline: none;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #0891b2;
  cursor: pointer;
  transition: all 0.2s ease;
}

input[type='range']::-webkit-slider-thumb:hover {
  background: #0e7490;
  transform: scale(1.1);
}

input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #0891b2;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

input[type='range']::-moz-range-thumb:hover {
  background: #0e7490;
  transform: scale(1.1);
}

input[type='range']:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Apply button */
.apply-btn {
  padding: 0.75rem;
  border: 1px solid #0891b2;
  background: white;
  color: #0891b2;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.apply-btn:hover {
  background: #f0f9ff;
}

.apply-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Empty state */
.section-hint {
  text-align: center;
  color: #6b7280;
  padding: 2rem;
  font-size: 1rem;
}

/* Toast messages */
#messages {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: 6px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: translateY(1rem);
  transition: all 0.3s ease;
  z-index: 1000;
}

#messages:not(:empty) {
  opacity: 1;
  transform: translateY(0);
}

#messages.success {
  background: #22c55e;
  color: white;
}

#messages.error {
  background: #ef4444;
  color: white;
}

#messages.info {
  background: #3b82f6;
  color: white;
}

/* Mobile responsive */
@media (max-width: 768px) {
  body {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .devices-list {
    grid-template-columns: 1fr;
  }

  .group-controls {
    flex-direction: column;
  }

  .group-btn {
    width: 100%;
  }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  body {
    background: #111;
    color: #f5f5f5;
  }

  header h1 {
    color: #22d3ee;
  }

  header p {
    color: #9ca3af;
  }

  .breadcrumb-link {
    color: #22d3ee;
  }

  .breadcrumb-separator,
  .breadcrumb-current {
    color: #9ca3af;
  }

  section {
    background: rgba(25, 25, 25, 0.9);
  }

  section h2 {
    color: #f5f5f5;
  }

  .overview-item .label {
    color: #9ca3af;
  }

  .overview-item .value {
    color: #22d3ee;
  }

  .group-btn {
    border-color: #22d3ee;
    background: #22d3ee;
    color: #111;
  }

  .group-btn:hover {
    background: #06b6d4;
    border-color: #06b6d4;
  }

  .group-btn.secondary {
    background: #1a1a1a;
    color: #22d3ee;
  }

  .group-btn.secondary:hover {
    background: #262626;
  }

  .group-btn.loading::after {
    color: #111;
  }

  .group-btn.secondary.loading::after {
    color: #22d3ee;
  }

  .device-card {
    background: #1a1a1a;
    border-color: #333;
  }

  .device-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  }

  .device-card.loading::before {
    background: rgba(34, 211, 238, 0.1);
  }

  .device-header {
    border-bottom-color: #333;
  }

  .device-name {
    color: #f5f5f5;
  }

  .device-model {
    color: #9ca3af;
  }

  .status-indicator.on {
    background: rgba(34, 211, 238, 0.2);
    color: #22d3ee;
  }

  .status-indicator.off {
    background: rgba(156, 163, 175, 0.2);
    color: #9ca3af;
  }

  .status-indicator.unknown {
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
  }

  .power-btn {
    border-color: #22d3ee;
    background: #22d3ee;
    color: #111;
  }

  .power-btn:hover {
    background: #06b6d4;
    border-color: #06b6d4;
  }

  .power-btn.off {
    background: #1a1a1a;
    color: #22d3ee;
  }

  .power-btn.off:hover {
    background: #262626;
  }

  .power-btn.unknown {
    background: #1a1a1a;
    color: #fb923c;
    border-color: #fb923c;
  }

  .power-btn.unknown:hover {
    background: #262626;
  }

  .brightness-control label,
  .color-control label {
    color: #9ca3af;
  }

  .mode-tabs {
    border-bottom-color: #333;
  }

  .mode-tab {
    background: #1a1a1a;
    color: #9ca3af;
    border-color: #333;
  }

  .mode-tab:hover {
    background: #262626;
  }

  .mode-tab.active {
    background: #22d3ee;
    color: #111;
    border-color: #22d3ee;
  }

  input[type='range'] {
    background: #333;
  }

  input[type='range']::-webkit-slider-thumb {
    background: #22d3ee;
  }

  input[type='range']::-webkit-slider-thumb:hover {
    background: #06b6d4;
  }

  input[type='range']::-moz-range-thumb {
    background: #22d3ee;
  }

  input[type='range']::-moz-range-thumb:hover {
    background: #06b6d4;
  }

  .apply-btn {
    background: #1a1a1a;
    color: #22d3ee;
    border-color: #22d3ee;
  }

  .apply-btn:hover {
    background: #262626;
  }

  .section-hint {
    color: #9ca3af;
  }
}
