* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Manrope", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px circle at 18% 18%, rgba(59, 130, 246, 0.18), transparent 52%),
    radial-gradient(1000px circle at 82% 6%, rgba(14, 165, 233, 0.14), transparent 50%),
    linear-gradient(135deg, #eef3ff 0%, #f7fbff 45%, #e9f2ff 100%);
  color: #0b1224;
}

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}

.shell.narrow {
  max-width: 540px;
}

header h1 {
  margin: 0 0 8px;
  font-size: 30px;
  letter-spacing: -0.02em;
}

header p {
  margin: 0 0 16px;
  color: #4b5563;
}

.brand-block {
  padding: 8px 10px;
  border-radius: 12px;
  background: #f4f7ff;
}

.app-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-radius: 18px;
  background: linear-gradient(135deg, #e8f1ff, #f7fbff);
  border: 1px solid #dfe8ff;
  box-shadow: 0 14px 40px rgba(37, 99, 235, 0.08);
}

.mobile-nav {
  display: none;
}

main {
  display: grid;
  gap: 18px;
}

.card {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.75));
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(6px);
}

.input-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: stretch;
}

textarea {
  min-height: 110px;
  padding: 14px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  background: #f8fbff;
  color: #0b1224;
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, filter 0.12s ease;
  letter-spacing: 0.01em;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button:active {
  transform: translateY(1px);
}

.primary {
  background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
  background-color: #2563eb !important;
  color: #ffffff !important;
  box-shadow: 0 10px 25px rgba(14, 165, 233, 0.35);
  border-color: #2563eb !important;
}

/* Ensure primary buttons stay visible in dark mode */
body.theme-dark .primary,
:root.theme-dark .primary {
  background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
  color: #ffffff !important;
  border-color: #2563eb !important;
  box-shadow: 0 10px 25px rgba(14, 165, 233, 0.35);
}

.danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  box-shadow: 0 10px 25px rgba(239, 68, 68, 0.3);
}

.ghost {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #e2e8f0;
}

/* Dark mode */




