/* ==========================================================================
   TallyKal - Calorie Tracker Styles
   Design System: macOS-inspired minimalism with glassmorphism
   ========================================================================== */

/* ==========================================================================
   1. CSS Variables (Design System)
   ========================================================================== */
:root {
  /* Primary (Accent) */
  --color-blue: #007AFF;
  --color-blue-hover: #0051D5;
  --color-blue-light: rgba(0, 122, 255, 0.1);
  --color-blue-glow: rgba(0, 122, 255, 0.08);
  --color-blue-glow-strong: rgba(0, 122, 255, 0.12);

  /* Semantic (Progress) */
  --color-green: #30D158;
  --color-green-end: #34C759;
  --color-yellow: #FFD60A;
  --color-orange: #FF9F0A;
  --color-red: #FF453A;

  /* Neutrals */
  --color-bg: #F5F5F7;
  --color-surface: rgba(255, 255, 255, 0.7);
  --color-surface-solid: #FFFFFF;
  --color-text-primary: #1D1D1F;
  --color-text-secondary: rgba(29, 29, 31, 0.6);
  --color-text-tertiary: rgba(29, 29, 31, 0.4);
  --color-border: rgba(0, 0, 0, 0.08);
  --color-border-light: rgba(255, 255, 255, 0.3);

  /* Spacing (8px Grid) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-base: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Typography */
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Monaco, 'Inconsolata', 'Roboto Mono', monospace;

  /* Font Sizes */
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 15px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 24px;

  /* Font Weights */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;

  /* Border Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-input-focus: 0 0 0 4px var(--color-blue-glow), 0 4px 16px var(--color-blue-glow-strong);
  --shadow-entry-hover: 0 2px 8px rgba(0, 0, 0, 0.06);

  /* Transitions */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-sharp: cubic-bezier(0.4, 0, 1, 1);
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
  --duration-progress: 400ms;
}

/* ==========================================================================
   2. Reset & Base
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: 1.5;
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  /* Subtle grid texture */
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.015) 1px, transparent 1px);
  background-size: 20px 20px;
  min-height: 100vh;
}

input, button {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

ul {
  list-style: none;
}

/* ==========================================================================
   3. Layout Components
   ========================================================================== */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-base);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  margin-bottom: var(--space-lg);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.footer {
  margin-top: auto;
  padding-top: var(--space-lg);
  display: flex;
  justify-content: center;
}

/* ==========================================================================
   4. Header Components
   ========================================================================== */
.date-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}

.nav-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: var(--text-lg);
  transition: all var(--duration-normal) var(--ease-smooth);
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-btn:hover {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

.nav-btn:active {
  transform: scale(0.95);
}

.nav-btn.disabled,
.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.date-display {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.date-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-text {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.past-date-indicator {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-orange);
  background-color: rgba(255, 159, 10, 0.15);
  padding: 2px var(--space-sm);
  border-radius: var(--radius-sm);
}

.today-jump-btn {
  border: 1px solid rgba(177, 203, 227, 0.78);
  border-radius: 999px;
  padding: 3px 10px;
  min-height: 24px;
  font-size: 12px;
  font-weight: 600;
  color: #315a7d;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(242, 249, 255, 0.86));
  transition: border-color var(--duration-fast) var(--ease-smooth), transform var(--duration-fast) var(--ease-smooth), background var(--duration-fast) var(--ease-smooth);
}

.today-jump-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(138, 194, 242, 0.88);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(236, 247, 255, 0.9));
}

.calorie-summary {
  text-align: center;
  margin: var(--space-lg) 0 var(--space-base) 0;
  padding: var(--space-base) var(--space-lg);
  background: linear-gradient(135deg, rgba(255,255,255,0.6) 0%, rgba(255,255,255,0.3) 100%);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255,255,255,0.5);
}

.total-display {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-text-primary);
}

.remaining-display {
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
}

.progress-container {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.progress-bar {
  flex: 1;
  height: 6px;
  background-color: rgba(0, 0, 0, 0.06);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-green), var(--color-green-end));
  border-radius: var(--radius-md);
  transition: width var(--duration-progress) ease-out, background var(--duration-slow) var(--ease-smooth);
}

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

.progress-fill.orange {
  background: var(--color-orange);
}

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

.progress-percent {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  min-width: 40px;
  text-align: right;
}

/* ==========================================================================
   5. Input Section
   ========================================================================== */
.input-section {
  margin-bottom: var(--space-lg);
}

.input-wrapper {
  position: relative;
}

.calorie-input {
  width: 100%;
  padding: var(--space-base) var(--space-lg);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.01em;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: all var(--duration-normal) var(--ease-smooth);
}

.calorie-input::placeholder {
  color: var(--color-text-tertiary);
}

.calorie-input:focus {
  border-color: var(--color-blue);
  box-shadow: var(--shadow-input-focus);
  transform: translateY(-1px);
}

.calorie-input.error {
  border-color: var(--color-red);
  animation: shake 200ms ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.input-error {
  margin-top: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background-color: rgba(255, 69, 58, 0.1);
  border-radius: var(--radius-md);
  color: var(--color-red);
  font-size: var(--text-sm);
  opacity: 1;
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

/* ==========================================================================
   6. Autocomplete Dropdown
   ========================================================================== */
.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + var(--space-sm));
  left: 0;
  right: 0;
  background: var(--color-surface-solid);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 300;
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--duration-fast) var(--ease-smooth),
              transform var(--duration-fast) var(--ease-smooth);
}

.autocomplete-dropdown.hidden {
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
}

.autocomplete-item {
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-smooth);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background-color: var(--color-blue-light);
}

.autocomplete-name {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--color-text-primary);
}

.autocomplete-meta {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ==========================================================================
   7. Entry List
   ========================================================================== */
.entries-section {
  flex: 1;
  margin-bottom: var(--space-base);
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.entry-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-smooth);
}

.entry-item:hover {
  background-color: var(--color-surface-solid);
  box-shadow: var(--shadow-entry-hover);
}

.entry-item.editing {
  background-color: var(--color-surface-solid);
  box-shadow: var(--shadow-entry-hover);
}

.entry-item.deleting {
  opacity: 0;
  transform: translateX(-20px);
  transition: all var(--duration-slow) var(--ease-sharp);
}

.entry-item.adding {
  animation: slideIn var(--duration-slow) var(--ease-smooth);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.entry-time {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  min-width: 45px;
}

.entry-name {
  flex: 1;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-calories {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 500;
  color: var(--color-text-primary);
  min-width: 75px;
  text-align: right;
}

.entry-delete {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-tertiary);
  font-size: var(--text-lg);
  opacity: 0.5;
  transition: all var(--duration-fast) var(--ease-smooth);
}

.entry-item:hover .entry-delete {
  opacity: 1;
}

.entry-delete:hover {
  background-color: rgba(255, 69, 58, 0.1);
  color: var(--color-red);
}

/* Time divider for time-of-day grouping */
.time-divider {
  height: var(--space-base);
}

/* ==========================================================================
   8. Inline Editing
   ========================================================================== */
.entry-item.editing {
  gap: var(--space-sm);
}

.edit-input {
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  background-color: var(--color-surface-solid);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-smooth);
}

.edit-input:focus {
  border-color: var(--color-blue);
}

.edit-name {
  flex: 1;
  min-width: 100px;
}

.edit-amount,
.edit-cal {
  width: 60px;
  font-family: var(--font-mono);
  text-align: right;
}

.edit-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ==========================================================================
   9. Empty State
   ========================================================================== */
.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-base);
}

.empty-message {
  color: var(--color-text-secondary);
  font-size: var(--text-md);
  margin-bottom: var(--space-base);
}

.help-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  transition: all var(--duration-normal) var(--ease-smooth);
}

.help-btn:hover {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

.help-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

/* ==========================================================================
   10. Metrics Section
   ========================================================================== */
.metrics-section {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-sm);
  margin-top: auto;
  padding-top: var(--space-base);
}

