/* ==========================================================
   WEEGKOERS — design tokens
   Concept: een rustige, "Apple"-achtige uitstraling — systeem-
   lettertype, glazen kaarten, zachte rondingen, één heldere accentkleur.
   ========================================================== */

:root {
  /* Color — geïnspireerd op het iOS dark mode palet (standaard) */
  --ink:        #000000;   /* systemBackground */
  --ink-raised: rgba(28, 28, 30, 0.72);   /* secondarySystemBackground, vervaagd */
  --ink-solid:  #1C1C1E;   /* zelfde, ondoorzichtig (voor elementen zonder blur) */
  --ink-line:   rgba(255, 255, 255, 0.12);   /* separator */
  --paper:      #F5F5F7;   /* label */
  --slate:      rgba(235, 235, 245, 0.6);   /* secondaryLabel */
  --slate-dim:  rgba(235, 235, 245, 0.3);   /* tertiaryLabel */
  --kinetic:    #0A84FF;   /* systemBlue — primaire accent */
  --ember:      #FF9F0A;   /* systemOrange — streak, weegdag */
  --good:       #30D158;   /* systemGreen */
  --bad:        #FF453A;   /* systemRed */
  --fill:       rgba(120, 120, 128, 0.16);   /* systemFill, voor inputs */

  --shadow-color: rgba(0, 0, 0, 0.25);
  --shadow-color-strong: rgba(0, 0, 0, 0.35);
  --bg-glow-1: rgba(10, 132, 255, 0.10);
  --bg-glow-2: rgba(255, 159, 10, 0.06);

  /* Type — systeemlettertype, geen webfont nodig */
  --font-display: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  /* Scale */
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --space-6: 4rem;

  --radius: 20px;
  --radius-sm: 14px;
}

/* Licht thema — Apple's licht-modus palet */
:root[data-theme="light"] {
  --ink:        #F2F2F7;   /* systemGroupedBackground */
  --ink-raised: rgba(255, 255, 255, 0.78);
  --ink-solid:  #FFFFFF;
  --ink-line:   rgba(60, 60, 67, 0.22);
  --paper:      #1C1C1E;
  --slate:      rgba(60, 60, 67, 0.6);
  --slate-dim:  rgba(60, 60, 67, 0.3);
  --kinetic:    #007AFF;
  --ember:      #FF9500;
  --good:       #34C759;
  --bad:        #FF3B30;
  --fill:       rgba(120, 120, 128, 0.12);

  --shadow-color: rgba(60, 60, 67, 0.10);
  --shadow-color-strong: rgba(60, 60, 67, 0.16);
  --bg-glow-1: rgba(0, 122, 255, 0.08);
  --bg-glow-2: rgba(255, 149, 0, 0.06);
}

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

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
  margin: 0;
  background: var(--ink);
  background-image: radial-gradient(ellipse 120% 60% at 50% -10%, var(--bg-glow-1), transparent),
                     radial-gradient(ellipse 100% 50% at 100% 100%, var(--bg-glow-2), transparent);
  background-attachment: fixed;
  color: var(--paper);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background-color .2s ease, color .2s ease;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

h1 { font-size: 2.25rem; font-weight: 600; letter-spacing: -0.015em; }
h2 {
  font-size: 0.72rem;
  color: var(--slate);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

a { color: var(--kinetic); text-decoration: none; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

button, input, select {
  font-family: inherit;
  font-size: 1rem;
}

/* ---------------- Layout shells ---------------- */

.auth-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.app-shell {
  max-width: 880px;
  margin: 0 auto;
  padding: calc(var(--space-4) + env(safe-area-inset-top)) var(--space-3) var(--space-6);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
}

.topbar .brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: -0.005em;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.topbar .brand .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 10px 1px var(--ember);
}

.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  flex: none;
}

.brand-mark-lg {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  vertical-align: middle;
  margin-right: 0.4rem;
}

.icon-btn {
  background: var(--fill);
  border: none;
  color: var(--paper);
  border-radius: 980px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}
.icon-btn:hover { background: rgba(120, 120, 128, 0.24); }
.icon-btn:active { transform: scale(0.95); }

/* ---------------- Auth card ---------------- */

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--ink-raised);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 0.5px solid var(--ink-line);
  border-radius: var(--radius);
  padding: var(--space-5) var(--space-4);
  box-shadow: 0 20px 60px var(--shadow-color-strong);
}