:root.theme-dark,
@media (prefers-color-scheme: dark) {
  body {
    background: radial-gradient(circle at 20% 20%, #0f172a 0, #0b1220 40%, #0a0f1c 80%);
    color: #e5e7eb;
  }
  .app-header {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.8), rgba(30, 41, 59, 0.8));
    border-color: #1f2937;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    color: #e5e7eb;
  }
  .brand-block {
    background: #f4f7ff;
    color: #0b1224;
  }
  .app-header h1 { color: #0b1224; }
  .app-header p { color: #4b5563; }
  .card {
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.9), rgba(17, 24, 39, 0.8));
    border-color: #1f2937;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
    color: #e5e7eb;
  }
  header h1 { color: #f8fafc; }
  header p { color: #cbd5e1; }
  .card h2, .card h3 { color: #f8fafc; }
  .tabs .tab { background: #111827; color: #e2e8f0; border-color: #334155; }
  .tabs .tab.active { background: linear-gradient(135deg, #2563eb, #0ea5e9); color: #ffffff; border-color: #2563eb; }
  textarea, .form input { background: #0f172a; border-color: #1f2937; color: #e5e7eb; }
  textarea::placeholder, .form input::placeholder { color: #9ca3af; }
  .ghost { background: transparent; color: #e5e7eb; border-color: #1f2937; }
  .primary {
    background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
    color: #ffffff !important;
    border-color: #2563eb !important;
    box-shadow: 0 10px 25px rgba(14, 165, 233, 0.35);
  }
  /* Extra specificity to ensure auth buttons stay visible */
  .card .primary,
  button#auth-submit.primary {
    background: linear-gradient(135deg, #0ea5e9, #2563eb) !important;
    color: #ffffff !important;
    border-color: #2563eb !important;
  }
  .tab { background: #111827; color: #e5e7eb; border-color: #1f2937; }
  .tab.active { background: linear-gradient(135deg, #2563eb, #0ea5e9); border-color: #2563eb; }
  .meal { background: #f7f9fd; border-color: #dfe4ee; color: #0b1224; }
  .meal .tag { background: #e2e8f0; color: #1f2937; }
  .macro { color: #475569; }
  .days li { background: linear-gradient(135deg, #0f172a, #111827); border-color: #1f2937; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35); color: #e5e7eb; }
  .update-banner { background: #0f172a; border-color: #1f2937; color: #e5e7eb; }
  .mobile-nav { background: rgba(15, 23, 42, 0.9); border-top-color: #1f2937; color: #e5e7eb; }
  .mobile-nav .tab { background: #111827; color: #e2e8f0; border-color: #334155; }
  .mobile-nav .tab.active { background: linear-gradient(135deg, #2563eb, #0ea5e9); color: #ffffff; border-color: #2563eb; }
}





.status {
  margin-top: 8px;
  min-height: 20px;
  color: #475569;
  font-size: 14px;
}

.error {
  color: #b91c1c;
}

.meal ul {
  list-style: none;
  padding: 0;
}

.meal li {
  margin-bottom: 10px;
}

.macro {
  color: #475569;
  font-size: 13px;
}

.total {
  margin-top: 8px;
  font-weight: 700;
}

/* Extra dark-mode overrides for visibility */
:root.theme-dark .app-header h1,
:root.theme-dark .app-header p {
  color: #e5e7eb;
}
:root.theme-dark .card h2,
:root.theme-dark .card h3 {
  color: #f8fafc;
}
:root.theme-dark .tab-row button:not(.active) {
  color: #e5e7eb;
  background: #0f172a;
  border-color: #1f2937;
}
:root.theme-dark .macro,
:root.theme-dark .meal li,
:root.theme-dark .total {
  color: #e5e7eb;
}

/* Force header text black in dark mode */
:root.theme-dark .brand-block h1,
:root.theme-dark .app-header h1,
:root.theme-dark header h1 {
  color: #0b1224 !important;
}
:root.theme-dark .brand-block p,
:root.theme-dark .app-header p,
:root.theme-dark header p {
  color: #0b1224 !important;
}

/* Day section styling */
.day {
  border: 1px dashed #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  background: #f8fbff;
  color: #0f172a;
}

.day h3 {
  color: #0f172a;
}

:root.theme-dark .day {
  background: #1f2937;
  border-color: #374151;
  color: #f8fafc;
}

:root.theme-dark .day h3 {
  color: #f8fafc;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.tabs {
  display: inline-flex;
  gap: 8px;
}

.tab {
  background: #e8edff;
  color: #0f172a;
  padding: 8px 12px;
  border-radius: 18px;
  border: 1px solid #cbd5e1;
  font-weight: 700;
  min-width: 80px;
}

.tab.active {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #ffffff;
  border-color: #2563eb;
}

.auth-card {
  overflow: hidden;
}

.auth-layout {
  display: grid;
  gap: 18px;
  align-items: stretch;
}

.auth-layout:has(.auth-visual) {
  grid-template-columns: minmax(280px, 1fr) 1fr;
}

@media (max-width: 820px) {
  .auth-layout:has(.auth-visual) {
    grid-template-columns: 1fr;
  }
  .auth-visual {
    order: 2;
  }
  .auth-card .form {
    order: 1;
  }
}

.auth-visual {
  position: relative;
  padding: 18px;
  border-radius: 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.85)),
    url("https://images.unsplash.com/photo-1504674900247-0877df9cc836?auto=format&fit=crop&w=1200&q=80") center/cover no-repeat;
  border: 1px solid rgba(219, 234, 254, 0.7);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75), 0 16px 40px rgba(14, 165, 233, 0.18);
}

.auth-visual h3 {
  margin: 10px 0 6px;
  font-size: 20px;
}

.auth-visual p {
  margin: 0 0 12px;
  color: #0f172a;
}

.auth-visual .pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #0ea5e9;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}

.form label {
  display: block;
  margin-bottom: 12px;
  color: #0f172a;
  font-weight: 600;
}

.form input {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
  background: #f8fbff;
  color: #0b1224;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-field input,
.inline-field select {
  flex: 1;
  margin-top: 0;
  width: auto;
}

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

.inline-pair .inline-field input {
  max-width: 120px;
  width: 100%;
}

.inline-pair .inline-field {
  flex-direction: column;
  align-items: flex-start;
}

.days {
  list-style: none;
  padding: 0;
  margin: 0;
}

.days li {
  padding: 8px 0;
  border-bottom: 1px solid #e2e8f0;
}

.chart {
  width: 100%;
  height: 200px;
}

.chart svg {
  width: 100%;
  height: 160px;
}

.chart-legend {
  font-size: 13px;
  color: #475569;
}

.profile-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  color: #6366f1;
  margin: 0 0 6px;
}

.two-col {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.meal {
  border: 1px dashed #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  background: #f8fbff;
}

:root.theme-dark .meal {
  background: #1f2937;
  border-color: #374151;
}

.meal .tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8edff;
  color: #1d4ed8;
  font-weight: 700;
  font-size: 12px;
}

:root.theme-dark .meal .tag {
  background: #374151;
  color: #60a5fa;
}

/* Meal text styling */
.meal,
.meal *,
.meal li,
.meal .macro,
.meal .total {
  color: #0f172a !important;
}

:root.theme-dark .meal,
:root.theme-dark .meal *,
:root.theme-dark .meal li,
:root.theme-dark .meal .macro,
:root.theme-dark .meal .total {
  color: #f8fafc !important;
}

/* Force history/days text black in dark mode */
:root.theme-dark .card h2,
:root.theme-dark .days li,
:root.theme-dark .days li strong {
  color: #0b1224 !important;
}

.days li {
  padding: 10px 12px;
  border: 1px solid #d4d7de;
  border-radius: 10px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #ffffff, #f7f9fd);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.06);
  color: #0b1224;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

label.checkbox input {
  width: auto;
}

header p span {
  background: #e8edff;
  padding: 3px 10px;
  border-radius: 12px;
  color: #1d4ed8;
  font-weight: 700;
}

body.theme-light,
:root.theme-light body {
  background:
    radial-gradient(1200px circle at 18% 18%, rgba(59, 130, 246, 0.18), transparent 52%),
    radial-gradient(1000px circle at 82% 6%, rgba(14, 165, 233, 0.14), transparent 50%),
    linear-gradient(135deg, #eef3ff 0%, #f7fbff 45%, #e9f2ff 100%);
  color: #0b1224;
}

body.theme-dark,
:root.theme-dark body {
  background:
    radial-gradient(1100px circle at 16% 16%, rgba(59, 130, 246, 0.16), transparent 52%),
    radial-gradient(900px circle at 84% 0%, rgba(14, 165, 233, 0.12), transparent 50%),
    linear-gradient(135deg, #080d1c 0%, #0b1224 45%, #060812 100%);
  color: #e5e7eb;
}

/* Auth hero dark tweaks */
:root.theme-dark .auth-visual {
  background:
    linear-gradient(135deg, rgba(8, 13, 28, 0.9), rgba(11, 18, 36, 0.85)),
    url("https://images.unsplash.com/photo-1504674900247-0877df9cc836?auto=format&fit=crop&w=1200&q=80") center/cover no-repeat;
  border-color: #1f2937;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 16px 40px rgba(0, 0, 0, 0.35);
}
:root.theme-dark .auth-visual p { color: #cbd5e1; }

.update-banner {
  margin: 12px 0;
  padding: 10px 14px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

/* MFA QR URL styling */
.qr-url {
  display: block;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-family: monospace;
  font-size: 12px;
  word-break: break-all;
  color: #0f172a;
  margin: 8px 0;
}

:root.theme-dark .qr-url {
  background: #1f2937;
  border-color: #374151;
  color: #e5e7eb;
}

/* Meal sections */
.meal-section {
  margin-bottom: 24px;
}

.meal-section h3 {
  margin: 0 0 12px;
  font-size: 18px;
  color: #0f172a;
}

:root.theme-dark .meal-section h3 {
  color: #f8fafc;
}

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

.meal-text {
  font-weight: 600;
}

.meal-time {
  font-size: 12px;
  color: #6b7280;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
}

:root.theme-dark .meal-time {
  color: #9ca3af;
  background: #374151;
}

.day-summary {
  margin-top: 24px;
  padding: 16px;
  background: #f8fafc;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
}

:root.theme-dark .day-summary {
  background: #1f2937;
  border-color: #374151;
}

.total-macros {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.macro-item {
  font-size: 14px;
  color: #4b5563;
}

:root.theme-dark .macro-item {
  color: #d1d5db;
}

.history-range {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.history-range label {
  font-size: 0.85rem;
  color: #6b7280;
}

.history-range input {
  margin-left: 0.25rem;
}

.history-days {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-day {
  padding: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
}

:root.theme-dark .history-day {
  border-color: #374151;
  background: #111827;
}

.history-day-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  font-size: 0.95rem;
}

.history-meal {
  margin-top: 0.5rem;
}

.history-meal-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.history-items {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.muted {
  color: #6b7280;
}

:root.theme-dark .muted {
  color: #9ca3af;
}

@media (max-width: 720px) {
  .input-row {
    grid-template-columns: 1fr;
  }
  .app-header {
    grid-template-columns: 1fr;
  }
  .desktop-tabs {
    display: none;
  }
  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 10px 12px 12px;
    background: rgba(255, 255, 255, 0.95);
    border-top: 1px solid #e2e8f0;
    box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(8px);
  }
  .mobile-nav .tab {
    padding: 10px 8px;
    text-align: center;
  }
  body {
    padding-bottom: 72px;
  }
}
