/* ============================================
   Servers Lights Control - Light Theme Base
   All colors via CSS custom properties for theming
   ============================================ */

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

:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #f1f5f9;
  --bg-card-hover: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --border-radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --transition: all 0.3s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ============================================
   Header & Navigation
   ============================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 100;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 16px;
  cursor: pointer;
  border-radius: var(--border-radius);
  transition: var(--transition);
  font-size: 0.9rem;
  white-space: nowrap;
}

.nav-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent);
  color: white;
}

.user-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.night-mode-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--border-radius);
  background: rgba(0, 0, 0, 0.05);
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
}

.night-mode-indicator:hover {
  background: rgba(0, 0, 0, 0.1);
}

.night-mode-indicator.active {
  background: rgba(22, 163, 74, 0.15);
  border: 1px solid var(--success);
}

.night-mode-indicator.inactive {
  background: rgba(100, 116, 139, 0.1);
  border: 1px solid transparent;
}

.night-mode-icon {
  font-size: 1rem;
}

.night-mode-text {
  color: var(--text-secondary);
  white-space: nowrap;
}

.night-mode-indicator.active .night-mode-text {
  color: var(--success);
}

/* ============================================
   Sections & Layout
   ============================================ */

.section {
  display: none;
}

.section.active {
  display: block;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-header h2 {
  font-size: 1.4rem;
}

.form {
  max-width: 400px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.95rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 0.95rem;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.15);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-back {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.95rem;
  margin-bottom: 16px;
  padding: 8px 0;
}

.btn-back:hover {
  color: var(--text-primary);
}

/* ============================================
   Login
   ============================================ */

.login-container {
  max-width: 400px;
  margin: 80px auto;
  padding: 30px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.login-container h2 {
  text-align: center;
  margin-bottom: 24px;
}

/* ============================================
   Buildings Grid
   ============================================ */

.buildings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.building-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.building-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
  background: var(--bg-card-hover);
}

.building-card h3 {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 1.1rem;
}

.building-card p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
}

/* ============================================
   Building Detail
   ============================================ */

.building-detail {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.building-detail h2 {
  margin-bottom: 20px;
  font-size: 1.3rem;
}

/* Camera Stream */

.camera-stream-section {
  margin-top: 20px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--border-radius);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.camera-stream-section h3 {
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 1rem;
}

.stream-container {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  background: #000;
  border-radius: var(--border-radius);
  overflow: hidden;
}

#streamImage {
  width: 100%;
  display: block;
  min-height: 200px;
  object-fit: contain;
}

.stream-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  z-index: 10;
}

.stream-overlay p {
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.light-controls {
  display: grid;
  gap: 24px;
  margin: 20px 0;
}

.light-controls h3 {
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Color Palette */

.palette-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  border: 3px solid transparent;
}

.color-swatch:hover {
  transform: scale(1.1);
  border-color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Flag Presets */

.flag-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
}

.flag-btn {
  width: 100%;
  aspect-ratio: 3/2;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: var(--transition);
  border: 2px solid transparent;
  background-size: cover;
  background-position: center;
  position: relative;
  overflow: hidden;
}

.flag-btn:hover {
  transform: scale(1.08);
  border-color: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.flag-btn .flag-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 0.65rem;
  text-align: center;
  padding: 2px 4px;
}

/* Custom Color */

.custom-color {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#customColorPicker {
  width: 50px;
  height: 40px;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  background: transparent;
}

.color-hex-input {
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-family: monospace;
  width: 100px;
}

/* Pattern Section */

.pattern-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.form-control {
  padding: 10px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
}

/* Spot Grid */

.spot-section {
  margin-top: 24px;
}

.spot-section h3 {
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.spot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 12px;
}

.spot {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  border: 3px solid rgba(0, 0, 0, 0.1);
}

.spot:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.spot-color-picker-popup {
  display: grid;
  grid-template-columns: repeat(4, 32px);
  gap: 4px;
  padding: 8px;
  background: var(--bg-secondary);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color, #e2e8f0);
}

.spot-color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease;
}

.spot-color-swatch:hover {
  transform: scale(1.2);
  border-color: var(--accent);
}

