/**
 * Estilos para Diario de Dolor Crónico y Mapa Anatómico (fijate.com)
 * Siluetas SVG interactivas, escala EVA, diseño táctil y @media print
 */

:root {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-subtle: #182234;
  --bg-input: #0b1120;
  --border-color: #334155;
  --border-color-hover: #475569;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #f97316;
  --accent-hover: #ea580c;
  --accent-glow: rgba(249, 115, 22, 0.2);
  --color-eva-0: #10b981;
  --color-eva-leve: #84cc16;
  --color-eva-mod: #f59e0b;
  --color-eva-sev: #ea580c;
  --color-eva-max: #dc2626;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

[data-theme="light"], body.light-theme {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-color-hover: #94a3b8;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent-primary: #ea580c;
  --accent-hover: #c2410c;
  --accent-glow: rgba(234, 88, 12, 0.15);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.08);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  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;
  line-height: 1.25;
  color: var(--text-primary);
}

.mono-num {
  font-family: 'JetBrains Mono', monospace;
}

.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: 2rem;
  align-items: flex-start;
}

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

.card-main {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
}

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

.card-title {
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}

.card-desc {
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-private {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Grid de entrada dual: Mapa vs Formulario */
.pain-entry-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.75rem;
}

/* Mapa anatómico */
.body-map-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.body-map-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.view-switch-tabs {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  width: 100%;
}

.btn-view-toggle {
  flex: 1;
  padding: 0.45rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-view-toggle.active {
  background: var(--accent-primary);
  color: #fff;
}

.body-map-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.body-map-stage {
  position: relative;
  width: 100%;
  max-width: 280px;
  height: 440px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.body-svg {
  width: 100%;
  height: 100%;
  display: none;
  cursor: pointer;
}

.body-svg.active {
  display: block;
}

.body-zone {
  fill: #334155;
  stroke: #475569;
  stroke-width: 1.5;
  transition: fill 0.2s, stroke 0.2s;
}

[data-theme="light"] .body-zone,
body.light-theme .body-zone {
  fill: #e2e8f0;
  stroke: #cbd5e1;
}

.body-zone:hover {
  fill: #f97316;
  stroke: #ea580c;
}

.body-zone.selected-zone {
  fill: #ea580c;
  stroke: #ffffff;
  stroke-width: 2.2;
}

.pain-pin {
  cursor: pointer;
  animation: pulsePin 1.5s infinite;
}

@keyframes pulsePin {
  0% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 0.95; }
}

.selected-zone-badge {
  margin-top: 0.75rem;
  padding: 0.4rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-align: center;
  width: 100%;
}

.selected-zone-badge strong {
  color: var(--accent-primary);
}

/* Formulario de parámetros */
.pain-form-col {
  display: flex;
  flex-direction: column;
}

.eva-selector-block {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

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

.eva-header label {
  font-size: 0.92rem;
  font-weight: 700;
}

.eva-score-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.5rem;
  font-weight: 800;
  padding: 0.2rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--accent-primary);
  color: #fff;
}

.eva-slider {
  width: 100%;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, #10b981 0%, #84cc16 25%, #f59e0b 50%, #ea580c 75%, #dc2626 100%);
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
  margin-bottom: 0.5rem;
}

.eva-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 3px solid #0f172a;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  cursor: pointer;
}

