* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: Helvetica, 'Helvetica Neue', Arial, sans-serif;
}

:root {
  --accent: #667eea;
  --accent-dark: #764ba2;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  --panel-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 8px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
  background: var(--bg-gradient);
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  overflow: hidden;
  transition: background 0.5s var(--transition);
}

body.minimized-mode {
  background: #1a1a1a;
  align-items: center;
}

/* ─── Layout ──────────────────────────────────────────────── */

.page-wrapper {
  width: 100%;
  max-width: 1400px;
  height: 100%;
  max-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#full-panel,
#mini-panel {
  transition: opacity 0.3s var(--transition);
  opacity: 1;
}

/* ─── Toggle Mode Button ──────────────────────────────────── */

.toggle-mode-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all var(--transition);
}

.toggle-mode-btn:hover {
  background: white;
  transform: scale(1.1);
}

.toggle-mode-btn .icon-maximize { display: none; }
.toggle-mode-btn.minimized .icon-minimize { display: none; }
.toggle-mode-btn.minimized .icon-maximize { display: block; }

/* ─── Panel Container ─────────────────────────────────────── */

.control-panel-container {
  background: rgba(255, 255, 255, 0.96);
  border-radius: var(--radius-lg);
  padding: 16px 24px 20px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px);
  width: 100%;
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header ──────────────────────────────────────────────── */

.panel-header {
  text-align: center;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.panel-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0;
}

/* ─── Event Tabs ──────────────────────────────────────────── */

.event-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(102, 126, 234, 0.15);
  flex-shrink: 0;
}

.event-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 40px;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
  color: #64748b;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.event-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(102, 126, 234, 0.06);
}

.event-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

.event-tab-icon {
  font-size: 18px;
  line-height: 1;
}

.event-tab-label {
  white-space: nowrap;
}

/* ─── Event Settings ─────────────────────────────────────── */

.event-settings {
  flex-shrink: 0;
  padding: 12px 16px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(102, 126, 234, 0.12);
}

.settings-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.event-settings-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-settings .setting-group {
  width: 100%;
}

.event-settings .setting-control-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.event-settings .setting-select {
  flex: 1;
  min-width: 0;
}

.event-settings .setting-save-btn {
  flex-shrink: 0;
}

/* ─── Controls Grid ───────────────────────────────────────── */

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

/* ─── Control Card ────────────────────────────────────────── */

.control-card {
  background: white;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--card-shadow);
  border: 2px solid transparent;
  transition: all var(--transition);
  min-height: 0;
}

.control-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  border-color: var(--accent);
}

.control-card.hidden {
  opacity: 0.55;
  border-color: #e2e8f0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-title-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.component-icon {
  font-size: 18px;
}

.component-title {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
}

.status-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.visible {
  background: #dcfce7;
  color: #16a34a;
}

.status-badge.hidden {
  background: #fee2e2;
  color: #dc2626;
}

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

.component-description {
  font-size: 12px;
  color: #64748b;
  line-height: 1.35;
  flex: 1;
}

/* ─── Card Settings ──────────────────────────────────────── */

.card-body:has(.card-settings) {
  flex-direction: column;
  align-items: stretch;
}

.card-settings {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.setting-label {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-input,
.setting-select {
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: #1e293b;
  background: #f8fafc;
  transition: border-color var(--transition);
  width: 100%;
}

.setting-input:focus,
.setting-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.setting-hint {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
}

.setting-save-btn {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  align-self: flex-start;
}

.setting-save-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.setting-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ─── Toggle Switch ───────────────────────────────────────── */

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 28px;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(24px);
}

.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ─── Action Buttons ──────────────────────────────────────── */

.action-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.action-btn {
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-btn:hover {
  transform: translateY(-2px);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-info {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

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

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 2px solid #e2e8f0;
}

.btn-secondary:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: #1e293b;
}

/* ─── Status Message ──────────────────────────────────────── */

.status-message {
  text-align: center;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.3s ease;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.status-message.show {
  opacity: 1;
}

.status-message.success { background: #dcfce7; color: #16a34a; }
.status-message.error   { background: #fee2e2; color: #dc2626; }
.status-message.info    { background: #dbeafe; color: #2563eb; }

/* ─── Bottom Section (Similarity + Links) ──────────────────── */

.control-panel-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px solid rgba(102, 126, 234, 0.12);
  flex-shrink: 0;
  min-height: 0;
}

/* ─── Similarity Section ─────────────────────────────────── */

.similarity-section {
  padding: 12px 16px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(102, 126, 234, 0.2);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: #667eea;
  margin-bottom: 4px;
}

.section-description {
  font-size: 11px;
  color: #888;
  margin-bottom: 10px;
  line-height: 1.4;
}

.similarity-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.similarity-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

.similarity-status {
  font-size: 12px;
  font-weight: 600;
  color: #666;
}

.similarity-threshold {
  display: flex;
  align-items: center;
  gap: 10px;
}

.similarity-threshold label {
  font-size: 14px;
  color: #555;
  white-space: nowrap;
  min-width: 130px;
}

.similarity-threshold input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 3px;
  outline: none;
}

.similarity-threshold input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  border: 3px solid #667eea;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

/* ─── Preview Links ───────────────────────────────────────── */

.preview-links {
  padding: 12px 16px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(102, 126, 234, 0.12);
}

.preview-title {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 10px;
}

.links-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background: #f1f5f9;
  text-decoration: none;
  color: #475569;
  font-size: 12px;
  font-weight: 500;
  transition: all var(--transition);
  border: 1px solid #e2e8f0;
}

.preview-link:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

.link-icon { font-size: 16px; }

/* ─── Loading ─────────────────────────────────────────────── */

.loading-container {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
}

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

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

.loading-text {
  color: #94a3b8;
  font-size: 14px;
}

/* ─── Mini Panel (Remote Control) ────────────────────────── */

.remote-control {
  background: #1a1a1a;
  border-radius: 32px;
  padding: 24px 20px 28px;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.remote-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.remote-logo { font-size: 22px; }

.remote-title {
  font-size: 16px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
}

.remote-event-label {
  margin-left: auto;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.remote-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
}

.remote-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}

.remote-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.remote-btn.active {
  background: rgba(102, 126, 234, 0.25);
  border-color: rgba(102, 126, 234, 0.5);
  color: white;
}

.remote-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.remote-btn-icon { font-size: 20px; flex-shrink: 0; }
.remote-btn-label { flex: 1; font-size: 14px; font-weight: 600; }
.remote-btn-shortcut { font-size: 11px; color: rgba(255, 255, 255, 0.3); }

.remote-btn-status {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.5px;
}

.remote-btn.active .remote-btn-status {
  background: rgba(102, 126, 234, 0.4);
  color: #a5b4fc;
}

.remote-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.remote-refresh {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.remote-refresh:hover {
  background: rgba(255, 255, 255, 0.12);
  color: white;
}

/* ─── Responsive ──────────────────────────────────────────── */

@media (max-width: 1100px) {
  .control-panel-bottom {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .control-panel-bottom {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  body { padding: 8px; }
  .control-panel-container { padding: 12px 16px; }
  .panel-title { font-size: 20px; }
  .event-tab-label { display: none; }
  .event-tab { padding: 6px 12px; }
  .controls-grid { grid-template-columns: 1fr; }
  .event-settings .setting-group { min-width: 100%; }
}
