/* ====== RESET & VARIABLES ====== */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-color: #f2f2f2;
  --text-color: #000000;
  --card-bg: #ffffff;
  --card-border: #e0e0e0;
  --input-bg: #ffffff;
  --input-border: #d0d0d0;
  --primary-color: #D400FF;
}

/* ====== IMAGE OPTIMIZATION ====== */

img {
  max-width: 100%;
  height: auto;
  display: block;
  /* Enable hardware acceleration for images */
  -webkit-font-smoothing: antialiased;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* Optimize logo image */
.logo-img {
  content-visibility: auto;
  contain: layout style paint;
}

/* Optimize nav icons with size containment */
.nav-icon {
  content-visibility: auto;
  will-change: opacity;
}

/* ====== BASE STYLES ====== */

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  overflow: auto;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* ====== APP LAYOUT ====== */

.app {
  width: 100%;
  height: 100%;
  max-width: 428px;
  background: var(--bg-color);
  border-radius: 0;
  overflow: visible;
  display: flex;
  flex-direction: column;
  box-shadow: none;
  position: relative;
}

/* ====== HEADER ====== */

.app-header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-color) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 201, 177, 0.2);
  position: relative;
  padding-top: max(16px, env(safe-area-inset-top));
}

.app-header .logo-img {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  object-fit: contain;
  position: absolute;
  left: 16px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  pointer-events: none;   
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  letter-spacing: 1px;
}

/* ====== SCREENS & CONTENT ====== */

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 8px 6px 70px;
  gap: 6px;
}

.screen.active {
  display: flex;
}

/* ====== CARDS ====== */

.card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-color);
  margin-bottom: 10px;
}

/* ====== DATA & TABLES ====== */

.data-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
  color: var(--text-color);
  border-bottom: 1px solid var(--card-border);
}

.data-row:last-child {
  border-bottom: none;
}

.data-row .label {
  color: var(--text-color);
  font-weight: 500;
  opacity: 0.75;
}

.data-row .value {
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.light .data-row .value {
  color: #0033aa;
}

.dark .data-row .value {
  color: #ffff00;
}

/* ====== PROGRESS BARS ====== */

.progress-container {
  margin: 8px 0;
}

.progress-label {
  font-size: 13px;
  color: var(--text-color);
  font-style: italic;
  margin-bottom: 3px;
  opacity: 0.8;
}

.progress-bar-bg {
  background: #e0e0e0;
  border-radius: 4px;
  height: 8px;
  width: 100%;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary-color);
  border-radius: 4px;
  width: 0%;
}

/* ====== IMC INDICATOR ====== */

.imc-bar-container {
  margin-top: 12px;
  position: relative;
}

.imc-bar {
  display: flex;
  gap: 2px;
  height: 24px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  margin-bottom: 32px;
}

.imc-zone {
  flex: 1;
  border-radius: 8px;
}

.imc-underweight {
  background: #2196F3;
}

.imc-normal {
  background: #4CAF50;
}

.imc-overweight {
  background: #FF9800;
}

.imc-obese-moderate {
  background: #FF5722;
}

.imc-obese-severe {
  background: #f44336;
}

.imc-pointer {
  position: absolute;
  width: 3px;
  height: 28px;
  background: var(--text-color);
  border-radius: 2px;
  top: -2px;
  left: 0%;
  transform: translateX(-50%);
  transition: left 0.3s ease;
}

.imc-category-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  gap: 2px;
  text-align: center;
}

.imc-category-labels span {
  flex: 1;
}

.imc-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  opacity: 0.7;
  gap: 2px;
}

.imc-range-labels span {
  flex: 1;
  text-align: center;
}

/* ====== SCORES & BIG NUMBERS ====== */

.score-big {
  font-size: 48px;
  font-weight: 700;
  text-align: center;
  line-height: 1.1;
  padding: 16px 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.light .score-big {
  color: #0033aa;
}

.dark .score-big {
  color: #ffff00;
}

.score-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 6px;
}

