/* ==========================================================================
   RESET & BASE
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: Arial, sans-serif;
  background-color: #f5f5f5;
  padding: 1em;
}

/* ==========================================================================
   LAYOUT & CONTAINERS
   ========================================================================== */
.container {
  width: 95%;
  max-width: 1100px;
  margin: auto;
}

section {
  margin: 1em 0;
}

.active {
  display: block;
}

.hidden {
  display: none;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
#app-header {
  background-color: #2c3e50;
  color: #ecf0f1;
  padding: 1em 2em;
  margin-bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#app-header h1 {
  margin: 0;
  color: white;
  font-size: 1.8em;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */
footer {
  background: #2c3e50;
  color: #ecf0f1;
  text-align: center;
  padding: 1.5em 2em;
  margin-top: 3em;
  border-top: 4px solid #3498db;
}

footer a {
  color: #3498db;
  text-decoration: none;
  font-weight: bold;
  transition: color 0.3s ease;
}

footer a:hover {
  color: #5dade2;
}

/* ==========================================================================
   USER ACCOUNT CONTROLS & MODALS
   ========================================================================== */
#auth-buttons button,
#user-info button {
  background-color: #3498db;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.5em 1.5em;
  margin: 0 0.3em;
  cursor: pointer;
  transition: background-color 0.3s ease;
  font-size: 0.9em;
}

#auth-buttons button:hover,
#user-info button:hover {
  background-color: #34495e;
}

#username-display {
  color: #2c3e50;
  margin-right: 1em;
}

/* Modal Styles */
.modal {
  position: fixed;
  z-index: 3000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: #fff;
  padding: 2em;
  border-radius: 8px;
  width: 90%;
  max-width: 400px;
  position: relative;
}

.modal-content h2 {
  margin-top: 0;
  color: #2c3e50;
}

.modal-content form {
  display: flex;
  flex-direction: column;
}

.modal-content label {
  margin-top: 1em;
  font-weight: bold;
  color: #2c3e50;
}

.modal-content input {
  padding: 0.5em;
  margin-top: 0.3em;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.modal-content button[type="submit"] {
  margin-top: 1.5em;
  padding: 0.7em;
  background-color: #ff6f61;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1em;
  transition: background-color 0.3s ease;
}

.modal-content button[type="submit"]:hover {
  background-color: #ff8f80;
}

.close {
  position: absolute;
  top: 0.5em;
  right: 0.8em;
  color: #aaa;
  font-size: 2em;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}

.close:hover,
.close:focus {
  color: #000;
}

.error-message {
  color: #d72638;
  margin-top: 1em;
  font-size: 0.9em;
  text-align: center;
}

/* ==========================================================================
   FORMS & INPUTS
   ========================================================================== */
#onboarding-form {
  background: #fff;
  padding: 1em;
  border-radius: 8px;
  margin: auto;
}

#onboarding-form h3 {
  margin-top: 1em;
}

/* General Input, Select, and Form Button Defaults */
input,
select,
form button {
  width: 100%;
  padding: 0.5em;
  margin: 0.5em 0;
}

/* Entry Form Specific */
#entry-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 1em;
}

#entry-form label {
  margin-right: 0.3em;
}

#entry-form input,
#entry-form select {
  width: auto;
}

.entry-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1em;
  margin-bottom: 1em;
}

.entry-field {
  flex: 1;
  min-width: 150px;
}

.entry-field label {
  display: block;
  margin-bottom: 0.3em;
  font-weight: bold;
  font-size: 0.9em;
  color: #2c3e50;
}

.entry-field input[type="number"] {
  width: 100%;
}

/* ==========================================================================
   BUTTONS (Retro Color Scheme)
   ========================================================================== */
button,
input[type="button"],
input[type="submit"] {
  background-color: #ff6f61;
  color: #fff;
  border: 1px;
  border-radius: 4px;
  padding: 0.3em 1em;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button:hover,
input[type="button"]:hover,
input[type="submit"]:hover {
  background-color: #ff8f80;
}

/* Delete buttons – a slightly different retro red */
.delete-btn {
  background-color: #d72638;
  color: #fff;
  padding: 0.3em 0.5em;
  cursor: pointer;
  border: none;
  border-radius: 3px;
}

/* Pagination buttons */
#pagination-controls button {
  background-color: #ff6f61;
  color: #fff;
  padding: 0.1em 0.1em;
  margin: 0 0.3em;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}

/* ==========================================================================
   DASHBOARD & METRICS
   ========================================================================== */