.auth-card .brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.85rem;
  letter-spacing: -0.015em;
  margin-bottom: var(--space-1);
}

.auth-card .tagline {
  color: var(--slate);
  font-size: 0.95rem;
  margin-bottom: var(--space-4);
}

.field {
  margin-bottom: var(--space-3);
}

.field label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--slate);
  margin-bottom: var(--space-1);
  font-weight: 600;
}

.field input {
  width: 100%;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.85rem 0.9rem;
  color: var(--paper);
  outline: none;
  transition: box-shadow .15s ease;
  min-height: 44px;
}
.field input:focus { box-shadow: 0 0 0 2px var(--kinetic); }

.btn-primary {
  width: 100%;
  background: var(--kinetic);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: filter .15s ease, transform .1s ease;
  min-height: 44px;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

.btn-ghost {
  width: 100%;
  background: var(--fill);
  color: var(--paper);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  cursor: pointer;
  margin-top: var(--space-2);
  min-height: 44px;
}
.btn-ghost:hover { background: rgba(120, 120, 128, 0.24); }

.auth-toggle {
  text-align: center;
  margin-top: var(--space-4);
  font-size: 0.9rem;
  color: var(--slate);
}
.auth-toggle button {
  background: none; border: none; color: var(--kinetic);
  cursor: pointer; font-size: inherit; padding: 0; font-weight: 500;
}

.form-msg {
  font-size: 0.85rem;
  margin-top: var(--space-2);
  min-height: 1.2em;
}
.form-msg.error { color: var(--bad); }
.form-msg.success { color: var(--good); }

/* ---------------- Weigh-day banner (signature moment) ---------------- */

.weigh-banner {
  display: none;
  align-items: center;
  gap: var(--space-3);
  background: rgba(255, 159, 10, 0.14);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 0.5px solid rgba(255, 159, 10, 0.35);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}
.weigh-banner.visible { display: flex; }
.weigh-banner .pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ember);
  flex: none;
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 159, 10, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(255, 159, 10, 0); }
}
.weigh-banner .text { flex: 1; }
.weigh-banner .text strong { display: block; font-size: 0.95rem; font-weight: 600; }
.weigh-banner .text span { color: var(--slate); font-size: 0.85rem; }
.weigh-banner button {
  background: var(--ember);
  border: none;
  color: #1A0F00;
  font-weight: 600;
  border-radius: 980px;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
}

@media (prefers-reduced-motion: reduce) {
  .weigh-banner .pulse { animation: none; }
}

/* ---------------- Cards / grid ---------------- */

.grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: var(--space-3);
}
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--ink-raised);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border: 0.5px solid var(--ink-line);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: 0 12px 40px var(--shadow-color);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.stat-big {
  font-family: var(--font-display);
  font-size: 2.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat-unit { font-size: 1.1rem; color: var(--slate); font-weight: 500; margin-left: 0.25rem; }
.stat-delta { font-family: var(--font-mono); font-size: 0.9rem; margin-top: 0.2rem; }
.stat-delta.down { color: var(--good); }
.stat-delta.up { color: var(--ember); }
.stat-delta.flat { color: var(--slate); }

/* Streak badge in card header */
.streak-badge {
  font-size: 0.85rem;
  color: var(--slate);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--fill);
  padding: 0.3rem 0.7rem;
  border-radius: 980px;
}
.streak-badge strong {
  color: var(--paper);
  font-family: var(--font-mono);
  font-weight: 700;
}

/* Calendar */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}
.calendar-nav .icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  min-height: unset;
  border-radius: 50%;
}
.calendar-month-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--paper);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: var(--space-2);
}
.calendar-weekdays span {
  text-align: center;
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--slate);
  letter-spacing: 0.04em;
  font-weight: 600;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-day {
  width: 100%;
  height: 100%;
  max-width: 40px;
  max-height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--fill);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease, transform .1s ease;
  color: var(--slate);
  font-size: 0.85rem;
  font-family: var(--font-body);
  font-weight: 500;
}
.cal-day:hover { background: rgba(120, 120, 128, 0.28); }
.cal-day:active { transform: scale(0.92); }
.cal-day.done {
  background: var(--kinetic);
  color: white;
  font-weight: 600;
}
.cal-day.today { box-shadow: 0 0 0 2px var(--ember); }
.cal-day.future { cursor: default; opacity: 0.3; }
.cal-day.future:hover { background: var(--fill); }

