@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;500;600;700;800&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;1,9..40,300&display=swap');

:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface2: #1c1c27;
  --border: #2a2a3d;
  --accent: #7c6cfc;
  --accent2: #fc6c8f;
  --accent3: #6cfcb8;
  --text: #eeeef5;
  --text-muted: #7a7a9a;
  --text-dim: #4a4a6a;
  --success: #6cfcb8;
  --warning: #fcb86c;
  --danger: #fc6c6c;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --glow: 0 0 40px rgba(124,108,252,0.15);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── NOISE TEXTURE OVERLAY ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  opacity: 0.4;
}

/* ── TYPOGRAPHY ── */
h1, h2, h3, h4 { font-family: 'Syne', sans-serif; font-weight: 700; line-height: 1.2; }

/* ── LAYOUT ── */
.page { min-height: 100vh; display: flex; flex-direction: column; }

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 24px; }

/* ── NAVBAR ── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

.navbar .container { display: flex; align-items: center; justify-content: space-between; }

.nav-brand {
  font-family: 'Syne', sans-serif;
  font-weight: 800; font-size: 1.25rem;
  color: var(--text);
  text-decoration: none;
  display: flex; align-items: center; gap: 10px;
}

.nav-brand span.dot { color: var(--accent); }

.nav-links { display: flex; align-items: center; gap: 8px; }

.nav-links a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--text);
  background: var(--surface2);
}

.nav-links a.active { color: var(--accent); }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px;
  border: none; border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem; font-weight: 500;
  cursor: pointer; text-decoration: none;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 20px rgba(124,108,252,0.3);
}
.btn-primary:hover { background: #6a5ae0; transform: translateY(-1px); box-shadow: 0 6px 28px rgba(124,108,252,0.4); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); transform: translateY(-1px); }

.btn-danger { background: rgba(252,108,108,0.15); color: var(--danger); border: 1px solid rgba(252,108,108,0.3); }
.btn-danger:hover { background: rgba(252,108,108,0.25); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface2); }

.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn-lg { padding: 16px 32px; font-size: 1.05rem; }
.btn-full { width: 100%; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 0.2s;
}
.card:hover { border-color: var(--border); }
.card-glow { box-shadow: var(--glow); }

/* ── FORMS ── */
.form-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }

label { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

input, textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  padding: 12px 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,108,252,0.15);
}

input::placeholder { color: var(--text-dim); }

/* ── BADGES ── */
.badge {
  display: inline-flex; align-items: center;
  padding: 4px 10px; border-radius: 100px;
  font-size: 0.75rem; font-weight: 600;
  letter-spacing: 0.03em;
}
.badge-accent { background: rgba(124,108,252,0.15); color: var(--accent); }
.badge-success { background: rgba(108,252,184,0.15); color: var(--success); }
.badge-warning { background: rgba(252,184,108,0.15); color: var(--warning); }
.badge-danger { background: rgba(252,108,108,0.15); color: var(--danger); }

/* ── STAT CARDS ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent-color, var(--accent));
}

.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 8px; }
.stat-value { font-family: 'Syne', sans-serif; font-size: 2rem; font-weight: 800; color: var(--text); }
.stat-unit { font-size: 0.85rem; color: var(--text-muted); font-weight: 400; }
.stat-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ── PROGRESS BAR ── */
.progress-wrap { background: var(--surface2); border-radius: 100px; height: 8px; overflow: hidden; }
.progress-bar {
  height: 100%; border-radius: 100px;
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── TABLE ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; }

thead tr { background: var(--surface2); }
thead th { padding: 14px 18px; text-align: left; font-size: 0.8rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }

tbody tr { border-top: 1px solid var(--border); transition: background 0.15s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 14px 18px; font-size: 0.9rem; color: var(--text); }

/* ── ALERTS ── */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); font-size: 0.9rem; display: flex; align-items: flex-start; gap: 10px; }
.alert-error { background: rgba(252,108,108,0.1); border: 1px solid rgba(252,108,108,0.2); color: #fc9a9a; }
.alert-success { background: rgba(108,252,184,0.1); border: 1px solid rgba(108,252,184,0.2); color: var(--success); }
.alert-info { background: rgba(124,108,252,0.1); border: 1px solid rgba(124,108,252,0.2); color: #a89cfc; }

/* ── LOADING SPINNER ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── AI CHAT ── */
.chat-messages {
  display: flex; flex-direction: column; gap: 16px;
  max-height: 420px; overflow-y: auto;
  padding-right: 4px;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg { display: flex; gap: 12px; animation: fadeUp 0.3s ease; }
.msg-user { flex-direction: row-reverse; }

.msg-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.msg-user .msg-avatar { background: var(--accent); }
.msg-ai .msg-avatar { background: var(--surface2); border: 1px solid var(--border); }

.msg-bubble {
  max-width: 80%; padding: 12px 16px;
  border-radius: 16px; font-size: 0.9rem; line-height: 1.6;
}
.msg-user .msg-bubble { background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.msg-ai .msg-bubble { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 4px; }

.chat-input-row { display: flex; gap: 10px; margin-top: 16px; }
.chat-input-row input { flex: 1; }

/* ── EMPTY STATE ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 0.95rem; }

/* ── SECTION HEADER ── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.section-title { font-family: 'Syne', sans-serif; font-size: 1.2rem; font-weight: 700; }

/* ── ANIMATIONS ── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-16px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity: 0.5; } }

.fade-up { animation: fadeUp 0.4s ease forwards; }
.fade-in { animation: fadeIn 0.4s ease forwards; }

/* ── TOAST ── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9000; display: flex; flex-direction: column; gap: 10px; }

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease;
  display: flex; align-items: center; gap: 10px;
  min-width: 260px;
}
.toast.success { border-color: rgba(108,252,184,0.3); }
.toast.error { border-color: rgba(252,108,108,0.3); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%; max-width: 500px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.3s ease;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-title { font-family: 'Syne', sans-serif; font-size: 1.3rem; font-weight: 700; }

/* ── NUTRIENT PILL ── */
.nutrient-pills { display: flex; gap: 10px; flex-wrap: wrap; }
.nutrient-pill {
  display: flex; flex-direction: column; align-items: center;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px; min-width: 80px;
}
.nutrient-pill .n-val { font-family: 'Syne', sans-serif; font-size: 1.3rem; font-weight: 700; }
.nutrient-pill .n-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .nav-links { gap: 4px; }
  .nav-links a { padding: 8px 10px; font-size: 0.82rem; }
  h1 { font-size: 1.6rem; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .container { padding: 0 16px; }
}
