/* === CSS Variables === */
:root {
  --color-primary: #22c55e;
  --color-primary-dark: #16a34a;
  --color-primary-light: #86efac;
  --color-primary-bg: #f0fdf4;
  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-warning: #f59e0b;
  --color-text: #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-text-light: #9ca3af;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-border-light: #f3f4f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 999px;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* === App Container === */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  position: relative;
}

/* === Header === */
.app-header {
  background: linear-gradient(135deg, var(--color-primary), #10b981);
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top, 0px));
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(34, 197, 94, 0.25);
}

.header-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  flex: 1;
}

.header-date {
  font-size: 0.8rem;
  opacity: 0.85;
  font-weight: 500;
  background: rgba(255,255,255,0.15);
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

/* === Main Content === */
.main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
  overflow-y: auto;
}

.tab-panel {
  display: none;
  animation: fadeSlideIn 0.3s ease;
}

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

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

/* === Section Header === */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  transition: all var(--transition);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

.btn-secondary {
  background: var(--color-primary-bg);
  color: var(--color-primary-dark);
  border: 1.5px solid var(--color-primary-light);
}

.btn-secondary:hover {
  background: #dcfce7;
}

.btn-outline {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1.5px solid var(--color-border);
}

.btn-outline:hover {
  background: var(--color-bg);
  border-color: var(--color-text-light);
}

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

.btn-danger:hover {
  background: #fee2e2;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-xs {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.btn-lg {
  padding: 14px 20px;
  font-size: 1rem;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  padding: 10px;
  min-width: 40px;
}

.btn-icon-only {
  padding: 8px;
  background: transparent;
  color: var(--color-text-secondary);
  border-radius: var(--radius-full);
}

.btn-icon-only:hover {
  background: var(--color-border-light);
}

/* === Inputs === */
.input, .select {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  transition: all var(--transition);
  outline: none;
  -webkit-appearance: none;
}

.input:focus, .select:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

.textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

/* === Meal List === */
.meal-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.meal-group {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--color-border-light);
}

.meal-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #f9fafb, #f3f4f6);
  border-bottom: 1px solid var(--color-border-light);
}

.meal-group-title {
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.meal-group-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.meal-group-icon.breakfast { background: #fef3c7; }
.meal-group-icon.lunch { background: #fee2e2; }
.meal-group-icon.dinner { background: #ede9fe; }
.meal-group-icon.snack { background: #e0f2fe; }

.meal-items {
  padding: 4px 16px;
}

.meal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border-light);
}

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

.meal-item-name {
  font-size: 0.9rem;
  font-weight: 500;
}

.meal-item-actions {
  display: flex;
  gap: 4px;
}

.meal-item-remove {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition);
}

.meal-item-remove:active {
  transform: scale(0.9);
}

.meal-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--color-text-light);
  font-size: 0.85rem;
}

/* === Add Food Section === */
.add-food-section {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  margin-bottom: 12px;
}

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

.add-food-row .input {
  flex: 1;
  min-width: 0;
}

.add-food-row .select {
  width: 80px;
  flex-shrink: 0;
  padding: 10px 24px 10px 10px;
  font-size: 0.8rem;
}

.daily-summary {
  background: linear-gradient(135deg, var(--color-primary-bg), #ecfdf5);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--color-primary-dark);
  font-weight: 500;
  border: 1px solid var(--color-primary-light);
}

/* === Body Log Sections === */
.log-section {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  margin-bottom: 10px;
}

.log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.log-icon {
  font-size: 1.1rem;
}

.log-title {
  font-weight: 700;
  font-size: 0.9rem;
}

.log-unit {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-left: auto;
}

.log-subtitle {
  font-size: 0.75rem;
  color: var(--color-text-light);
  margin-left: 4px;
  font-weight: 400;
}

.log-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.log-input-row .input {
  flex: 1;
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.log-empty {
  text-align: center;
  padding: 8px;
  color: var(--color-text-light);
  font-size: 0.8rem;
}

.log-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.log-entry-time {
  color: var(--color-text-light);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  min-width: 42px;
}

.log-entry-value {
  flex: 1;
  font-weight: 500;
}

.log-entry-del {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-text-light);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.log-entry-del:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* === Water Section === */
.water-section {
  margin-bottom: 16px;
}

.water-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
}

.water-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.water-bottle {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e0f2fe, #bae6fd);
  border-radius: var(--radius-md);
  color: #0284c7;
}

.water-total {
  flex: 1;
}

.water-total-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-text);
  line-height: 1;
}

