/* ==========================================================================
   style.css
   Estilo Moderno y Limpio para NutriWeb
   ========================================================================== */

/* ==========================================================================
   1. Reset & Global Styles
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  /* Fondo degradado moderno */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
}

/* ==========================================================================
   2. Layout & Container
   ========================================================================== */
.container {
  background: white;
  border-radius: 20px;
  /* Bordes grandes y redondeados */
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  padding: 40px;
  max-width: 1000px;
  margin: 0 auto;
  animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1 {
  color: #333;
  margin-bottom: 30px;
  font-size: 2em;
  text-align: center;
}

.section-header {
  background: #6c757d;
  /* Gris oscuro para las secciones */
  color: white;
  padding: 12px 20px;
  margin: 30px 0 20px 0;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1.1em;
}

/* ==========================================================================
   3. Form Elements
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.input-group {
  margin-bottom: 20px;
}

.input-group.full-width {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: #444;
  font-size: 0.95em;
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 15px;
  border-radius: 10px;
  border: 2px solid #e0e0e0;
  font-size: 16px;
  transition: all 0.3s ease;
  background: #fffef0;
  /* Fondo ligeramente crema */
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #667eea;
  /* Color del degradado como foco */
  background: white;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

.unit {
  color: #666;
  font-size: 0.9em;
  margin-left: 5px;
}

.note {
  font-size: 0.85em;
  color: #d9534f;
  /* Rojo de alerta */
  margin-top: 5px;
  font-style: italic;
}

.note.info {
  color: #5bc0de;
  /* Azul de información */
}

button {
  width: 100%;
  padding: 15px;
  margin-top: 20px;
  border: none;
  border-radius: 10px;
  /* Botón con degradado */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

button:active {
  transform: translateY(0);
}

/* ==========================================================================
   4. Responsive Design
   ========================================================================== */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 25px;
  }

  h1 {
    font-size: 1.5em;
  }
}

/* ==========================================================================
   5. Results & Chips
   ========================================================================== */
.chip {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  /* Chip redondeado */
  font-weight: 700;
  color: white;
  margin-left: 8px;
  /* Pequeño margen para separarlo de la etiqueta */
  font-size: 0.95em;
}

.chip.normal {
  background: #2e7d32;
}

/* verde */
.chip.sobrepeso {
  background: #ff9800;
}

/* naranja */
.chip.obesidad {
  background: #d32f2f;
}

/* rojo */
.chip.desnutricion {
  background: #6a1b9a;
}

/* morado */
.chip.riesgo {
  background: #c62828;
}

/* rojo oscuro */

.result-card {
  margin-top: 40px;
  padding: 20px;
  background: #f8f9fa;
  border-radius: 15px;
  border: 2px solid #e0e0e0;
}

.result-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: 8px 0;
  padding: 5px 0;
  border-bottom: 1px solid #e0e0e0;
}

.result-row:last-child {
  border-bottom: none;
}

.result-label {
  color: #333;
  font-weight: 600;
}

.result-value {
  color: #111;
  font-weight: 700;
}

.small-note {
  font-size: 0.9em;
  color: #666;
  margin-top: 6px;
}

/* Separador visual para la sección IMC */
hr {
  border: none;
  border-top: 1px solid #ddd;
  margin: 20px 0;
}

/* ==========================================================================
   6. Macro Distribution Table
   ========================================================================== */
.macro-table-container {
  overflow-x: auto;
}

.macro-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.95em;
}

.macro-table th,
.macro-table td {
  padding: 8px;
  text-align: center;
  border: none;
}

.macro-table th {
  font-weight: 700;
  color: #333;
}

/* Input cells styling */
.input-cell input {
  width: 100%;
  text-align: center;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-weight: 600;
}

/* Yellow background for manual inputs */
.yellow-bg {
  background-color: #ffff00 !important;
  color: black;
  font-weight: 700;
}

.yellow-bg:focus {
  background-color: #ffffcc !important;
}

/* Result cells styling */
.result-cell {
  font-weight: 600;
  color: #333;
}

/* Specific column widths if needed */
.macro-table td:first-child {
  text-align: right;
  padding-right: 15px;
  font-weight: 700;
}

.macro-header {
  background-color: #e9ecef;
  color: #495057;
  font-weight: 700;
}

.macro-label {
  background-color: #e9ecef;
  font-weight: 700;
  color: #495057;
  font-size: 0.9em;
}

/* ==========================================================================
   7. Developed Formula Table
   ========================================================================== */
.dev-formula-container {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.dev-formula-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1200px;
  /* Force horizontal scroll on small screens */
  font-size: 0.85em;
}

.dev-formula-table th,
.dev-formula-table td {
  padding: 4px;
  border: 1px solid #ccc;
  text-align: center;
}

