/* ============================================
   Baby Milk Tracker — Light Theme Stylesheet
   ============================================ */

/* --- Design Tokens (CSS Custom Properties) --- */
:root {
  --primary: #4FC3F7;
  --secondary: #81C784;
  --tertiary: #F48FB1;
  --bg: #F8FAFE;
  --card: #FFFFFF;
  --text: #333333;
  --text-light: #888888;
  --border: #E8EDF2;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Prevent iOS zoom on input focus (font-size >= 16px) */
input[type="number"],
input[type="text"],
input[type="date"],
input[type="time"] {
  font-size: 16px;
}

/* Prevent iOS inputs from overflowing containers */
input[type="date"],
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  max-width: 100%;
  min-width: 0;
}

/* --- Layout --- */
.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 80px; /* space for fixed tab bar */
}

/* --- App Header --- */
.app-header {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 0;
  text-align: center;
}

.app-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

/* --- Bottom Tab Bar --- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  background: white;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 100;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.tab-btn {
  flex: 1;
  height: 56px;
  border: none;
  background: transparent;
  font-size: 0.85rem;
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  color: var(--primary);
  font-weight: 600;
}

.tab-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.tab-label {
  font-size: 0.75rem;
  line-height: 1;
}

/* --- Tab Content Panels --- */
.tab-content {
  display: none;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 80px;
  overflow: hidden;
}

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

/* --- Cards --- */
.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 16px;
  margin-bottom: 12px;
  animation: fadeIn 0.2s ease-out;
}

.card-header {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.card-header-info {
  flex: 1;
}

.card-date {
  font-weight: 700;
  font-size: 1rem;
}

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

.card-details {
  display: none;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.card.expanded .card-details {
  display: block;
}

/* --- Chevron (expand/collapse) --- */
.chevron {
  transition: transform 0.2s;
}

.card.expanded .chevron {
  transform: rotate(180deg);
}

/* --- Banner --- */
.banner {
  margin: 12px 0 0;
  border-radius: 16px;
  overflow: hidden;
}

.banner-img {
  display: block;
  width: 100%;
  height: auto;
}

/* --- Today Summary --- */
.today-summary {
  text-align: center;
  padding: 24px 0;
}

.total-label {
  font-size: 0.9rem;
  color: var(--text-light);
  margin: 0 0 4px;
}

.total-amount {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  line-height: 1.2;
}

.today-total {
  /* Inherits from .total-amount parent */
}

.today-date {
  font-size: 0.9rem;
  color: var(--text-light);
}

/* --- Quick Input Form --- */
.quick-input {
  margin: 16px 0;
}

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

/* Also support spec class name */
.input-group {
  display: flex;
  gap: 12px;
  margin: 16px 0;
}

.input-row input,
.input-group input {
  flex: 1;
  height: 48px;
  border-radius: 12px;
  border: 2px solid var(--border);
  padding: 0 16px;
  font-size: 1.2rem;
  outline: none;
  transition: border-color 0.2s;
  background: var(--card);
  color: var(--text);
}

.input-row input:focus,
.input-group input:focus {
  border-color: var(--primary);
}

/* Input unit suffix (e.g., "ml") */
.input-unit {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 0.9rem;
  pointer-events: none;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  min-height: 48px;
  padding: 0 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

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

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

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

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

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

/* Record button — full-width primary CTA */
.btn-record {
  width: 100%;
  min-height: 52px;
  font-size: 1.1rem;
  background: var(--primary);
  color: white;
}

/* Full-width block button */
.btn-block {
  width: 100%;
  min-height: 52px;
  font-size: 1.05rem;
}

/* --- Week Navigation --- */
.week-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}

.week-nav {
  background: none;
  border: none;
  font-size: 0.9rem;
  color: var(--primary);
  cursor: pointer;
  padding: 8px;
  -webkit-tap-highlight-color: transparent;
  font-weight: 500;
}

.week-nav:disabled {
  color: var(--border);
  cursor: default;
}

/* Spec-based week-nav layout (alternative structure) */
.week-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
}

.week-label,
#week-label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95rem;
}

/* --- Section Title --- */
.section-title {
  font-size: 0.9rem;
  color: var(--text-light);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --- Day Cards Container (weekly history) --- */
.day-cards-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- Feeding Detail Row --- */
.feeding-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.95rem;
}

.feeding-time {
  color: var(--text-light);
}

.feeding-amount {
  font-weight: 600;
}

/* --- Growth Form --- */
.growth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 16px;
  margin: 16px 0;
}

.growth-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.growth-form .form-group.full-width {
  grid-column: 1 / -1;
}

.growth-form label {
  font-size: 0.85rem;
  color: var(--text-light);
}

.growth-form input {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  border: 2px solid var(--border);
  padding: 0 12px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
  background: var(--bg);
  color: var(--text);
}

.growth-form input[type="date"] {
  font-size: 1rem;
}

.growth-form input:focus {
  border-color: var(--primary);
}

.growth-form .btn,
.growth-form .btn-primary {
  width: 100%;
}

/* --- Growth Dashboard --- */
.growth-dashboard {
  margin: 16px 0;
}

.growth-dashboard .dashboard-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dashboard-card {
  text-align: center;
  padding: 20px 12px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  min-width: 0;
  overflow: hidden;
}

.dashboard-value {
  font-size: 1.6rem;
  font-weight: 700;
  word-break: break-all;
}

.dashboard-value small {
  font-size: 0.7em;
  font-weight: 400;
  color: var(--text-light);
}

.dashboard-label {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 4px;
}

.dashboard-delta {
  font-size: 0.8rem;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 8px;
  display: inline-block;
}

