/* ==========================================================
   Estilos específicos de Calculadora de Lomo de Libro y Sangrado
   ========================================================== */

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

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

  --primary-indigo: #6366f1;
  --primary-indigo-dark: #4f46e5;
  --primary-indigo-light: #e0e7ff;

  --color-bleed: #ef4444;
  --color-trim: #3b82f6;
  --color-safe: #10b981;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

body {
  font-family: var(--font-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

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

.mono, code, .kpi-value, .dim-val, .breakdown-list span {
  font-family: var(--font-mono);
}

/* Layout */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
}

.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%;
}

.card-main {
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  margin-bottom: 2rem;
}

[data-theme="dark"] .card-main {
  background: #111827;
  border-color: #1f2937;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

/* Pestañas */
.nav-tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted, #64748b);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main, #0f172a);
  background: var(--bg-secondary, #f8fafc);
}

[data-theme="dark"] .tab-btn:hover {
  color: #f1f5f9;
  background: #1e293b;
}

.tab-btn.active {
  color: #6366f1;
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.25);
}

[data-theme="dark"] .tab-btn.active {
  color: #818cf8;
  background: rgba(129, 140, 248, 0.12);
  border-color: rgba(129, 140, 248, 0.3);
}

.tab-panel[hidden] {
  display: none !important;
}

/* Grid del editor */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
}

@media (max-width: 900px) {
  .editor-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

.panel-subtitle {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main, #0f172a);
  margin-top: 0;
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

[data-theme="dark"] .panel-subtitle {
  color: #f8fafc;
  border-color: #334155;
}

/* Formulario */
.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-main, #1e293b);
  margin-bottom: 0.4rem;
}

[data-theme="dark"] .form-label {
  color: #e2e8f0;
}

.field-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted, #64748b);
  margin-top: 0.25rem;
  line-height: 1.35;
}

[data-theme="dark"] .field-hint {
  color: #94a3b8;
}