/* Weight history mini chart */
.chart-wrap { margin-top: var(--space-2); }
.chart-empty {
  color: var(--slate);
  font-size: 0.9rem;
  padding: var(--space-3) 0;
}

.history-list {
  margin-top: var(--space-3);
  border-top: 0.5px solid var(--ink-line);
}
.history-link {
  display: block;
  text-align: center;
  font-size: 0.85rem;
  color: var(--kinetic);
  padding: var(--space-2) 0 0;
  font-weight: 500;
}
.history-row {
  display: flex;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 0.5px solid var(--ink-line);
  font-size: 0.92rem;
}
.history-row .d { color: var(--slate); }
.history-row .w { font-family: var(--font-mono); font-weight: 500; }

/* Log weight form inline */
.log-form {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.log-form input {
  flex: 1;
  background: var(--fill);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  color: var(--paper);
  outline: none;
  min-height: 44px;
  transition: box-shadow .15s ease;
}
.log-form input:focus { box-shadow: 0 0 0 2px var(--kinetic); }
.log-form button {
  background: var(--kinetic);
  border: none;
  color: white;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.1rem;
  cursor: pointer;
  min-height: 44px;
  transition: filter .15s ease, transform .1s ease;
}
.log-form button:hover { filter: brightness(1.1); }
.log-form button:active { transform: scale(0.97); }

.log-form input:disabled,
.log-form button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.form-hint {
  font-size: 0.82rem;
  color: var(--slate);
  margin-top: var(--space-1);
  min-height: 1.2em;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 0.5px solid var(--ink-line);
}
.settings-row select {
  background: var(--fill);
  border: none;
  color: var(--paper);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  min-height: 40px;
  color-scheme: dark;
}
:root[data-theme="light"] .settings-row select { color-scheme: light; }
.settings-row select option {
  background: var(--ink-solid);
  color: var(--paper);
}

.mini-input {
  width: 72px;
  background: var(--fill);
  border: none;
  color: var(--paper);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  min-height: 40px;
  text-align: right;
  outline: none;
  transition: box-shadow .15s ease;
}
.mini-input:focus { box-shadow: 0 0 0 2px var(--kinetic); }

.goal-progress {
  margin-top: var(--space-2);
}
.goal-progress .goal-label {
  font-size: 0.85rem;
  color: var(--slate);
  margin-bottom: 0.4rem;
}
.goal-progress .goal-label strong {
  color: var(--paper);
  font-family: var(--font-mono);
  font-weight: 600;
}
.goal-bar-track {
  height: 6px;
  border-radius: 999px;
  background: var(--fill);
  overflow: hidden;
}
.goal-bar-fill {
  height: 100%;
  background: var(--kinetic);
  border-radius: 999px;
  transition: width .4s ease;
}
.goal-bar-fill.reached { background: var(--good); }

.loading-state, .empty-state {
  color: var(--slate);
  font-size: 0.92rem;
  text-align: center;
  padding: var(--space-5) 0;
}

/* Voeding: zoekresultaten */
.food-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0.7rem 0;
  border-bottom: 0.5px solid var(--ink-line);
}
.food-result-name { font-size: 0.94rem; font-weight: 500; }
.food-result-meta { font-size: 0.8rem; color: var(--slate); margin-top: 0.15rem; }
.food-result button {
  flex: none;
  white-space: nowrap;
}

.food-row .d { line-height: 1.4; }
.delete-btn {
  background: none;
  border: none;
  color: var(--slate);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem;
}
.delete-btn:hover { color: var(--bad); }

/* Modaal voor hoeveelheid invullen */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.visible { display: flex; }
.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--ink-solid);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px var(--shadow-color-strong);
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: var(--radius); }
}
.modal-title { font-size: 1.05rem; font-weight: 600; }
.modal-sub { font-size: 0.85rem; color: var(--slate); margin-top: 0.2rem; margin-bottom: var(--space-3); }
.modal-preview {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--kinetic);
  min-height: 1.3em;
  margin-top: var(--space-1);
}
