/* ========== Design Tokens ========== */
:root {
  --color-bg: #f8fafc;
  --color-card: #ffffff;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-border: #e2e8f0;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-neat: #8b5cf6;
  --color-eat: #f97316;
  --color-tef: #06b6d4;
  --color-bmr: #2563eb;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --max-width: 800px;
}

/* ========== Reset ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-stack);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ========== Typography ========== */
h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.1rem; font-weight: 600; line-height: 1.4; }

/* ========== Layout ========== */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

/* ========== Header ========== */
.header {
  text-align: center;
  padding: 32px 0 24px;
  position: relative;
}

.header h1 {
  margin-bottom: 4px;
}

.header .subtitle {
  color: var(--color-text-secondary);
  font-size: 0.95rem;
}

/* ========== Language Toggle ========== */
.lang-toggle {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s ease;
}

.lang-toggle:hover {
  border-color: var(--color-primary);
}

.lang-toggle svg {
  width: 24px;
  height: 16px;
}

/* ========== Unit Toggle ========== */
.unit-toggle {
  display: flex;
  justify-content: center;
  margin: 16px 0 24px;
}

.unit-toggle-group {
  display: inline-flex;
  background: var(--color-border);
  border-radius: 999px;
  padding: 3px;
}

.unit-toggle-group button {
  border: none;
  background: transparent;
  padding: 8px 24px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 999px;
  color: var(--color-text-secondary);
  transition: all 0.2s ease;
  font-family: var(--font-stack);
}

.unit-toggle-group button.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* ========== Card ========== */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ========== Form Elements ========== */
.form-grid {
  display: grid;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.form-group input,
.form-group select {
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font-stack);
  color: var(--color-text);
  background: #fff;
  transition: border-color 0.2s ease;
  width: 100%;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-group input.error {
  border-color: var(--color-danger);
}

.form-group .error-msg {
  color: var(--color-danger);
  font-size: 0.8rem;
  display: none;
}

.form-group .error-msg.visible {
  display: block;
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 42px;
}

.input-with-unit .unit-label {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  pointer-events: none;
}

.height-imperial {
  display: none;
  gap: 8px;
}

.height-imperial.visible {
  display: flex;
}

.height-imperial .form-group {
  flex: 1;
}

/* ========== Radio Group ========== */
.radio-group {
  display: flex;
  gap: 12px;
}

.radio-option {
  flex: 1;
}

.radio-option input {
  display: none;
}

.radio-option label {
  display: block;
  padding: 10px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  text-align: center;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.radio-option input:checked + label {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-primary);
}

/* ========== Body Fat Link ========== */
.bf-info-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--color-primary);
  font-size: 0.8rem;
  text-decoration: none;
  font-weight: 500;
}

.bf-info-link:hover {
  text-decoration: underline;
}

.bf-info-link .info-icon {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--color-primary);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ========== Day Panels ========== */
.day-panels {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.day-panel {
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.day-panel.has-activity {
  border-color: var(--color-primary);
}

.day-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  background: var(--color-bg);
  user-select: none;
  transition: background-color 0.2s ease;
}

.day-panel-header:hover {
  background: #f1f5f9;
}

.day-panel-header .day-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.day-panel-header .day-summary {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-left: 8px;
}

.day-panel-header .chevron {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.day-panel.open .day-panel-header .chevron {
  transform: rotate(180deg);
}

.day-panel-body {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--color-border);
}

.day-panel.open .day-panel-body {
  display: block;
}

/* ========== Day Panel Content ========== */
.neat-section {
  margin-bottom: 16px;
}

.neat-section label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.neat-section select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: var(--font-stack);
  color: var(--color-text);
  background: #fff;
}

.neat-section select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.exercises-section h4 {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
}

.exercise-entry {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.exercise-entry select {
  flex: 2;
  min-width: 140px;
  padding: 8px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-stack);
  color: var(--color-text);
  background: #fff;
}

.exercise-entry select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.exercise-entry .duration-input {
  position: relative;
  flex: 1;
  min-width: 90px;
}

.exercise-entry .duration-input input {
  width: 100%;
  padding: 8px 40px 8px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: var(--font-stack);
  color: var(--color-text);
}

.exercise-entry .duration-input input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.exercise-entry .duration-input .unit-label {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  pointer-events: none;
}

.exercise-entry .btn-remove {
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-danger);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.exercise-entry .btn-remove:hover {
  background: #fef2f2;
  border-color: var(--color-danger);
}

.exercise-entry .btn-remove svg {
  width: 16px;
  height: 16px;
}

