/* style.css */
:root {
  --bg: #071018;
  --bg-2: #091722;
  --panel: rgba(11, 20, 34, 0.58);
  --panel-strong: rgba(13, 24, 42, 0.85);
  --line: rgba(255, 255, 255, 0.08);
  --text: #f5fbff;
  --muted: #9bb2c7;
  --accent: #36e4ff;
  --accent-2: #8b5cf6;
  --success: #39d98a;
  --warning: #ffbe0b;
  --danger: #ff5d73;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  --radius: 20px;
  --radius-sm: 12px;
  --sidebar-w: 290px;
  --transition: 180ms ease;
  --glow: 0 0 0 1px rgba(54, 228, 255, 0.25), 0 0 18px rgba(54, 228, 255, 0.18);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(54, 228, 255, 0.08), transparent 30%),
    radial-gradient(circle at bottom right, rgba(139, 92, 246, 0.1), transparent 32%),
    linear-gradient(135deg, var(--bg), var(--bg-2));
  color: var(--text);
  font-family: var(--font);
}

body {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.app-shell {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(circle at center, black, transparent 80%);
  pointer-events: none;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(60px);
  opacity: 0.18;
  pointer-events: none;
  animation: floatOrb 10s ease-in-out infinite;
}

.orb-1 {
  width: 300px;
  height: 300px;
  top: -60px;
  left: -40px;
  background: #00d4ff;
}

.orb-2 {
  width: 360px;
  height: 360px;
  bottom: -100px;
  right: -80px;
  background: #7c3aed;
  animation-delay: -4s;
}

@keyframes floatOrb {
  0%, 100% { transform: translateY(0) translateX(0) scale(1); }
  50% { transform: translateY(20px) translateX(10px) scale(1.05); }
}

.glass {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

.glow-border {
  box-shadow: var(--shadow), var(--glow);
}

.glow-on {
  box-shadow: var(--shadow), 0 0 30px rgba(54, 228, 255, 0.08), inset 0 0 0 1px rgba(54, 228, 255, 0.12);
}

.muted {
  color: var(--muted);
}

.setup-screen {
  min-height: 100vh;
  display: none;
  padding: 32px;
  overflow-y: auto;
}

.setup-screen.active {
  display: block;
}

.setup-wrapper {
  max-width: 1320px;
  margin: 0 auto;
}

.setup-hero {
  padding: 28px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-row.compact {
  margin-bottom: 20px;
}

.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(54, 228, 255, 0.25), rgba(139, 92, 246, 0.22));
  color: white;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 0 25px rgba(54, 228, 255, 0.15);
}

.setup-instructions {
  margin: 24px 0;
  color: var(--muted);
}

.setup-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
}

.setup-card {
  padding: 20px;
}

.setup-form,
.stack-form {
  display: grid;
  gap: 16px;
}

.setup-form label,
.stack-form label {
  display: grid;
  gap: 8px;
}

.setup-form span,
.stack-form span {
  color: var(--muted);
  font-size: 0.94rem;
}

.setup-actions,
.inline-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.help-box {
  margin-top: 18px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed rgba(255,255,255,0.14);
  border-radius: 18px;
  color: var(--muted);
  padding: 16px;
}

.empty-icon {
  font-size: 2rem;
  opacity: 0.85;
}

.bridge-results {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

.bridge-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--line);
}

.app-shell input,
.app-shell select,
.app-shell textarea {
  width: 100%;
  background: rgba(255,255,255,0.05);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.app-shell input:focus,
.app-shell select:focus,
.app-shell textarea:focus {
  border-color: rgba(54, 228, 255, 0.45);
  box-shadow: 0 0 0 4px rgba(54, 228, 255, 0.1);
  background: rgba(255,255,255,0.08);
}

.btn,
.quick-btn,
.icon-btn,
.nav-btn {
  border: 0;
  cursor: pointer;
  color: white;
  transition: transform var(--transition), opacity var(--transition), box-shadow var(--transition), background var(--transition);
}

.btn:hover,
.quick-btn:hover,
.icon-btn:hover,
.nav-btn:hover {
  transform: translateY(-1px);
}

.btn {
  padding: 11px 16px;
  border-radius: 14px;
  font-weight: 700;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #2aa8ff);
  color: #02131d;
  box-shadow: 0 10px 24px rgba(54, 228, 255, 0.22);
}

.btn-secondary {
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--line);
}