.eva-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.eva-feedback-box {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Cuadrícula de descriptores McGill */
.pain-descriptors-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.check-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.check-pill:hover {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

.check-pill input[type="radio"]:checked + span {
  color: var(--accent-primary);
  font-weight: 700;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.input-group label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  height: 44px;
  padding: 0 0.85rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}

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

.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 40px 0 0.85rem;
  background-color: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
  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 14px center;
  background-size: 16px;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

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

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--bg-card-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

/* Tabs */
.card-tabs-section {
  padding: 0;
  overflow: hidden;
}

.tabs-nav-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  padding: 0 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tabs-nav {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  white-space: nowrap;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.9rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.tabs-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.btn-action-sm {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-action-sm:hover { background: var(--border-color); }
.btn-danger-soft { color: #ef4444; }
.btn-danger-soft:hover { background: rgba(239, 68, 68, 0.15); border-color: #ef4444; }

.tab-pane {
  display: none;
  padding: 1.5rem;
}

.tab-pane.active { display: block; }

/* Resumen del dolor */
.pain-summary-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.summary-metric-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.summary-metric-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.summary-metric-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.summary-metric-val-text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.summary-metric-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Tabla clínica */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

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

.clinical-table th {
  background: var(--bg-card-subtle);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

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

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

.empty-row td {
  text-align: center;
  color: var(--text-muted);
  padding: 2.5rem 1rem;
}

.eva-tag {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 800;
  font-size: 0.8rem;
  color: #fff;
}

.eva-0 { background: var(--color-eva-0); }
.eva-leve { background: var(--color-eva-leve); color: #000; }
.eva-mod { background: var(--color-eva-mod); color: #000; }
.eva-sev { background: var(--color-eva-sev); }
.eva-max { background: var(--color-eva-max); }

.btn-table-del {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
}

.btn-table-del:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

/* Gráfico */
.chart-container-box {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.canvas-responsive-wrapper {
  width: 100%;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  overflow: hidden;
}

.canvas-responsive-wrapper canvas {
  width: 100%;
  height: auto;
  display: block;
}

.chart-footnote {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* FAQ */
.faq-section { margin-top: 1rem; }
.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1rem;
}

.faq-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  padding: 0.85rem 1.15rem;
}

.faq-question {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  cursor: pointer;
}

.faq-answer {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Modales */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
  backdrop-filter: blur(4px);
}

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

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-width: 480px;
  width: 100%;
  overflow: hidden;
}

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

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
}

.modal-body {
  padding: 1.25rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background: var(--bg-card-subtle);
  border-top: 1px solid var(--border-color);
}

.report-clinical-header,
.report-footer-signatures {
  display: none;
}

/* Responsividad Móvil */
@media (max-width: 900px) {
  .pain-entry-grid {
    grid-template-columns: 1fr;
  }
  .pain-descriptors-grid {
    grid-template-columns: 1fr;
  }
  .pain-summary-metrics {
    grid-template-columns: 1fr 1fr;
  }
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
  .form-actions .btn {
    width: 100%;
  }
}

/* @media print para la Unidad del Dolor */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 9.5pt;
  }
  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .pain-entry-grid,
  .tabs-nav-wrapper,
  .btn-action-sm,
  .btn-table-del,
  .faq-section,
  #tab-evolucion,
  #tab-historial {
    display: none !important;
  }
  .tool-layout {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .card-main {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
  }
  .tab-pane {
    display: block !important;
    padding: 0 !important;
  }
  .report-clinical-header {
    display: flex !important;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #000;
    padding-bottom: 10px;
    margin-bottom: 15px;
  }
  .report-doc-title h3 {
    font-size: 14pt;
    color: #000;
    margin-bottom: 3px;
  }
  .report-patient-meta {
    text-align: right;
    font-size: 9pt;
  }
  .pain-summary-metrics {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 15px !important;
  }
  .summary-metric-card {
    border: 1px solid #ccc !important;
    background: #fafafa !important;
    padding: 6px !important;
  }
  .summary-metric-val {
    color: #000 !important;
    font-size: 12pt !important;
  }
  .clinical-table {
    border: 1px solid #333 !important;
    font-size: 8.5pt !important;
  }
  .clinical-table th {
    background: #eaeaea !important;
    color: #000 !important;
    padding: 5px !important;
    border: 1px solid #ccc !important;
  }
  .clinical-table td {
    padding: 4px 6px !important;
    border: 1px solid #ddd !important;
    color: #000 !important;
  }
  .report-footer-signatures {
    display: flex !important;
    justify-content: space-between;
    margin-top: 35px;
    gap: 30px;
  }
  .sig-box {
    flex: 1;
    font-size: 8.5pt;
  }
  .sig-line {
    border-bottom: 1px dashed #666;
    margin-top: 45px;
  }
}
