/* ═══════════════════════════════════════
   NUTRISYNC — DARK MOBILE-FIRST DESIGN
   ═══════════════════════════════════════ */

:root {
  --bg: #0a0a0f;
  --bg2: #11111a;
  --bg3: #18182a;
  --surface: #1c1c2e;
  --surface2: #22223a;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);

  --accent: #7c6af7;
  --accent2: #a78bfa;
  --accent-glow: rgba(124,106,247,0.25);
  --green: #34d399;
  --green-glow: rgba(52,211,153,0.2);
  --red: #f87171;
  --yellow: #fbbf24;

  --text: #f0f0f8;
  --text2: #a0a0c0;
  --text3: #606080;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;

  --header-h: 110px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
  height: 100%;
  background: var(--bg);
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ── */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100dvh; }

/* ══════════════════════════════════════
   AUTH SCREEN
══════════════════════════════════════ */
#auth-screen {
  position: relative;
  justify-content: center;
  align-items: center;
  padding: 24px;
  overflow: hidden;
}

.auth-bg {
  position: absolute; inset: 0; pointer-events: none;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.35;
}
.orb-1 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  top: -80px; right: -80px;
  animation: orb-float 6s ease-in-out infinite alternate;
}
.orb-2 {
  width: 250px; height: 250px;
  background: radial-gradient(circle, #7c3aed 0%, transparent 70%);
  bottom: -60px; left: -60px;
  animation: orb-float 8s ease-in-out infinite alternate-reverse;
}
@keyframes orb-float {
  from { transform: translateY(0px) scale(1); }
  to   { transform: translateY(20px) scale(1.08); }
}

.auth-container {
  position: relative; z-index: 1;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 32px;
  padding-top: var(--safe-top);
}

.auth-logo {
  text-align: center;
}
.logo-icon {
  font-size: 48px;
  display: block; margin-bottom: 8px;
  filter: drop-shadow(0 0 20px var(--accent));
  animation: pulse-glow 3s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%,100% { filter: drop-shadow(0 0 16px var(--accent)); }
  50%      { filter: drop-shadow(0 0 32px var(--accent2)); }
}

.auth-logo h1 {
  font-family: 'Syne', sans-serif;
  font-size: 36px; font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--text) 0%, var(--accent2) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-logo p {
  color: var(--text2); font-size: 14px; margin-top: 6px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 28px 24px;
  display: flex; flex-direction: column; gap: 14px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4), 0 0 0 1px var(--border);
}

.auth-error {
  background: rgba(248,113,113,0.12);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-xs);
  padding: 10px 14px;
  font-size: 13px; color: var(--red);
  text-align: center;
}

/* ── INPUTS ── */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder { color: var(--text3); }
input.readonly { opacity: 0.5; cursor: not-allowed; }

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a0a0c0' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  cursor: pointer;
}

/* ── BUTTONS ── */
.btn-primary {
  width: 100%; padding: 15px;
  background: linear-gradient(135deg, var(--accent) 0%, #6d5de8 100%);
  border: none; border-radius: var(--radius-sm);
  color: #fff; font-family: 'Syne', sans-serif;
  font-size: 15px; font-weight: 700;
  letter-spacing: 0.3px; cursor: pointer;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:active { transform: scale(0.97); opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  width: 100%; padding: 14px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-family: 'DM Sans', sans-serif;
  font-size: 15px; cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn-ghost:active { background: var(--bg3); }

.btn-danger {
  padding: 14px 20px;
  background: rgba(248,113,113,0.12);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: var(--radius-sm);
  color: var(--red);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; cursor: pointer;
  transition: background 0.2s;
}
.btn-danger:active { background: rgba(248,113,113,0.2); }

.btn-icon {
  background: none; border: none;
  color: var(--text2); font-size: 20px;
  cursor: pointer; padding: 8px;
  border-radius: 8px;
  transition: color 0.2s;
  line-height: 1;
}
.btn-icon:active { color: var(--text); }

/* ══════════════════════════════════════
   APP HEADER
══════════════════════════════════════ */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}

.header-logo {
  font-family: 'Syne', sans-serif;
  font-size: 18px; font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}

.header-actions {
  display: flex; align-items: center; gap: 8px;
}

.header-date {
  font-size: 12px; color: var(--text3);
  font-weight: 500;
}

/* USER TABS */
.user-tabs {
  display: flex; gap: 8px;
  padding: 10px 16px 12px;
}

.user-tab {
  flex: 1; display: flex; align-items: center;
  justify-content: center; gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.user-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.user-tab:not(.active):active { background: var(--surface2); }

.tab-avatar {
  width: 22px; height: 22px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}

/* ══════════════════════════════════════
   DIET VIEW
══════════════════════════════════════ */
.diet-view {
  flex: 1;
  padding: 16px 16px calc(32px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 14px;
}

/* LOADING */
.loading-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 60px 0;
  color: var(--text3); font-size: 14px;
}
.spinner {
  width: 32px; height: 32px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* SUMMARY CARD */
.summary-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--bg3) 100%);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.summary-kcal {
  display: flex; align-items: baseline;
  justify-content: center; gap: 4px;
  font-family: 'Syne', sans-serif;
}
#summary-checked-kcal { font-size: 36px; font-weight: 800; color: var(--accent2); }
.summary-sep { font-size: 22px; color: var(--text3); }
#summary-total-kcal { font-size: 22px; font-weight: 700; color: var(--text2); }
.summary-unit { font-size: 13px; color: var(--text3); font-weight: 500; margin-left: 4px; }

.summary-bar-wrap {
  height: 5px; background: var(--bg);
  border-radius: 99px; margin-top: 14px;
  overflow: hidden;
}
.summary-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 99px;
  transition: width 0.5s ease;
}

.day-complete {
  margin-top: 12px;
  font-size: 14px; color: var(--green);
  font-weight: 500;
  animation: fade-in 0.4s ease;
}

/* ── MEAL CARD ── */
.meal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.3s;
}
.meal-card.complete {
  border-color: rgba(52,211,153,0.3);
}