.metric-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-xs);
  min-height: 68px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.metric-label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: var(--weight-medium);
}

.debt-value {
  font-family: var(--font-mono);
  font-weight: var(--weight-medium);
}

.debt-positive { color: #FF3B30; }  /* Red - over goal */
.debt-negative { color: #34C759; }  /* Green - under goal */
.debt-zero { color: var(--color-text-secondary); }  /* Gray */

/* ==========================================================================
   11. Help Tooltip
   ========================================================================== */
.help-tooltip {
  position: fixed;
  inset: 0;
  z-index: 360;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(16, 28, 40, 0.16);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.help-tooltip.hidden {
  display: none;
}

.tooltip-content {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 56px);
  overflow: auto;
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.9), rgba(238, 247, 255, 0.82));
  border: 1px solid rgba(186, 209, 232, 0.72);
  border-radius: var(--radius-xl);
  box-shadow: 0 18px 36px rgba(79, 112, 147, 0.24);
  padding: 14px 16px 16px;
  position: relative;
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

.tooltip-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 2px 2px 8px;
  border-bottom: 1px solid rgba(183, 208, 231, 0.64);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.tooltip-header:active {
  cursor: grabbing;
}

.tooltip-title-block {
  min-width: 0;
}

.tooltip-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.45;
}

.tooltip-close {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--text-xl);
  transition: all var(--duration-fast) var(--ease-smooth);
}

.tooltip-close:hover {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

.tooltip-content h3 {
  font-size: 20px;
  font-weight: var(--weight-semibold);
  margin-bottom: 0;
  line-height: 1.25;
}

.tooltip-section {
  margin-bottom: 14px;
}

.tooltip-section:last-child {
  margin-bottom: 0;
}

.tooltip-section h4 {
  font-size: 13px;
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: var(--space-sm);
}

.tooltip-section code {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 14px;
  background: linear-gradient(90deg, rgba(139, 199, 255, 0.2), rgba(120, 207, 165, 0.12));
  color: #24506f;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

.tooltip-example {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

.tooltip-section ul {
  font-size: 14px;
  color: var(--color-text-secondary);
  padding-left: var(--space-base);
}

.tooltip-section ul li {
  list-style: disc;
  margin-bottom: var(--space-xs);
}

.shortcuts-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.shortcuts-list li {
  list-style: none !important;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(181, 205, 229, 0.8);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-sm);
}

.tooltip-content.tooltip-dragging {
  box-shadow: 0 22px 42px rgba(73, 106, 140, 0.28);
}

/* ==========================================================================
   12. Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  opacity: 1;
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--color-surface-solid);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  margin: var(--space-base);
  transform: scale(1);
  transition: transform var(--duration-normal) var(--ease-spring);
}

.modal-overlay.hidden .modal {
  transform: scale(0.95);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-base) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: var(--text-xl);
  transition: all var(--duration-fast) var(--ease-smooth);
}

.modal-close:hover {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-base) var(--space-lg);
  border-top: 1px solid var(--color-border);
}

.setting-group {
  margin-bottom: var(--space-base);
}

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

.setting-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-sm);
}

.setting-input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.setting-input {
  width: 120px;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-smooth);
}

.setting-input:focus {
  border-color: var(--color-blue);
}

.setting-unit {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.setting-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-base) 0;
}

.data-buttons {
  display: flex;
  gap: var(--space-sm);
}

/* Goal management styles */
.current-goal-display {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text-primary);
}

.goal-effective-date {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-normal);
  color: var(--color-text-secondary);
  margin-top: var(--space-xs);
}

.goal-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.setting-sublabel {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-xs);
}

.setting-input-date {
  width: 160px;
}

.setting-input-wide {
  width: 100%;
}

.recent-goals {
  margin-bottom: var(--space-sm);
}

.recent-goal-item {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
}

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

.goal-calories {
  font-family: var(--font-mono);
  font-weight: var(--weight-medium);
}

.goal-date {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* Goal history modal styles */
.goal-history-list {
  max-height: 400px;
  overflow-y: auto;
}

.goal-history-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-border);
  gap: var(--space-md);
}

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

.goal-history-item.active {
  background-color: var(--color-blue-light);
  border-radius: var(--radius-md);
}

.goal-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex: 1;
}

.goal-info .goal-calories {
  font-size: var(--text-lg);
}

.goal-effective,
.goal-created {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.goal-notes {
  font-size: var(--text-sm);
  color: var(--color-text-tertiary);
  font-style: italic;
}

.active-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  background-color: var(--color-green);
  color: white;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-sm);
  margin-left: var(--space-sm);
}

.btn-small {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--text-sm);
}

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

.btn-danger:hover {
  background-color: #E0322A;
}

/* ==========================================================================
   13. Buttons
   ========================================================================== */
.btn {
  padding: var(--space-sm) var(--space-base);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  transition: all var(--duration-normal) var(--ease-smooth);
}

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

.btn-primary:hover {
  background-color: var(--color-blue-hover);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background-color: var(--color-border);
  color: var(--color-text-primary);
}

.btn-secondary:hover {
  background-color: rgba(0, 0, 0, 0.12);
}

/* ==========================================================================
   14. Offline Banner
   ========================================================================== */

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(135deg, #FF9F0A 0%, #FF6B35 100%);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(255, 159, 10, 0.3);
  animation: slideDown 0.3s ease;
}

.offline-banner.hidden {
  display: none;
}

.offline-icon {
  font-size: 18px;
  animation: pulse 2s ease infinite;
}

.offline-text {
  flex: 0 0 auto;
}

.sync-queue {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Adjust main content to account for offline banner */
body.offline-mode {
  padding-top: 48px;
}

/* ==========================================================================
   15. Utility Classes
   ========================================================================== */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   16. Responsive Adjustments
   ========================================================================== */
@media (max-width: 480px) {
  .container {
    padding: var(--space-base);
  }

  .date-text {
    font-size: var(--text-lg);
  }

  .total-display {
    font-size: var(--text-xl);
  }

  .shortcuts-list {
    grid-template-columns: 1fr;
  }

  .data-buttons {
    flex-direction: column;
  }
}

/* ==========================================================================
   17. Print Styles
   ========================================================================== */
@media print {
  body {
    background: white;
    background-image: none;
  }

  .calorie-input,
  .help-tooltip,
  .modal-overlay,
  .entry-delete,
  .burger-btn,
  .sidebar,
  .sidebar-backdrop {
    display: none !important;
  }
}

/* ==========================================================================
   18. Sidebar
   ========================================================================== */

/* Burger Icon */
.burger-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--color-text-secondary);
  z-index: 400;
  transition: color var(--duration-fast) var(--ease-smooth);
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

.burger-btn:hover {
  color: var(--color-blue);
}

/* Sidebar Container */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-lg);
  z-index: 500;
  transform: translateX(-100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar:not(.hidden) {
  transform: translateX(0);
}

.sidebar-content {
  padding: 64px 16px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Sidebar Sections */
.sidebar-section {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-smooth);
  text-align: left;
  width: 100%;
}

.sidebar-section:hover {
  background: rgba(0, 122, 255, 0.1);
}

.sidebar-icon {
  font-size: 20px;
  width: 24px;
  text-align: center;
}

.sidebar-section-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-section-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.sidebar-section-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.sidebar-chevron {
  font-size: 20px;
  color: var(--color-text-tertiary);
}

/* Sidebar Subview */
.sidebar-subview {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-lg);
  z-index: 510;
  transform: translateX(-100%);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.sidebar-subview:not(.hidden) {
  transform: translateX(0);
}

.subview-header {
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.subview-back {
  font-size: 20px;
  color: var(--color-blue);
  padding: 4px;
  border: none;
  background: none;
  cursor: pointer;
  transition: opacity var(--duration-fast);
}

.subview-back:hover {
  opacity: 0.7;
}

.subview-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.subview-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subview-action {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 12px 16px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-smooth);
  text-align: left;
  width: 100%;
}

.subview-action:hover {
  background: var(--color-blue-light);
  border-color: var(--color-blue);
}

.subview-action span:first-child {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.subview-action-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.about-version {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 16px;
}

.subview-content h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.subview-content .shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  list-style: none;
  padding: 0;
}

.subview-content .shortcuts-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-primary);
}

/* Backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 450;
  opacity: 0;
  transition: opacity 200ms cubic-bezier(0.4, 0, 1, 1);
  pointer-events: none;
}

.sidebar-backdrop:not(.hidden) {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   14. Dashboard Styles
   ========================================================================== */

.dashboard-view {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-base) var(--space-lg);
  background: var(--color-bg);
}

.dashboard-view.hidden {
  display: none;
}

.time-range-selector {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

.time-range-btn {
  background: var(--color-surface-solid);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: var(--text-sm);
  font-family: var(--font-body);
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all 150ms ease;
}

.time-range-btn:hover {
  border-color: var(--color-blue);
  color: var(--color-blue);
}

.time-range-btn.active {
  background: var(--color-blue);
  border-color: var(--color-blue);
  color: white;
}

.dashboard-card {
  background: var(--color-surface-solid);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  max-width: 900px;
}

.card-title {
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--color-text-primary);
  margin: 0 0 var(--space-md) 0;
  font-family: var(--font-body);
}

.consistency-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.consistency-stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.consistency-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font-body);
}

.consistency-stat-value {
  font-size: 28px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: -0.5px;
}

.consistency-stat-value.green {
  color: var(--color-green);
}

.consistency-stat-value.blue {
  color: var(--color-blue);
}

.consistency-stat-value.orange {
  color: var(--color-orange);
}

.consistency-stat-subtext {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
}

.chart-container {
  position: relative;
  height: 300px;
  margin: 0;
}

.chart-container.day-of-week {
  height: 250px;
}

.performance-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
}

.performance-stat {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.performance-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font-body);
}

.performance-stat-value {
  font-size: 20px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--color-text-primary);
}

.performance-stat-subtext {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
}

.no-data-message {
  text-align: center;
  padding: var(--space-xl);
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  font-size: var(--text-sm);
}

/* ==========================================================================
   19. Brand Guide Overrides (TallyKal Glass System)
   ========================================================================== */
:root {
  --color-blue: #5ba9ff;
  --color-blue-hover: #3f93f4;
  --color-blue-light: rgba(91, 169, 255, 0.14);
  --color-blue-glow: rgba(91, 169, 255, 0.2);
  --color-blue-glow-strong: rgba(91, 169, 255, 0.14);

  --color-green: #56c98d;
  --color-green-end: #86df75;
  --color-yellow: #ffd067;
  --color-orange: #ffb37e;
  --color-red: #ef6e6e;

  --color-bg: #f3f7fb;
  --color-surface: rgba(255, 255, 255, 0.74);
  --color-surface-solid: #ffffff;
  --color-text-primary: #1f2a37;
  --color-text-secondary: #425466;
  --color-text-tertiary: #7f95aa;
  --color-border: rgba(177, 203, 227, 0.62);
  --color-border-light: rgba(255, 255, 255, 0.7);

  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 6px 16px rgba(89, 120, 158, 0.1);
  --shadow-md: 0 10px 24px rgba(89, 120, 158, 0.13);
  --shadow-lg: 0 16px 32px rgba(89, 120, 158, 0.16);
  --shadow-input-focus: 0 0 0 3px rgba(120, 191, 248, 0.28), 0 8px 18px rgba(96, 147, 191, 0.18);

  --duration-normal: 220ms;
  --duration-slow: 320ms;
}

body {
  background:
    radial-gradient(circle at 10% 8%, rgba(86, 201, 141, 0.16) 0, transparent 26%),
    radial-gradient(circle at 92% 15%, rgba(139, 199, 255, 0.2) 0, transparent 32%),
    radial-gradient(circle at 84% 84%, rgba(255, 208, 103, 0.12) 0, transparent 28%),
    linear-gradient(180deg, #f3f7fb 0%, #eef4fa 100%);
  background-size: auto;
}

.container {
  max-width: 720px;
  padding-top: 40px;
}

.header,
.input-section,
.entries-section,
.metric-card,
.dashboard-card,
.tooltip-content,
.modal,
.sidebar,
.sidebar-subview {
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.78), rgba(238, 247, 255, 0.7));
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px) saturate(118%);
  -webkit-backdrop-filter: blur(10px) saturate(118%);
}

.header {
  border-radius: var(--radius-xl);
  padding: 18px;
  margin-bottom: var(--space-lg);
}

.input-section,
.entries-section,
.metric-card {
  border-radius: var(--radius-lg);
}

.input-section {
  position: relative;
  z-index: 30;
  padding: 14px;
}

.entries-section {
  position: relative;
  z-index: 20;
  padding: 10px;
}

.metrics-section {
  margin-top: 12px;
  gap: 12px;
  padding-top: 0;
}

.metric-card {
  padding: 12px 14px;
}

.calorie-summary {
  background: linear-gradient(138deg, rgba(255, 255, 255, 0.84) 0%, rgba(237, 246, 255, 0.7) 100%);
  border: 1px solid var(--color-border-light);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.nav-btn,
.help-btn,
.entry-item,
.btn,
.time-range-btn,
.sidebar-section,
.subview-action,
.dashboard-card {
  transition:
    transform var(--duration-normal) var(--ease-smooth),
    border-color var(--duration-normal) var(--ease-smooth),
    box-shadow var(--duration-normal) var(--ease-smooth),
    background-color var(--duration-normal) var(--ease-smooth),
    color var(--duration-normal) var(--ease-smooth);
}

.nav-btn:hover,
.help-btn:hover {
  background: linear-gradient(90deg, rgba(132, 201, 255, 0.2), rgba(134, 223, 117, 0.14));
  color: var(--color-text-primary);
}

.calorie-input {
  border-color: rgba(181, 205, 229, 0.78);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 250, 255, 0.84));
  color: var(--color-text-primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.84), var(--shadow-sm);
}

.calorie-input:focus {
  transform: translateY(-1px);
}

.autocomplete-dropdown {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(243, 249, 255, 0.92));
  border-color: rgba(169, 198, 225, 0.8);
  box-shadow: var(--shadow-md);
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: linear-gradient(90deg, rgba(132, 201, 255, 0.2), rgba(134, 223, 117, 0.14));
}

.entry-item {
  border: 1px solid rgba(187, 211, 233, 0.58);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.83), rgba(246, 251, 255, 0.78));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.78);
}

.entry-item:hover,
.entry-item.editing {
  transform: translateY(-1px);
  border-color: rgba(152, 198, 239, 0.84);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82), 0 8px 16px rgba(98, 144, 186, 0.12);
}

.btn {
  border: 1px solid transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.58);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(92, 139, 181, 0.18);
}

.btn-primary {
  color: #24513e;
  border-color: rgba(126, 182, 155, 0.58);
  background: linear-gradient(95deg, rgba(182, 228, 205, 0.84), rgba(214, 240, 224, 0.88));
}

.btn-primary:hover {
  border-color: rgba(116, 170, 145, 0.66);
  background: linear-gradient(95deg, rgba(168, 219, 191, 0.9), rgba(202, 232, 212, 0.92));
}

.btn-secondary {
  background: linear-gradient(95deg, rgba(187, 224, 255, 0.84), rgba(230, 242, 255, 0.9));
  border-color: rgba(147, 198, 240, 0.82);
  color: #244e6c;
}

.btn-secondary:hover {
  background: linear-gradient(95deg, rgba(173, 216, 252, 0.86), rgba(220, 236, 255, 0.92));
}

.modal {
  border: 1px solid var(--color-border-light);
}

.modal-header,
.modal-footer,
.setting-divider,
.recent-goal-item,
.goal-history-item {
  border-color: rgba(183, 208, 231, 0.65);
}

