/* =================================================================
   ACCID Data Streams Panel + Template Replicator
   Drop into: htmlbuilder_local/css/data-streams.css
   ================================================================= */

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

.streams-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  height: 100vh;
  background: linear-gradient(180deg, #1e293b 0%, #334155 100%);
  border-left: 1px solid #30363d;
  color: white;
  box-shadow: -2px 0 10px rgba(0, 0, 0, 0.3);
  z-index: 11000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(280px);
}

.streams-panel--open {
  transform: translateX(0);
}


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

.sp-header {
  padding: 12px;
  border-bottom: 1px solid #30363d;
  flex-shrink: 0;
}

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

.sp-title {
  font-size: 12px;
  font-weight: 600;
  color: #e6edf3;
}

.sp-load-row {
  display: flex;
  gap: 6px;
}

.sp-filter {
  width: 100%;
  padding: 5px 8px;
  background: #1c2129;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #e6edf3;
  font-size: 11px;
  font-family: inherit;
  margin-top: 4px;
}

.sp-filter:focus {
  outline: none;
  border-color: #58a6ff;
}

.sp-status {
  font-size: 10px;
  color: #6e7681;
  margin-top: 6px;
}


/* ── Panel Buttons ────────────────────────────────────────── */

.sp-btn {
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #30363d;
  background: #1c2129;
  color: #e6edf3;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}

.sp-btn:hover {
  background: #21262d;
  border-color: #484f58;
}

.sp-btn-close {
  background: none;
  border: none;
  color: #6e7681;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
}

.sp-btn-close:hover {
  color: #e6edf3;
  background: none;
}

.sp-btn-load {
  flex: 1;
}

.sp-btn-danger {
  background: #dc2626 !important;
  border-color: #b91c1c !important;
  flex: 0 0 auto;
}
.sp-btn-danger:hover {
  background: #ef4444 !important;
}

.sp-btn-accent {
  background: #58a6ff;
  color: #0e1117;
  border-color: #58a6ff;
  font-weight: 600;
}

.sp-btn-accent:hover {
  opacity: 0.9;
  background: #58a6ff;
}

.sp-btn-green {
  background: #3fb950;
  color: #0e1117;
  border-color: #3fb950;
  font-weight: 600;
}

.sp-btn-green:hover {
  opacity: 0.9;
  background: #3fb950;
}


/* ── Stream List ──────────────────────────────────────────── */

.sp-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sp-empty {
  font-size: 12px;
  color: #6e7681;
  padding: 16px;
  text-align: center;
  line-height: 1.5;
}

.sp-group-label {
  font-size: 10px;
  font-weight: 600;
  color: #6e7681;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 6px 4px;
}


/* ── Stream Item ──────────────────────────────────────────── */

.sp-stream-item {
  display: block;
  padding: 7px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: grab;
  transition: background 0.12s;
  border: 1px solid transparent;
  margin-bottom: 2px;
}

.sp-stream-item:hover {
  background: #1c2129;
}

.sp-stream-item:active {
  cursor: grabbing;
}

.sp-stream-item.sp-bound {
  opacity: 0.4;
}

.sp-stream-item.sp-dragging {
  opacity: 0.6;
  border-color: #58a6ff;
  background: rgba(88, 166, 255, 0.08);
}

.sp-stream-name {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  color: #e6edf3;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sp-scope {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.sp-scope-global {
  background: rgba(63, 185, 80, 0.15);
  color: #3fb950;
}

.sp-scope-context {
  background: rgba(88, 166, 255, 0.15);
  color: #58a6ff;
}

.sp-page-count {
  font-size: 10px;
  color: #6e7681;
  flex-shrink: 0;
  min-width: 16px;
  text-align: right;
}


/* ── Drop Target on Modules (canvas) ─────────────────────── */

[data-module-id].stream-drop-target {
  outline: 2px solid #3fb950 !important;
  outline-offset: -2px;
  box-shadow: 0 0 12px rgba(63, 185, 80, 0.25) !important;
  transition: outline 0.15s, box-shadow 0.15s;
}

/* Binding indicator shown on modules that have a dataSource */
.module-binding-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(63, 185, 80, 0.15);
  border: 1px solid rgba(63, 185, 80, 0.3);
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 10px;
  color: #3fb950;
  z-index: 10;
  cursor: default;
}

