/* =============================================
   ESTILOS GENERALES
   ============================================= */

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f5f7fa;
  overflow: hidden;
}

/* =============================================
   HEADER ROW (LOGO + BANNER)
   ============================================= */

#header-row {
  display: flex;
  height: 50px;
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
}

#logo-corner {
  width: 220px;
  min-width: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e293b;
  border-right: 1px solid #334155;
}

#logo-corner .logo-placeholder {
  color: #64748b;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1px;
}

#top-banner {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 20px;
}

.banner-tabs {
  display: flex;
  gap: 4px;
}

.banner-tab {
  padding: 8px 20px;
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.banner-tab:hover {
  background: #1e293b;
  color: #e2e8f0;
}

.banner-tab.active {
  background: #3b82f6;
  color: #ffffff;
}

/* =============================================
   APP CONTAINER - LAYOUT FLEX
   ============================================= */

#app-container {
  display: flex;
  height: calc(100vh - 50px);
  width: 100%;
}

/* =============================================
   VIEW PANELS
   ============================================= */

.view-panel {
  display: none;
  width: 100%;
  height: 100%;
}

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

/* =============================================
   P&ID FILTER CHECKBOX
   ============================================= */

#view-pid {
  position: relative;
}

.pid-filter {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  display: flex;
  gap: 12px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.pid-filter-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  user-select: none;
}

.pid-filter-select {
  padding: 2px 6px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  margin-left: 4px;
}

.pid-filter-select:hover,
.pid-filter-select:focus {
  border-color: #3b82f6;
}

/* =============================================
   DASHBOARD
   ============================================= */

#view-dashboard {
  background: #f1f5f9;
  padding: 24px;
  overflow-y: auto;
}

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

.dashboard-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #1e293b;
}

#dashboard-area-select {
  padding: 8px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #1e293b;
  font-size: 13px;
  cursor: pointer;
  min-width: 180px;
}

#dashboard-area-select:focus {
  outline: none;
  border-color: #3b82f6;
}

/* Orders Alert Banner */
.orders-alert {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.orders-alert-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: #fef3c7;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orders-alert-text {
  flex: 1;
  font-size: 13px;
  color: #78350f;
}

.orders-alert-text strong {
  font-size: 18px;
  color: #b45309;
}

.orders-alert-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  background: #f59e0b;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease;
}

.orders-alert-btn:hover {
  background: #d97706;
}

.dashboard-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

.chart-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-card h3 {
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  text-align: center;
}

.chart-container {
  width: 100%;
  max-width: 220px;
  margin: 0 auto;
  aspect-ratio: 1;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 16px;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.legend-value {
  font-weight: 600;
  color: #1e293b;
}

/* =============================================
   SIDEBAR
   ============================================= */

#sidebar {
  width: 220px;
  min-width: 220px;
  background: #1e293b;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #334155;
}

/* Botones de Area */
#area-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
}

.area-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.area-btn:hover {
  background: #334155;
  color: #e2e8f0;
}

.area-btn.active {
  background: #3b82f6;
  color: #ffffff;
}

.area-btn .area-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.area-btn .area-name {
  flex: 1;
}

.area-btn .area-count {
  font-size: 11px;
  color: #64748b;
  background: #1e293b;
  padding: 2px 8px;
  border-radius: 10px;
}

.area-btn.active .area-count {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

.area-btn.active .area-color {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

/* =============================================
   MAIN CONTENT
   ============================================= */

#main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#main_svg {
  display: block;
  width: 100%;
  height: 100%;
  background: #ffffff;
}

/* =============================================
   POPUP - CONTENEDOR PRINCIPAL
   ============================================= */

.popup_hidden {
  display: none;
}

.popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  z-index: 500;
  width: 480px;
  max-width: 95vw;
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 10px 30px -5px rgba(0, 0, 0, 0.15);
}

/* =============================================
   POPUP - TITULO
   ============================================= */

.popup_title_text {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a2e;
  margin: 0 0 8px 0;
  text-align: center;
  letter-spacing: -0.5px;
}

/* =============================================
   POPUP - NAVEGACION (TABS)
   ============================================= */

.popup_nav {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  padding: 2px;
  background: #f0f2f5;
  border-radius: 6px;
  border: none;
}

.popup_btn {
  flex: 1;
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #64748b;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.popup_btn:hover {
  background: #e2e8f0;
  color: #334155;
}