.setting-input,
.edit-input {
  border-color: rgba(178, 203, 228, 0.8);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(244, 250, 255, 0.88));
}

.setting-input:focus,
.edit-input:focus {
  box-shadow: 0 0 0 3px rgba(125, 194, 248, 0.28);
}

.burger-btn {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  border: 1px solid rgba(183, 208, 231, 0.75);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 255, 0.88));
  box-shadow: var(--shadow-sm);
  color: #37526a;
}

.burger-btn:hover {
  color: #204d6f;
  transform: translateY(-1px);
}

.burger-glyph {
  width: 16px;
  height: 16px;
}

.sidebar,
.sidebar-subview {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.88), rgba(236, 247, 255, 0.84));
  border-right-color: rgba(180, 205, 229, 0.72);
}

.sidebar-section,
.subview-action {
  border: 1px solid transparent;
  border-radius: 12px;
}

.sidebar-section:hover,
.subview-action:hover {
  background: linear-gradient(90deg, rgba(132, 201, 255, 0.2), rgba(134, 223, 117, 0.14));
  border-color: rgba(144, 195, 237, 0.82);
}

.dashboard-view {
  background: transparent;
}

.time-range-selector {
  gap: 10px;
}

.time-range-btn {
  border-radius: 999px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 250, 255, 0.86));
  border-color: rgba(177, 203, 227, 0.72);
}

.time-range-btn:hover {
  border-color: rgba(140, 194, 239, 0.88);
  color: #214d6f;
}

.time-range-btn.active {
  background: linear-gradient(95deg, rgba(132, 201, 255, 0.88), rgba(184, 177, 255, 0.84));
  border-color: rgba(130, 187, 236, 0.88);
  color: #143c59;
}

.dashboard-card {
  border-radius: 14px;
  border-color: rgba(176, 202, 227, 0.72);
}

.dashboard-card:hover {
  transform: translateY(-1px);
  border-color: rgba(144, 194, 237, 0.84);
  box-shadow: 0 12px 24px rgba(95, 139, 178, 0.14);
}

.range-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  align-self: center;
  margin-right: 2px;
}

.card-subtitle {
  margin: -2px 0 10px;
  color: var(--color-text-secondary);
  font-size: 13px;
}

.consistency-content {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.consistency-stat {
  border: 1px solid rgba(182, 207, 231, 0.72);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 255, 0.86));
  padding: 12px;
  min-height: 98px;
}

.consistency-stat-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  letter-spacing: 0.03em;
}

.consistency-stat-value {
  margin-top: 4px;
  font-size: 26px;
  line-height: 1.1;
  font-weight: 700;
  color: #294a64;
}

.consistency-stat-value.green {
  color: #1f8c5f;
}

.consistency-stat-value.blue,
.consistency-stat-value.neutral {
  color: #3b6f99;
}

.consistency-stat-value.orange {
  color: #be7d44;
}

.consistency-stat-subtext {
  margin-top: 4px;
  font-size: 12px;
  color: #6b7f92;
}

.performance-content {
  gap: 10px;
}

.performance-stat {
  border: 1px solid rgba(182, 207, 231, 0.72);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 255, 0.86));
  padding: 12px;
  min-height: 92px;
}

.performance-stat-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  letter-spacing: 0.03em;
}

.performance-stat-value {
  margin-top: 4px;
  font-size: 20px;
  line-height: 1.2;
  color: #274760;
}

.performance-stat-value-mono {
  font-family: var(--font-mono);
}

.performance-stat-value-good {
  color: #1f8c5f;
}

.performance-stat-value-warn {
  color: #bb5f58;
}

.performance-stat-subtext {
  margin-top: 4px;
  color: #6b7f92;
}

.chart-container {
  height: 280px;
  padding: 8px 6px 2px;
  border-radius: 12px;
  border: 1px solid rgba(182, 207, 231, 0.58);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(245, 251, 255, 0.84));
}

.chart-legend {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #4f6578;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(186, 209, 232, 0.7);
  border-radius: 999px;
  padding: 5px 9px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.legend-dot-good {
  background: #56c98d;
}

.legend-dot-neutral {
  background: #8fa3b7;
}

.legend-dot-over {
  background: #ef6e6e;
}

.offline-banner {
  background: linear-gradient(95deg, rgba(255, 179, 126, 0.96), rgba(239, 110, 110, 0.95));
  box-shadow: 0 6px 16px rgba(225, 126, 111, 0.26);
}

@media (max-width: 480px) {
  .header {
    padding: 14px;
  }

  .range-label {
    width: 100%;
    margin-bottom: 2px;
  }

  .consistency-content {
    grid-template-columns: 1fr;
  }

  .performance-content {
    grid-template-columns: 1fr;
  }

  .chart-container {
    height: 230px;
  }

  .input-section,
  .entries-section,
  .metric-card {
    padding-left: 10px;
    padding-right: 10px;
  }

  .metrics-section {
    gap: 8px;
  }
}

/* ==========================================================================
   20. App Shell Refresh (Desktop-First Sidebar)
   ========================================================================== */
body {
  background-image: none;
  background: linear-gradient(180deg, rgba(237, 246, 253, 0.96), rgba(225, 238, 249, 0.88));
  position: relative;
  overflow-x: hidden;
  isolation: isolate;
}

body::before,
body::after {
  content: "";
  position: fixed;
  pointer-events: none;
  z-index: 0;
}

body::before {
  left: -20vw;
  top: -18vh;
  width: 142vw;
  height: 54vh;
  border-radius: 0 0 58% 42% / 0 0 72% 68%;
  transform: rotate(-7deg);
  opacity: 0.66;
  background:
    linear-gradient(102deg, rgba(139, 199, 255, 0.48) 0%, rgba(139, 199, 255, 0.26) 34%, rgba(120, 207, 165, 0.22) 68%, rgba(120, 207, 165, 0.1) 100%),
    radial-gradient(42% 80% at 12% 26%, rgba(255, 255, 255, 0.24), transparent 74%),
    radial-gradient(28% 56% at 78% 22%, rgba(255, 208, 103, 0.14), transparent 70%);
  filter: blur(0.25px);
}

body::after {
  left: -18vw;
  bottom: -26vh;
  width: 136vw;
  height: 52vh;
  border-radius: 60% 40% 0 0 / 66% 62% 0 0;
  transform: rotate(8deg);
  opacity: 0.58;
  background:
    linear-gradient(94deg, rgba(139, 199, 255, 0.38) 0%, rgba(139, 199, 255, 0.2) 44%, rgba(255, 208, 103, 0.14) 72%, rgba(239, 110, 110, 0.12) 100%),
    radial-gradient(30% 60% at 26% 70%, rgba(255, 255, 255, 0.22), transparent 78%),
    radial-gradient(24% 48% at 82% 42%, rgba(120, 207, 165, 0.16), transparent 72%);
  filter: blur(0.3px);
}

.app-shell {
  width: min(100%, 1360px);
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  min-height: 100vh;
  transition: grid-template-columns 260ms ease, width 260ms ease;
  position: relative;
  isolation: isolate;
  z-index: 1;
}

.app-shell::before {
  content: "";
  position: absolute;
  inset: 24px;
  pointer-events: none;
  z-index: 0;
  border-radius: 26px;
  background:
    radial-gradient(70% 58% at 20% 30%, rgba(255, 255, 255, 0.2), transparent 72%),
    radial-gradient(34% 42% at 76% 68%, rgba(120, 207, 165, 0.11), transparent 74%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
}

.app-shell.collapsed {
  grid-template-columns: 88px minmax(0, 1fr);
}

@media (min-width: 1360px) {
  .app-shell {
    max-width: none;
    width: min(calc(1360px + (100vw - 1360px) * 0.75), 2100px);
  }
}

.app-sidebar {
  width: 100%;
  height: calc(100vh - 48px);
  position: sticky;
  top: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.24), rgba(233, 245, 255, 0.14));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 14px 30px rgba(78, 108, 138, 0.18);
  backdrop-filter: blur(22px) saturate(155%);
  -webkit-backdrop-filter: blur(22px) saturate(155%);
  overflow: visible;
  transition: padding 260ms ease;
  z-index: 2;
}