.obj-percent {
  font-size: 48px;
  font-weight: 700;
  text-align: center;
  padding: 16px 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.light .obj-percent {
  color: #0033aa;
}

.dark .obj-percent {
  color: #ffff00;
}

/* ====== BUTTONS ====== */

.btn-teal {
  background: var(--primary-color);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  text-align: center;
  letter-spacing: 0.3px;
  transition: filter 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.btn-teal:hover {
  filter: brightness(0.85);
}

.btn-teal:active {
  transform: scale(0.98);
  filter: brightness(0.75);
}

.btn-params {
  background: #D400FF;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  text-align: center;
}

/* ====== SESSIONS & ITEMS ====== */

.session-item {
  background: var(--input-bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-color);
  text-align: center;
  border: 1px solid var(--input-border);
}

.session-history-container {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
}

/* ====== AI CARD ====== */

.ia-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
  flex: 1;
  display: flex;
  flex-direction: column;
}

.ia-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-color);
  margin-bottom: 6px;
}

.ia-text {
  font-size: 13px;
  color: var(--text-color);
  line-height: 1.5;
  flex: 1;
  display: block;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  opacity: 0.9;
  transition: all 0.3s ease-in-out;
  max-height: 200px;
  overflow-y: auto;
}

.ia-text.ia-updated {
  animation: pulse-update 0.6s ease-in-out;
}

@keyframes pulse-update {
  0% {
    opacity: 0.5;
    transform: scale(0.98);
  }

  50% {
    opacity: 1;
    transform: scale(1.01);
  }

  100% {
    opacity: 0.9;
    transform: scale(1);
  }
}

/* ====== HEATMAP ====== */

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 12px;
  padding: 8px 0;
}

.heatmap-days-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 8px;
  margin-bottom: 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-color);
  opacity: 0.6;
}

.heatmap-cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  transition: all 0.2s ease;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  border: 2px solid transparent;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.heatmap-cell:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.heatmap-cell .day-num {
  color: inherit;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.heatmap-cell.active {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-color));
  color: #fff;
  opacity: 1;
  border-color: rgba(212, 0, 255, 0.3);
}

.heatmap-cell.active:hover {
  filter: brightness(1.2);
}

.heatmap-cell.active-low {
  background: var(--primary-color);
  color: #fff;
  opacity: 0.35;
  border-color: rgba(212, 0, 255, 0.15);
}

.heatmap-cell.active-mid {
  background: var(--primary-color);
  color: #fff;
  opacity: 0.65;
  border-color: rgba(212, 0, 255, 0.25);
}

.heatmap-cell.inactive {
  background: var(--card-border);
  color: var(--text-color);
  opacity: 0.3;
  border-color: transparent;
}

.heatmap-legend {
  font-size: 12px;
  color: var(--text-color);
  opacity: 0.7;
}

.heatmap-legend-header {
  font-size: 12px;
  opacity: 0.7;
  margin-bottom: 8px;
}

.heatmap-legend-items {
  display: flex;
  gap: 16px;
  font-size: 12px;
  opacity: 0.8;
}

.heatmap-legend-item {
  display: flex;
  gap: 6px;
  align-items: center;
}

.heatmap-legend-box {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.heatmap-box-repos {
  background: var(--card-border);
  opacity: 0.3;
}

.heatmap-box-faible {
  background: var(--primary-color);
  opacity: 0.35;
}

.heatmap-box-modere {
  background: var(--primary-color);
  opacity: 0.65;
}

.heatmap-box-eleve {
  background: var(--primary-color);
  opacity: 1;
}

/* ====== BOTTOM NAVIGATION ====== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 428px;
  background: var(--card-bg);
  border-top: 1px solid var(--card-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 0 6px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 10;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  flex: 1;
  padding: 2px 0;
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
  opacity: 0.6;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-label {
  font-size: 10px;
  font-weight: 500;
}

.light .nav-label {
  color: #000000;
}

.dark .nav-label {
  color: #ffffff;
}

.nav-item.active .nav-label {
  font-weight: 700;
}

.light .nav-item.active .nav-label {
  color: #0033aa;
}

.dark .nav-item.active .nav-label {
  color: #ffff00;
}

/* ====== MODAL ====== */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  justify-content: center;
  align-items: flex-end;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 428px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--card-border);
  gap: 10px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-color);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: #000;
}

.modal-body {
  padding: 20px;
}