#dashboard {
  background: #fff;
  padding: 1em;
  border-radius: 8px;
}

#starting-summary {
  margin: 0.5em 0 1em 0;
  font-size: 0.85em;
  color: #555;
  text-align: center;
}

#metrics {
  margin: 1em 0;
}

.metric-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-bottom: 0.5em;
}

.metric {
  flex: 1;
  min-width: 150px;
  padding: 0.5em;
  margin: 0.3em;
  border-radius: 5px;
  color: #fff;
  font-weight: bold;
  text-align: center;
}

/* Retro-inspired Metric Backgrounds */
#metric-calorie-deficit { background-color: #e74c3c; }
#metric-fat-loss         { background-color: #3498db; }
#metric-current-bmr      { background-color: #2ecc71; }
#metric-current-weight   { background-color: #8e44ad; }
#metric-fat-percent      { background-color: #16a085; }
#time-since-start        { background-color: #9b59b6; }
#time-till-finish        { background-color: #f39c12; }
#metric-trend            { background-color: #d35400; }
#metric-catchup          { background-color: #27ae60; }
#metric-progress         { background-color: #2980b9; }

/* New Metrics with Retro Colors */
#metric-total-burned {
  background-color: #ff6f61 !important;
  color: #fff !important;
  padding: 0.5em;
  border-radius: 5px;
  text-align: center;
  font-weight: bold;
}

#metric-calorie-deficit-actual {
  background-color: #e67e22;
  color: #fff;
  padding: 0.5em;
  border-radius: 5px;
  text-align: center;
  font-weight: bold;
}

#metric-bmr-burned {
  background-color: #ff6f61 !important;
  color: #fff !important;
  padding: 0.5em;
  border-radius: 5px;
  text-align: center;
  font-weight: bold;
}
#metric-total-food   { background-color: #6b5b95; }
#metric-total-protein { background-color: #e67e22; }
#metric-total-carbs   { background-color: #3498db; }
#metric-total-fat     { background-color: #e74c3c; }

/* ==========================================================================
   METRICS TABLE (New Clean Design)
   ========================================================================== */
#metrics-table {
  width: 100%;
  border-collapse: collapse;
}

#metrics-table tbody tr {
  border-bottom: 1px solid #e0e0e0;
}

#metrics-table tbody tr:last-child {
  border-bottom: none;
}

#metrics-table tbody tr:hover {
  background-color: #f8f9fa;
}

.metric-label {
  padding: 0.9em 1.2em;
  font-weight: 500;
  color: #555;
  font-size: 0.95em;
  width: 40%;
  text-align: left;
}

.metric-value {
  padding: 0.9em 1.2em;
  font-weight: 600;
  color: #2c3e50;
  font-size: 1em;
  text-align: right;
}

#metric-deficit-label {
  font-weight: 600;
}

#calorie-deficit-actual {
  font-size: 1.1em;
  font-weight: 700;
}

/* ==========================================================================
   ENTRY FORM TABLE
   ========================================================================== */
#entry-form-table tbody tr {
  border-bottom: 1px solid #e0e0e0;
}

#entry-form-table tbody tr:last-child {
  border-bottom: none;
}

#entry-form-table tbody tr:hover {
  background-color: #f8f9fa;
}

.entry-label {
  padding: 0.9em 1.2em;
  font-weight: 500;
  color: #555;
  font-size: 0.95em;
  white-space: nowrap;
  text-align: left;
}

.entry-input {
  padding: 0.7em 1.2em;
}

.entry-input input,
.entry-input select {
  width: 100%;
  padding: 0.5em;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.95em;
  box-sizing: border-box;
}

.entry-input input:focus,
.entry-input select:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.1);
}

.entry-input button {
  padding: 0.6em 1.2em;
  margin-left: 0.5em;
  background-color: #3498db;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 500;
  transition: background-color 0.2s;
}

.entry-input button:hover {
  background-color: #2980b9;
}

.entry-input button[type="submit"] {
  background-color: #2ecc71;
}

.entry-input button[type="submit"]:hover {
  background-color: #27ae60;
}

#estimate-cals-btn {
  background-color: #e67e22;
}

#estimate-cals-btn:hover {
  background-color: #d35400;
}

/* ==========================================================================
   TABLES & EVENT LOG
   ========================================================================== */
#entries-list {
  list-style: none;
  margin-top: 1em;
  padding: 0;
  overflow:auto;
}

#entries-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5em;
  border-bottom: 1px solid #ccc;
}

.entry-info {
  flex: 1;
}

.entries-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1em;
}