.tag-inline-warning {
  font-size: 0.75rem;
  font-weight: 700;
  color: #dc2626;
  background: rgba(239, 68, 68, 0.15);
  padding: 0.15rem 0.45rem;
  border-radius: 0.25rem;
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.75rem 0.85rem;
  font-size: 0.95rem;
  font-family: var(--font-main);
  background: var(--bg-input, #f8fafc);
  color: var(--text-main, #0f172a);
  border: 1.5px solid var(--border-color, #cbd5e1);
  border-radius: 0.5rem;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select {
  background: #0f172a;
  border-color: #334155;
  color: #f8fafc;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-select,
select {
  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='%2364748b' 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;
  background-size: 16px 16px;
  padding-right: 40px;
  cursor: pointer;
  color-scheme: dark light;
}

select option,
select optgroup {
  background-color: var(--bg-card, #ffffff);
  color: var(--text-main, #0f172a);
}

[data-theme="dark"] select option,
[data-theme="dark"] select optgroup {
  background-color: #0f172a;
  color: #f8fafc;
}

.custom-inputs-row {
  display: flex;
  gap: 0.75rem;
}

.half-width {
  flex: 1 1 0%;
  min-width: 0;
}

/* Columna de resultados */
.spine-hero-box {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(129, 140, 248, 0.12));
  border: 1.5px solid rgba(99, 102, 241, 0.25);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  text-align: center;
}

[data-theme="dark"] .spine-hero-box {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(79, 70, 229, 0.08));
  border-color: rgba(129, 140, 248, 0.3);
}

.kpi-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6366f1;
  margin-bottom: 0.35rem;
}

[data-theme="dark"] .kpi-label {
  color: #818cf8;
}

.kpi-value {
  display: block;
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-main, #0f172a);
}

[data-theme="dark"] .kpi-value {
  color: #ffffff;
}

.kpi-sub-value {
  display: block;
  font-size: 0.95rem;
  color: var(--text-muted, #64748b);
  margin-top: 0.25rem;
}

[data-theme="dark"] .kpi-sub-value {
  color: #94a3b8;
}

.spine-warning-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 0.35rem 0.65rem;
  border-radius: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 0.75rem;
}

[data-theme="dark"] .spine-warning-chip {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

/* Tarjetas de medidas totales */
.cover-dimensions-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.dim-card {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 0.5rem;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
}

[data-theme="dark"] .dim-card {
  background: #1e293b;
  border-color: #334155;
}

.dim-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted, #64748b);
  margin-bottom: 0.2rem;
}

[data-theme="dark"] .dim-label {
  color: #94a3b8;
}

.dim-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: #4f46e5;
  line-height: 1.2;
}

[data-theme="dark"] .dim-val {
  color: #818cf8;
}

.dim-sub {
  font-size: 0.78rem;
  color: var(--text-muted, #64748b);
  margin-top: 0.15rem;
}

[data-theme="dark"] .dim-sub {
  color: #94a3b8;
}

/* Desglose */
.breakdown-box {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

[data-theme="dark"] .breakdown-box {
  background: #1e293b;
  border-color: #334155;
}

.breakdown-title {
  font-size: 0.88rem;
  font-weight: 700;
  margin-top: 0;
  margin-bottom: 0.6rem;
  color: var(--text-main, #0f172a);
}

[data-theme="dark"] .breakdown-title {
  color: #f1f5f9;
}

.breakdown-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.6;
}

.breakdown-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  border-bottom: 1px dashed var(--border-color, #e2e8f0);
}

[data-theme="dark"] .breakdown-list li {
  border-color: #334155;
}

.breakdown-list li:last-child {
  border-bottom: none;
}

.actions-download-bar {
  display: flex;
  gap: 0.75rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: #6366f1;
  color: #ffffff;
  border: none;
  border-radius: 0.5rem;
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  flex: 1;
}

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

.btn-secondary {
  background: var(--bg-secondary, #f1f5f9);
  color: var(--text-main, #334155);
  border: 1px solid var(--border-color, #cbd5e1);
  border-radius: 0.5rem;
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

[data-theme="dark"] .btn-secondary {
  background: #1e293b;
  border-color: #334155;
  color: #cbd5e1;
}

/* Visor del plano blueprint */
.blueprint-viewer-section {
  background: var(--bg-secondary, #f8fafc);
  border: 1.5px solid var(--border-color, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-top: 1rem;
}

[data-theme="dark"] .blueprint-viewer-section {
  background: #0f172a;
  border-color: #334155;
}

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

.blueprint-header h3 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main, #0f172a);
}

[data-theme="dark"] .blueprint-header h3 {
  color: #f1f5f9;
}

.blueprint-legend {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted, #64748b);
}

[data-theme="dark"] .legend-chip {
  color: #94a3b8;
}

.legend-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot-bleed { background: #ef4444; }
.dot-trim { background: #3b82f6; }
.dot-safe { background: #10b981; }

.blueprint-canvas-container {
  width: 100%;
  overflow-x: auto;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 0.5rem;
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

[data-theme="dark"] .blueprint-canvas-container {
  background: #111827;
  border-color: #1e293b;
}

.blueprint-svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Modo DIN ISO */
.din-intro-header {
  margin-bottom: 1.5rem;
}

.din-intro-header h3 {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.din-intro-header p {
  color: var(--text-muted, #64748b);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 0;
}

[data-theme="dark"] .din-intro-header p {
  color: #94a3b8;
}

.din-compare-controls {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 640px) {
  .din-compare-controls {
    flex-direction: column;
  }
}

.din-visual-box {
  background: var(--bg-secondary, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1.75rem;
}

[data-theme="dark"] .din-visual-box {
  background: #1e293b;
  border-color: #334155;
}

.din-canvas-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 260px;
}

.din-comp-text {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main, #334155);
}

[data-theme="dark"] .din-comp-text {
  color: #cbd5e1;
}

.din-table-section {
  margin-top: 1.5rem;
}

.table-section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.table-responsive-wrapper {
  overflow-x: auto;
}

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

.data-table th, .data-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

[data-theme="dark"] .data-table th, [data-theme="dark"] .data-table td {
  border-color: #334155;
}

.data-table th {
  background: var(--bg-secondary, #f1f5f9);
  color: var(--text-muted, #475569);
  font-weight: 600;
}

[data-theme="dark"] .data-table th {
  background: #0f172a;
  color: #94a3b8;
}

/* Responsive */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }
  .card-main {
    padding: 1rem;
  }
  .actions-download-bar {
    flex-direction: column;
  }
}