.modal-form {
  border-radius: 16px;
  margin: 20px;
  max-height: none;
}

/* ====== FORMS ====== */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  box-sizing: border-box;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text-color);
}

.form-group input:focus {
  outline: none;
  border-color: #D400FF;
  box-shadow: 0 0 0 3px rgba(0, 201, 177, 0.2);
}

.radio-group {
  display: flex;
  gap: 12px;
  flex-direction: column;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-color);
}

.radio-label input[type="radio"] {
  width: auto;
  cursor: pointer;
  accent-color: #D400FF;
}

.radio-label span {
  font-weight: 500;
}

.form-group-spacing {
  margin-bottom: 12px;
}

/* ====== CHARTS & DATA ====== */

.chart-container {
  position: relative;
  width: 100%;
  height: 250px;
  margin: 12px 0;
}

.data-item {
  background: rgba(212, 0, 255, 0.1);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  border: 1px solid rgba(212, 0, 255, 0.2);
}

.data-item .date {
  font-weight: 600;
  color: var(--text-color);
}

.data-item .value {
  font-weight: 700;
}

.light .data-item .value {
  color: #0033aa;
}

.dark .data-item .value {
  color: #ffff00;
}

.average-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.avg-stat {
  background: rgba(212, 0, 255, 0.1);
  border-left: 4px solid #D400FF;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.avg-label {
  font-size: 12px;
  color: var(--text-color);
  font-weight: 500;
  opacity: 0.8;
}

.avg-value {
  font-size: 16px;
  font-weight: 700;
  color: #D400FF;
}

/* ====== SETTINGS & SELECT ====== */

#settings-date-format {
  background: var(--input-bg);
  color: var(--text-color);
  border: 1px solid var(--input-border);
}

/* ====== COLORS ====== */

.color-picker-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.color-swatch {
  width: 35px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.color-swatch.color-teal {
  background: #00c9b1;
}

.color-swatch.color-blue {
  background: #2196F3;
}

.color-swatch.color-violet {
  background: #9C27B0;
}

.color-swatch.color-green {
  background: #4CAF50;
}

.color-swatch.color-orange {
  background: #FF9800;
}

.color-swatch.color-red {
  background: #f44336;
}

.color-swatch.color-pink {
  background: #E91E63;
}

.color-swatch.color-magenta {
  background: #d400ff;
}

/* ====== SLEEP ====== */

.sleep-duration-container {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sleep-input-group {
  flex: 1;
}

.sleep-input-group input {
  width: 100%;
}

.sleep-input-label {
  font-size: 11px;
  opacity: 0.7;
}

/* ====== FOOD ====== */

.foods-list-container {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 4px;
}

.food-search-item {
  padding: 10px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--card-bg);
  color: var(--text-color);
}

.food-search-item:hover {
  background: var(--input-bg);
  opacity: 0.8;
}

.food-details-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ====== GOALS ====== */

.goal-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.goal-stat-value {
  font-size: 13px;
  font-weight: 600;
}

.goal-stat-label {
  margin-bottom: 0;
}

/* ====== UTILITIES ====== */

.nutrition-text {
  font-size: 12px;
  margin-top: 4px;
}

.empty-state {
  text-align: center;
  opacity: 0.6;
  color: var(--text-color);
}

.modal-button-spacing {
  margin-bottom: 12px;
}

.search-results-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.about-content {
  font-size: 13px;
  color: var(--text-color);
  line-height: 1.6;
}

.about-copyright {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 12px;
}

.about-license {
  font-size: 11px;
  opacity: 0.7;
  margin-top: 8px;
  line-height: 1.5;
}

.mt-12 {
  margin-top: 12px;
}

/* ====== FORM STYLES ====== */

.settings-allergies {
  min-height: 80px;
  padding: 8px;
  border-radius: 4px;
  font-family: inherit;
  font-size: inherit;
  background: var(--input-bg);
  color: var(--text-color);
  border: 1px solid var(--input-border);
}

.about-help-text {
  font-size: 12px;
  color: #999;
  margin-top: 8px;
}

.github-link {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  display: inline-block;
  margin-top: 12px;
}

.github-link:hover {
  text-decoration: underline;
}