.entries-table th,
.entries-table td {
  border: 1px solid #ccc;
  padding: 0.5em;
  text-align: left;
}

.entries-table th {
  background-color: #f0f0f0;
}

/* ==========================================================================
   PAGINATION
   ========================================================================== */
#pagination-controls {
  display: flex;
  justify-content: center;
  margin-top: 1em;
}

/* ==========================================================================
   POPUP & MODAL
   ========================================================================== */
.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-content {
  position: relative;
  background: #fff;
  width: 95%;
  height: 95%;
  padding: 0.5em;
  box-sizing: border-box;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.popup-content canvas {
  flex: 1;
  width: 100%;
}

.popup-close-btn {
  position: absolute;
  top: 0.5em;
  right: 0.5em;
  background: none;
  border: none;
  font-size: 2em;
  color: #333;
  cursor: pointer;
}

/* ==========================================================================
   CHART ZOOM BUTTON (MOBILE)
   ========================================================================== */
.chart-zoom-btn {
  display: none;
}

@media (max-width: 600px) {
  .chart-zoom-btn {
    display: inline-block;
    margin-bottom: 0.5em;
    padding: 0.5em;
    font-size: 1em;
    cursor: pointer;
  }
}

#progressChart,
#dailyCaloriesChart {
  width: 100%;
  height: auto;
}

/* Chart wrapper for better mobile sizing */
#chart-section {
  overflow-x: hidden;
}

#chart-section canvas {
  max-width: 100%;
}

/* ==========================================================================
   MOBILE RESPONSIVE STYLES
   ========================================================================== */