.meal-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.meal-check-all {
  width: 22px; height: 22px; flex-shrink: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.meal-title-wrap { flex: 1; min-width: 0; }
.meal-name {
  font-family: 'Syne', sans-serif;
  font-size: 15px; font-weight: 700;
  color: var(--text); letter-spacing: -0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meal-kcal {
  font-size: 12px; color: var(--text3); margin-top: 2px;
}

.meal-actions {
  display: flex; gap: 4px;
}
.meal-action-btn {
  background: none; border: none;
  color: var(--text3); font-size: 18px;
  cursor: pointer; padding: 6px;
  border-radius: 8px;
  transition: color 0.2s, background 0.15s;
  line-height: 1;
}
.meal-action-btn:active { color: var(--text); background: var(--bg3); }

/* FOOD LIST */
.food-list {
  border-top: 1px solid var(--border);
}

.food-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.food-item:last-child { border-bottom: none; }
.food-item:active { background: var(--bg3); }
.food-item.checked { opacity: 0.55; }
.food-item.checking {
  animation: check-bounce 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes check-bounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(0.95); }
  70%  { transform: scale(1.02); }
  100% { transform: scale(1); }
}

.food-checkbox {
  width: 20px; height: 20px; flex-shrink: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.food-info { flex: 1; min-width: 0; }
.food-name {
  font-size: 14px; color: var(--text); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.food-details {
  font-size: 12px; color: var(--text3); margin-top: 2px;
}

.food-kcal {
  font-size: 13px; font-weight: 600;
  color: var(--accent2); flex-shrink: 0;
  font-family: 'Syne', sans-serif;
}

.food-edit-btn {
  background: none; border: none;
  color: var(--text3); font-size: 16px;
  cursor: pointer; padding: 4px 8px;
  border-radius: 6px; flex-shrink: 0;
  transition: color 0.2s;
}
.food-edit-btn:active { color: var(--text); }

/* ADD FOOD ROW */
.add-food-row {
  padding: 11px 16px;
  background: var(--bg3);
}
.btn-add-food {
  width: 100%; padding: 10px;
  background: none;
  border: 1px dashed var(--border2);
  border-radius: var(--radius-xs);
  color: var(--text3);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-add-food:active { border-color: var(--accent); color: var(--accent); }

/* MEAL COMPLETE BADGE */
.meal-complete-badge {
  display: inline-block;
  background: var(--green-glow);
  color: var(--green);
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px;
  margin-left: 8px;
}

/* ADD MEAL */
.add-meal-wrap { padding-top: 4px; }
.btn-add-meal {
  width: 100%; padding: 14px;
  background: var(--surface);
  border: 1px dashed var(--border2);
  border-radius: var(--radius);
  color: var(--text2);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.btn-add-meal:active { border-color: var(--accent); color: var(--accent); background: var(--bg3); }

/* ══════════════════════════════════════
   MODALS
══════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: flex-end;
  padding: 0;
  animation: overlay-in 0.2s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: calc(16px + var(--safe-bottom));
  animation: modal-up 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  border: 1px solid var(--border2);
  border-bottom: none;
  max-height: 90dvh;
  overflow-y: auto;
}
@keyframes modal-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
}
.modal-header h3 {
  font-family: 'Syne', sans-serif;
  font-size: 18px; font-weight: 700;
  color: var(--text);
}
.modal-close {
  background: var(--bg3); border: none;
  color: var(--text2); font-size: 14px;
  cursor: pointer; padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.2s;
}
.modal-close:active { background: var(--surface2); }

.modal-body {
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-body label {
  font-size: 12px; color: var(--text3);
  font-weight: 500; letter-spacing: 0.5px;
  text-transform: uppercase;
  display: block; margin-bottom: -6px;
}

.form-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { margin-bottom: 0; }

.quick-meals {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-bottom: 4px;
}
.quick-meal-btn {
  padding: 12px 8px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px; cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.quick-meal-btn:active,
.quick-meal-btn.selected {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent2);
}

.modal-footer {
  display: flex; gap: 10px;
  padding: 0 20px;
}

/* ══════════════════════════════════════
   TOAST
══════════════════════════════════════ */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 300;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 99px;
  padding: 12px 22px;
  font-size: 14px; color: var(--text);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  white-space: nowrap;
  animation: toast-in 0.3s ease;
}
.toast.hidden { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ══════════════════════════════════════
   UTILS
══════════════════════════════════════ */
.hidden { display: none !important; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.meal-card { animation: fade-in 0.3s ease both; }

/* ══════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
