/* public/ui/css/builder.css - Estilos para el Constructor Visual de Dashboards IoT */

/* Barra de herramientas superior del constructor */
.builder-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 60px;
  z-index: 90;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.builder-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Modo Edición / Constructor */
.badge-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  transition: all 0.2s ease;
}

.badge-mode.edit-mode {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-mode.live-mode {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

/* Grid del Lienzo del Constructor */
.builder-canvas {
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
  min-height: calc(100vh - 140px);
}

.builder-grid, .widgets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px;
}

@media (min-width: 1200px) {
  .builder-grid, .widgets-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Widget Card */
.builder-widget, .widget-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease, border-color 0.2s ease;
}

.builder-widget:hover, .widget-card:hover {
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: var(--shadow-card-hover);
}

/* Spans de columna en el grid */
.builder-widget.span-1, .widget-card.span-1 {
  grid-column: span 1;
}

.builder-widget.span-2, .widget-card.span-2 {
  grid-column: span 1;
}

@media (min-width: 768px) {
  .builder-widget.span-2, .widget-card.span-2 {
    grid-column: span 2;
  }
}

.builder-widget.span-3, .widget-card.span-3 {
  grid-column: 1 / -1;
}

/* Tiradores y controles de edición en cada Widget */
.widget-edit-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--bg-body);
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.mode-edit .widget-edit-controls {
  display: flex;
}

body.mode-edit .builder-widget {
  cursor: grab;
  border-style: dashed;
}

body.mode-edit .builder-widget:active {
  cursor: grabbing;
}

.widget-drag-handle {
  cursor: grab;
  color: var(--text-muted);
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

body.mode-edit .widget-drag-handle {
  display: inline-flex;
}

.btn-icon-sm {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 0.875rem;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-sm:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #6366f1;
}

.btn-icon-sm.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

/* Encabezado del Widget */
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.widget-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.widget-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* Contenedor del contenido del Widget */
.widget-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  min-height: 120px;
}

/* Estilos de Widget: Medidor Radial (Gauge) */
.gauge-container {
  width: 100%;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding: 4px 0;
}

.gauge-canvas {
  width: 100%;
  max-height: 150px;
}

.gauge-value-display {
  position: absolute;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.gauge-numeric {
  font-size: 1.875rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
  font-family: var(--font-family);
  letter-spacing: -0.02em;
}

.gauge-unit {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

.gauge-scale-limits {
  display: flex;
  justify-content: space-between;
  width: 80%;
  margin-top: -6px;
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: monospace;
}

/* Estilos de Widget: Gráfico Temporal con Indicador Digital */
.chart-container {
  width: 100%;
  height: 190px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chart-header-stat {
  position: absolute;
  top: 6px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 2;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

:root[data-theme="light"] .chart-header-stat {
  background: rgba(241, 245, 249, 0.8);
}

.chart-current-val {
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--text-main);
  font-family: monospace;
}

.chart-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-ok);
  box-shadow: 0 0 6px var(--status-ok);
  animation: pulseLive 2s infinite ease-in-out;
}

@keyframes pulseLive {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

.chart-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Consola de Diagnóstico SCADA con Temas */
.console-box-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

:root[data-theme="light"] .console-box-wrapper {
  background: #1e293b;
  border-color: #cbd5e1;
}

.console-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.3);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.console-filter-group {
  display: flex;
  gap: 4px;
}

.console-filter-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #94a3b8;
  font-size: 0.6875rem;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.console-filter-btn.active, .console-filter-btn:hover {
  background: rgba(99, 102, 241, 0.3);
  border-color: #6366f1;
  color: #ffffff;
}

.console-log-scroll {
  width: 100%;
  height: 150px;
  padding: 8px 12px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: #e2e8f0;
  overflow-y: auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.console-entry {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  line-height: 1.4;
  word-break: break-all;
}

.console-tag {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
}

.console-tag-ws { background: rgba(56, 189, 248, 0.2); color: #38bdf8; border: 1px solid rgba(56, 189, 248, 0.4); }
.console-tag-mqtt { background: rgba(34, 197, 94, 0.2); color: #22c55e; border: 1px solid rgba(34, 197, 94, 0.4); }
.console-tag-rest { background: rgba(168, 85, 247, 0.2); color: #c084fc; border: 1px solid rgba(168, 85, 247, 0.4); }
.console-tag-err { background: rgba(239, 68, 68, 0.2); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.4); }
.console-tag-sys { background: rgba(245, 158, 11, 0.2); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }

/* Estilos de Widget: Botones de Actuador */
.actuator-btn-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
}

.btn-actuator {
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.875rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-actuator:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-actuator:active {
  transform: translateY(0);
}

/* Estilos de Widget: Slider Numérico */
.slider-control-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slider-range-input {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--border-color);
  outline: none;
  cursor: pointer;
  accent-color: #6366f1;
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Modal de Configuración y Catálogo de Widgets */
.builder-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.builder-modal-backdrop.active {
  display: flex;
}

.builder-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.builder-modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.builder-modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-main);
}

.builder-modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.builder-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Catálogo de tipos de widgets */
.widget-catalog-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.catalog-item {
  background: var(--bg-body);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.catalog-item:hover {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.08);
  transform: translateY(-2px);
}

.catalog-item-icon {
  font-size: 1.5rem;
}

.catalog-item-title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-main);
}

.catalog-item-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Formulario en Modal */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-input, .form-select {
  background: var(--bg-body) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-main) !important;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.form-select option {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  padding: 8px 12px;
}

:root[data-theme="light"] .form-select option {
  background-color: #ffffff !important;
  color: #1e1b4b !important;
}

.form-input:focus, .form-select:focus {
  border-color: #6366f1;
}

/* Drag over visual drop target */
.builder-widget.drag-over {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px #6366f1;
  opacity: 0.8;
}
