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

:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --bg: #f0f4ff;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.12);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
}

body {
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #e0e7ff 0%, #f0f4ff 30%, #fdf2f8 70%, #fce7f3 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ── App Container ── */
.app-container {
  max-width: 500px;
  margin: 0 auto;
  padding-bottom: 30px;
}

/* ── Header ── */
.app-header {
  position: relative;
  padding: 28px 20px 20px;
  overflow: hidden;
}

.header-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 40%, #ec4899 100%);
  border-radius: 0 0 32px 32px;
  opacity: 0.92;
}

.header-bg::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -30%;
  width: 200px;
  height: 200px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}

.header-bg::before {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -10%;
  width: 150px;
  height: 150px;
  background: rgba(255,255,255,.06);
  border-radius: 50%;
}

.header-content {
  position: relative;
  z-index: 1;
}

.app-title {
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -.5px;
  text-shadow: 0 2px 4px rgba(0,0,0,.1);
}

.app-subtitle {
  font-size: 14px;
  color: rgba(255,255,255,.85);
  margin-top: 4px;
  font-weight: 500;
}

/* ── Tab Bar ── */
.tab-bar {
  display: flex;
  gap: 6px;
  padding: 0 16px;
  margin-top: -12px;
  position: relative;
  z-index: 2;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex: 1;
  min-width: 0;
  padding: 12px 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  font-family: inherit;
}

.tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.tab:active { transform: scale(.95); }

/* ── Tab Content ── */
.tab-content {
  display: none;
  padding: 16px;
  animation: fadeSlideIn .3s ease;
}

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

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

/* ── Cards ── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}

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

.card-icon { font-size: 24px; }
.card-header h3 { font-size: 17px; font-weight: 700; }

/* ── Dashboard ── */
.dashboard-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dash-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: all .25s;
}

.dash-card:active { transform: scale(.98); }

.dash-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: 4px 0 0 4px;
}

.dash-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.dash-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
  flex-shrink: 0;
}

.dash-name {
  font-size: 18px;
  font-weight: 700;
}

.dash-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.dash-stat {
  text-align: center;
  padding: 10px 6px;
  background: var(--bg);
  border-radius: var(--radius-xs);
}

.dash-stat-value {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.dash-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

.dash-weight-info {
  margin-top: 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #fef3c7, #fef9c3);
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.dash-weight-info .trend-down { color: var(--success); font-size: 14px; }
.dash-weight-info .trend-up { color: var(--danger); font-size: 14px; }
.dash-weight-info .trend-flat { color: var(--text-muted); font-size: 14px; }

/* ── Member Selector ── */
.member-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding: 4px 0;
  -webkit-overflow-scrolling: touch;
}

/* ── Date Picker Bar ── */
.date-picker-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #fff;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.date-arrow {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
  font-family: inherit;
}

.date-arrow:active { background: #e2e8f0; color: var(--primary); }

.date-input {
  flex: 1;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  background: var(--bg);
  text-align: center;
  font-family: inherit;
  min-width: 0;
}

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

.date-today-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
  font-family: inherit;
}

.date-today-btn:active { transform: scale(.95); opacity: .9; }

.member-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 50px;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all .2s;
  flex-shrink: 0;
  font-family: inherit;
}

.member-chip.active {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(99,102,241,.2);
}

.member-chip:active { transform: scale(.95); }

.member-chip-emoji { font-size: 18px; }

/* ── Meal & Exercise Lists ── */
.meal-list, .exercise-list {
  max-height: 300px;
  overflow-y: auto;
}

.meal-item, .ex-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  background: var(--bg);
  margin-bottom: 6px;
  transition: all .2s;
}

.meal-item .meal-icon, .ex-item .ex-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.meal-item .meal-info, .ex-item .ex-info {
  flex: 1;
  min-width: 0;
}

.meal-item .meal-title, .ex-item .ex-title {
  font-weight: 600;
  font-size: 14px;
}

.meal-item .meal-meta, .ex-item .ex-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.meal-advice {
  font-size: 12px;
  color: #7c3aed;
  background: #f5f3ff;
  padding: 3px 8px;
  border-radius: 6px;
  margin-top: 4px;
  line-height: 1.4;
}