.water-total-unit {
  font-size: 0.8rem;
  color: var(--color-text-light);
  margin-left: 4px;
}

.water-target {
  font-size: 0.75rem;
  color: var(--color-primary);
  font-weight: 600;
  background: var(--color-primary-bg);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.water-bar-wrapper {
  height: 8px;
  background: var(--color-border-light);
  border-radius: var(--radius-full);
  margin-bottom: 14px;
  overflow: hidden;
}

.water-bar {
  height: 100%;
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: var(--radius-full);
  transition: width 0.5s ease;
  min-width: 0;
}

.water-quick-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.water-log-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
}

.water-log-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.water-log-del {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-text-light);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
}

.water-log-del:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* === History List === */
.history-section {
  margin-bottom: 16px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  transition: all var(--transition);
}

.history-item:hover {
  box-shadow: var(--shadow-md);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-date {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-primary-dark);
}

.history-delete {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-text-light);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.1rem;
  transition: all var(--transition);
}

.history-delete:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.history-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 8px;
}

.history-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
}

.history-stat-value {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-text);
}

.history-stat-label {
  font-size: 0.7rem;
  color: var(--color-text-light);
  margin-top: 2px;
}

.history-notes {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  line-height: 1.5;
  padding-top: 8px;
  border-top: 1px solid var(--color-border-light);
}

/* === Trend Chart === */
.trend-section {
  margin-bottom: 12px;
}

.trend-chart {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  min-height: 180px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  overflow-x: auto;
}

.trend-placeholder {
  color: var(--color-text-light);
  font-size: 0.9rem;
  align-self: center;
}

.trend-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.trend-bar {
  width: 32px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: linear-gradient(180deg, var(--color-primary), var(--color-primary-light));
  min-height: 4px;
  transition: height 0.5s ease;
}

.trend-bar-value {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-text-secondary);
}

.trend-bar-date {
  font-size: 0.65rem;
  color: var(--color-text-light);
  writing-mode: vertical-lr;
  margin-top: 4px;
}

/* === Bottom Navigation === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-light);
  padding: 6px 16px;
  padding-bottom: calc(6px + var(--safe-bottom));
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-light);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 500;
  transition: all var(--transition);
  border-radius: var(--radius-md);
}

.nav-item.active {
  color: var(--color-primary);
  font-weight: 700;
}

.nav-item svg {
  transition: all var(--transition);
}

/* === Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recipe-categories {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.recipe-cat-btn {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  border: 1.5px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.recipe-cat-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.recipe-item {
  padding: 12px;
  border: 1.5px solid var(--color-border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
}

.recipe-item:hover {
  border-color: var(--color-primary-light);
  background: var(--color-primary-bg);
}

.recipe-item:active {
  transform: scale(0.98);
}

.recipe-item-emoji {
  font-size: 1.3rem;
}

/* === Toast === */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: var(--color-text);
  color: white;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 300;
  transition: transform 0.3s ease;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* === Responsive: Desktop === */
@media (min-width: 481px) {
  .app-container {
    border-left: 1px solid var(--color-border-light);
    border-right: 1px solid var(--color-border-light);
    box-shadow: 0 0 40px rgba(0,0,0,0.05);
  }

  .bottom-nav {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .modal {
    border-radius: var(--radius-xl);
    max-height: 80vh;
    margin-bottom: 40px;
  }
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-full);
}

/* === Utility === */
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-center { text-align: center; }