.popup_btn.active,
.popup_btn:focus {
  background: #ffffff;
  color: #1a1a2e;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* =============================================
   POPUP - BOTON CERRAR
   ============================================= */

.popup_video_close {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: none;
  background: #fee2e2;
  color: #dc2626;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup_video_close:hover {
  background: #dc2626;
  color: #ffffff;
}

/* =============================================
   POPUP - ESTADO 1 (DATOS)
   ============================================= */

.popup_state {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pop-up-estado-1-left,
.pop-up-estado-1-right {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px;
}

.pop-up-estado-1-left p,
.pop-up-estado-1-right p {
  margin: 3px 0;
  font-size: 10px;
  color: #475569;
  line-height: 1.3;
}

.pop-up-estado-1-left p strong,
.pop-up-estado-1-right p strong {
  color: #1e293b;
  font-weight: 600;
}

.pop-up-estado-1-left label,
.pop-up-estado-1-right label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: #475569;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
}

/* =============================================
   CHECKBOXES PERSONALIZADOS
   ============================================= */

input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: #3b82f6;
  cursor: pointer;
}

/* =============================================
   POPUP - SECCION I/O DINAMICA
   ============================================= */

#popup-io-dynamic {
  margin-top: 6px;
}

#popup-io-dynamic p {
  margin: 1px 0;
  font-size: 9px;
  display: inline-block;
  margin-right: 8px;
}

#popup-io-dynamic hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 4px 0;
}

#popup-io-dynamic h4 {
  font-size: 10px;
  font-weight: 600;
  color: #1e293b;
  margin: 6px 0 4px 0;
}

.io-field-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 4px;
}

.io-field-row label {
  font-size: 9px;
  font-weight: 500;
  color: #475569;
  min-width: 45px;
  text-align: right;
}

.io-field-row select {
  flex: 1;
  padding: 2px 6px;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  font-size: 9px;
  background: #ffffff;
  color: #1e293b;
  height: 20px;
  box-sizing: border-box;
}

.io-field-row select:disabled {
  background: #f1f5f9;
  color: #64748b;
}

.io-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 4px 6px;
  margin-bottom: 3px;
}

.io-signal-name {
  display: flex;
  align-items: center;
  gap: 4px;
}

.io-signal-name strong {
  color: #1e293b;
  font-size: 9px;
}

.io-signal-name span {
  color: #64748b;
  font-size: 8px;
}

.io-signal-fields {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.io-signal-fields label {
  font-size: 8px;
  color: #64748b;
  margin-right: 1px;
}

.io-row label {
  font-size: 8px;
  color: #64748b;
  margin-right: 1px;
}

.io-row input,
.io-row select {
  padding: 2px 4px;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  font-size: 9px;
  background: #ffffff;
  color: #1e293b;
  margin: 0;
  height: 18px;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.io-row input {
  width: 40px;
}

.io-row select {
  min-width: 60px;
}

.io-row input:focus,
.io-row select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.io-row input:disabled,
.io-row select:disabled {
  background: #f1f5f9;
  color: #64748b;
  cursor: not-allowed;
}

/* =============================================
   POPUP - BOTONES ACCIONES (EDIT/SAVE)
   ============================================= */

.popup-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #e2e8f0;
}

.popup-actions button {
  flex: 1;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

#btn-edit-io {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
}

#btn-edit-io:hover:not(:disabled) {
  background: #e2e8f0;
  color: #1e293b;
}

#btn-save-io {
  background: #3b82f6;
  border: none;
  color: #ffffff;
}

#btn-save-io:hover:not(:disabled) {
  background: #2563eb;
}

#btn-edit-io:disabled,
#btn-save-io:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =============================================
   POPUP - DETAIL INPUTS (LEFT SIDE)
   ============================================= */

.popup-detail-input {
  background: transparent;
  border: 1px solid transparent;
  font-size: 10px;
  font-family: inherit;
  color: #334155;
  padding: 1px 4px;
  width: 60%;
  outline: none;
}

.popup-detail-input:disabled {
  color: #334155;
  cursor: default;
}

.popup-detail-input:not(:disabled) {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
  color: #0f172a;
  cursor: text;
}

.popup-detail-input:not(:disabled):focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#btn-edit-details {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
}

#btn-edit-details:hover:not(:disabled) {
  background: #e2e8f0;
  color: #1e293b;
}

#btn-save-details {
  background: #3b82f6;
  border: none;
  color: #ffffff;
}

#btn-save-details:hover:not(:disabled) {
  background: #2563eb;
}

#btn-edit-details:disabled,
#btn-save-details:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =============================================
   POPUP - LINKS (MANUAL/YOUTUBE)
   ============================================= */

.popup_links {
  grid-column: 1 / -1;
  margin-top: 10px;
}

.popup_links_buttons {
  display: flex;
  gap: 6px;
}

.popup_btn_link_1,
.popup_btn_link_2 {
  flex: 1;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.popup_btn_link_1 {
  background: #f0fdf4;
  color: #166534;
}

.popup_btn_link_1:hover {
  background: #dcfce7;
}

.popup_btn_link_2 {
  background: #fef2f2;
  color: #dc2626;
}

.popup_btn_link_2:hover {
  background: #fee2e2;
}

/* =============================================
   POPUP - VIDEO CONTAINER
   ============================================= */

.popup_video_container {
  display: none;
  margin-top: 16px;
  border-radius: 12px;
  overflow: hidden;
  background: #1a1a2e;
}

.popup_video_container[style*="display: block"] {
  display: block;
}

.popup_video_header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #1e293b;
  color: #ffffff;
  font-weight: 500;
  font-size: 14px;
}