.app-sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.01) 46%, rgba(180, 214, 240, 0.06)),
    radial-gradient(120px 120px at 18% 8%, rgba(255, 255, 255, 0.12), transparent 72%);
  z-index: 0;
}

.app-sidebar > * {
  position: relative;
  z-index: 1;
}

.app-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.app-brand-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(137, 198, 241, 0.55);
  background: linear-gradient(145deg, rgba(139, 199, 255, 0.22), rgba(120, 207, 165, 0.2));
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  color: #27506d;
  flex-shrink: 0;
  overflow: hidden;
}

.app-brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.app-brand-word {
  white-space: nowrap;
  font-size: 16px;
  font-weight: 700;
  color: #1f2a37;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-sidebar-nav {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.app-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: #53687b;
  padding: 0 8px;
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.app-nav-item:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 199, 255, 0.66);
  background: linear-gradient(90deg, rgba(139, 199, 255, 0.28), rgba(120, 207, 165, 0.18));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.42);
  color: #1f5376;
}

.app-nav-item:hover .app-nav-icon {
  border-color: rgba(139, 199, 255, 0.7);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(232, 245, 255, 0.94));
}

.app-nav-item.active {
  border-color: rgba(139, 199, 255, 0.52);
  background: linear-gradient(90deg, rgba(139, 199, 255, 0.2), rgba(120, 207, 165, 0.14));
  color: #24506f;
}

.app-nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(195, 214, 232, 0.9);
  flex-shrink: 0;
}

.app-nav-icon svg {
  width: 16px;
  height: 16px;
  stroke: #4f6a83;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-nav-label {
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-sidebar-spacer {
  flex: 1;
}

.app-profile-menu-anchor {
  position: relative;
  width: 100%;
}

.app-theme-btn {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(188, 212, 232, 0.92);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.96), rgba(241, 249, 255, 0.9));
  color: #2d4d69;
  border-radius: 14px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.app-theme-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 199, 255, 0.68);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.99), rgba(226, 243, 255, 0.94));
}

.app-theme-btn:focus-visible,
.app-avatar-btn:focus-visible {
  outline: 2px solid rgba(88, 156, 209, 0.5);
  outline-offset: 2px;
}

.app-theme-btn-icon {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(139, 199, 255, 0.55);
  background: rgba(255, 255, 255, 0.74);
  color: #295476;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}

.app-theme-btn-label {
  font-size: 12px;
  line-height: 1;
}

.app-avatar-btn {
  width: 100%;
  min-height: 52px;
  border: 1px solid rgba(186, 209, 232, 0.84);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.95), rgba(241, 249, 255, 0.88));
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
  cursor: pointer;
  color: #1f2a37;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.app-avatar-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 199, 255, 0.68);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.99), rgba(226, 243, 255, 0.94));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.46);
}

.app-avatar-btn[aria-expanded="true"] {
  border-color: rgba(139, 199, 255, 0.78);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.99), rgba(220, 240, 255, 0.94));
}

.app-avatar-dot {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(139, 199, 255, 0.64), rgba(120, 207, 165, 0.56));
  border: 1px solid rgba(123, 190, 236, 0.7);
  flex-shrink: 0;
}

.app-avatar-label {
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  opacity: 1;
  transform: translateX(0);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-profile-menu-popover {
  position: absolute;
  left: calc(100% + 12px);
  bottom: 0;
  width: 240px;
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(180, 199, 219, 0.9);
  background: linear-gradient(165deg, rgba(250, 252, 255, 0.98), rgba(242, 247, 252, 0.95));
  box-shadow: 0 18px 30px rgba(59, 88, 118, 0.2);
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-6px) scale(0.97);
  transform-origin: left bottom;
  transition: opacity 170ms ease, transform 170ms ease, visibility 170ms ease;
  z-index: 40;
}

.app-profile-menu-popover::before {
  content: "";
  position: absolute;
  left: -6px;
  bottom: 19px;
  width: 11px;
  height: 11px;
  background: linear-gradient(165deg, rgba(250, 252, 255, 0.98), rgba(242, 247, 252, 0.95));
  border-left: 1px solid rgba(180, 199, 219, 0.9);
  border-bottom: 1px solid rgba(180, 199, 219, 0.9);
  transform: rotate(45deg);
}

.app-profile-menu-popover.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0) scale(1);
}

.app-profile-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: #27435c;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  padding: 10px 10px;
  transition: background 160ms ease, color 160ms ease;
}

.app-profile-menu-item:hover {
  background: linear-gradient(95deg, rgba(139, 199, 255, 0.16), rgba(120, 207, 165, 0.12));
  color: #1e4f70;
}

.app-profile-menu-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px;
}

.app-profile-menu-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(200, 154, 166, 0.78);
  background: linear-gradient(135deg, rgba(243, 205, 214, 0.9), rgba(236, 242, 248, 0.9));
  color: #5f3140;
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.app-profile-menu-user-meta {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.app-profile-menu-user-name {
  font-size: 13px;
  font-weight: 700;
  color: #1f2a37;
  line-height: 1.2;
}

.app-profile-menu-user-email {
  font-size: 12px;
  color: #617286;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-profile-menu-divider {
  width: 100%;
  height: 1px;
  background: rgba(191, 206, 222, 0.82);
}

.app-profile-menu-account {
  margin-top: 2px;
}

.app-profile-menu-title {
  font-size: 13px;
  font-weight: 600;
}

.app-profile-menu-logout {
  margin-top: 6px;
  color: #37495b;
  border-top: 1px solid rgba(182, 206, 229, 0.7);
  border-radius: 10px;
}

.app-profile-menu-logout:hover {
  color: #203042;
}

.app-profile-menu-icon {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.app-profile-menu-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-sidebar:not(.expanded) {
  padding: 16px 10px;
}

.app-sidebar:not(.expanded) .app-sidebar-head {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.app-sidebar:not(.expanded) .app-brand-cluster {
  justify-content: center;
  gap: 0;
}

.app-sidebar:not(.expanded) .app-brand-word,
.app-sidebar:not(.expanded) .app-nav-label,
.app-sidebar:not(.expanded) .app-avatar-label {
  display: none;
}

.app-sidebar:not(.expanded) .app-sidebar-nav {
  width: 100%;
  justify-items: center;
}

.app-sidebar:not(.expanded) .app-nav-item {
  justify-content: center;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  min-height: 44px;
  gap: 0;
  padding: 0;
  border-radius: 12px;
}

.app-sidebar:not(.expanded) .app-nav-icon {
  margin: 0 auto;
  width: 30px;
  height: 30px;
}

.app-sidebar:not(.expanded) .app-avatar-btn {
  justify-content: center;
  width: 100%;
  min-height: 46px;
  border-radius: 14px;
  padding: 0;
  margin: 0;
}

.app-sidebar:not(.expanded) .app-profile-menu-anchor {
  width: 46px;
  margin: 0 auto;
}

.app-sidebar:not(.expanded) .app-theme-btn {
  width: 46px;
  min-height: 46px;
  border-radius: 14px;
  justify-content: center;
  padding: 0;
  margin: 0 auto;
}

.app-sidebar:not(.expanded) .app-theme-btn-label {
  display: none;
}

.app-content {
  min-width: 0;
  position: relative;
  z-index: 1;
}

.app-content .container {
  max-width: min(920px, 100%);
  min-height: auto;
  margin: 0 auto;
  padding: 40px 10px 30px;
}

/* ==========================================================================
   21. Settings Page
   ========================================================================== */
.settings-view {
  display: grid;
  gap: 16px;
}

.settings-hero,
.settings-card {
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.86), rgba(236, 247, 255, 0.78));
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px) saturate(118%);
  -webkit-backdrop-filter: blur(10px) saturate(118%);
}