.btn-danger {
  background: linear-gradient(135deg, rgba(255, 93, 115, 0.95), rgba(255, 64, 93, 0.84));
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
}

.main-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  margin: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
}

.nav {
  display: grid;
  gap: 10px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  padding: 13px 14px;
  border-radius: 16px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
}

.nav-btn.active {
  background: rgba(54, 228, 255, 0.1);
  border-color: rgba(54, 228, 255, 0.25);
  box-shadow: 0 0 20px rgba(54, 228, 255, 0.08);
}

.bridge-status {
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-indicator {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 18px rgba(255, 93, 115, 0.4);
}

.status-indicator.connected {
  background: var(--success);
  box-shadow: 0 0 18px rgba(57, 217, 138, 0.45);
}

.kbd-shortcuts {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.85rem;
  display: grid;
  gap: 8px;
}

kbd {
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 8px;
  padding: 2px 7px;
}

.content {
  padding: 14px 14px 14px 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  padding: 16px 18px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 14px;
}

.topbar-left,
.topbar-right {
  display: flex;
  gap: 14px;
  align-items: center;
}

.search-wrap {
  min-width: 260px;
}

.view-section {
  display: none;
  overflow-y: auto;
  padding-right: 4px;
  animation: fadeUp 220ms ease;
}

.view-section.active {
  display: block;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.stat-card {
  padding: 18px;
}

.stat-label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  margin: 8px 0;
}

.stat-sub {
  color: var(--muted);
  font-size: 0.88rem;
}

.dashboard-grid,
.groups-layout,
.scenes-layout,
.effects-layout,
.settings-layout {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.span-2 {
  grid-column: span 2;
}

.panel-header,
.card-header,
.section-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.section-toolbar {
  padding: 14px 16px;
  margin-bottom: 14px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  gap: 12px;
  align-items: center;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.quick-btn {
  padding: 16px;
  border-radius: 16px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
}

.details-list {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.activity-feed {
  display: grid;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.activity-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
}

.layout-controls {
  display: grid;
  gap: 14px;
}

.lights-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  min-height: 120px;
}

.light-card {
  position: relative;
  padding: 16px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  box-shadow: var(--shadow);
  min-height: 270px;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.light-card.dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

.light-card.on {
  border-color: rgba(54, 228, 255, 0.32);
  box-shadow: var(--shadow), 0 0 28px rgba(54, 228, 255, 0.12);
}

.light-card.offline {
  opacity: 0.72;
}

.light-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.light-name {
  font-weight: 800;
}

.light-meta,
.small-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.light-bulb {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  margin: 16px 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.65), rgba(255,255,255,0.08));
  border: 1px solid var(--line);
  box-shadow: inset 0 0 18px rgba(255,255,255,0.06);
}

.light-card.on .light-bulb {
  box-shadow:
    inset 0 0 18px rgba(255,255,255,0.12),
    0 0 26px rgba(54, 228, 255, 0.22),
    0 0 54px rgba(54, 228, 255, 0.08);
}

.light-controls {
  display: grid;
  gap: 12px;
}

.control-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.range-wrap {
  display: grid;
  gap: 6px;
}

input[type="range"] {
  appearance: none;
  height: 8px;
  border-radius: 999px;
  padding: 0;
  background: linear-gradient(90deg, rgba(54, 228, 255, 0.9), rgba(139, 92, 246, 0.9));
  border: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: white;
  box-shadow: 0 0 0 4px rgba(54, 228, 255, 0.2);
  cursor: pointer;
}

input[type="color"] {
  height: 44px;
  padding: 6px;
}

.toggle {
  position: relative;
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  border: 1px solid var(--line);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 999px;
  transition: transform var(--transition), background var(--transition);
}

.toggle.active {
  background: rgba(57, 217, 138, 0.25);
}

.toggle.active::after {
  transform: translateX(24px);
  background: var(--success);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--line);
  font-size: 0.88rem;
}

.rooms-container,
.groups-container,
.effects-list {
  display: grid;
  gap: 14px;
}

.room-card,
.group-card,
.scene-card,
.sensor-card,
.effect-item {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.room-card summary {
  list-style: none;
  cursor: pointer;
}

.room-card summary::-webkit-details-marker {
  display: none;
}

.room-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.room-body {
  margin-top: 16px;
  display: grid;
  gap: 16px;
}

.room-lights {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.mini-chip {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 220px;
  overflow-y: auto;
}

.check-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line);
}

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

.scene-preview {
  height: 84px;
  border-radius: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
}

.sensors-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.sensor-values {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.effects-layout {
  grid-template-columns: 1.1fr 0.9fr;
}

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

.effect-item.running {
  border-color: rgba(54, 228, 255, 0.26);
  box-shadow: var(--shadow), 0 0 24px rgba(54, 228, 255, 0.08);
}

.notification-container {
  position: fixed;
  top: 16px;
  right: 16px;
  width: min(380px, calc(100vw - 24px));
  z-index: 9999;
  display: grid;
  gap: 10px;
}

.notification {
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 32, 0.92);
  box-shadow: var(--shadow);
  animation: slideIn 220ms ease, pulseGlow 2.2s ease-in-out infinite;
}

.notification.success { border-color: rgba(57, 217, 138, 0.25); }
.notification.error { border-color: rgba(255, 93, 115, 0.25); }
.notification.info { border-color: rgba(54, 228, 255, 0.25); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px) translateX(10px); }
  to { opacity: 1; transform: translateY(0) translateX(0); }
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: var(--shadow), 0 0 18px rgba(54, 228, 255, 0.08); }
}

