/* === Base === */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: #121212;
  color: #e0e0e0;
  margin: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

h1 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 3em;
  max-width: 90%;
  word-wrap: break-word;
}

/* === Tabs === */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 20px;
}

.tab-btn {
  padding: 12px 20px;
  cursor: pointer;
  background: #1f1f1f;
  color: #e0e0e0;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 1.2em;
  transition: background 0.2s;
}

.tab-btn:hover {
  background: #2a2a2a;
}

.tab-btn.active {
  background: #3a3a3a;
  border-color: #555;
}

/* === Tab content === */
.tab-content {
  display: none;
  width: 100%;
  max-width: calc(100% - 20px);
  text-align: center;
}

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

/* === Forms === */
form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 15px;
}

input, select, button {
  padding: 12px;
  border-radius: 6px;
  border: 1px solid #333;
  background-color: #1f1f1f;
  color: #e0e0e0;
  font-size: 1.2em;
}

input:focus, select:focus {
  outline: 2px solid #555;
}

button {
  cursor: pointer;
  background-color: #3a3a3a;
  border: 1px solid #555;
  transition: background 0.2s;
}

button:hover {
  background-color: #4a4a4a;
}

/* === Barcode Scanner Section === */
.barcode-section {
  background-color: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
}

/* === Auto-Scale Notice === */
.auto-scale-notice {
  background-color: #1a3a1a;
  border: 1px solid #2a5a2a;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  color: #6aff6a;
  text-align: center;
  font-size: 0.95em;
}

.auto-scale-notice.disabled {
  background-color: #3a2a1a;
  border-color: #5a4a2a;
  color: #ffaa6a;
}

/* === Barcode Scanner Section === */

.barcode-section h3 {
  margin-top: 0;
  margin-bottom: 15px;
  font-size: 1.3em;
}

.barcode-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 15px;
}

.barcode-controls button {
  flex: 1;
  max-width: 200px;
}

#barcodeReader {
  margin: 15px auto;
  max-width: 100%;
  border-radius: 8px;
  overflow: hidden;
}

.barcode-manual {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.barcode-manual input {
  flex: 1;
}

.barcode-manual button {
  flex: 0 0 auto;
  padding: 12px 20px;
}

#barcodeResult {
  margin-top: 15px;
  padding: 12px;
  background-color: #2a2a2a;
  border-radius: 6px;
  min-height: 20px;
  text-align: left;
}

/* === Recent Entries Section === */
.recent-entries {
  margin-top: 30px;
  padding: 20px;
  background-color: #1a1a1a;
  border: 1px solid #333;
  border-radius: 8px;
  text-align: left;
}

.recent-entries h3 {
  margin-top: 0;
  margin-bottom: 15px;
  text-align: center;
  font-size: 1.3em;
  color: #00ffff;
}

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

.date-group:last-child {
  margin-bottom: 0;
}

.date-header {
  font-weight: bold;
  color: #00ffff;
  margin-bottom: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid #333;
  font-size: 1.1em;
}

.entry-item {
  background-color: #2a2a2a;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  border: 1px solid #3a3a3a;
  transition: background-color 0.2s;
}

.entry-item:hover {
  background-color: #333;
}

.entry-name {
  font-weight: bold;
  margin-bottom: 5px;
  font-size: 1.1em;
}

.entry-details {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.9em;
  color: #b0b0b0;
}

.entry-value {
  color: #00ff00;
  font-weight: 500;
}

.entry-time {
  color: #888;
  font-size: 0.85em;
}

.no-entries {
  text-align: center;
  color: #666;
  font-style: italic;
  padding: 20px;
}

/* === Results / Stats === */
#weightResult, #mealResult, #workoutResult, #userResult, #statsDisplay {
  margin-top: 10px;
  padding: 12px;
  background-color: #1f1f1f;
  border-radius: 6px;
  border: 1px solid #333;
  width: 100%;
  max-width: calc(100% - 20px);
  box-sizing: border-box;
}

/* === Stats Refresh Button === */
#refreshStats {
  margin-bottom: 10px;
}

/* === Chart Canvas === */
#statsDisplay canvas {
  width: 100% !important;
  max-width: calc(100% - 20px);
  height: 400px;
}

/* === Responsive adjustments === */
@media (max-width: 500px) {
  .tab-btn {
    flex: 1 1 45%;
    max-width: none;
  }
  
  .barcode-controls {
    flex-direction: column;
  }
  
  .barcode-controls button {
    max-width: 100%;
  }
  
  .entry-details {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* === Scanner Video Styling === */
#barcodeReader video {
  width: 100%;
  max-width: 400px;
  border-radius: 8px;
}

#barcodeReader canvas {
  display: none;
}