.delta-positive {
  background: #E8F5E9;
  color: #2E7D32;
}

.delta-negative {
  background: #FFEBEE;
  color: #C62828;
}

/* --- Growth History --- */
.growth-history {
  margin-top: 16px;
}

.growth-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 0.9rem;
}

.growth-row span {
  flex: 1;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.growth-row span:first-child {
  text-align: left;
}

.growth-row .delete-btn {
  flex: 0 0 auto;
}

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

/* --- Data Management --- */
.data-actions,
.data-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 0;
}

.btn-action {
  width: 100%;
  min-height: 56px;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 16px;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  padding: 0 20px;
  -webkit-tap-highlight-color: transparent;
}

.btn-action:active {
  transform: scale(0.96);
  background: var(--bg);
}

.btn-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.data-btn {
  width: 100%;
  min-height: 56px;
  font-size: 1.05rem;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-light);
  font-size: 0.95rem;
}

/* --- Delete Button --- */
.delete-btn {
  background: none;
  border: none;
  color: #EF5350;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.delete-btn:hover {
  background: #FFEBEE;
}

/* --- Weekly Bar Chart --- */
.weekly-chart {
  margin-bottom: 16px;
}

.chart-title {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 12px;
  font-weight: 500;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 140px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.bar-value {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-bottom: 4px;
  font-weight: 600;
}

.bar-fill {
  width: 100%;
  border-radius: 6px 6px 0 0;
  background: var(--primary);
  min-height: 2px;
  transition: height 0.3s ease;
}

.bar-col.today .bar-fill {
  background: var(--tertiary);
}

.bar-label {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 6px;
  white-space: nowrap;
}

/* --- Weekly History Section --- */
.weekly-history {
  margin-top: 16px;
}

/* --- Record Main Button --- */
.btn-record-main {
  margin-top: 8px;
  font-size: 1.15rem;
  min-height: 56px;
}

.btn-history-entry {
  margin-top: 12px;
  font-size: 0.95rem;
  min-height: 44px;
  color: var(--text-light);
  border-color: var(--border);
}

/* --- Modal (bottom sheet) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-sheet {
  background: white;
  width: 100%;
  max-width: 480px;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.modal-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.modal-field label {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
}

#feeding-form input[type="number"] {
  width: 100%;
  height: 56px;
  border-radius: 14px;
  border: 2px solid var(--border);
  padding: 0 20px;
  font-size: 1.4rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  background: var(--bg);
  color: var(--text);
}

#feeding-form input[type="time"] {
  width: 100%;
  height: 56px;
  border-radius: 14px;
  border: 2px solid var(--border);
  padding: 0 12px;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  background: var(--bg);
  color: var(--text);
}

#feeding-form input:focus {
  border-color: var(--primary);
}

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

/* --- History Page (full-screen overlay) --- */
.page-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 150;
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.2s ease-out;
}

.page-overlay[hidden] {
  display: none;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

.page-back {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--primary);
  cursor: pointer;
  padding: 4px 8px;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}

.page-title {
  font-size: 1rem;
  font-weight: 600;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

/* --- Animations --- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  animation: fadeIn 0.2s ease-out;
}

/* --- Login Gate --- */
.login-gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-gate[hidden] {
  display: none;
}

.login-card {
  text-align: center;
  max-width: 320px;
  width: 100%;
}

.login-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.login-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 24px;
}

.login-form input[type="text"] {
  width: 100%;
  height: 52px;
  border-radius: 14px;
  border: 2px solid var(--border);
  padding: 0 20px;
  font-size: 1.1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
  background: var(--card);
  color: var(--text);
}

.login-form input[type="text"]:focus {
  border-color: var(--primary);
}

.login-error {
  color: #EF5350;
  font-size: 0.9rem;
  margin: 8px 0;
}

.login-error[hidden] {
  display: none;
}

.login-form .btn {
  margin-top: 16px;
}

/* --- Today's Feedings List --- */
.today-feedings-card {
  margin-top: 16px;
}

.today-feedings-header {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.today-feedings-card .feeding-row:last-child {
  border-bottom: none;
}

/* --- Supplement (AD/D3) — Modal Options --- */
.supplement-options {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.supplement-option {
  flex: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.supplement-option input[type="radio"] {
  display: none;
}

.supplement-option-label {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 64px;
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  transition: all 0.2s;
}

.supplement-option input[type="radio"]:checked + .supplement-option-label {
  border-color: var(--primary);
  background: #E1F5FE;
  color: var(--primary);
}

/* --- Supplement Tag (in record lists) --- */
.supplement-tag {
  display: inline-block;
  padding: 2px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

.supplement-ad {
  background: #FFF3E0;
  color: #E65100;
}

.supplement-d3 {
  background: #E8F5E9;
  color: #2E7D32;
}

/* --- AD/D3 Add Button (today header) --- */
.btn-supplement-add {
  background: none;
  border: 1.5px solid var(--primary);
  color: var(--primary);
  border-radius: 8px;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}

.btn-supplement-add:active {
  background: #E1F5FE;
}

/* --- Card Actions Row (history) --- */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.card-actions .btn-backfill {
  flex: 1;
  margin-top: 0;
}

.btn-supplement-history {
  color: var(--secondary);
  border-color: var(--secondary);
}

/* --- Backfill Button in History --- */
.btn-backfill {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 10px 0;
  border: 2px dashed var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}

.btn-backfill:active {
  background: var(--bg);
}

/* --- Update Toast --- */
.update-toast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.update-toast[hidden] {
  display: none;
}

.update-btn {
  background: white;
  color: var(--primary);
  border: none;
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