.dev-formula-table th {
  background-color: #f2f2f2;
  font-weight: 700;
  color: #333;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Input styling for the table */
.fd-input-text {
  width: 100%;
  min-width: 100px;
  padding: 4px;
  border: none;
  background: transparent;
}

.fd-input-num {
  width: 100%;
  min-width: 50px;
  padding: 4px;
  border: none;
  text-align: center;
  background: transparent;
}

.fd-input-text:focus,
.fd-input-num:focus {
  background-color: white;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.3);
  outline: none;
}

/* Info Bar for Developed Formula */
.info-bar {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 5px;
  margin-bottom: 20px;
  background: linear-gradient(to right, #f8f9fa, #e9ecef);
  padding: 15px 20px;
  border-radius: 10px;
  border-left: 5px solid #667eea;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.info-bar div {
  font-size: 1em;
  color: #444;
}

@media (max-width: 768px) {
  .info-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Remove borders from inputs to make them look like part of the cell */
.dev-formula-table input {
  border-radius: 0;
}

/* Alternating row colors */
.dev-formula-table tbody tr:nth-child(even) {
  background-color: #fafafa;
}

/* ==========================================================================
   8. Export Buttons
   ========================================================================== */
.btn-export {
  display: inline-block;
  width: auto;
  padding: 12px 25px;
  margin: 0 10px;
  font-size: 16px;
  font-weight: 600;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-export:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.btn-export.excel {
  background-color: #217346;
  /* Excel Green */
}

.btn-export.pdf {
  background-color: #d32f2f;
  /* PDF Red */
}

.btn-suggestion {
  background: linear-gradient(135deg, #20B2AA 0%, #008080 100%);
  /* LightSeaGreen to Teal */
  margin-top: 20px;
}

.btn-suggestion:hover {
  box-shadow: 0 6px 20px rgba(32, 178, 170, 0.4);
}

/* Print Styles */
@media print {
  body {
    background: white;
    padding: 0;
  }

  .container {
    box-shadow: none;
    max-width: 100%;
    padding: 10px;
  }

  button,
  .btn-export,
  #btnAddRow {
    display: none !important;
  }

  .dev-formula-table {
    min-width: 100%;
    /* Reset min-width for print */
    font-size: 0.7em;
    /* Smaller font for print */
  }

  .dev-formula-container {
    overflow: visible;
  }
}

/* ==========================================================================
   9. Mobile / Tablet Responsiveness
   ========================================================================== */
@media (max-width: 768px) {
  .container {
    padding: 15px;
    margin: 10px;
    width: auto;
  }

  h1 {
    font-size: 1.8em;
  }

  h2 {
    font-size: 1.5em;
  }

  /* Make inputs larger for touch and prevent zoom */
  input,
  select,
  textarea,
  .fd-input-num,
  .fd-input-text {
    font-size: 16px !important;
    padding: 10px;
  }

  /* Stack flex containers that are row-based */
  .input-group {
    margin-bottom: 15px;
  }

  /* Ensure tables scroll horizontally */
  .macro-table-container,
  .dev-formula-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
    margin-bottom: 15px;
  }

  /* Buttons full width */
  button,
  .btn-export {
    width: 100%;
    margin: 5px 0;
    display: block;
  }

  #exportSection {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  .btn-export {
    margin: 0;
    /* Reset margin since we use gap */
  }

  /* Adjust result cards */
  .result-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }

  .result-value {
    align-self: flex-end;
    font-weight: 700;
  }
}

/* PDF Generation Styles */
body.generating-pdf .btn-export,
body.generating-pdf #btnAddRow,
body.generating-pdf #exportSection {
  display: none !important;
}

body.generating-pdf .container {
  box-shadow: none;
  margin: 0;
  padding: 0;
  max-width: 100%;
}

/* ==========================================================================
   10. Dedicated PDF Report Styles
   ========================================================================== */
.pdf-report-container {
  font-family: 'Helvetica', 'Arial', sans-serif;
  padding: 20px;
  background: white;
  color: #333;
}

.pdf-header {
  text-align: center;
  margin-bottom: 30px;
  border-bottom: 4px solid #667eea;
  padding-bottom: 15px;
}

.pdf-header h1 {
  margin: 0;
  color: #333;
  font-size: 28px;
  font-weight: 800;
}

.pdf-section {
  margin-bottom: 30px;
}

.pdf-section h3 {
  background-color: #6c757d;
  color: white;
  padding: 10px 15px;
  border-radius: 5px;
  margin-bottom: 15px;
  font-size: 16px;
  font-weight: 700;
}

.pdf-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.pdf-row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
  padding: 8px 0;
}

.pdf-label {
  font-weight: 700;
  color: #555;
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.pdf-table th,
.pdf-table td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: center;
}

.pdf-table th {
  background-color: #e9ecef;
  color: #495057;
  font-weight: 700;
}

.pdf-summary {
  margin-top: 20px;
  background-color: #e8f5e9;
  padding: 15px;
  border-radius: 5px;
}

/* Hide the report container from the web view */
#pdfReportHidden {
  display: none;
}