.btn-add-exercise {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.85rem;
  font-family: var(--font-stack);
  color: var(--color-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-add-exercise:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.btn-add-exercise svg {
  width: 14px;
  height: 14px;
}

.copy-buttons {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.btn-copy {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.78rem;
  font-family: var(--font-stack);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-copy:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ========== Diet Quality ========== */
.diet-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.diet-option {
  position: relative;
}

.diet-option input {
  display: none;
}

.diet-option label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
}

.diet-option label:hover {
  border-color: #cbd5e1;
}

.diet-option input:checked + label {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.diet-option .diet-radio {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  transition: border-color 0.2s ease;
}

.diet-option input:checked + label .diet-radio {
  border-color: var(--color-primary);
}

.diet-option input:checked + label .diet-radio::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  background: var(--color-primary);
  border-radius: 50%;
}

.diet-option .diet-info {
  flex: 1;
}

.diet-option .diet-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.diet-option .diet-desc {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

/* ========== Calculate Button ========== */
.calculate-section {
  text-align: center;
  margin: 8px 0 24px;
}

.btn-calculate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 48px;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: var(--font-stack);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.btn-calculate:hover {
  background: var(--color-primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.btn-calculate:active {
  transform: translateY(0);
}

.btn-calculate svg {
  width: 20px;
  height: 20px;
}

/* ========== Results ========== */
.results-section {
  display: none;
  margin-bottom: 40px;
}

.results-section.visible {
  display: block;
}

.weekly-avg {
  text-align: center;
  padding: 24px;
}

.weekly-avg .avg-label {
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.weekly-avg .avg-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.1;
}

.weekly-avg .avg-unit {
  font-size: 1rem;
  font-weight: 400;
  color: var(--color-text-secondary);
}

/* Daily breakdown table */
.daily-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -24px;
  padding: 0 24px;
}

.daily-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 500px;
  font-size: 0.9rem;
}

.daily-table th {
  padding: 10px 8px;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-secondary);
  border-bottom: 2px solid var(--color-border);
  text-align: center;
}

.daily-table td {
  padding: 12px 8px;
  text-align: center;
  border-bottom: 1px solid var(--color-border);
}

.daily-table .tdee-row td {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-primary);
  border-bottom: none;
}

.daily-table .component-label {
  text-align: left;
  font-weight: 500;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
}

/* Stacked bar chart */
.bar-chart {
  margin: 24px 0;
}

.bar-chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.bar-track {
  height: 32px;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  background: var(--color-border);
}

.bar-segment {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: #fff;
  transition: width 0.5s ease;
  min-width: 0;
  overflow: hidden;
}

.bar-segment.bmr { background: var(--color-bmr); }
.bar-segment.neat { background: var(--color-neat); }
.bar-segment.eat { background: var(--color-eat); }
.bar-segment.tef { background: var(--color-tef); }

.bar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
}

.bar-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}

.bar-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bar-legend-dot.bmr { background: var(--color-bmr); }
.bar-legend-dot.neat { background: var(--color-neat); }
.bar-legend-dot.eat { background: var(--color-eat); }
.bar-legend-dot.tef { background: var(--color-tef); }

.bar-legend-value {
  font-weight: 600;
}

/* Expandable detail */
.detail-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  font-family: var(--font-stack);
  font-size: 0.85rem;
  color: var(--color-primary);
  cursor: pointer;
  padding: 8px 0;
  font-weight: 500;
}

.detail-toggle:hover {
  text-decoration: underline;
}

.detail-toggle .chevron-sm {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.detail-toggle.open .chevron-sm {
  transform: rotate(180deg);
}

.detail-content {
  display: none;
}

.detail-content.visible {
  display: block;
}

.results-note {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-align: center;
  margin-top: 16px;
  font-style: italic;
}

/* ========== Body Fat Guide Page ========== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 20px;
}

.back-link:hover {
  text-decoration: underline;
}

.back-link svg {
  width: 16px;
  height: 16px;
}

.warning-box {
  background: #fffbeb;
  border: 1.5px solid #fcd34d;
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 20px 0;
}

.warning-box .warning-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: #92400e;
  margin-bottom: 8px;
}

.warning-box .warning-title svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.warning-box p {
  font-size: 0.85rem;
  color: #78350f;
  line-height: 1.5;
}

.measure-img {
  max-width: 300px;
  width: 100%;
  border-radius: 8px;
  margin-bottom: 12px;
}

.instructions-list {
  list-style: none;
  counter-reset: step;
  margin: 16px 0;
}

.instructions-list li {
  counter-increment: step;
  padding: 10px 0 10px 40px;
  position: relative;
  font-size: 0.9rem;
  line-height: 1.5;
  border-bottom: 1px solid var(--color-border);
}

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

.instructions-list li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 10px;
  width: 28px;
  height: 28px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.bf-result {
  text-align: center;
  padding: 20px;
  background: var(--color-primary-light);
  border-radius: var(--radius-md);
  margin-top: 16px;
  display: none;
}

.bf-result.visible {
  display: block;
}

.bf-result .bf-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
}

.bf-result .bf-label {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.navy-calc .form-grid {
  margin-bottom: 16px;
}

.btn-navy-calc {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 24px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-stack);
  cursor: pointer;
  transition: background 0.2s ease;
}

.btn-navy-calc:hover {
  background: var(--color-primary-hover);
}

/* ========== Validation ========== */
.validation-error {
  background: #fef2f2;
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: none;
}

.validation-error.visible {
  display: block;
}

.validation-error p {
  color: var(--color-danger);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ========== Footer ========== */
.footer {
  text-align: center;
  padding: 24px 0;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
}

/* ========== Responsive: Tablet+ ========== */
@media (min-width: 768px) {
  .container {
    padding: 0 24px;
  }

  .header {
    padding: 40px 0 28px;
  }

  h1 { font-size: 2rem; }

  .form-grid-2col {
    grid-template-columns: 1fr 1fr;
  }

  .exercise-entry {
    flex-wrap: nowrap;
  }

  .diet-options {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }

  .diet-option {
    flex: 1 1 calc(33.333% - 8px);
    min-width: calc(33.333% - 8px);
  }

  .diet-option label {
    flex-direction: column;
    text-align: center;
    padding: 16px;
    min-height: 100%;
  }

  .daily-table-wrapper {
    margin: 0;
    padding: 0;
  }
}

/* ========== Responsive: Desktop ========== */
@media (min-width: 1024px) {
  .header h1 { font-size: 2.25rem; }

  .card {
    padding: 28px;
  }
}