.settings-hero {
  padding: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.settings-hero-copy h2 {
  margin: 0;
  font-size: clamp(26px, 3.4vw, 34px);
  letter-spacing: -0.02em;
}

.settings-hero-copy p {
  margin: 8px 0 0;
  max-width: 56ch;
  color: var(--color-text-secondary);
}

.settings-goal-chip {
  min-width: 210px;
  border-radius: 14px;
  border: 1px solid rgba(169, 196, 222, 0.8);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(240, 248, 255, 0.88));
  padding: 12px 14px;
  text-align: right;
}

.settings-goal-chip-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-tertiary);
}

.settings-goal-chip strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: #2a4a64;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-card {
  padding: 18px;
  min-height: 320px;
}

.settings-card h3 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: #274760;
}

.settings-card-copy {
  margin: 8px 0 0;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.settings-goal-form {
  margin-top: 14px;
  gap: 12px;
}

.settings-field {
  display: grid;
  gap: 6px;
}

.settings-inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-view .setting-sublabel {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.settings-view .setting-input {
  width: 100%;
  min-height: 40px;
  border-radius: 11px;
}

.settings-view .setting-input-date {
  width: 100%;
}

.settings-view .setting-unit {
  min-width: 34px;
}

.settings-cta {
  min-height: 40px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(181, 205, 229, 0.8);
  color: var(--color-text-secondary);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(152, 198, 239, 0.84);
}

.settings-action-stack {
  margin-top: 14px;
  display: grid;
  gap: 10px;
}

.settings-warning-note {
  margin-top: 14px;
  border-radius: 12px;
  border: 1px solid rgba(239, 194, 123, 0.76);
  background: rgba(255, 249, 237, 0.9);
  color: #7a5f34;
  font-size: 13px;
  padding: 10px 12px;
}

.settings-history-card {
  min-height: 0;
}

.settings-history-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.settings-history-card .recent-goals {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.settings-history-card .goal-history-list {
  max-height: none;
  overflow: visible;
}

.settings-history-card .goal-history-item {
  border: 1px solid rgba(182, 207, 231, 0.72);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 255, 0.86));
  margin-bottom: 10px;
}

.settings-history-card .goal-history-item:last-child {
  margin-bottom: 0;
}

.settings-history-card .goal-history-item.active {
  border-color: rgba(139, 199, 255, 0.72);
  background: linear-gradient(95deg, rgba(139, 199, 255, 0.2), rgba(120, 207, 165, 0.14));
}

html[data-theme="dark"] {
  color-scheme: dark;
}

html[data-theme="dark"] body {
  color: #e5effa;
  background-color: #081018;
  background-image:
    linear-gradient(102deg, rgba(89, 168, 240, 0.22) 0%, rgba(89, 168, 240, 0.14) 34%, rgba(87, 203, 152, 0.12) 68%, rgba(87, 203, 152, 0.05) 100%),
    radial-gradient(42% 80% at 12% 26%, rgba(145, 185, 221, 0.14), transparent 74%),
    radial-gradient(28% 56% at 78% 22%, rgba(245, 194, 91, 0.11), transparent 70%);
}

html[data-theme="dark"] .app-shell::before {
  background: none;
}

html[data-theme="dark"] .app-sidebar {
  background: linear-gradient(165deg, rgba(19, 33, 49, 0.72), rgba(11, 22, 34, 0.62));
  border: 1px solid rgba(129, 175, 214, 0.26);
  box-shadow: inset 0 1px 0 rgba(201, 226, 248, 0.12), 0 18px 38px rgba(3, 7, 13, 0.6);
}

html[data-theme="dark"] .app-sidebar::before {
  background:
    linear-gradient(180deg, rgba(181, 215, 243, 0.08), rgba(181, 215, 243, 0.01) 46%, rgba(106, 150, 181, 0.04)),
    radial-gradient(120px 120px at 18% 8%, rgba(155, 201, 234, 0.12), transparent 72%);
}

html[data-theme="dark"] .app-brand-mark {
  border-color: rgba(122, 177, 220, 0.54);
  background: linear-gradient(145deg, rgba(89, 168, 240, 0.27), rgba(87, 203, 152, 0.23));
}

html[data-theme="dark"] .app-brand-word,
html[data-theme="dark"] .date-text,
html[data-theme="dark"] .total-display,
html[data-theme="dark"] .card-title,
html[data-theme="dark"] .entry-name,
html[data-theme="dark"] .entry-calories,
html[data-theme="dark"] .settings-hero-copy h2,
html[data-theme="dark"] .settings-card h3,
html[data-theme="dark"] .app-profile-menu-user-name {
  color: #edf5ff;
}

html[data-theme="dark"] .app-nav-item {
  color: #9eb4c7;
}

html[data-theme="dark"] .app-nav-item.active {
  border-color: rgba(112, 171, 216, 0.54);
  background: linear-gradient(90deg, rgba(79, 146, 198, 0.3), rgba(76, 170, 129, 0.21));
  color: #d9ebfc;
}

html[data-theme="dark"] .app-nav-item:hover .app-nav-icon {
  border-color: rgba(126, 177, 215, 0.68);
  background: linear-gradient(145deg, rgba(24, 41, 59, 0.95), rgba(18, 33, 49, 0.93));
}

html[data-theme="dark"] .app-nav-item.active .app-nav-icon {
  border-color: rgba(126, 177, 215, 0.66);
  background: linear-gradient(145deg, rgba(26, 44, 63, 0.95), rgba(19, 35, 52, 0.93));
}

html[data-theme="dark"] .app-nav-icon {
  background: rgba(20, 34, 50, 0.9);
  border-color: rgba(111, 152, 188, 0.52);
}

html[data-theme="dark"] .app-nav-icon svg {
  stroke: #9fc0dc;
}

html[data-theme="dark"] .app-avatar-btn {
  border-color: rgba(105, 151, 190, 0.5);
  background: linear-gradient(160deg, rgba(22, 37, 53, 0.95), rgba(17, 30, 44, 0.88));
  color: #d6e7f7;
}

html[data-theme="dark"] .app-avatar-dot {
  border-color: rgba(112, 173, 217, 0.55);
  background: linear-gradient(135deg, rgba(89, 168, 240, 0.66), rgba(87, 203, 152, 0.62));
}

html[data-theme="dark"] .app-theme-btn {
  border-color: rgba(104, 152, 190, 0.58);
  background: linear-gradient(160deg, rgba(20, 35, 51, 0.95), rgba(15, 27, 40, 0.9));
  color: #d6e7f7;
}

html[data-theme="dark"] .app-theme-btn-icon {
  border-color: rgba(116, 160, 197, 0.52);
  background: rgba(22, 35, 51, 0.88);
  color: #b9cee0;
}

html[data-theme="dark"] .app-avatar-label,
html[data-theme="dark"] .remaining-display,
html[data-theme="dark"] .progress-percent,
html[data-theme="dark"] .entry-time,
html[data-theme="dark"] .empty-message,
html[data-theme="dark"] .tooltip-subtitle,
html[data-theme="dark"] .tooltip-example,
html[data-theme="dark"] .tooltip-section ul,
html[data-theme="dark"] .goal-effective,
html[data-theme="dark"] .goal-created,
html[data-theme="dark"] .goal-date,
html[data-theme="dark"] .settings-card-copy,
html[data-theme="dark"] .app-profile-menu-user-email {
  color: #a3bad0;
}

html[data-theme="dark"] .header,
html[data-theme="dark"] .input-section,
html[data-theme="dark"] .entries-section,
html[data-theme="dark"] .calorie-summary,
html[data-theme="dark"] .metric-card,
html[data-theme="dark"] .dashboard-card,
html[data-theme="dark"] .entry-item,
html[data-theme="dark"] .autocomplete-dropdown,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .settings-hero,
html[data-theme="dark"] .settings-card,
html[data-theme="dark"] .settings-goal-chip,
html[data-theme="dark"] .settings-history-card .goal-history-item,
html[data-theme="dark"] .app-profile-menu-popover,
html[data-theme="dark"] .tooltip-content {
  border-color: rgba(101, 145, 180, 0.52);
  background: linear-gradient(150deg, rgba(17, 31, 46, 0.94), rgba(14, 25, 38, 0.9));
  box-shadow: 0 16px 36px rgba(4, 9, 16, 0.56);
}

html[data-theme="dark"] .app-profile-menu-popover::before {
  background: linear-gradient(150deg, rgba(17, 31, 46, 0.94), rgba(14, 25, 38, 0.9));
  border-left-color: rgba(101, 145, 180, 0.52);
  border-bottom-color: rgba(101, 145, 180, 0.52);
}

html[data-theme="dark"] .consistency-stat,
html[data-theme="dark"] .performance-stat,
html[data-theme="dark"] .chart-container,
html[data-theme="dark"] .legend-item {
  border-color: rgba(90, 133, 169, 0.52);
  background: linear-gradient(150deg, rgba(17, 31, 46, 0.94), rgba(14, 25, 38, 0.9));
}

html[data-theme="dark"] .range-label,
html[data-theme="dark"] .card-subtitle,
html[data-theme="dark"] .consistency-stat-label,
html[data-theme="dark"] .consistency-stat-subtext,
html[data-theme="dark"] .performance-stat-label,
html[data-theme="dark"] .performance-stat-subtext,
html[data-theme="dark"] .legend-item {
  color: #a3bad0;
}

html[data-theme="dark"] .consistency-stat-value.blue,
html[data-theme="dark"] .consistency-stat-value.neutral,
html[data-theme="dark"] .performance-stat-value,
html[data-theme="dark"] .performance-stat-value-good,
html[data-theme="dark"] .performance-stat-value-warn {
  color: #d9ebfc;
}

html[data-theme="dark"] .consistency-stat-value.green {
  color: #83ddb1;
}

html[data-theme="dark"] .consistency-stat-value.orange {
  color: #f3be8a;
}

html[data-theme="dark"] .time-range-btn {
  border-color: rgba(104, 152, 190, 0.58);
  background: linear-gradient(160deg, rgba(20, 35, 51, 0.95), rgba(15, 27, 40, 0.9));
  color: #b9cee0;
}

html[data-theme="dark"] .time-range-btn:hover {
  border-color: rgba(112, 171, 216, 0.54);
  color: #d9ebfc;
}

html[data-theme="dark"] .time-range-btn.active {
  border-color: rgba(112, 171, 216, 0.54);
  background: linear-gradient(90deg, rgba(79, 146, 198, 0.3), rgba(76, 170, 129, 0.21));
  color: #d9ebfc;
}

html[data-theme="dark"] .calorie-input,
html[data-theme="dark"] .edit-input,
html[data-theme="dark"] .setting-input,
html[data-theme="dark"] .setting-input-date {
  border-color: rgba(90, 133, 169, 0.52);
  background: rgba(17, 31, 45, 0.94);
  color: #e6f1fb;
}

html[data-theme="dark"] .calorie-input::placeholder {
  color: rgba(163, 186, 208, 0.72);
}

html[data-theme="dark"] .progress-bar {
  background-color: rgba(143, 174, 203, 0.2);
}

/* Tracking view hierarchy: section container -> control surface -> row surface */
html[data-theme="dark"] .header {
  background: linear-gradient(160deg, rgba(16, 32, 49, 0.95), rgba(12, 25, 39, 0.93));
  border-color: rgba(116, 163, 202, 0.58);
}

html[data-theme="dark"] .input-section {
  background: linear-gradient(160deg, rgba(16, 33, 51, 0.94), rgba(12, 25, 39, 0.92));
  border-color: rgba(117, 165, 204, 0.62);
  box-shadow: 0 14px 30px rgba(3, 8, 14, 0.5);
}

html[data-theme="dark"] .entries-section {
  background: linear-gradient(160deg, rgba(12, 26, 40, 0.95), rgba(8, 18, 30, 0.93));
  border-color: rgba(108, 155, 193, 0.6);
  box-shadow: 0 14px 30px rgba(3, 8, 14, 0.52);
}

html[data-theme="dark"] .calorie-input {
  background: linear-gradient(180deg, rgba(5, 14, 24, 0.99), rgba(7, 17, 28, 0.98));
  border-color: rgba(133, 187, 226, 0.72);
  box-shadow: inset 0 1px 0 rgba(190, 221, 245, 0.11), inset 0 -1px 0 rgba(54, 91, 122, 0.28);
}

html[data-theme="dark"] .calorie-input::placeholder {
  color: rgba(188, 210, 230, 0.84);
}

html[data-theme="dark"] .calorie-input:focus {
  border-color: rgba(144, 198, 238, 0.88);
  box-shadow: 0 0 0 3px rgba(91, 169, 255, 0.2), inset 0 1px 0 rgba(201, 227, 248, 0.12);
}

html[data-theme="dark"] .autocomplete-dropdown {
  background: linear-gradient(165deg, rgba(16, 32, 49, 0.98), rgba(13, 26, 40, 0.96));
  border-color: rgba(113, 161, 199, 0.62);
  box-shadow: 0 16px 30px rgba(3, 8, 14, 0.58);
}

html[data-theme="dark"] .autocomplete-item {
  background: linear-gradient(180deg, rgba(17, 34, 52, 0.96), rgba(13, 27, 42, 0.94));
  border-top: 0;
}

html[data-theme="dark"] .autocomplete-item:hover,
html[data-theme="dark"] .autocomplete-item.selected {
  background: linear-gradient(90deg, rgba(54, 102, 145, 0.72), rgba(46, 87, 124, 0.74));
}

html[data-theme="dark"] .autocomplete-name {
  color: #ecf5ff;
}

html[data-theme="dark"] .autocomplete-meta {
  color: #c8dcef;
}

html[data-theme="dark"] .entry-item {
  background: linear-gradient(180deg, rgba(20, 39, 59, 0.96), rgba(15, 31, 47, 0.94));
  border: 1px solid rgba(121, 170, 207, 0.64);
  box-shadow: inset 0 1px 0 rgba(194, 223, 247, 0.12), 0 5px 12px rgba(4, 10, 18, 0.36);
}

html[data-theme="dark"] .entry-item:hover,
html[data-theme="dark"] .entry-item.editing {
  border-color: rgba(151, 203, 239, 0.88);
  background: linear-gradient(180deg, rgba(24, 45, 67, 0.97), rgba(18, 36, 54, 0.95));
  box-shadow: inset 0 1px 0 rgba(206, 230, 250, 0.16), 0 10px 22px rgba(4, 10, 18, 0.55);
}

html[data-theme="dark"] .entry-delete {
  color: #8ea8c0;
}

html[data-theme="dark"] .entry-delete:hover {
  background-color: rgba(239, 110, 110, 0.18);
  color: #ffb0b0;
}

html[data-theme="dark"] .app-profile-menu-item {
  color: #c5d8ea;
}

html[data-theme="dark"] .app-profile-menu-item:hover {
  background: linear-gradient(95deg, rgba(89, 168, 240, 0.24), rgba(87, 203, 152, 0.14));
  color: #e4f0fc;
}

html[data-theme="dark"] .app-profile-menu-avatar {
  border-color: rgba(124, 165, 201, 0.54);
  background: linear-gradient(135deg, rgba(89, 168, 240, 0.28), rgba(87, 203, 152, 0.22));
  color: #d8e9f8;
}

html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .btn-ghost {
  border-color: rgba(90, 133, 169, 0.52);
  background: rgba(17, 31, 45, 0.94);
  color: #d6e7f7;
}

html[data-theme="dark"] .settings-hero {
  background: linear-gradient(155deg, rgba(18, 35, 54, 0.94), rgba(13, 27, 42, 0.92));
  border-color: rgba(113, 159, 198, 0.58);
}

html[data-theme="dark"] .settings-card {
  background: linear-gradient(155deg, rgba(14, 29, 45, 0.94), rgba(10, 22, 35, 0.92));
  border-color: rgba(102, 145, 181, 0.56);
}

html[data-theme="dark"] .settings-goal-chip,
html[data-theme="dark"] .settings-history-card .goal-history-item {
  background: linear-gradient(155deg, rgba(11, 24, 38, 0.96), rgba(8, 18, 29, 0.94));
  border-color: rgba(90, 133, 169, 0.62);
  box-shadow: inset 0 1px 0 rgba(173, 208, 238, 0.08);
}

html[data-theme="dark"] .settings-view .setting-sublabel,
html[data-theme="dark"] .settings-card-copy,
html[data-theme="dark"] .settings-hero-copy p,
html[data-theme="dark"] .goal-effective-date,
html[data-theme="dark"] .goal-date,
html[data-theme="dark"] .goal-created {
  color: #b8cde1;
}

html[data-theme="dark"] .settings-goal-chip-label {
  color: #9eb8d0;
}

html[data-theme="dark"] .settings-goal-chip strong {
  color: #e9f4ff;
}

html[data-theme="dark"] .settings-view .setting-input,
html[data-theme="dark"] .settings-view .setting-input-date,
html[data-theme="dark"] .settings-view .setting-input-wide {
  background: linear-gradient(180deg, rgba(8, 19, 31, 0.98), rgba(9, 21, 34, 0.96));
  border-color: rgba(102, 149, 189, 0.62);
  color: #e9f4ff;
  box-shadow: inset 0 1px 0 rgba(175, 208, 237, 0.08);
}

html[data-theme="dark"] .settings-view .setting-input::placeholder {
  color: rgba(168, 192, 214, 0.7);
}

html[data-theme="dark"] .settings-view .setting-input:focus,
html[data-theme="dark"] .settings-view .setting-input-date:focus {
  border-color: rgba(132, 187, 235, 0.82);
  box-shadow: 0 0 0 3px rgba(91, 169, 255, 0.22), inset 0 1px 0 rgba(196, 223, 246, 0.1);
}

html[data-theme="dark"] .settings-view .btn-secondary.settings-cta {
  border-color: rgba(116, 173, 217, 0.74);
  background: linear-gradient(95deg, rgba(53, 106, 149, 0.72), rgba(48, 90, 128, 0.76));
  color: #eaf4ff;
  box-shadow: inset 0 1px 0 rgba(194, 221, 245, 0.18);
}

html[data-theme="dark"] .settings-view .btn-secondary.settings-cta:hover {
  border-color: rgba(138, 194, 238, 0.9);
  background: linear-gradient(95deg, rgba(67, 122, 168, 0.8), rgba(54, 103, 146, 0.82));
}

html[data-theme="dark"] .settings-view .btn-ghost.settings-cta {
  border-color: rgba(96, 140, 176, 0.66);
  background: linear-gradient(95deg, rgba(20, 38, 57, 0.95), rgba(16, 31, 48, 0.94));
  color: #d5e7f8;
}

html[data-theme="dark"] .settings-view .btn-ghost.settings-cta:hover {
  border-color: rgba(120, 176, 221, 0.8);
  background: linear-gradient(95deg, rgba(25, 46, 68, 0.96), rgba(20, 39, 58, 0.95));
}

html[data-theme="dark"] .settings-warning-note {
  border-color: rgba(182, 149, 94, 0.62);
  background: linear-gradient(160deg, rgba(74, 58, 35, 0.42), rgba(62, 49, 31, 0.36));
  color: #ddc7a1;
  box-shadow: inset 0 1px 0 rgba(232, 206, 164, 0.12);
}

@media (max-width: 1024px) {
  :root {
    --mobile-edge-gap: 14px;
  }

  .app-shell,
  .app-shell.collapsed {
    grid-template-columns: 1fr;
    width: 100%;
    padding: 14px var(--mobile-edge-gap);
  }

  .app-shell::before {
    inset: 14px;
  }

  .app-sidebar {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: var(--mobile-edge-gap);
    right: var(--mobile-edge-gap);
    width: auto;
    max-width: none;
    z-index: 30;
    height: 58px;
    min-height: 58px;
    max-height: 58px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand nav theme avatar";
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 16px;
  }

  .app-sidebar-head {
    grid-area: brand;
    width: auto;
    justify-content: flex-start;
  }

  .app-brand-cluster {
    gap: 8px;
  }

  .app-brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .app-sidebar-nav {
    grid-area: nav;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 0;
  }

  .app-nav-item {
    justify-content: center;
    gap: 0;
    padding: 0;
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    min-height: 40px;
    border-radius: 10px;
  }

  .app-nav-icon {
    width: 26px;
    height: 26px;
  }

  .app-brand-word,
  .app-nav-label,
  .app-avatar-label,
  .app-theme-btn-label,
  .app-sidebar-spacer {
    display: none;
  }

  .app-theme-btn {
    grid-area: theme;
    width: 40px;
    min-height: 40px;
    border-radius: 12px;
    padding: 0;
    justify-content: center;
  }

  .app-avatar-btn {
    width: 100%;
    min-height: 40px;
    border-radius: 12px;
    padding: 0;
    justify-content: center;
  }

  .app-profile-menu-anchor {
    grid-area: avatar;
    width: 40px;
  }

  .app-avatar-dot {
    width: 22px;
    height: 22px;
  }

  .app-sidebar:not(.expanded) {
    padding: 8px 10px;
  }

  .app-sidebar:not(.expanded) .app-sidebar-head {
    width: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
  }

  .app-sidebar:not(.expanded) .app-brand-cluster {
    gap: 8px;
  }

  .app-sidebar:not(.expanded) .app-sidebar-nav {
    width: 100%;
    justify-items: initial;
    justify-content: center;
  }

  .app-sidebar:not(.expanded) .app-nav-item {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    min-height: 40px;
    border-radius: 10px;
  }

  .app-sidebar:not(.expanded) .app-nav-icon {
    width: 26px;
    height: 26px;
  }

  .app-sidebar:not(.expanded) .app-avatar-btn {
    width: 100%;
    min-height: 40px;
    border-radius: 12px;
    margin: 0;
  }

  .app-sidebar:not(.expanded) .app-theme-btn {
    width: 40px;
    min-height: 40px;
    border-radius: 12px;
    margin: 0;
  }

  .app-sidebar:not(.expanded) .app-profile-menu-anchor {
    width: 40px;
    margin: 0;
  }

  .app-profile-menu-popover {
    left: auto;
    right: 0;
    top: calc(100% + 10px);
    bottom: auto;
    transform: translateY(-6px) scale(0.97);
    transform-origin: top right;
  }

  .app-profile-menu-popover::before {
    left: auto;
    right: 14px;
    top: -6px;
    bottom: auto;
    border-left: 1px solid rgba(177, 206, 233, 0.86);
    border-top: 1px solid rgba(177, 206, 233, 0.86);
    border-bottom: 0;
  }

  .app-profile-menu-popover.open {
    transform: translateY(0) scale(1);
  }

  .app-content .container {
    max-width: 760px;
    padding-top: calc(78px + env(safe-area-inset-top));
  }

  .date-navigation {
    align-items: center;
    gap: 8px;
  }

  .date-display {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
  }

  .date-text {
    line-height: 1.2;
  }

  .date-status-row {
    justify-content: center;
  }

  .past-date-indicator {
    align-self: center;
    font-size: 11px;
    line-height: 1.2;
    padding: 2px 8px;
    color: #b8763d;
    background: rgba(255, 179, 126, 0.18);
    border: 1px solid rgba(239, 194, 123, 0.46);
    border-radius: 8px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .settings-card {
    min-height: 0;
  }

  .settings-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-goal-chip {
    width: 100%;
    text-align: left;
  }
}

@media print {
  .app-shell {
    grid-template-columns: 1fr !important;
    width: 100% !important;
  }

  .app-sidebar {
    display: none !important;
  }
}