@media (max-width: 768px) {
  /* Body and Container */
  body {
    padding: 0.5em;
    font-size: 14px;
  }

  .container {
    width: 100%;
    padding: 0;
  }

  section {
    margin: 0.5em 0;
  }

  /* Header */
  #app-header {
    padding: 0.5em;
    font-size: 0.8em;
    flex-direction: column;
    gap: 0.5em;
  }

  #app-header h1 {
    font-size: 1.3em;
  }

  #header-right {
    text-align: center;
  }

  #user-info span {
    display: block;
    margin-bottom: 0.5em;
  }

  /* User Account Controls */
  #auth-buttons button,
  #user-info button {
    padding: 0.4em 0.8em;
    margin: 0.2em;
    font-size: 0.85em;
  }

  #username-display {
    display: block;
    margin-bottom: 0.5em;
  }

  /* Modals - Full screen on mobile */
  .modal-content {
    width: 95%;
    max-width: 95%;
    padding: 1.5em;
    max-height: 90vh;
    overflow-y: auto;
  }

  .modal-content h2 {
    font-size: 1.3em;
  }

  .modal-content input,
  .modal-content select,
  .modal-content button {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Dashboard */
  #dashboard {
    padding: 0.5em;
  }

  #dashboard h2,
  #dashboard h3 {
    font-size: 1.2em;
    margin: 0.5em 0;
  }

  #event-log h3 {
    font-size: 1.1em;
  }

  /* Metrics - Stack vertically on mobile */
  .metric-row {
    flex-direction: column;
  }

  .metric {
    min-width: 100%;
    width: 100%;
    margin: 0.2em 0;
    font-size: 0.9em;
    padding: 0.7em;
  }

  /* Today's Intake row - make separators smaller on mobile */
  .metric-value span[style*="margin"] {
    margin: 0 0.3em !important;
    font-size: 0.9em;
  }

  /* Starting Summary - Stack on mobile */
  #starting-summary {
    font-size: 0.75em;
    line-height: 1.6;
  }

  .summary-row {
    display: inline;
  }

  .summary-label,
  .summary-value {
    display: inline;
  }

  /* Entry Form Table - Stack vertically on mobile */
  #entry-form-table,
  #entry-form-table tbody,
  #entry-form-table tr,
  #entry-form-table td {
    display: block;
    width: 100%;
  }

  #entry-form-table tr {
    margin-bottom: 0.8em;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.8em;
  }

  #entry-form-table tr:last-child {
    border-bottom: none;
    margin-bottom: 0;
  }

  .entry-label {
    padding: 0.3em 0;
    font-size: 0.85em;
    font-weight: 600;
  }

  .entry-input {
    padding: 0.3em 0;
  }

  .entry-input input,
  .entry-input select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.6em;
  }

  .entry-input input[type="number"],
  .entry-input input[type="text"] {
    width: 100% !important;
    display: block !important;
    margin-bottom: 0.3em;
  }

  .entry-input span {
    display: none !important;
  }

  .entry-input button {
    width: 100% !important;
    padding: 0.7em;
    font-size: 1em;
    margin-left: 0 !important;
    margin-bottom: 0.5em;
    display: block !important;
  }

  .entry-input button:last-child {
    margin-bottom: 0;
  }

  /* Show labels on mobile for macros row */
  #entry-form-table tr:nth-child(4) .entry-label:nth-of-type(1) {
    display: block;
  }

  #entry-form-table tr:nth-child(4) .entry-label:nth-of-type(2) {
    display: block;
  }

  /* Show labels for description and calories row on mobile */
  #calories-row .entry-label {
    display: block !important;
    padding: 0.5em 0 0.2em 0;
    text-align: left;
  }

  #calories-row .entry-input {
    display: block !important;
    width: 100% !important;
  }

  /* Entries Table - Card layout on mobile */
  .entries-table {
    display: block;
    overflow-x: visible;
  }

  .entries-table thead {
    display: none; /* Hide table headers on mobile */
  }

  .entries-table tbody {
    display: block;
  }

  .entries-table tr {
    display: block;
    margin-bottom: 1em;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 0.5em;
    background: #f9f9f9;
  }

  .entries-table td {
    display: block;
    border: none;
    padding: 0.3em 0;
    text-align: left !important;
  }

  .entries-table td:before {
    content: attr(data-label);
    font-weight: bold;
    display: inline-block;
    width: 100px;
    color: #2c3e50;
  }

  .entries-table td:last-child {
    margin-top: 0.5em;
    padding-top: 0.5em;
    border-top: 1px solid #ddd;
  }

  /* Buttons in entries */
  .entries-table button {
    padding: 0.6em 1em;
    font-size: 0.9em;
    margin-right: 0.3em;
    margin-bottom: 0.3em;
    min-height: 44px; /* Touch-friendly size */
  }

  .delete-btn {
    min-height: 44px; /* Touch-friendly size */
  }

  /* Pagination */
  #pagination-controls {
    flex-wrap: wrap;
    font-size: 0.9em;
  }

  #pagination-controls button {
    padding: 0.4em 0.8em;
    margin: 0.2em;
  }

  /* Charts */
  #progressChart,
  #dailyCaloriesChart {
    width: 100% !important;
    max-height: 250px;
  }

  #chart-section {
    padding: 0.5em;
  }

  #chart-controls {
    margin: 0.5em 0;
  }

  #chart-type-selector,
  #daily-chart-type-selector {
    width: 100%;
    padding: 0.5em;
    font-size: 16px;
  }

  /* Chart Popup - Full screen on mobile */
  .popup-content {
    width: 98%;
    height: 98%;
    padding: 0.3em;
  }

  .popup-close-btn {
    font-size: 1.5em;
    top: 0.3em;
    right: 0.3em;
  }

  /* Onboarding Form */
  #onboarding-form {
    padding: 0.5em;
  }

  #onboarding-form input,
  #onboarding-form select,
  #onboarding-form button {
    font-size: 16px; /* Prevents zoom on iOS */
  }

  #onboarding-form h3 {
    font-size: 1.1em;
    margin-top: 1em;
  }

  /* Goal Edit Container */
  #goal-edit-container {
    padding: 0.5em;
  }

  #goal-edit-container input,
  #goal-edit-container button {
    font-size: 16px;
  }

  /* Tracking Header Buttons */
  #tracking-header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em;
    justify-content: center;
    margin-bottom: 1em;
  }

  #tracking-header button {
    padding: 0.5em 1em;
    margin: 0;
    font-size: 0.9em;
    flex: 1 1 auto;
    min-width: 120px;
  }

  /* Import/Export buttons */
  #import-btn-onboarding {
    width: 100%;
    margin: 0.5em 0;
  }
}

/* Extra small devices */
@media (max-width: 400px) {
  #app-header h1 {
    font-size: 1.1em;
  }

  .metric {
    font-size: 0.85em;
  }

  #starting-summary {
    font-size: 0.7em;
  }

  .modal-content {
    padding: 1em;
  }
}

.disabled-button {
  background-color: #ccc !important;
  color: #666 !important;
  cursor: not-allowed;
  opacity: 0.7;
}

/* ==========================================================================
   SUMMARY STYLES
   ========================================================================== */
.summary-row {
  margin-bottom: 0.2em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.summary-label {
  font-weight: bold;
  color: #555;
  margin-right: 0.1em;
}

.summary-value {
  color: #2c3e50;
}
