/**
 * Calculadora de corte de telas y bloques de patchwork
 * Estilos corporativos Canónicos Fijate Tools (Dark-First, Accesible, Responsive)
 */

:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Tema oscuro por defecto (Midnight Slate) */
  --bg-page: #0b0f17;
  --bg-card: #111827;
  --bg-card-hover: #1e293b;
  --bg-card-subtle: #1a2234;
  --border-color: #243049;
  --border-color-focus: #3b82f6;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --primary: #c27852; /* Tono terracota artesanal cálido */
  --primary-hover: #d9885e;
  --primary-subtle: rgba(194, 120, 82, 0.15);
  --primary-contrast: #ffffff;

  --accent-teal: #0d9488;
  --accent-gold: #d97706;
  --accent-blue: #3b82f6;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-card-subtle: #f8fafc;
  --border-color: #e2e8f0;
  --border-color-focus: #c27852;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;

  --primary: #a85834;
  --primary-hover: #8f4828;
  --primary-subtle: rgba(168, 88, 52, 0.1);
  --primary-contrast: #ffffff;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.06);
}

/* Reset y estructura canónica */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

.text-mono {
  font-family: var(--font-mono);
}

.text-muted {
  color: var(--text-muted);
}

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

.font-bold {
  font-weight: 700;
}

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

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Cabecera introductoria de la herramienta */
.tool-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.hero-badge-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--primary-subtle);
  color: var(--primary);
}

.tool-title {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 0.5rem;
  color: var(--text-main);
}

.tool-lead {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 0;
}

/* Tarjetas de sección */
.card-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.75rem;
  box-shadow: var(--shadow-sm);
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.section-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 1.25rem;
}

/* Cuadrículas de formulario */
.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.form-label-hint {
  font-size: 0.75rem;
  color: var(--text-subtle);
  font-weight: 400;
}

.form-control {
  width: 100%;
  height: 42px;
  padding: 0 0.85rem;
  font-family: var(--font-main);
  font-size: 0.95rem;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--border-color-focus);
  box-shadow: 0 0 0 3px rgba(194, 120, 82, 0.2);
}

/* Selectores estilizados */
select.form-control {
  cursor: pointer;
  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='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.5rem;
}

select.form-control option {
  background-color: var(--bg-card);
  color: var(--text-main);
}

/* Interruptor de unidades */
.unit-toggle-group {
  display: flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2px;
  width: fit-content;
}

.unit-toggle-label {
  display: flex;
  align-items: center;
  padding: 0.35rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  color: var(--text-muted);
}

.unit-toggle-radio {
  display: none;
}

.unit-toggle-radio:checked + .unit-toggle-label {
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: var(--shadow-sm);
}

/* Bloque interactivo informativo */
.block-info-card {
  background: var(--bg-card-subtle);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.badge-difficulty {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  text-transform: capitalize;
}

.badge-iniciacion, .badge-basico {
  background: rgba(13, 148, 136, 0.15);
  color: var(--accent-teal);
}

.badge-intermedio {
  background: rgba(217, 119, 6, 0.15);
  color: var(--accent-gold);
}

.badge-avanzado {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

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

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.kpi-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.kpi-card-highlight {
  border-color: var(--primary);
  background: var(--primary-subtle);
}

.kpi-card-highlight .kpi-value {
  color: var(--primary);
}

/* Mosaico interactivo de la colcha */
.quilt-preview-wrapper {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 992px) {
  .quilt-preview-wrapper {
    grid-template-columns: 1fr;
  }
}

.quilt-canvas-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 380px;
}

.quilt-svg-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quilt-svg {
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  transition: transform 0.2s ease;
}

.quilt-preview-aside {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.palette-control-box {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

/* Tabla de despiece de cortes */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

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

.pieces-table th {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  font-weight: 600;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pieces-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

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

.pieces-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.col-fabric {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
}

.fabric-badge {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.highlight-cut {
  color: var(--primary);
  font-weight: 700;
}

.qty-pill {
  display: inline-block;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-weight: 700;
}

/* Lista de la compra */
.shopping-list-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-top: 1rem;
}

.shopping-item-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.25rem;
  transition: var(--transition);
}

.shopping-item-card:hover {
  border-color: var(--primary);
}

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

.shopping-item-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.fabric-swatch-circle {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.material-icon-box {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--primary-subtle);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.shopping-item-category {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  font-weight: 700;
  display: block;
}

.shopping-item-name {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0.15rem 0 0;
  color: var(--text-main);
}

.shopping-item-amount {
  text-align: right;
  flex-shrink: 0;
}

.meters-number {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}

.meters-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

.shopping-item-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0;
}

/* Botones de acción */
.actions-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 44px;
  padding: 0 1.25rem;
  font-family: var(--font-main);
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card-subtle);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

/* Acordeón de consejos y FAQ */
.faq-accordion {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-card-subtle);
  overflow: hidden;
  transition: var(--transition);
}

.faq-item details {
  width: 100%;
}

.faq-item summary {
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-main);
}

.faq-item summary::-webkit-details-marker {
  display: none;
}

.faq-item summary::after {
  content: '+';
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--primary);
  transition: transform 0.2s ease;
}

.faq-item details[open] summary::after {
  content: '−';
}

.faq-content {
  padding: 0 1.25rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.faq-content p {
  margin: 0.5rem 0;
}

.faq-content ul {
  padding-left: 1.25rem;
  margin: 0.5rem 0;
}

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

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

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 1.75rem;
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.85rem;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}

.btn-close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.btn-close-modal:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

/* Estilos de la ficha técnica dentro del modal */
.sheet-print-header {
  margin-bottom: 1.25rem;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 0.85rem;
}

.sheet-print-header h3 {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  margin: 0 0 0.35rem;
  color: var(--text-main);
}

.sheet-section {
  margin-bottom: 1.35rem;
}

.sheet-section h4 {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sheet-bullets {
  list-style: disc;
  padding-left: 1.25rem;
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.table-sheet {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin-top: 0.5rem;
}

.table-sheet th {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table-sheet td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.sheet-shopping-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sheet-shopping-list li {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-size: 0.88rem;
}

.sheet-shopping-list .item-title {
  color: var(--text-main);
}

.sheet-shopping-list .item-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.sheet-actions-bar {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Toast flotante accesible */
.custom-toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: #1e293b;
  color: #ffffff;
  border: 1px solid #334155;
  padding: 0.85rem 1.35rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 10000;
  display: none;
  align-items: center;
  gap: 0.6rem;
  animation: toastFadeIn 0.3s ease;
}

.custom-toast.visible {
  display: flex;
}

@keyframes toastFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Ajustes de impresión */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .app-header, .tool-ad-sidebar, .tools-ad-banner-section, .fijate-footer, .affiliate-showcase, .actions-bar, .faq-accordion {
    display: none !important;
  }
  .main-wrapper.tool-layout {
    margin: 0;
    padding: 0;
    max-width: 100%;
  }
  .card-section {
    border: none;
    box-shadow: none;
    padding: 0;
  }
}

/* Responsividad para móviles */
@media (max-width: 768px) {
  .tool-title {
    font-size: 1.45rem;
  }
  .form-grid-2, .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .btn {
    width: 100%;
  }
}
