/* Pro-Cal - Nutrition Tracker Calculator */
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3345;
  --text: #e4e6ed;
  --text-dim: #8b8fa3;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --green: #00b894;
  --green-dim: #00b89433;
  --yellow: #fdcb6e;
  --yellow-dim: #fdcb6e33;
  --red: #e17055;
  --red-dim: #e1705533;
  --blue: #74b9ff;
  --orange: #e67e22;
  --purple: #a29bfe;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 0;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

/* --- Header --- */
.header {
  text-align: center;
  margin-bottom: 20px;
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent-light);
}

.header .subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* --- Date Nav --- */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}

.date-nav button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.date-nav button:hover {
  background: var(--surface2);
}

#current-date {
  font-size: 15px;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
}

#btn-today {
  font-size: 11px;
  width: auto;
  padding: 4px 10px;
  color: var(--accent-light);
  border-color: var(--accent);
}

/* --- Progress Section --- */
.progress-section {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.progress-row {
  margin-bottom: 12px;
}

.progress-row:last-child {
  margin-bottom: 0;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.progress-label span:first-child {
  font-weight: 600;
}

.progress-label span:last-child {
  color: var(--text-dim);
}

.progress-bar {
  height: 10px;
  background: var(--surface2);
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 5px;
  background: var(--green);
  transition: width 0.3s ease, background 0.3s ease;
  min-width: 0;
}

.progress-fill.near {
  background: var(--yellow);
}

.progress-fill.over {
  background: var(--red);
}

.progress-fill.complete {
  background: var(--green);
}

/* --- Macro Summary --- */
.macro-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  background: var(--surface);
  border-radius: 12px;
  padding: 14px 8px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  gap: 8px 0;
}

.macro-item {
  text-align: center;
  min-width: 60px;
}

.macro-value {
  font-size: 20px;
  font-weight: 700;
}

.macro-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.macro-item:nth-child(1) .macro-value { color: var(--blue); }
.macro-item:nth-child(2) .macro-value { color: var(--green); }
.macro-item:nth-child(3) .macro-value { color: var(--yellow); }
.macro-item:nth-child(4) .macro-value { color: var(--red); }
.sugar-color { color: var(--orange) !important; }
.alcohol-color { color: var(--purple) !important; }

.remaining {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.remaining strong {
  color: var(--text);
}

/* --- Insights --- */
.insights-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.insights-section h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.insights-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.insight-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 12px;
}

.insight-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 2px;
}

.insight-value {
  font-size: 14px;
  font-weight: 600;
}

.insight-green { color: var(--green); }
.insight-yellow { color: var(--yellow); }
.insight-red { color: var(--red); }
.insight-blue { color: var(--blue); }
.insight-orange { color: var(--orange); }
.insight-purple { color: var(--purple); }
.insight-dim { color: var(--text-dim); }

.insight-detail {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* --- Search --- */
.search-container {
  position: relative;
  margin-bottom: 12px;
}

#food-search {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

#food-search::placeholder {
  color: var(--text-dim);
}

#food-search:focus {
  border-color: var(--accent);
}

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  margin-top: 4px;
}

#search-results.active {
  display: block;
}

.search-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover {
  background: var(--surface2);
}

.search-item.loading {
  color: var(--text-dim);
  cursor: default;
  text-align: center;
  font-size: 13px;
}

.search-item-name {
  font-size: 14px;
  font-weight: 500;
}

.search-item-macros {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.search-item-serving {
  margin-left: 8px;
  color: var(--accent-light);
  font-size: 11px;
}

/* --- Add Panel --- */
.add-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  margin-bottom: 12px;
}

.add-panel.active {
  max-height: 500px;
  padding: 16px;
}

.add-panel .form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.portion-row {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: 6px;
  margin-bottom: 10px;
}

