* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-primary: #ffffff;
  --bg-secondary: #f5f7fa;
  --bg-tertiary: #e8ecf3;
  --text-primary: #333333;
  --text-secondary: #666666;
  --border-color: #e0e0e0;
  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
  --danger: #ff6b6b;
  --danger-hover: #ee5a5a;
  --success: #51cf66;
  --proteins-color: #4dabf7;
  --fats-color: #ffd43b;
  --carbs-color: #69db7c;
}

[data-theme="dark"] {
  --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --text-primary: #e4e4e4;
  --text-secondary: #a0a0a0;
  --border-color: #2d3748;
  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-primary);
  transition: background 0.3s, color 0.3s;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

/* Auth Section */
#authSection {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--bg-primary);
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 400px;
}

.auth-card h1 {
  text-align: center;
  color: var(--accent-primary);
  margin-bottom: 10px;
}

.auth-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.auth-card h2 {
  margin-bottom: 20px;
  color: var(--text-primary);
}

.auth-card input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.3s, background 0.3s;
}

.auth-card input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.auth-card button {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.auth-card button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.switch-link {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
}

.switch-link a {
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 600;
}

/* Header */
header {
  background: var(--bg-primary);
  padding: 16px 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-content h1 {
  color: var(--accent-primary);
  font-size: 24px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-actions span {
  color: var(--text-secondary);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  background: var(--bg-secondary);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
}

/* Tabs */
.tabs {
  background: var(--bg-primary);
  padding: 0 20px;
  display: flex;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.tab {
  padding: 16px 24px;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.3s;
}

.tab:hover {
  color: var(--accent-primary);
}

.tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
  font-weight: 600;
}

/* Tab Content */
.tab-content {
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Daily Summary */
.daily-summary {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.daily-summary h2 {
  margin-bottom: 20px;
}

.summary-card {
  margin-bottom: 16px;
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.progress-bar {
  flex: 1;
  height: 24px;
  background: var(--bg-tertiary);
  border-radius: 12px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  transition: width 0.5s ease;
  border-radius: 12px;
}

.progress-fill.over-goal {
  background: linear-gradient(135deg, var(--danger) 0%, #ee5a5a 100%);
}

#progressText {
  font-weight: 600;
  color: var(--accent-primary);
  min-width: 50px;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  text-align: center;
  margin-bottom: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat .label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat .value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.stat .unit {
  font-size: 12px;
  color: var(--text-secondary);
}

.stat .value.negative {
  color: var(--danger);
}

/* Macros Section */
.macros-section {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 12px;
  margin-top: 16px;
}

.macros-section h4 {
  margin-bottom: 12px;
  color: var(--text-primary);
}

.macros-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.macro-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.macro-label {
  width: 90px;
  font-size: 14px;
  color: var(--text-secondary);
}

.macro-bar-container {
  flex: 1;
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}

.macro-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.macro-bar.proteins {
  background: var(--proteins-color);
}

.macro-bar.fats {
  background: var(--fats-color);
}

.macro-bar.carbs {
  background: var(--carbs-color);
}

.macro-value {
  width: 60px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Add Entry Section */
.add-entry-section {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.add-entry-section h3 {
  margin-bottom: 16px;
}

.add-entry-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.add-entry-form select,
.add-entry-form input {
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: border-color 0.3s;
}

.add-entry-form select:focus,
.add-entry-form input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.add-entry-form select {
  flex: 2;
  min-width: 200px;
}

.add-entry-form input {
  flex: 1;
  min-width: 120px;
}

/* Entries Section */
.entries-section {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.entries-section h3 {
  margin-bottom: 16px;
}

.date-picker {
  margin-bottom: 16px;
}

.date-picker input {
  padding: 10px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-info h4 {
  margin-bottom: 4px;
}

.entry-info p {
  color: var(--text-secondary);
  font-size: 14px;
}

.entry-macros {
  display: flex;
  gap: 8px;
  font-size: 11px;
  margin-top: 4px;
}

.entry-macros span {
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-secondary);
}

.entry-macros .p { color: var(--proteins-color); }
.entry-macros .f { color: var(--fats-color); }
.entry-macros .c { color: var(--carbs-color); }

.entry-calories {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-primary);
  margin-right: 16px;
}

.entry-actions {
  display: flex;
  gap: 8px;
}

/* Products Section */
.products-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 16px 16px 0 0;
}

.products-header h2 {
  margin: 0;
}

.products-actions {
  display: flex;
  gap: 8px;
}

.search-box {
  background: var(--bg-primary);
  padding: 16px 24px;
}

.search-box input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

#productsList {
  background: var(--bg-primary);
  padding: 0 24px 24px;
  border-radius: 0 0 16px 16px;
}

.product-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}

.product-item:last-child {
  border-bottom: none;
}

.product-info h4 {
  margin-bottom: 4px;
}

.product-info p {
  color: var(--text-secondary);
  font-size: 14px;
}

.product-macros {
  display: flex;
  gap: 8px;
  font-size: 11px;
  margin-top: 4px;
}

.product-macros span {
  color: var(--text-secondary);
}

.product-actions {
  display: flex;
  gap: 8px;
}

/* Statistics Section */
.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 16px 16px 0 0;
}

.stats-header select {
  padding: 10px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  background: var(--bg-primary);
  padding: 24px;
}

.stat-card {
  text-align: center;
  padding: 20px;
  background: var(--bg-secondary);
  border-radius: 12px;
}

.stat-card .label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent-primary);
}

.stat-card .unit {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.chart-container {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.chart-container h3 {
  margin-bottom: 16px;
}

.chart-bar {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.chart-bar-label {
  width: 80px;
  font-size: 12px;
  color: var(--text-secondary);
}

.chart-bar-container {
  flex: 1;
  height: 24px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  margin: 0 12px;
}

.chart-bar-fill {
  height: 100%;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  transition: width 0.5s ease;
}

.chart-bar-fill.over-goal {
  background: linear-gradient(135deg, var(--danger) 0%, #ee5a5a 100%);
}

.chart-bar-value {
  width: 60px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
}

/* Buttons */
button {
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.3s;
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
}

.btn-danger {
  padding: 10px 20px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.3s;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-small {
  padding: 6px 12px;
  font-size: 14px;
}

.full-width {
  width: 100%;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg-primary);
  padding: 32px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-content h3 {
  margin-bottom: 20px;
}

.modal-content input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.modal-content input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
}

.modal-large {
  max-width: 500px;
}

.macros-inputs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.macros-inputs input {
  margin-bottom: 0;
}

/* Import Modal */
.import-hint {
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.import-format {
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
  margin-bottom: 12px;
}

.import-preview {
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: 8px;
  margin-top: 12px;
}

.import-preview p {
  margin-bottom: 4px;
  font-size: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease;
  z-index: 1001;
}

.toast.error {
  background: var(--danger);
  color: white;
}

.toast.success {
  background: var(--success);
  color: white;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Hidden */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 600px) {
  .summary-stats {
    grid-template-columns: 1fr;
  }
  
  .add-entry-form {
    flex-direction: column;
  }
  
  .add-entry-form select,
  .add-entry-form input {
    width: 100%;
  }
  
  .stats-summary {
    grid-template-columns: 1fr;
  }
  
  .header-content {
    flex-direction: column;
    gap: 12px;
  }
  
  .header-actions {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .products-header {
    flex-direction: column;
    gap: 12px;
  }
  
  .macros-inputs {
    grid-template-columns: 1fr;
  }
  
  .entry-macros {
    flex-wrap: wrap;
  }
}