.module-binding-badge .binding-unbind {
  cursor: pointer;
  opacity: 0.5;
  margin-left: 4px;
  font-family: sans-serif;
}

.module-binding-badge .binding-unbind:hover {
  opacity: 1;
}


/* ── Modal Overlay (CSV + Replicate) ──────────────────────── */

.sp-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sp-modal {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 10px;
  padding: 24px;
  width: 480px;
  max-height: 80vh;
  overflow-y: auto;
}

.sp-modal h3 {
  font-size: 16px;
  color: #e6edf3;
  margin-bottom: 8px;
}

.sp-modal p {
  font-size: 13px;
  color: #8b949e;
  margin-bottom: 16px;
  line-height: 1.5;
}

.sp-modal-textarea {
  width: 100%;
  height: 180px;
  background: #1c2129;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #e6edf3;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  padding: 12px;
  resize: vertical;
  line-height: 1.5;
}

.sp-modal-textarea:focus {
  outline: none;
  border-color: #58a6ff;
}

.sp-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.sp-input {
  padding: 6px 10px;
  background: #1c2129;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #e6edf3;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

.sp-input:focus {
  outline: none;
  border-color: #58a6ff;
}


/* ── Replicate Dialog ─────────────────────────────────────── */

.sp-replicate-name {
  margin-bottom: 16px;
}

.sp-replicate-name label {
  display: block;
  font-size: 12px;
  color: #8b949e;
  margin-bottom: 4px;
}

.sp-replicate-types {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.sp-replicate-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #1c2129;
  border: 1px solid #30363d;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.12s;
}

.sp-replicate-option:hover {
  border-color: #484f58;
}

.sp-replicate-option input[type="checkbox"] {
  accent-color: #3fb950;
}

.sp-replicate-label {
  font-size: 13px;
  color: #e6edf3;
  flex: 1;
}

.sp-replicate-count {
  font-size: 11px;
  color: #6e7681;
}

.sp-replicate-summary {
  font-size: 13px;
  color: #8b949e;
  padding: 8px 0;
  text-align: center;
}


/* ── Toggle Button (for topbar) ───────────────────────────── */

.sp-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid #30363d;
  background: #1c2129;
  color: #8b949e;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.12s;
}

.sp-toggle-btn:hover {
  background: #21262d;
  color: #e6edf3;
}

.sp-toggle-btn.active {
  background: rgba(88, 166, 255, 0.1);
  border-color: #58a6ff;
  color: #58a6ff;
}

.sp-toggle-btn .sp-toggle-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6e7681;
}

.sp-toggle-btn.active .sp-toggle-dot {
  background: #3fb950;
}


/* ── Scrollbar (panel only) ───────────────────────────────── */

.sp-list::-webkit-scrollbar {
  width: 5px;
}

.sp-list::-webkit-scrollbar-track {
  background: transparent;
}

.sp-list::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

.sp-list::-webkit-scrollbar-thumb:hover {
  background: #6e7681;
}


/* ── Stream Item Preview ─────────────────────────────────── */

.sp-stream-top {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
}

.sp-stream-top .sp-stream-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sp-stream-preview {
  margin-top: 3px;
  line-height: 1.3;
}

.sp-preview-text {
  font-size: 11px;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.sp-preview-image {
  margin-top: 4px;
}

.sp-preview-image img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.1);
  vertical-align: middle;
}

.sp-bound .sp-stream-preview {
  opacity: 0.5;
}
