/* ── Design Tokens ───────────────────────────────────────────── */
:root,
.sl-theme-light {
  color-scheme: light;

  /* App colour palette */
  --bg:          #f5f7fb;
  --card:        #ffffff;
  --text:        #111827;
  --muted:       #6b7280;
  --line:        #e5e7eb;
  --accent:      #2563eb;
  --accent-soft: #dbeafe;
  --danger:      #dc2626;

  /* AI error box colours (overridden in dark mode) */
  --error-bg:    #fff5f5;
  --error-border:#fecaca;

  /* Bottom nav height (used for body padding-bottom) */
  --nav-h: 64px;

  /* Override Shoelace primary colour to our blue */
  --sl-color-primary-50:  #eff6ff;
  --sl-color-primary-100: #dbeafe;
  --sl-color-primary-200: #bfdbfe;
  --sl-color-primary-300: #93c5fd;
  --sl-color-primary-400: #60a5fa;
  --sl-color-primary-500: #3b82f6;
  --sl-color-primary-600: #2563eb;
  --sl-color-primary-700: #1d4ed8;
  --sl-color-primary-800: #1e40af;
  --sl-color-primary-900: #1e3a8a;
  --sl-color-primary-950: #172554;

  --sl-font-sans: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sl-border-radius-medium: 10px;
  --sl-border-radius-large:  12px;
}

html.sl-theme-dark {
  color-scheme: dark;

  --bg:          #0f172a;
  --card:        #1e293b;
  --text:        #f1f5f9;
  --muted:       #94a3b8;
  --line:        #334155;
  --accent:      #3b82f6;
  --accent-soft: #1e3a8a;

  /* AI error box colours in dark mode */
  --error-bg:    #3f1010;
  --error-border:#7f1d1d;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--sl-font-sans);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  /* Reserve room for fixed bottom nav */
  padding-bottom: var(--nav-h);
}

h1, h2, h3 { margin: 0; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.83rem; }

/* ── Sticky Header ───────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}

.app-header__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.app-title {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
}

.header-kcal {
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.page-progress {
  position: sticky;
  top: 56px;
  z-index: 110;
  height: 3px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 18%, #60a5fa 50%, var(--accent) 82%, transparent 100%);
  background-size: 200% 100%;
  animation: page-progress-slide 0.9s linear infinite;
}

.date-input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 0.83rem;
  font: inherit;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

/* ── Install Banner ──────────────────────────────────────────── */
.install-banner {
  display: block;
}

/* ── App Content ─────────────────────────────────────────────── */
.app-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page-host {
  opacity: 1;
  transform: translateY(0);
  filter: blur(0);
  transition: opacity 0.22s ease, transform 0.22s ease, filter 0.22s ease;
  will-change: opacity, transform, filter;
}

.page-host[aria-busy="true"] {
  pointer-events: none;
}

.page-host--loading,
.page-host--leaving {
  opacity: 0;
  transform: translateY(12px);
  filter: blur(3px);
}

.page-host--entering {
  animation: page-host-enter 0.28s ease;
}

.panel {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel--legal {
  padding-bottom: 96px;
}

.page-intro {
  gap: 6px;
}

.page-eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.page-intro h1 {
  font-size: 1.2rem;
}

.start-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.start-highlight {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 0.84rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.auth-panel {
  max-width: 480px;
}

.auth-shell {
  gap: 8px;
}

.auth-form sl-button {
  width: 100%;
  justify-content: center;
}

.card h3 {
  font-size: 1rem;
}

.legal-footer {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 12px 24px;
}

.legal-footer__inner {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  font-size: 0.92rem;
}

.legal-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.legal-link:hover,
.legal-link:focus-visible {
  text-decoration: underline;
}

.legal-list {
  display: grid;
  gap: 6px;
}

.legal-list p {
  line-height: 1.55;
}

.legal-note {
  font-size: 0.92rem;
  line-height: 1.55;
}

/* ── Bottom Navigation ───────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  z-index: 100;
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: stretch;
  /* Safe-area for notched phones */
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font: inherit;
  font-size: 0.72rem;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  transition: color 0.15s, background 0.15s;
  border-radius: 0;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav__item sl-icon {
  font-size: 1.35rem;
  transition: transform 0.15s;
}

.bottom-nav__item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.bottom-nav__item.active {
  color: var(--accent);
  font-weight: 600;
}

.bottom-nav__item.active sl-icon {
  transform: scale(1.12);
}

.bottom-nav__item.is-loading sl-icon {
  animation: nav-pulse 0.9s ease-in-out infinite;
}

/* ── SVG Donut Chart ─────────────────────────────────────────── */
.summary-card .summary-layout {
  display: flex;
  align-items: center;
  gap: 20px;
}

.donut-wrap { flex-shrink: 0; }

.donut {
  width: 110px;
  height: 110px;
  overflow: visible;
}

.donut__track {
  fill: none;
  stroke: var(--line);
  stroke-width: 12;
}

.donut__progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
}

.donut__value {
  font-size: 22px;
  font-weight: 700;
  fill: var(--text);
}

.donut__label {
  font-size: 10px;
  fill: var(--muted);
}

/* ── Macro Bars ──────────────────────────────────────────────── */
.macro-bars {
  flex: 1;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.macro-item__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.85rem;
}

sl-progress-bar {
  --height: 6px;
  --track-color: var(--line);
  --border-radius: 999px;
}

/* ── Entry Cards ─────────────────────────────────────────────── */
.entries {
  display: grid;
  gap: 10px;
}

sl-card.entry-card {
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}

sl-card.entry-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}