.popup_video_header .popup_video_close {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.popup_video_header .popup_video_close:hover {
  background: #dc2626;
}

/* =============================================
   POPUP - ESTADO 2 (SPARES/REFERENCIAS)
   ============================================= */

.popup_state_2 {
  display: none;
  overflow-y: auto;
  max-height: 60vh;
}

.popup_state_2[style*="display: grid"],
.popup_state_2[style*="display: block"] {
  display: block;
}

.reference-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  line-height: 1.2;
}

.reference-table th,
.reference-table td {
  padding: 4px 6px;
  text-align: left;
}

.reference-table th {
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.reference-table td {
  color: #1e293b;
  border-bottom: 1px solid #f1f5f9;
}

.reference-table tr:hover td {
  background: #f8fafc;
}

.ref-request-cell {
  white-space: nowrap;
  text-align: center;
}

.ref-stock {
  position: relative;
  cursor: help;
  font-weight: 600;
  color: #059669;
}

/* =============================================
   POPUP - ESTADO 3 & 4 (INCIDENCIAS / LOGS)
   ============================================= */

.popup_state_table {
  overflow-y: auto;
  max-height: 60vh;
}

.popup-incidents-table,
.popup-logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  line-height: 1.2;
}

.popup-incidents-table th,
.popup-incidents-table td,
.popup-logs-table th,
.popup-logs-table td {
  padding: 4px 6px;
  text-align: left;
}

.popup-incidents-table th,
.popup-logs-table th {
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.popup-incidents-table td,
.popup-logs-table td {
  color: #1e293b;
  border-bottom: 1px solid #f1f5f9;
}

.popup-incident-row,
.popup-log-row {
  cursor: pointer;
}

.popup-incident-row:hover td,
.popup-log-row:hover td {
  background: #f0f4ff;
}

.popup-incident-resolved td {
  opacity: 0.55;
}

.incident-status-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
}

.incident-status-badge.active {
  background: #fef2f2;
  color: #dc2626;
}

.incident-status-badge.resolved {
  background: #f0fdf4;
  color: #16a34a;
}

/* =============================================
   INCIDENT DETAIL POPUP
   ============================================= */

.incident-detail-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.incident-detail-content {
  background: #ffffff;
  border-radius: 10px;
  padding: 16px;
  width: 500px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
              0 10px 30px -5px rgba(0, 0, 0, 0.15);
}

.incident-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.incident-detail-header h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1a1a2e;
  margin: 0;
}

.incident-detail-info {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
}

.incident-detail-info p {
  margin: 2px 0;
  font-size: 11px;
  color: #334155;
}

.incident-timeline-section {
  margin-bottom: 12px;
}