.meal-item .meal-cal, .ex-item .ex-cal {
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.meal-item .meal-cal.in { color: var(--warning); }
.ex-item .ex-cal.out { color: var(--success); }

.btn-del {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #fee2e2;
  color: var(--danger);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  font-family: inherit;
}

.btn-del:active { background: #fecaca; transform: scale(.9); }

.btn-edit {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: #eef2ff;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  font-family: inherit;
}

.btn-edit:active { background: #dbeafe; transform: scale(.9); }

/* ── Buttons ── */
.btn-add {
  display: block;
  width: 100%;
  padding: 12px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 12px;
  transition: all .2s;
  font-family: inherit;
}

.btn-add:hover { border-color: var(--primary); color: var(--primary); }
.btn-add:active { background: #eef2ff; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  box-shadow: 0 4px 12px rgba(99,102,241,.35);
  font-family: inherit;
}

.btn-primary:active { transform: scale(.96); opacity: .9; }
.btn-primary.full { width: 100%; margin-top: 8px; }

/* ── Weight Section ── */
.weight-input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.weight-input {
  flex: 1;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: border-color .2s;
  font-family: inherit;
  background: var(--bg);
}

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

.weight-chart-container {
  position: relative;
  height: 200px;
  margin-bottom: 16px;
  background: var(--bg);
  border-radius: var(--radius-xs);
  padding: 8px;
}

.weight-chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

.weight-history {
  max-height: 260px;
  overflow-y: auto;
}

.weight-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  background: var(--bg);
  margin-bottom: 6px;
}

.weight-row .w-date { font-size: 13px; color: var(--text-muted); }
.weight-row .w-val { font-size: 18px; font-weight: 800; }
.weight-row .w-change {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 50px;
}

.w-change.down { background: #d1fae5; color: #059669; }
.w-change.up { background: #fee2e2; color: #dc2626; }
.w-change.flat { background: #f1f5f9; color: #64748b; }

/* ── Family List ── */
.family-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.family-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius-xs);
  transition: all .2s;
}

.family-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  flex-shrink: 0;
}

.family-info { flex: 1; }
.family-info .fname { font-size: 16px; font-weight: 700; }
.family-info .fmeta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.family-del {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: #fee2e2;
  color: var(--danger);
  font-size: 14px;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.family-del:active { background: #fecaca; transform: scale(.9); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

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

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

.modal {
  background: #fff;
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85dvh;
  overflow-y: auto;
  animation: slideUp .3s ease;
  box-shadow: var(--shadow-lg);
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
}

.modal-header h3 { font-size: 18px; font-weight: 800; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.modal-body { padding: 0 20px 24px; }

/* ── Form ── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
  font-family: inherit;
  background: var(--bg);
  resize: vertical;
}

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

/* ── Chips ── */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 50px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.chip.active {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
}

.chip:active { transform: scale(.95); }

/* ── Emoji & Color Pickers ── */
.emoji-picker, .color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emoji-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn.active {
  border-color: var(--primary);
  background: #eef2ff;
  transform: scale(1.1);
}

.color-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
}

.color-btn.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px currentColor, var(--shadow);
  transform: scale(1.15);
}

/* ── Toast ── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: #1e293b;
  color: #fff;
  padding: 12px 24px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  transition: transform .35s cubic-bezier(.175,.885,.32,1.275);
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}

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

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Extra Animations ── */
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.pulse-anim { animation: pulse .6s ease; }

/* ── Image Upload ── */
.image-upload-area {
  position: relative;
}

.image-upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  cursor: pointer;
  transition: all .2s;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
}

.image-upload-btn:active {
  border-color: var(--primary);
  background: #eef2ff;
  color: var(--primary);
}

.upload-icon { font-size: 28px; }

.image-preview {
  position: relative;
  border-radius: var(--radius-xs);
  overflow: hidden;
  margin-top: 0;
}

.image-preview img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-xs);
}

.image-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.btn-analyze {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border: 2px solid var(--primary);
  border-radius: var(--radius-xs);
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}

.btn-analyze:active { transform: scale(.97); background: #dbeafe; }
.btn-analyze:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  animation: pulse 1.5s ease infinite;
}

/* Meal list with image */
.meal-item .meal-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  cursor: pointer;
  border: 2px solid var(--border);
}

/* Fullscreen image viewer */
.image-viewer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.image-viewer-overlay.show { display: flex; }

.image-viewer-overlay img {
  max-width: 95vw;
  max-height: 90vh;
  border-radius: 12px;
  object-fit: contain;
}

.image-viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
