/* === Base / Reset === */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fdf8ec;
  color: #1a1a2e;
  min-height: 100vh;
  padding: 16px;
}

h1 {
  text-align: center;
  font-size: 1.4rem;
  margin-bottom: 16px;
  color: #0d1b2a;
}

/* === Quick Buttons === */
.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}

.quick-btn {
  padding: 14px 18px;
  border: 2px solid #0d1b2a;
  border-radius: 10px;
  font-size: 1.5rem;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  transition: transform 0.1s, box-shadow 0.1s;
}

.quick-btn:active {
  transform: scale(0.95);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  background: #f0f4f8;
}

/* === Form Section === */
.form-section {
  background: #112240;
  border-radius: 14px;
  padding: 20px;
  max-width: 420px;
  margin: 0 auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.field { margin-bottom: 16px; }
.inline-fields { display: flex; gap: 12px; }
.inline-fields .field { flex: 1; }

.field label {
  display: block;
  font-size: 0.8rem;
  color: #8892a4;
  margin-bottom: 6px;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: #fdf8ec;
  color: #1a1a2e;
  font-size: 1rem;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #00b4d8;
  background: #fff;
}

.field textarea { resize: vertical; min-height: 60px; }
.field input::placeholder,
.field textarea::placeholder { color: #556680; }

.meal-toggles { display: flex; gap: 8px; margin-bottom: 16px; }

.meal-btn {
  flex: 1;
  padding: 10px 4px;
  border: 1px solid rgba(0,180,216,0.3);
  border-radius: 8px;
  background: rgba(0,180,216,0.08);
  color: #00b4d8;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.meal-btn.active {
  background: #00b4d8;
  color: #fff;
  border-color: #00b4d8;
}

.submit-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: #00b4d8;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.1s;
  box-shadow: 0 2px 8px rgba(0,180,216,0.2);
}

.submit-btn:active {
  transform: scale(0.97);
  opacity: 0.85;
}

.submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Dashboard === */
.dashboard {
  background: #112240;
  border-radius: 14px;
  padding: 20px;
  max-width: 420px;
  margin: 20px auto 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.medicine-banner {
  background: #ef476f;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.medicine-banner.hidden { display: none; }

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.dash-header h2 { font-size: 1rem; color: #e0e6ed; }

.refresh-btn {
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  background: #0d1b2a;
  font-size: 0.8rem;
  cursor: pointer;
  color: #8892a4;
}

.refresh-btn:active { background: #1b2838; }

/* === Macro Bars === */
.macro-row { margin-bottom: 14px; }

.macro-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #8892a4;
  margin-bottom: 4px;
}

.macro-bar-bg {
  height: 18px;
  background: rgba(255,255,255,0.06);
  border-radius: 9px;
  position: relative;
  overflow: hidden;
}

.macro-bar-fill {
  height: 100%;
  border-radius: 9px;
  transition: width 0.4s ease;
}

.macro-bar-target {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: rgba(255,255,255,0.4);
}

.bar-calories { background: #06d6a0; }
.bar-protein { background: #00b4d8; }
.bar-carbs { background: #ffd166; }
.bar-fat { background: #ef476f; }

/* === Distribution Chart === */
.distribution {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.dist-label { font-size: 0.75rem; color: #8892a4; margin-bottom: 4px; }

.dist-bar {
  display: flex;
  height: 22px;
  border-radius: 11px;
  overflow: hidden;
  margin-bottom: 10px;
}

.dist-seg {
  transition: width 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  color: #fff;
  min-width: 0;
  overflow: hidden;
}

.seg-protein { background: #00b4d8; }
.seg-carbs { background: #ffd166; color: #333; }
.seg-fat { background: #ef476f; }

.dist-legend { display: flex; gap: 12px; font-size: 0.7rem; color: #8892a4; }

.dist-legend span::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

.legend-protein::before { background: #00b4d8; }
.legend-carbs::before { background: #ffd166; }
.legend-fat::before { background: #ef476f; }

/* === Last Logged === */
.last-logged {
  display: none;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.75rem;
  color: #8892a4;
  line-height: 1.4;
}

.last-logged.visible { display: block; }
.last-logged .ll-header { font-size: 0.65rem; font-weight: 600; color: #556680; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 2px; }
.last-logged .ll-name { font-weight: 600; color: #e0e6ed; }
.last-logged .ll-macros { color: #8892a4; }
.last-logged .ll-warning { color: #ef476f; font-weight: 600; margin-left: 4px; }

/* === Counters === */
.counters { display: flex; gap: 16px; margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); }
.counter-item { font-size: 0.9rem; color: #8892a4; }
.counter-item span { font-weight: 700; color: #e0e6ed; }

/* === Toast === */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #0d1b2a;
  color: #06d6a0;
  padding: 14px 28px;
  border-radius: 8px;
  font-weight: 600;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  z-index: 1000;
}

.toast.error { background: #0d1b2a; color: #ef476f; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* === Tab Bar === */
.tab-bar {
  display: flex;
  gap: 0;
  max-width: 420px;
  margin: 0 auto 16px;
  background: #112240;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.tab-btn {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: #112240;
  color: #8892a4;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active { background: #00b4d8; color: #fff; }
.tab-btn.tab-stats { color: #ffd166; }
.tab-btn.tab-stats.active { background: #ffd166; color: #0d1b2a; }

.app-container { display: flex; flex-direction: column; }
.main-panel { flex: 1; }

/* === Presets Panel === */
.presets-panel {
  display: none;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: #112240;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.presets-panel.visible { display: block; }

.presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 6px;
  border: 2px solid #00b4d8;
  border-radius: 10px;
  cursor: pointer;
  background: #e0f7fa;
  box-shadow: 0 2px 6px rgba(0,180,216,0.1);
  transition: transform 0.1s;
}

.preset-btn:active {
  transform: scale(0.95);
  background: #b2ebf2;
}

.preset-btn .preset-emoji { font-size: 1.4rem; line-height: 1; }
.preset-btn .preset-label { font-size: 0.6rem; color: #0d1b2a; margin-top: 4px; text-align: center; line-height: 1.1; font-weight: 600; }

.presets-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #8892a4;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
}

.presets-section-label:first-child { margin-top: 0; }

.preset-btn.processed {
  background: #fce4ec;
  border-color: #ef476f;
  box-shadow: 0 2px 6px rgba(239,71,111,0.1);
}

.preset-btn.processed:active { background: #f8bbd0; }

.preset-btn.gold {
  background: #fff8e1;
  border-color: #ffd166;
  box-shadow: 0 2px 6px rgba(255,209,102,0.1);
}

.preset-btn.gold:active { background: #ffecb3; }

/* === Manual Entry === */
.manual-entry {
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 12px;
  background: #0d1b2a;
  border: 1px solid rgba(255,255,255,0.08);
}

.manual-entry input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  font-size: 0.8rem;
  background: #fdf8ec;
  color: #1a1a2e;
  margin-bottom: 6px;
}

.manual-entry input::placeholder { color: #999; }

.manual-entry input[type="number"]::-webkit-inner-spin-button,
.manual-entry input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.manual-entry input[type="number"] { -moz-appearance: textfield; }

.manual-macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 6px; }
.manual-macros input { margin-bottom: 0; text-align: center; }

.manual-desc-row {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}

.manual-desc-row input { flex: 4; margin-bottom: 0; }

.manual-desc-row select {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  font-size: 0.75rem;
  background: #fdf8ec;
  color: #1a1a2e;
  text-align: center;
}

.manual-submit {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: 6px;
  background: #00b4d8;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.manual-submit:active {
  transform: scale(0.97);
  opacity: 0.85;
}

/* === Stats Panel === */
.stats-panel {
  display: none;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: #112240;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.stats-panel.visible { display: block; }
.stats-section { margin-bottom: 16px; }
.stats-section:last-child { margin-bottom: 0; }

.stats-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #ffd166;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stats-grid { background: #0d1b2a; border-radius: 10px; overflow: hidden; }

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 0.8rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: #8892a4; }
.stat-row span:last-child { font-weight: 600; color: #e0e6ed; }

/* === Comparison Table === */
#compareGrid .stat-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
}

#compareGrid .stat-row span:nth-child(2),
#compareGrid .stat-row span:nth-child(3) {
  text-align: right;
  min-width: 40px;
  color: #e0e6ed;
}

#compareGrid .stat-row span:nth-child(4) {
  text-align: right;
  min-width: 40px;
}

#compareGrid .compare-header span {
  font-size: 0.65rem;
  font-weight: 700;
  color: #556680;
  text-transform: uppercase;
}

.delta-up {
  color: #06d6a0;
  font-weight: 700;
  text-shadow:
    0 0 4px rgba(6, 214, 160, 0.6),
    0 0 10px rgba(6, 214, 160, 0.4),
    0 0 20px rgba(6, 214, 160, 0.2);
}

.delta-down {
  color: #ef476f;
  font-weight: 700;
  text-shadow:
    0 0 4px rgba(239, 71, 111, 0.6),
    0 0 10px rgba(239, 71, 111, 0.4),
    0 0 20px rgba(239, 71, 111, 0.2);
}

.delta-neutral { color: #556680; }

/* === Badges === */
.badges-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.badge-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 8px 10px;
  border-radius: 12px;
  justify-content: center;
  border: 3px solid;
  cursor: pointer;
  transition: transform 0.15s;
}

.badge-item::before {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 8px;
  opacity: 0.6;
  pointer-events: none;
}

.badge-item:active { transform: scale(0.93); }

/* Daily: teal, short dash */
.badge-item.cat-daily {
  background-color: #e0f7fa;
  border-color: #00b4d8;
  box-shadow: 0 0 10px rgba(0,180,216,0.3);
}
.badge-item.cat-daily::before {
  border: 2px dashed #00b4d8;
}

/* Streak: orange, long dash */
.badge-item.cat-streak {
  background-color: #fff3e0;
  border-color: #ff8c42;
  box-shadow: 0 0 10px rgba(255,140,66,0.3);
}
.badge-item.cat-streak::before {
  border: 2px dashed #ff8c42;
}

/* Fun: purple, dotted */
.badge-item.cat-fun {
  background-color: #ede7f6;
  border-color: #7c5cbf;
  box-shadow: 0 0 10px rgba(124,92,191,0.3);
}
.badge-item.cat-fun::before {
  border: 2px dotted #7c5cbf;
}

.badge-item .badge-emoji { font-size: 1.4rem; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.2)); }
.badge-item .badge-label { font-size: 0.55rem; font-weight: 800; color: #333; margin-top: 5px; text-align: center; line-height: 1.1; text-transform: uppercase; letter-spacing: 0.02em; }

.badge-item .badge-desc {
  display: none;
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%);
  background: #0d1b2a;
  color: #fff;
  font-size: 0.6rem;
  padding: 5px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 10;
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.badge-item .badge-desc::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid #0d1b2a;
}

.badge-item.show-desc .badge-desc { display: block; }
.badges-empty { grid-column: 1 / -1; text-align: center; font-size: 0.75rem; color: #556680; padding: 20px; }

/* === History Panel === */
.history-panel {
  display: none;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: #112240;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

.history-panel.visible { display: block; }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history-header .presets-section-label { margin: 0; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-empty { text-align: center; font-size: 0.8rem; color: #556680; padding: 20px; }

.history-item {
  background: #0d1b2a;
  border-radius: 10px;
  padding: 12px 14px;
  border: 1px solid rgba(255,255,255,0.06);
}

.hist-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hist-row:first-child { margin-bottom: 4px; }

.hist-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e0e6ed;
  cursor: pointer;
  border-bottom: 1px dashed rgba(255,255,255,0.2);
}

.hist-time {
  font-size: 0.65rem;
  color: #556680;
}

.hist-macros {
  font-size: 0.75rem;
  color: #8892a4;
  display: flex;
  align-items: baseline;
  gap: 2px;
}

.hist-macro {
  cursor: pointer;
  color: #e0e6ed;
  font-weight: 600;
  border-bottom: 1px dashed rgba(255,255,255,0.2);
  padding: 0 1px;
}

.hist-macro-sep {
  color: #556680;
  font-size: 0.65rem;
  margin-right: 8px;
}

.hist-macro-sep:last-child { margin-right: 0; }

.hist-delete {
  background: none;
  border: none;
  color: #ef476f;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.hist-delete:active { opacity: 1; }

.tab-btn.tab-history { color: #06d6a0; }
.tab-btn.tab-history.active { background: #06d6a0; color: #0d1b2a; }

/* === Wide Screen: Sidebar Layout === */
/* === Sidebar Right (desktop only) === */
.sidebar-right {
  display: contents;
}

.sidebar-tabs { display: none; }
.sidebar-history { display: none; }

@media (min-width: 768px) {
  .tab-bar { display: none; }

  .app-container {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 48px;
  }

  .main-panel { flex: 0 1 auto; max-width: 460px; }

  .presets-panel {
    display: block !important;
    position: sticky;
    top: 16px;
    width: 460px;
    max-width: 460px;
    margin: 0;
    background: #112240;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  }

  .presets-grid { grid-template-columns: repeat(3, 1fr); }

  .history-panel { display: none !important; }

  .sidebar-right {
    display: block;
    position: sticky;
    top: 16px;
    width: 320px;
    max-width: 320px;
    flex-shrink: 0;
    margin: 0;
    background: #112240;
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  }

  .sidebar-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 12px;
    background: #0d1b2a;
    border-radius: 8px;
    overflow: hidden;
  }

  .sidebar-tab {
    flex: 1;
    padding: 8px 4px;
    border: none;
    background: #0d1b2a;
    color: #8892a4;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }

  .sidebar-tab.active { background: #00b4d8; color: #fff; }

  .sidebar-right .stats-panel {
    display: block !important;
    position: static;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
  }

  .sidebar-right .stats-panel.sidebar-hidden { display: none !important; }

  .sidebar-history { display: none; }
  .sidebar-history.sidebar-visible { display: block; }
}