.incident-timeline-section h4 {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  margin: 0 0 8px 0;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.incident-timeline {
  border-left: 2px solid #e2e8f0;
  margin-left: 8px;
  padding-left: 16px;
}

.incident-timeline.empty {
  border-left: none;
  margin-left: 0;
  padding-left: 0;
  font-size: 11px;
  color: #94a3b8;
  font-style: italic;
}

.timeline-entry {
  position: relative;
  margin-bottom: 12px;
}

.timeline-entry::before {
  content: '';
  position: absolute;
  left: -21px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 2px #e2e8f0;
}

.timeline-entry:last-child {
  margin-bottom: 0;
}

.timeline-date {
  font-size: 9px;
  color: #94a3b8;
  font-weight: 500;
  margin-bottom: 2px;
}

.timeline-text {
  font-size: 11px;
  color: #1e293b;
  line-height: 1.4;
}

.incident-action-form {
  border-top: 1px solid #e2e8f0;
  padding-top: 10px;
}

.incident-action-textarea {
  width: 100%;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}

.incident-action-textarea:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.incident-action-buttons {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.btn-add-action {
  flex: 1;
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: #3b82f6;
  color: #ffffff;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-add-action:hover {
  background: #2563eb;
}

.btn-resolve-incident {
  flex: 1;
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: #16a34a;
  color: #ffffff;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-resolve-incident:hover {
  background: #15803d;
}

/* =============================================
   TOOLTIPS
   ============================================= */

.ref-stock.tooltip-bottom::after,
.ref-stock.tooltip-top::after {
  content: attr(data-tooltip);
  position: absolute;
  background: #1e293b;
  color: #ffffff;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 400;
  display: none;
  white-space: pre;
  width: max-content;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ref-stock.tooltip-bottom:hover::after,
.ref-stock.tooltip-top:hover::after {
  display: block;
}

.ref-stock.tooltip-bottom::after {
  top: 100%;
  right: 0;
  margin-top: 4px;
}

.ref-stock.tooltip-top::after {
  bottom: 100%;
  right: 0;
  margin-bottom: 4px;
}

/* =============================================
   BOTONES DE REFERENCIA
   ============================================= */

.ref-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: #e2e8f0;
  color: #475569;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
}

.ref-btn:hover {
  background: #3b82f6;
  color: #ffffff;
}

.ref-step-btn {
  width: 24px;
  height: 24px;
  font-size: 14px;
  padding: 0;
  margin: 0 2px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ref-step-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.ref-step-value {
  display: inline-block;
  width: 24px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: #1e293b;
}

/* =============================================
   SVG VALVULAS
   ============================================= */

g.valve {
  pointer-events: all;
  cursor: pointer;
}

g.valve:hover {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.valve-tag {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
}

/* =============================================
   SELECTS ASI
   ============================================= */

#asi-plc,
#asi-cabinet,
#asi-master {
  width: 100%;
  padding: 4px 8px;
  margin: 2px 0 6px 0;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  font-size: 11px;
  background: #ffffff;
}

#popup-io-dynamic > label {
  display: block;
  font-size: 10px;
  font-weight: 500;
  color: #64748b;
  margin-top: 4px;
  margin-bottom: 0;
}

/* =============================================
   IQ PHOTO BUTTONS
   ============================================= */

.iq-photo-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}

.btn-iq-camera {
  flex: 1;
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: #8b5cf6;
  color: #ffffff;
  font-size: 9px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-iq-camera:hover {
  background: #7c3aed;
}

.btn-iq-camera:disabled {
  background: #c4b5fd;
  cursor: not-allowed;
}

.btn-view-photo {
  padding: 6px 10px;
  border: 1px solid #8b5cf6;
  border-radius: 4px;
  background: transparent;
  color: #8b5cf6;
  font-size: 9px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-view-photo:hover {
  background: #8b5cf6;
  color: #ffffff;
}

/* =============================================
   IQ PHOTO PREVIEW
   ============================================= */

.iq-photo-preview {
  margin-top: 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  background: #f8fafc;
}

.iq-photo-preview img {
  width: 100%;
  display: block;
  object-fit: contain;
  max-height: 180px;
}

/* =============================================
   CAMERA MODAL
   ============================================= */

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

.camera-modal.active {
  display: flex;
}

.camera-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

#camera-video {
  max-width: 100vw;
  max-height: 100vh;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

/* Close button - top right overlay */
.btn-camera-close-overlay {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: #ffffff;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-camera-close-overlay:hover {
  background: rgba(0, 0, 0, 0.7);
}

/* Capture button - bottom center overlay */
.btn-camera-capture-overlay {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #ffffff;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn-camera-capture-overlay::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  bottom: 4px;
  border-radius: 50%;
  background: #ffffff;
  transition: background 0.2s ease;
}

.btn-camera-capture-overlay:hover {
  border-color: #e2e8f0;
}

.btn-camera-capture-overlay:active::after {
  background: #d1d5db;
}

/* =============================================
   ORDERS (PEDIDOS)
   ============================================= */

#view-orders {
  background: #f1f5f9;
  padding: 24px;
  display: none;
  flex-direction: column;
  height: 100%;
}

#view-orders.active {
  display: flex;
}

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

.orders-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #1e293b;
}

.orders-table-wrapper {
  flex: 1;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  line-height: 1.2;
}

.orders-table th,
.orders-table td {
  padding: 4px 6px;
  text-align: left;
}

.orders-table th {
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.orders-table td {
  color: #1e293b;
  border-bottom: 1px solid #f1f5f9;
}

.orders-table tr:hover td {
  background: #f8fafc;
}

.orders-table input[type="text"],
.orders-table input[type="date"] {
  width: 100%;
  padding: 2px 4px;
  border: 1px solid #d1d5db;
  border-radius: 3px;
  font-size: 10px;
  background: #ffffff;
  color: #1e293b;
  box-sizing: border-box;
  transition: border-color 0.2s ease;
}

.orders-table input[type="text"]:focus,
.orders-table input[type="date"]:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.orders-table input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: #3b82f6;
  cursor: pointer;
}

.orders-center {
  text-align: center;
}

.orders-qty {
  text-align: center;
  font-weight: 600;
}

/* =============================================
   ITEMS TABLE
   ============================================= */

#view-items {
  background: #f1f5f9;
  padding: 24px;
  display: none;
  flex-direction: column;
  height: 100%;
}

#view-items.active {
  display: flex;
}

.items-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.items-tag-search {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  outline: none;
  width: 180px;
}

.items-tag-search:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#items-area-select {
  padding: 8px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #1e293b;
  font-size: 13px;
  cursor: pointer;
  min-width: 180px;
}