.portion-label {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.portion-source {
  font-size: 10px;
  color: var(--accent-light);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.add-panel input {
  flex: 1;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.add-panel input:focus {
  border-color: var(--accent);
}

.add-panel input::placeholder {
  color: var(--text-dim);
}

.add-panel label {
  font-size: 11px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.add-panel .input-group {
  flex: 1;
}

.add-panel .form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* --- Buttons --- */
.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
  flex: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-light);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  color: var(--text);
}

.action-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.action-row .btn {
  font-size: 13px;
  padding: 8px 12px;
}

/* --- Food Log --- */
.log-section h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.log-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.log-entry-name {
  font-size: 14px;
  font-weight: 500;
}

.log-entry-portion {
  font-size: 11px;
  color: var(--accent-light);
  margin-left: 6px;
  font-weight: 400;
}

.log-entry-macros {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.btn-remove:hover {
  color: var(--red);
  background: var(--red-dim);
}

.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.empty-state-small {
  text-align: center;
  padding: 12px 8px;
  color: var(--text-dim);
  font-size: 12px;
}

/* --- Goals Section --- */
.goals-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.goals-section h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.goals-row {
  display: flex;
  gap: 12px;
}

.goal-input {
  flex: 1;
}

.goal-input label {
  font-size: 12px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.goal-input input {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.goal-input input:focus {
  border-color: var(--accent);
}

.goals-hint {
  font-size: 12px;
  margin-top: 8px;
  padding: 0 2px;
  color: var(--text-dim);
}

.goals-hint.hit {
  color: var(--green);
}

.goals-hint.above {
  color: var(--accent-light);
}

.goals-hint.below {
  color: var(--yellow);
}

/* --- Supplements Section --- */
.supplements-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.supplements-section h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.supp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.supp-row:last-child {
  border-bottom: none;
}

.supp-header-row {
  padding-bottom: 8px;
}

.supp-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.supp-name {
  font-size: 14px;
  font-weight: 500;
}

.supp-detail {
  font-size: 12px;
  color: var(--text-dim);
}

.supp-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.supp-input {
  width: 60px;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  text-align: center;
}

.supp-input:focus {
  border-color: var(--accent);
}

.supp-unit {
  font-size: 12px;
  color: var(--text-dim);
}

.supp-vitamins {
  margin-top: 8px;
}

.vitamin-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.vitamin-entry:last-child {
  border-bottom: none;
}

.vitamin-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.vitamin-name {
  font-size: 13px;
  font-weight: 500;
}

.vitamin-amount {
  font-size: 12px;
  color: var(--blue);
}

.vitamin-source {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.vitamin-src-supplement {
  background: var(--accent);
  color: white;
}

.vitamin-src-food {
  background: var(--green);
  color: white;
}

.vitamin-rda {
  font-size: 11px;
  color: var(--text-dim);
}

/* Add Vitamin Panel */
.add-vitamin-panel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.add-vitamin-panel.active {
  max-height: 200px;
  padding-top: 8px;
}

.add-vitamin-panel .form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.add-vitamin-panel .input-group {
  flex: 1;
}

.add-vitamin-panel label {
  font-size: 11px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
}

.add-vitamin-panel input,
.add-vitamin-panel select {
  width: 100%;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.add-vitamin-panel input:focus,
.add-vitamin-panel select:focus {
  border-color: var(--accent);
}

.add-vitamin-panel select option {
  background: var(--surface2);
  color: var(--text);
}

.add-vitamin-panel .form-actions {
  display: flex;
  gap: 8px;
}

/* --- History Panel --- */
.history-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  margin-bottom: 16px;
}

.history-panel.active {
  max-height: 400px;
  overflow-y: auto;
}

.history-row {
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.history-row:last-child {
  border-bottom: none;
}

.history-row:hover {
  background: var(--surface2);
}

.history-row.current {
  border-left: 3px solid var(--accent);
}

.history-stats {
  color: var(--text-dim);
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* --- Danger Button --- */
.btn-danger {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid var(--red);
}

.btn-danger:hover {
  background: var(--red);
  color: white;
}

/* --- Data Section --- */
.data-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.data-section h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-row {
  display: flex;
  gap: 8px;
}

.data-row .btn {
  font-size: 13px;
  padding: 8px 12px;
}

/* --- Mobile Improvements --- */
/* Prevent text size adjust on orientation change */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Safe area for notched phones */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Minimum 44px touch targets + prevent double-tap zoom */
.btn, .date-nav button, .btn-remove, .btn-small {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

.btn-small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Prevent zoom on input focus (iOS) */
input, select, textarea {
  font-size: 16px;
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .app {
    padding: 10px;
  }

  .macro-summary {
    padding: 12px 4px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px 4px;
  }

  .macro-item {
    min-width: unset;
  }

  .macro-value {
    font-size: 18px;
  }

  .remaining {
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .goals-row {
    flex-direction: column;
    gap: 10px;
  }

  .goal-input {
    min-width: 100%;
  }

  .add-vitamin-panel .form-row {
    flex-direction: column;
  }

  .add-vitamin-panel .input-group {
    width: 100%;
  }

  .supp-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .supp-controls {
    width: 100%;
    justify-content: flex-end;
  }

  .log-entry {
    padding: 10px 12px;
  }

  .log-entry-macros {
    font-size: 11px;
  }

  .action-row {
    gap: 6px;
  }

  .add-panel .form-row {
    flex-direction: column;
  }

  .add-panel .form-row .input-group {
    width: 100%;
  }

  /* Keep servings row horizontal */
  .add-panel .form-row:last-of-type {
    flex-direction: row;
  }
}

@media (max-width: 360px) {
  .header h1 {
    font-size: 20px;
  }

  .macro-value {
    font-size: 16px;
  }

  .date-nav {
    gap: 6px;
  }

  #current-date {
    font-size: 13px;
    min-width: 140px;
  }
}
