/* NL Fit Food Pal: app shell styles.
   Look kept from the original sketch (dark slate + teal); tokens below are the single place to change it. */

:root {
  /* Colour */
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-2: #273449;
  --color-border: #334155;
  --color-text: #f1f5f9;
  --color-muted: #94a3b8;
  --color-accent: #0d9488;
  --color-accent-strong: #0f766e;
  --color-accent-text: #5eead4;
  --color-danger: #ef4444;
  --color-good: #22c55e;
  --color-on-accent: #ffffff;

  /* Spacing (4px scale) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Type */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;

  /* Layout */
  --touch: 44px;
  --header-h: 56px;
  --tabbar-h: 58px;
  --content-max: 720px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--color-bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--color-accent-text); outline-offset: 2px; }
[hidden] { display: none !important; }

.muted { color: var(--color-muted); }

/* ---------- Shell ---------- */

.app {
  max-width: var(--content-max);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--space-4) + var(--safe-right)) 0 calc(var(--space-4) + var(--safe-left));
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.app-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-accent-text);
  white-space: nowrap;
}

.app-main {
  flex: 1;
  padding: var(--space-4) calc(var(--space-4) + var(--safe-right))
           calc(var(--tabbar-h) + var(--safe-bottom) + var(--space-5))
           calc(var(--space-4) + var(--safe-left));
  outline: none;
}

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid var(--color-border);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.tabbar-inner {
  display: flex;
  width: 100%;
  max-width: var(--content-max);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-1) 0;
  color: var(--color-muted);
  text-decoration: none;
  font-size: var(--text-xs);
  font-weight: 500;
}

.tab svg { width: 24px; height: 24px; flex: none; }
.tab-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab[aria-current="page"] { color: var(--color-accent-text); }
.tab:active { opacity: 0.7; }

/* ---------- Profile switcher ---------- */

.profile-switcher {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.select {
  min-height: var(--touch);
  max-width: 11rem;
  padding: 0 var(--space-6) 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-2) center;
  background-size: 18px;
  -webkit-appearance: none;
  appearance: none;
  text-overflow: ellipsis;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--color-surface-2); }

/* ---------- Content ---------- */

.screen-title { margin: 0 0 var(--space-1); font-size: var(--text-xl); }
.screen-sub { margin: 0 0 var(--space-4); color: var(--color-muted); font-size: var(--text-sm); }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}
.card h3 { margin: 0 0 var(--space-2); font-size: var(--text-md); }
.card p { margin: 0 0 var(--space-2); }
.card p:last-child { margin-bottom: 0; }

.coming-soon {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  color: var(--color-muted);
}
.coming-soon svg { width: 22px; height: 22px; flex: none; color: var(--color-accent-text); margin-top: 1px; }

.notice {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.notice.error { border-color: var(--color-danger); }

.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--touch);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}
.list-item:last-child { border-bottom: none; }
.badge {
  font-size: var(--text-xs);
  color: var(--color-accent-text);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-pill);
  padding: 2px var(--space-2);
}

/* ---------- Buttons and forms ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch);
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  font-weight: 600;
}
.btn-primary { background: var(--color-accent); color: var(--color-on-accent); }
.btn-primary:active { background: var(--color-accent-strong); }
.btn-secondary { background: var(--color-border); color: var(--color-text); }
.btn-block { width: 100%; }

.field { display: block; margin: var(--space-3) 0; font-size: var(--text-sm); }
.field > span { display: block; margin-bottom: var(--space-1); color: var(--color-muted); }
.field input, .field select {
  width: 100%;
  min-height: var(--touch);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  font-size: var(--text-md); /* 16px stops iOS zooming on focus */
}

.form-error { color: #fca5a5; font-size: var(--text-sm); margin: var(--space-2) 0; }

.actions { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-4); }
.actions .btn { flex: 1; }

/* ---------- Dialog (new profile sheet) ---------- */

.sheet {
  width: min(100% - 2 * var(--space-4), 420px);
  margin: auto;
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
}
.sheet::backdrop { background: rgba(2, 6, 23, 0.7); }
.sheet h2 { margin: 0 0 var(--space-2); font-size: var(--text-lg); }
.sheet p { margin: 0 0 var(--space-2); font-size: var(--text-sm); }

@media (min-width: 721px) {
  .app-main { padding-top: var(--space-5); }
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.field-row .field { margin: var(--space-3) 0; }
.field input[type="date"] { -webkit-appearance: none; appearance: none; display: flex; align-items: center; color-scheme: dark; }

.segmented { display: flex; gap: var(--space-2); border: none; padding: 0; }
.segmented legend { padding: 0; margin-bottom: var(--space-1); color: var(--color-muted); }
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label span {
  display: flex; align-items: center; justify-content: center;
  min-height: var(--touch);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  font-size: var(--text-md);
}
.segmented input:checked + span { border-color: var(--color-accent); background: var(--color-accent-strong); color: var(--color-on-accent); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--color-accent-text); outline-offset: 2px; }

.sheet { max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 2 * var(--space-4)); overflow-y: auto; }