.spot-controls {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.turn-off-all-section {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.turn-off-all-section .btn-danger {
  font-size: 1rem;
  padding: 12px 24px;
  flex: 1;
  min-width: 180px;
}

.apply-all-floors-btn {
  margin-top: 12px;
}

/* ============================================
   Animations List
   ============================================ */

.animations-list {
  display: grid;
  gap: 12px;
}

.animation-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: var(--shadow);
}

.animation-info h3 {
  margin-bottom: 4px;
  font-size: 1rem;
}

.animation-info p {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.animation-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ============================================
   Night Mode
   ============================================ */

.nightmode-status {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.nightmode-status p {
  margin-bottom: 8px;
  line-height: 1.6;
}

.status-indicator {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.status-indicator.active {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.status-indicator.inactive {
  background: var(--text-secondary);
}

.nightmode-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============================================
   Modal & Toast
   ============================================ */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.modal-close {
  float: right;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  z-index: 2000;
  transition: opacity 0.3s ease;
}

.toast.hidden {
  display: none;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 40px 20px;
  font-size: 0.95rem;
}

/* ============================================
   Settings Section
   ============================================ */

.settings-group {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.settings-group h3 {
  margin-bottom: 16px;
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.stream-settings-form .form-group,
.password-form .form-group {
  margin-bottom: 16px;
}

.form-hint {
  display: block;
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  line-height: 1.4;
}

.theme-select-wrapper {
  margin-bottom: 24px;
}

.theme-select-wrapper label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 600;
}

.theme-dropdown {
  width: 100%;
  max-width: 300px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  cursor: pointer;
}

.theme-dropdown:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.password-form .form-group input.valid {
  border-color: var(--success);
}

.password-form .form-group input.invalid {
  border-color: var(--danger);
}

.validation-message {
  font-size: 0.8rem;
  margin-top: 4px;
  min-height: 18px;
}

.validation-message.success {
  color: var(--success);
}

.validation-message.error {
  color: var(--danger);
}

.spot-count-editor {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.spot-count-editor input[type="number"] {
  width: 80px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.95rem;
  text-align: center;
}

.spot-count-editor input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ============================================
   Tablet (481px - 768px)
   ============================================ */

@media (max-width: 768px) {
  #app {
    padding: 0 16px;
  }

  .header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 0;
  }

  .nav {
    order: 3;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
  }

  .nav-btn {
    padding: 7px 12px;
    font-size: 0.85rem;
  }

  .buildings-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
  }

  .palette-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .flag-presets {
    grid-template-columns: repeat(4, 1fr);
  }

  .spot-grid {
    grid-template-columns: repeat(auto-fill, minmax(35px, 1fr));
  }

  .building-detail {
    padding: 20px;
  }

  .camera-stream-section {
    padding: 12px;
  }

  .light-controls {
    gap: 20px;
  }

  .animation-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal-content {
    width: 95%;
    padding: 20px;
  }
}

/* ============================================
   Phone (<480px)
   ============================================ */

@media (max-width: 480px) {
  #app {
    padding: 0 12px;
  }

  .logo {
    font-size: 1.1rem;
  }

  .nav-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .user-info {
    font-size: 0.75rem;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .section-header h2 {
    font-size: 1.2rem;
  }

  .buildings-grid {
    grid-template-columns: 1fr;
  }

  .login-container {
    margin: 40px auto;
    padding: 24px;
  }

  .building-detail {
    padding: 16px;
  }

  .building-detail h2 {
    font-size: 1.1rem;
  }

  .camera-stream-section {
    padding: 10px;
  }

  .camera-stream-section h3 {
    font-size: 0.9rem;
  }

  .palette-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .flag-presets {
    grid-template-columns: repeat(3, 1fr);
  }

  .spot-grid {
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 4px;
  }

  .custom-color {
    flex-direction: column;
    align-items: flex-start;
  }

  .pattern-section {
    flex-direction: column;
    align-items: flex-start;
  }

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

  .spot-controls .btn {
    width: 100%;
  }

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

  .nightmode-controls .btn {
    width: 100%;
  }

  .animation-card {
    padding: 14px;
  }

  .modal-content {
    padding: 16px;
    margin: 10px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    text-align: center;
  }

  .spot-count-editor {
    flex-direction: column;
    align-items: flex-start;
  }

  .theme-select-wrapper {
    max-width: 100%;
  }

  .theme-dropdown {
    max-width: 100%;
  }
}

/* ============================================
   Desktop enhancements (>1024px)
   ============================================ */

@media (min-width: 1025px) {
  .light-controls {
    grid-template-columns: repeat(3, 1fr);
  }

  .flag-presets {
    grid-template-columns: repeat(6, 1fr);
  }

  .spot-grid {
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
  }
}

/* ============================================
   Large desktop (>1400px)
   ============================================ */

@media (min-width: 1401px) {
  #app {
    max-width: 1600px;
  }

  .spot-grid {
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
  }
}

/* ============================================
   Password Change Form
   ============================================ */

.password-form {
  max-width: 400px;
}

.validation-message {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  min-height: 1.2em;
}

.validation-message.error {
  color: var(--danger);
}

.validation-message.success {
  color: var(--success);
}

/* ============================================
   Theme Dropdown
   ============================================ */

.theme-dropdown {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
}

.theme-dropdown:hover {
  border-color: var(--accent);
}

.theme-dropdown:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ============================================
   Spot Count Editor
   ============================================ */

.spot-count-input {
  width: 80px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  text-align: center;
}

.spot-count-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