#items-area-select:focus {
  outline: none;
  border-color: #3b82f6;
}

.items-table-wrapper {
  flex: 1;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.4;
}

.items-table th,
.items-table td {
  padding: 8px 12px;
  text-align: left;
}

.items-table th {
  font-weight: 600;
  color: #475569;
  background: #f8fafc;
  border-bottom: 2px solid #e2e8f0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.items-table td {
  color: #1e293b;
  border-bottom: 1px solid #f1f5f9;
}

.items-row {
  cursor: pointer;
  transition: background 0.15s ease;
}

.items-row:hover td {
  background: #eff6ff;
}

.items-center {
  text-align: center;
}

.items-check.ok {
  color: #22c55e;
  font-weight: 700;
}

.items-check.no {
  color: #ef4444;
  font-weight: 700;
}

.items-sortable {
  cursor: pointer;
  user-select: none;
}

.items-sortable::after {
  content: ' \25B2';
  font-size: 8px;
  color: #94a3b8;
}

.items-sortable[data-sort="desc"]::after {
  content: ' \25BC';
}

.items-filter-select {
  padding: 2px 4px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #ffffff;
  color: #475569;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-transform: uppercase;
}

.items-filter-select:focus {
  outline: none;
  border-color: #3b82f6;
}

/* =============================================
   SETTINGS - GEAR BUTTON
   ============================================= */

.settings-gear-btn {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-gear-btn:hover {
  background: #1e293b;
  color: #e2e8f0;
}

/* =============================================
   SETTINGS - MODAL
   ============================================= */

.settings-hidden {
  display: none !important;
}

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

.settings-panel {
  background: #ffffff;
  border-radius: 12px;
  width: 480px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e2e8f0;
}

.settings-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
}

.settings-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: #fee2e2;
  color: #dc2626;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.settings-close-btn:hover {
  background: #dc2626;
  color: #ffffff;
}

/* =============================================
   SETTINGS - SECTIONS
   ============================================= */

.settings-section {
  margin-bottom: 16px;
}

.settings-section h4 {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 8px 0;
}

.settings-info-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 8px;
  font-size: 12px;
}

.settings-label {
  color: #64748b;
  font-weight: 500;
}

.settings-value {
  color: #1e293b;
  font-weight: 400;
}

/* =============================================
   SETTINGS - PROFILES
   ============================================= */

.settings-profiles-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.settings-profile-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 12px;
}

.settings-profile-item.active {
  border-color: #3b82f6;
  background: #eff6ff;
}

.settings-profile-name {
  font-weight: 600;
  color: #1e293b;
}

.settings-profile-url {
  flex: 1;
  color: #64748b;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-profile-btn {
  padding: 3px 8px;
  border: none;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.settings-profile-btn.connect {
  background: #3b82f6;
  color: #ffffff;
}

.settings-profile-btn.connect:hover {
  background: #2563eb;
}

.settings-profile-btn.delete {
  background: #fee2e2;
  color: #dc2626;
}

.settings-profile-btn.delete:hover {
  background: #dc2626;
  color: #ffffff;
}

/* =============================================
   SETTINGS - INPUTS
   ============================================= */

.settings-input {
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 12px;
  color: #1e293b;
  background: #ffffff;
  transition: border-color 0.2s ease;
}

.settings-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.settings-input-wide {
  flex: 1;
}

.settings-add-profile {
  display: flex;
  gap: 6px;
}

.settings-add-profile .settings-input {
  flex: 1;
}

.settings-url-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.settings-btn-add,
.settings-btn-test,
.settings-btn-apply {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.settings-btn-add {
  background: #10b981;
  color: #ffffff;
}

.settings-btn-add:hover {
  background: #059669;
}

.settings-btn-test {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #475569;
}

.settings-btn-test:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.settings-btn-apply {
  background: #3b82f6;
  color: #ffffff;
}

.settings-btn-apply:hover {
  background: #2563eb;
}

.settings-status {
  font-size: 11px;
  margin-top: 6px;
  min-height: 16px;
}

.settings-status.success {
  color: #059669;
}

.settings-status.error {
  color: #dc2626;
}

.settings-status.loading {
  color: #64748b;
}

/* =============================================
   WARNING / INCIDENCIAS (POPUP)
   ============================================= */

.warning-section {
  margin-top: 10px;
  border-top: 1px solid #e2e8f0;
  padding-top: 8px;
}

.popup-action-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-add-warning {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  color: #92400e;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-add-warning:hover {
  background: #fde68a;
  border-color: #d97706;
}

.btn-add-warning svg {
  stroke: #92400e;
  flex-shrink: 0;
}

.warning-form {
  margin-top: 8px;
}

.warning-textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

.warning-textarea:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.btn-save-warning {
  margin-top: 6px;
  padding: 5px 14px;
  background: #f59e0b;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-save-warning:hover {
  background: #d97706;
}

.warning-badge {
  margin-top: 6px;
  padding: 4px 8px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: 11px;
  color: #92400e;
  font-weight: 500;
}

.warning-badge span {
  font-weight: 700;
}

/* Replace valve button */
.btn-replace-valve {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #eff6ff;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  color: #1e40af;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-replace-valve:hover {
  background: #dbeafe;
  border-color: #2563eb;
}

.btn-replace-valve svg {
  stroke: #1e40af;
  flex-shrink: 0;
}

/* Replace form */
.replace-form {
  margin-top: 8px;
}

.replace-loading {
  font-size: 12px;
  color: #64748b;
  padding: 8px 0;
}

.replace-no-stock {
  font-size: 12px;
  color: #dc2626;
  padding: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
}

.replace-stock-header {
  font-size: 12px;
  color: #334155;
  margin-bottom: 6px;
}

.replace-stock-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.replace-stock-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 12px;
}

.replace-stock-option:hover {
  border-color: #3b82f6;
  background: #f8fafc;
}

.replace-stock-option input[type="radio"] {
  accent-color: #3b82f6;
}

.replace-stock-detail {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 1;
}

.replace-stock-loc {
  font-family: 'SF Mono', 'Consolas', monospace;
  font-weight: 600;
  color: #1e293b;
}

.replace-stock-desc {
  color: #64748b;
  flex: 1;
}

.replace-stock-qty {
  font-weight: 600;
  color: #059669;
  white-space: nowrap;
}

.replace-serial-row {
  margin-bottom: 8px;
}

.replace-serial-label {
  display: block;
  font-size: 11px;
  color: #64748b;
  margin-bottom: 4px;
}

.replace-serial-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}

