/**
 * style.css - Optimizador de corte de tableros
 * Fijate Tools - Estándar canónico
 */

:root {
  --bg: #090d16;
  --surface: #0f172a;
  --surface-hover: #1e293b;
  --surface-active: #283548;
  --border: #1e293b;
  --border-subtle: #2d3b4e;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.2);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --surface-active: #e2e8f0;
  --border: #e2e8f0;
  --border-subtle: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-glow: rgba(37, 99, 235, 0.12);
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.03);
}

/* Reset y contención canónica */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

code, pre, .font-mono, .metric-val {
  font-family: 'JetBrains Mono', monospace;
}

/* Layout canónico */
.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  flex: 1 0 auto;
}

.tool-with-sidebar {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Tarjetas y contenedores */
.card-main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

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

.section-title {
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Formularios de configuración de tablero */
.form-grid-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.form-control, select.form-control {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-suffix-wrap {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  height: 42px;
  padding: 0 0.75rem;
  transition: border-color 0.2s;
}

.input-suffix-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-suffix-wrap input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  outline: none;
}

.input-suffix {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.35rem;
  font-weight: 500;
}

/* Tabla dinámica de piezas */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.pieces-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.pieces-table th {
  background: var(--surface-hover);
  padding: 0.75rem 0.6rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.pieces-table td {
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.pieces-table tr:last-child td {
  border-bottom: none;
}

.input-table {
  width: 100%;
  height: 38px;
  padding: 0 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
}

.input-table.piece-w, .input-table.piece-h, .input-table.piece-count {
  font-family: 'JetBrains Mono', monospace;
}

.color-badge {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
}

.toggle-checkbox-wrap {
  display: inline-flex;
  cursor: pointer;
  user-select: none;
  align-items: center;
  justify-content: center;
}

.toggle-checkbox-wrap input {
  display: none;
}

.custom-toggle {
  width: 38px;
  height: 22px;
  background: var(--surface-active);
  border-radius: 999px;
  position: relative;
  transition: background 0.2s;
}

.custom-toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-checkbox-wrap input:checked + .custom-toggle {
  background: var(--primary);
}

.toggle-checkbox-wrap input:checked + .custom-toggle::after {
  transform: translateX(16px);
}

.btn-delete-row {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-delete-row:hover {
  background: rgba(239, 68, 68, 0.15);
}

/* Botones de acción */
.table-actions-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.btn-group-left {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-secondary {
  height: 40px;
  padding: 0 1rem;
  background: var(--surface-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: var(--surface-active);
}

.btn-primary-action {
  height: 44px;
  padding: 0 1.5rem;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 12px var(--primary-glow);
  transition: background 0.2s, transform 0.1s;
}

.btn-primary-action:hover {
  background: var(--primary-hover);
}

.btn-primary-action:active {
  transform: scale(0.98);
}

/* Tarjetas de métricas */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.metric-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.metric-val {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
}

.metric-card.highlight-metric .metric-val {
  color: var(--success);
}

/* Diagramas de tableros SVG */
.sheet-diagram-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.sheet-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sheet-title {
  font-size: 1.15rem;
}

.sheet-subinfo {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.badge-tablero {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  background: var(--surface-active);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
}

.sheet-svg-wrapper {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sheet-svg {
  width: 100%;
  max-height: 500px;
  display: block;
}

/* Retales útiles */
.offcuts-card {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1.5rem;
}

.offcuts-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.offcuts-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.offcut-item {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.825rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.offcut-badge {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
}

.no-offcuts {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.optimization-alert-warning {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--warning);
  color: #fef08a;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

/* Modal personalizado */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.is-open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 440px;
  width: 100%;
  padding: 1.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  animation: modalScale 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-title {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
}

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Adaptación táctil y móvil */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }
  .table-actions-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .btn-group-left {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
  .btn-primary-action {
    width: 100%;
  }
}

/* Impresión limpia */
@media print {
  .app-header, .fijate-footer, .tool-ad-sidebar, .tools-ad-banner-section,
  .table-actions-bar, .form-grid-sheet, .table-responsive, #btn-calculate, #btn-print {
    display: none !important;
  }
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .card-main, .sheet-diagram-card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  .sheet-svg {
    max-height: 400px;
    page-break-inside: avoid;
  }
}
