:root {
  --bg-color: #0b1329;
  --card-bg: #152238;
  --card-border: #233554;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --wine-primary: #881337;
  --wine-light: #9f1239;
  --wine-border: #be123c;
  --wine-glow: rgba(190, 18, 60, 0.25);
  --accent-color: #38bdf8;
  --accent-hover: #0284c7;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --surface-alt: #0d1b2a;
  --input-bg: #0b1329;
  --input-border: #233554;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.4);
  --transition-fast: 0.2s ease;
}

[data-theme="light"] {
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --card-border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --wine-primary: #881337;
  --wine-light: #9f1239;
  --wine-border: #e11d48;
  --wine-glow: rgba(225, 29, 72, 0.12);
  --accent-color: #0284c7;
  --accent-hover: #0369a1;
  --surface-alt: #f1f5f9;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.08);
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
  width: 100%;
}

h1, h2, h3, h4, h5, h6, .brand-title, .modal-title {
  font-family: var(--font-heading);
}

button, input, select, textarea {
  font-family: inherit;
}

.brand-logo-box {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #1e3a8a 0%, #0369a1 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(3, 105, 161, 0.35);
}

.badge-logistics {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  text-transform: none;
}

[data-theme="light"] .badge-logistics {
  background: #e0f2fe;
  color: #0369a1;
  border-color: #bae6fd;
}

.tool-layout {
  max-width: 1380px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 1.75rem;
  align-items: start;
}

@media (max-width: 1024px) {
  .tool-grid {
    grid-template-columns: 1fr;
  }
}

.card-panel {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.card-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

/* Presets */
.preset-chips-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  scrollbar-width: thin;
}

.preset-chip-btn {
  background: var(--surface-alt);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 40px;
}

.preset-chip-btn:hover {
  border-color: var(--accent-color);
  background: rgba(56, 189, 248, 0.15);
  color: #bae6fd;
}

.preset-chip-btn.active {
  background: #0284c7;
  border-color: var(--accent-color);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

/* Formulario */
.inputs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
}

@media (max-width: 640px) {
  .inputs-grid {
    grid-template-columns: 1fr;
  }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.field-helper {
  font-size: 0.75rem;
  color: var(--text-muted);
}

select.select-custom {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 42px;
  padding: 0 40px 0 0.85rem;
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.88rem;
  font-family: var(--font-main);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2338bdf8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: calc(100% - 14px) center;
  color-scheme: dark;
  transition: var(--transition-fast);
}

select.select-custom option {
  background-color: #152238;
  color: #f8fafc;
  padding: 10px;
}

select.select-custom optgroup {
  background-color: #0b1329;
  color: #38bdf8;
  font-weight: 700;
}

[data-theme="light"] select.select-custom {
  background-color: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230284c7' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  color-scheme: light;
}

[data-theme="light"] select.select-custom option {
  background-color: #ffffff;
  color: #0f172a;
}

[data-theme="light"] select.select-custom optgroup {
  background-color: #f1f5f9;
  color: #0284c7;
}

select.select-custom:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.input-with-unit {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
  min-height: 42px;
  transition: var(--transition-fast);
}

.input-with-unit:focus-within {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.input-with-unit input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  outline: none;
}

.unit-tag {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-mono);
  margin-left: 0.5rem;
}

/* Switches y checkboxes */
.checkbox-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.85rem;
  background: var(--surface-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.checkbox-toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #0284c7;
  cursor: pointer;
}

/* Visualizador Canvas */
.canvas-card-wrapper {
  background: var(--surface-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1.25rem;
}

.canvas-header-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

canvas.container-canvas {
  width: 100%;
  height: 200px;
  background: #0f172a;
  border-radius: 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

canvas.pallet-canvas {
  width: 100%;
  height: 200px;
  background: #0f172a;
  border-radius: 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* Indicadores de Peso y Volumen (Gauges / Barras) */
.metrics-gauges-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 500px) {
  .metrics-gauges-grid {
    grid-template-columns: 1fr;
  }
}

.gauge-card {
  background: var(--surface-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.gauge-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.gauge-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.gauge-val-big {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.gauge-progress-bar {
  width: 100%;
  height: 10px;
  background: var(--input-bg);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.gauge-progress-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.3s ease;
}

.fill-weight {
  background: linear-gradient(90deg, #10b981 0%, #f59e0b 80%, #ef4444 100%);
}

.fill-volume {
  background: linear-gradient(90deg, #0284c7 0%, #38bdf8 100%);
}

/* Cuello de botella y alertas */
.bottleneck-banner {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  line-height: 1.4;
  margin-bottom: 1.25rem;
}

.bottleneck-banner.info {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #bae6fd;
}

[data-theme="light"] .bottleneck-banner.info {
  background: #f0f9ff;
  border-color: #bae6fd;
  color: #0369a1;
}

.bottleneck-banner.warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

[data-theme="light"] .bottleneck-banner.warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #b45309;
}

.bottleneck-banner.danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

[data-theme="light"] .bottleneck-banner.danger {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

/* Tabla de escandallo logístico */
.logistics-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.logistics-data-table td {
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--card-border);
}

.logistics-data-table td:last-child {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
}

.logistics-data-table tr.highlight-row td {
  font-weight: 700;
  color: var(--accent-color);
  background: rgba(56, 189, 248, 0.08);
}

/* Botones de acción */
.actions-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}

@media (max-width: 500px) {
  .actions-row {
    grid-template-columns: 1fr;
  }
}

.btn-primary-logistics {
  background: #0284c7;
  border: 1px solid var(--accent-color);
  color: #ffffff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  width: 100%;
  transition: var(--transition-fast);
}

.btn-primary-logistics:hover {
  background: #0369a1;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);
}

.btn-secondary-logistics {
  background: var(--surface-alt);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  width: 100%;
  transition: var(--transition-fast);
}

.btn-secondary-logistics:hover {
  border-color: var(--accent-color);
  color: #38bdf8;
}

/* Modal */
.fijate-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(4px);
}

.fijate-modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.fijate-modal-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  max-width: 540px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

.fijate-modal-backdrop.active .fijate-modal-box {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.modal-body {
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-main);
  margin-bottom: 1.25rem;
}

.modal-textarea {
  width: 100%;
  height: 150px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.75rem;
  margin-top: 0.5rem;
  resize: vertical;
}

/* Guía explicativa */
.logistics-notes-card {
  background: var(--surface-alt);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin-top: 2rem;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.logistics-notes-card h3 {
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.logistics-notes-card ul {
  padding-left: 1.2rem;
  margin-top: 0.5rem;
}

.logistics-notes-card li {
  margin-bottom: 0.35rem;
}

/* Animación de feedback y pulso */
@keyframes pulseFeedback {
  0% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.45);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(56, 189, 248, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(56, 189, 248, 0);
  }
}

.highlight-pulse {
  animation: pulseFeedback 0.6s ease-out;
}