.global-loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 9998;
  background: rgba(2, 8, 15, 0.55);
  backdrop-filter: blur(10px);
}

.loader-card {
  width: min(420px, calc(100vw - 30px));
  padding: 26px;
  text-align: center;
}

.loader-ring {
  width: 74px;
  height: 74px;
  margin: 0 auto 18px;
  border-radius: 999px;
  border: 4px solid rgba(255,255,255,0.08);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 16, 0.68);
  backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  width: min(860px, calc(100vw - 24px));
  margin: 5vh auto;
  padding: 18px;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-header,
.modal-body {
  display: grid;
  gap: 14px;
}

.modal-header {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.mobile-only {
  display: none;
}

.compact-mode .light-card {
  min-height: 225px;
  padding: 12px;
}

.compact-mode .lights-grid {
  gap: 10px;
}

@media (max-width: 1400px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .lights-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .sensors-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1100px) {
  .main-app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 9000;
    top: 14px;
    left: 14px;
    bottom: 14px;
    width: min(320px, calc(100vw - 28px));
    transform: translateX(-115%);
    transition: transform 220ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .content {
    padding: 14px;
  }

  .mobile-only {
    display: inline-grid;
  }

  .setup-grid,
  .dashboard-grid,
  .groups-layout,
  .scenes-layout,
  .settings-layout,
  .effects-layout {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .lights-grid,
  .scenes-grid,
  .sensors-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .quick-actions {
    grid-template-columns: repeat(2, 1fr);
  }

  .range-grid,
  .modal-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    overflow: auto;
  }

  .setup-screen {
    padding: 14px;
  }

  .setup-hero,
  .sidebar,
  .panel,
  .topbar,
  .section-toolbar {
    border-radius: 18px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-left,
  .topbar-right {
    flex-wrap: wrap;
  }

  .search-wrap {
    min-width: 100%;
  }

  .stats-grid,
  .lights-grid,
  .scenes-grid,
  .sensors-grid,
  .room-lights,
  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  .quick-actions {
    grid-template-columns: 1fr;
  }
}