.entry-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.entry-card__actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.entry-card__actions .action-delete {
  color: var(--danger);
}

.entry-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

/* Custom badge colours (via CSS parts) */
.badge-kcal::part(base) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.badge-protein::part(base) {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #bfdbfe;
}
.badge-carbs::part(base) {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}
.badge-fat::part(base) {
  background: #ede9fe;
  color: #5b21b6;
  border-color: #ddd6fe;
}

html.sl-theme-dark .badge-protein::part(base) {
  background: #1e3a8a;
  color: #93c5fd;
  border-color: #1d4ed8;
}
html.sl-theme-dark .badge-carbs::part(base) {
  background: #78350f;
  color: #fcd34d;
  border-color: #92400e;
}
html.sl-theme-dark .badge-fat::part(base) {
  background: #3b0764;
  color: #c4b5fd;
  border-color: #5b21b6;
}

/* ── Search Results ──────────────────────────────────────────── */
.search-results {
  display: grid;
  gap: 6px;
}

.search-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* ── Form Layout ─────────────────────────────────────────────── */
.form-stack {
  display: grid;
  gap: 14px;
}

.entry-form-intro {
  display: grid;
  gap: 4px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

@media (max-width: 400px) {
  .form-row-2,
  .form-row-3 {
    grid-template-columns: 1fr 1fr;
  }
  .form-row-3 sl-input:last-child {
    grid-column: span 2;
  }
}

.portion-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}

.portion-box__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.portion-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.portion-presets sl-button::part(base) {
  border-radius: 999px;
}

.form-section-note {
  margin-top: 2px;
}

/* ── Shared Meal Fields ──────────────────────────────────────── */
.shared-fields {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.participant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.participant-list {
  display: grid;
  gap: 8px;
}

.participant-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.participant-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.9rem;
  background: var(--card);
  color: var(--text);
}

.participant-row .participant-share {
  max-width: 100px;
}

/* ── Drawer Footer ───────────────────────────────────────────── */
.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.entry-drawer {
  --size: min(620px, 92dvh);
}

/* ── Delete Dialog Footer ────────────────────────────────────── */
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Skeleton ────────────────────────────────────────────────── */
.skeleton-stack {
  display: grid;
  gap: 10px;
}

.entry-skeleton {
  --border-radius: 10px;
  height: 72px;
}

/* ── Details (accordion) ─────────────────────────────────────── */
.stack {
  display: grid;
  gap: 10px;
}

sl-details {
  --border-color: var(--line);
  border-radius: 10px;
}

/* ── Add Entry Button ────────────────────────────────────────── */
.add-entry-btn {
  width: 100%;
  justify-content: center;
}

/* ── AI Result Box ───────────────────────────────────────────── */
.ai-result-box {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  display: grid;
  gap: 4px;
}

.ai-result-box--error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--danger);
}

.ai-confidence { font-size: 0.85rem; font-weight: 600; }
.ai-confidence--high   { color: #15803d; }
.ai-confidence--medium { color: #b45309; }
.ai-confidence--low    { color: var(--danger); }

/* ── Scanner Preview ─────────────────────────────────────────── */
.scanner-preview {
  position: fixed;
  right: 12px;
  bottom: calc(var(--nav-h) + 12px);
  width: 160px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #000;
  z-index: 200;
}

/* ── Weekly List ─────────────────────────────────────────────── */
.weekly {
  display: grid;
  gap: 6px;
}

.weekly-day {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.88rem;
  gap: 8px;
}

/* ── Inline helper ───────────────────────────────────────────── */
.inline {
  display: flex;
  gap: 8px;
}

.inline > sl-button {
  flex: 1;
}

@media (max-width: 480px) {
  .drawer-footer {
    width: 100%;
  }

  .drawer-footer sl-button {
    flex: 1;
  }
}

/* ── Responsive: Desktop centre column ──────────────────────── */
@media (min-width: 600px) {
  .bottom-nav {
    max-width: 640px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
  }
}

@keyframes page-host-enter {
  from {
    opacity: 0;
    transform: translateY(12px);
    filter: blur(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

@keyframes nav-pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.65;
  }
}

@keyframes page-progress-slide {
  from { background-position: 200% 0; }
  to { background-position: 0 0; }
}