.replace-serial-input:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.replace-serial-input.replace-serial-error {
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.replace-btn-row {
  display: flex;
  gap: 6px;
}

.replace-confirm-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 6px;
  background: #3b82f6;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.replace-confirm-btn:hover {
  background: #2563eb;
}

.replace-cancel-btn {
  padding: 5px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  color: #64748b;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.replace-cancel-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.replace-status {
  font-size: 11px;
  margin-top: 6px;
  min-height: 16px;
  color: #64748b;
}

.replace-status.error {
  color: #dc2626;
}

.replace-success {
  font-size: 12px;
  color: #059669;
  padding: 8px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 6px;
}

/* =============================================
   INCIDENTS ALERT (DASHBOARD)
   ============================================= */

.incidents-alert {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.incidents-alert-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: #fee2e2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.incidents-alert-text {
  flex: 1;
  font-size: 13px;
  color: #7f1d1d;
}

.incidents-alert-text strong {
  font-size: 18px;
  color: #dc2626;
}

.incidents-alert-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  background: #dc2626;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease;
}

.incidents-alert-btn:hover {
  background: #b91c1c;
}

/* =============================================
   INCIDENTS TABLE (VISTA)
   ============================================= */

.incidents-header {
  padding: 16px 20px 8px;
}

.incidents-header h2 {
  margin: 0;
  font-size: 18px;
  color: #1e293b;
}

.incidents-table-wrapper {
  padding: 0 20px 20px;
  overflow-x: auto;
}

.incidents-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.incidents-table thead th {
  background: #f1f5f9;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.incidents-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}

.incidents-table tbody tr:hover {
  background: #f8fafc;
}

.incidents-table tbody tr.incident-resolved {
  opacity: 0.55;
}

.incident-tag {
  font-weight: 600;
  color: #1e293b;
}

.incident-date {
  white-space: nowrap;
  color: #64748b;
  font-size: 12px;
}

.incident-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.incident-badge.active {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.incident-badge.resolved {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

.incident-resolve-btn {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: #10b981;
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.incident-resolve-btn:hover {
  background: #059669;
}

.incident-resolve-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.incident-resolve-textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 44px;
}

.incident-resolve-textarea:focus {
  outline: none;
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.incident-resolve-textarea.incident-resolve-error {
  border-color: #ef4444;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

.incident-resolve-btn-row {
  display: flex;
  gap: 6px;
}

.incident-resolve-confirm {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: #10b981;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.incident-resolve-confirm:hover {
  background: #059669;
}

.incident-resolve-cancel {
  padding: 4px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #f8fafc;
  color: #64748b;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.incident-resolve-cancel:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.incident-resolution-cell {
  max-width: 250px;
}

.incident-resolution-text {
  font-size: 12px;
  color: #334155;
  line-height: 1.4;
}

.incident-resolution-date {
  font-size: 10px;
  color: #94a3b8;
  margin-top: 2px;
}

/* =============================================
   WAREHOUSE / ALMACEN
   ============================================= */

.warehouse-header {
  padding: 16px 20px 8px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.warehouse-header h2 {
  margin: 0;
  font-size: 18px;
  color: #1e293b;
  white-space: nowrap;
}

.warehouse-search {
  flex: 1;
  max-width: 350px;
  padding: 7px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.warehouse-search:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.warehouse-table-wrapper {
  padding: 0 20px 20px;
  overflow-x: auto;
}

.warehouse-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.warehouse-table thead th {
  background: #f1f5f9;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}

.warehouse-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}

.warehouse-table tbody tr:hover {
  background: #f8fafc;
}

.wh-reference {
  font-weight: 600;
  color: #1e293b;
  white-space: nowrap;
}

.wh-location {
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
}

.wh-date {
  white-space: nowrap;
  color: #64748b;
  font-size: 12px;
}

.wh-updated-by {
  color: #64748b;
  font-size: 12px;
}

.wh-desc-input {
  width: 100%;
  min-width: 140px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
  transition: all 0.15s;
}

.wh-desc-input:hover {
  border-color: #e2e8f0;
  background: #fff;
}

.wh-desc-input:focus {
  outline: none;
  border-color: #3b82f6;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* Cantidad con botones +/- */
.wh-quantity-cell {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0;
}

.wh-qty-btn {
  width: 26px;
  height: 26px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  line-height: 1;
}

.wh-qty-minus {
  border-radius: 6px 0 0 6px;
}

.wh-qty-plus {
  border-radius: 0 6px 6px 0;
}

.wh-qty-btn:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.wh-qty-btn:active {
  background: #cbd5e1;
}

.wh-qty-value {
  min-width: 36px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid #e2e8f0;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 700;
  font-size: 13px;
  background: #fff;
}

.wh-qty-zero {
  color: #dc2626;
  background: #fef2f2;
}

.wh-qty-low {
  color: #d97706;
  background: #fffbeb;
}

.wh-qty-ok {
  color: #059669;
  background: #f0fdf4;
}

.wh-condition-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.wh-cond-stock {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

.wh-cond-damaged {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

/* =============================================
   LOGS ALERT (DASHBOARD)
   ============================================= */

.logs-alert {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.logs-alert-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: #e0e7ff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logs-alert-text {
  flex: 1;
  font-size: 13px;
  color: #312e81;
}

.logs-alert-text strong {
  font-size: 18px;
  color: #6366f1;
}

.logs-alert-btn {
  padding: 7px 16px;
  border: none;
  border-radius: 6px;
  background: #6366f1;
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease;
}

.logs-alert-btn:hover {
  background: #4f46e5;
}

/* =============================================
   LOGS TABLE
   ============================================= */

.logs-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 8px;
}

.logs-header h2 {
  margin: 0;
  font-size: 18px;
  color: #1e293b;
}

.logs-tag-search {
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
  width: 200px;
}

.logs-tag-search:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.logs-status-filter {
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
  background: #ffffff;
}

.logs-table-wrapper {
  padding: 0 20px 20px;
  overflow: auto;
  max-height: calc(100vh - 160px);
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.4;
}

.logs-table thead th {
  background: #f1f5f9;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  z-index: 1;
}

.logs-table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}

.logs-row { cursor: pointer; transition: background 0.15s; }
.logs-row:hover { background: #f8fafc; }
.logs-row.log-closed { opacity: 0.5; }

.logs-sortable { cursor: pointer; user-select: none; }
.logs-sortable::after { content: ' \25B2'; font-size: 8px; color: #94a3b8; }
.logs-sortable[data-sort="desc"]::after { content: ' \25BC'; color: #6366f1; }
.logs-sortable[data-sort="asc"]::after { color: #6366f1; }

.log-date { white-space: nowrap; color: #64748b; font-size: 11px; font-family: monospace; }
.log-tag { font-weight: 600; color: #1e293b; }
.log-old, .log-new { font-family: monospace; font-size: 11px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.log-source-badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.log-source-badge.event { background: #dbeafe; color: #1d4ed8; }
.log-source-badge.hw { background: #fef3c7; color: #b45309; }

.log-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.log-badge.nuevo { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.log-badge.revisado { background: #eff6ff; color: #2563eb; border: 1px solid #bfdbfe; }
.log-badge.accion { background: #fffbeb; color: #d97706; border: 1px solid #fde68a; }
.log-badge.cerrado { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; }

/* =============================================
   LOG DETAIL POPUP
   ============================================= */

.log-popup-hidden { display: none; }

.log-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #ffffff;
  border-radius: 12px;
  z-index: 600;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 10px 30px -5px rgba(0,0,0,0.15);
}

.log-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  border-radius: 12px 12px 0 0;
}

.log-popup-header h3 { margin: 0; font-size: 15px; color: #1e293b; }

.log-popup-body { padding: 18px; }

.log-popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin-bottom: 18px;
}

.log-popup-label { font-size: 12px; font-weight: 600; color: #64748b; }
.log-popup-value { font-size: 12px; color: #1e293b; word-break: break-all; }

.log-popup-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.log-popup-status-label { font-size: 12px; font-weight: 600; color: #475569; }

.log-popup-status-select {
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  background: #ffffff;
}

.log-popup-status-select:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.log-popup-comment-section { margin-bottom: 14px; }
.log-popup-comment-label { display: block; font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 6px; }

.log-popup-comment-textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
  box-sizing: border-box;
}

.log-popup-comment-textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.log-popup-footer { display: flex; justify-content: flex-end; }

.log-popup-save-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  background: #6366f1;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.log-popup-save-btn:hover { background: #4f46e5; }

/* =============================================
   EDIT MODE - P&ID
   ============================================= */

.pid-filter-separator {
  width: 1px;
  height: 20px;
  background: #e2e8f0;
  margin: 0 4px;
  flex-shrink: 0;
}

.pid-edit-mode-btn {
  padding: 4px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.pid-edit-mode-btn:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

.pid-edit-mode-btn.active {
  background: #f59e0b;
  color: #ffffff;
  border-color: #f59e0b;
}

/* SVG canvas when edit mode is active */
#main_svg.edit-mode-active {
  background: #fffbeb;
  outline: 2px dashed #f59e0b;
  outline-offset: -2px;
}

/* Edit mode toolbar */
.edit-mode-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 4px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 4px;
}

.edit-toolbar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #ffffff;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.edit-toolbar-btn:hover:not(:disabled) {
  border-color: #3b82f6;
  color: #3b82f6;
}

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

.edit-toolbar-btn-danger:hover:not(:disabled) {
  border-color: #ef4444;
  color: #ef4444;
}

.edit-toolbar-btn-exit {
  background: #f59e0b;
  color: #ffffff;
  border-color: #f59e0b;
}

.edit-toolbar-btn-exit:hover:not(:disabled) {
  background: #d97706;
  border-color: #d97706;
  color: #ffffff;
}

.edit-toolbar-separator {
  width: 1px;
  height: 20px;
  background: #e2e8f0;
  flex-shrink: 0;
}

.edit-mode-status {
  font-size: 11px;
  color: #94a3b8;
  font-style: italic;
  margin-left: 8px;
}

/* Selected valve glow */
g.valve.valve-selected {
  filter: drop-shadow(0 0 6px #3b82f6);
}

/* Edit mode cursors */
#main_svg.edit-mode-active g.valve {
  cursor: grab;
}

#main_svg.edit-mode-active g.valve:active {
  cursor: grabbing;
}

/* SVG Picker */
.edit-svg-picker {
  position: absolute;
  top: 80px;
  right: 10px;
  z-index: 20;
  width: 320px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.edit-svg-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

.edit-svg-picker-header h4 {
  margin: 0;
  font-size: 14px;
  color: #0f172a;
}

.edit-create-close {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: #94a3b8;
  padding: 0;
  line-height: 1;
}

.edit-create-close:hover {
  color: #475569;
}

.edit-svg-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  max-height: 50vh;
  overflow-y: auto;
}

.edit-svg-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: #ffffff;
}

.edit-svg-card:hover {
  border-color: #3b82f6;
  background: #eff6ff;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.15);
}

.edit-svg-card img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.edit-svg-card-label {
  font-size: 10px;
  font-weight: 600;
  color: #475569;
  text-align: center;
  line-height: 1.2;
}

.edit-svg-picker-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 20px;
  color: #94a3b8;
  font-size: 13px;
}

/* =============================================
   PIPES (Tuberias P&ID)
   ============================================= */

/* Visible pipe line */
.pipe-line {
  stroke: #334155;
  stroke-width: 3;
  stroke-linecap: round;
}

/* Invisible hitarea for click/hover detection */
.pipe-hitarea {
  stroke: transparent;
  stroke-width: 12;
  stroke-linecap: round;
  pointer-events: stroke;
  cursor: pointer;
}

/* Selected pipe */
g.pipe.pipe-selected .pipe-line {
  stroke: #3b82f6;
}

/* Endpoint handles (visible when selected) */
.pipe-handle {
  fill: #3b82f6;
  stroke: #ffffff;
  stroke-width: 2;
  cursor: grab;
  r: 5;
}

.pipe-handle:hover {
  r: 6;
  fill: #2563eb;
}

/* Preview line during drawing */
.pipe-preview {
  stroke: #94a3b8;
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
}

/* Edit mode cursor for pipe tool */
#main_svg.pipe-drawing-active {
  cursor: crosshair;
}

/* Active pipe tool button */
.edit-toolbar-btn.pipe-tool-active {
  background: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
}

/* Rubber-band selection rectangle */
.selection-rect {
  fill: rgba(59, 130, 246, 0.08);
  stroke: #3b82f6;
  stroke-width: 1;
  stroke-dasharray: 5 3;
  pointer-events: none;
}
