/* Dieta PWA styles. No inline styles anywhere (CSP style-src 'self').
   Theme: <html data-theme="system|light|dark">. Touch targets at least 48 px. Safe areas for iPhone. */

:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ec;
  --text: #17211b;
  --text-muted: #56635a;
  --border: #d6ddd5;
  --primary: #2f7d52;
  --primary-strong: #256743;
  --primary-text: #ffffff;
  --accent-soft: #dcefe3;
  --danger: #c53030;
  --danger-soft: #fde8e8;
  --warning-soft: #fff4d6;
  --warning-border: #e6c25c;
  --focus: #2b6cb0;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --radius: 14px;
  --radius-small: 10px;
  --touch: 48px;
  --nav-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #0f1712;
    --surface: #18241c;
    --surface-2: #213027;
    --text: #e7efe9;
    --text-muted: #a3b2a8;
    --border: #2f4136;
    --primary: #4fb07c;
    --primary-strong: #67c290;
    --primary-text: #08140d;
    --accent-soft: #1f3a2a;
    --danger: #f07070;
    --danger-soft: #3a1c1c;
    --warning-soft: #3a3016;
    --warning-border: #8a7330;
    --focus: #7fb3ec;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1712;
  --surface: #18241c;
  --surface-2: #213027;
  --text: #e7efe9;
  --text-muted: #a3b2a8;
  --border: #2f4136;
  --primary: #4fb07c;
  --primary-strong: #67c290;
  --primary-text: #08140d;
  --accent-soft: #1f3a2a;
  --danger: #f07070;
  --danger-soft: #3a1c1c;
  --warning-soft: #3a3016;
  --warning-border: #8a7330;
  --focus: #7fb3ec;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

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

a {
  color: var(--primary);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[tabindex="-1"]:focus {
  outline: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 24px;
  height: 24px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------ boot */
.layout-boot {
  display: grid;
  place-items: center;
  min-height: 100dvh;
}

.boot-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ------------------------------------------------------------ layouts */
.layout-guest {
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 16px);
  max-width: 560px;
  margin: 0 auto;
}

.guest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--touch);
  margin-bottom: 12px;
}

.guest-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
}

.layout-app {
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: calc(var(--safe-top) + 4px) calc(var(--safe-right) + 16px) 4px calc(var(--safe-left) + 16px);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.app-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.35rem;
  font-weight: 700;
}

/* Sync status in the header (src/sync/status-indicator.js): only a coloured dot in a 48 px touch
   target. The text stays for screen readers (aria-live); the full status is in Settings. */
.sync-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: var(--touch);
  height: var(--touch);
  margin-right: -12px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  cursor: pointer;
}

.sync-status-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sync-status-dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
}

.sync-status--ok .sync-status-dot { background: var(--primary); }
.sync-status--busy .sync-status-dot { background: var(--focus); }
.sync-status--pending .sync-status-dot { background: var(--warning-border); }
.sync-status--offline .sync-status-dot { background: var(--text-muted); }
.sync-status--warn .sync-status-dot { background: var(--warning-border); }
.sync-status--error .sync-status-dot { background: var(--danger); }

.sync-status:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -4px;
}

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px calc(var(--safe-right) + 16px) 24px calc(var(--safe-left) + 16px);
}

.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--nav-height);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
}

.nav-item.is-active {
  color: var(--primary);
}

.nav-item .icon {
  width: 26px;
  height: 26px;
}

/* ------------------------------------------------------------ screens */
.screen {
  display: grid;
  gap: 16px;
}

.screen-title {
  font-size: 1.6rem;
  line-height: 1.2;
}

.screen-subtitle {
  color: var(--text-muted);
}

.screen-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
}

.hero {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 24px 0 8px;
}

.hero-icon,
.brand-icon {
  color: var(--primary);
}

.hero-icon {
  width: 64px;
  height: 64px;
}

.hero-title {
  font-size: 1.8rem;
  line-height: 1.2;
}

.hero-subtitle {
  color: var(--text-muted);
}

.choices {
  display: grid;
  gap: 12px;
}

.choice {
  display: grid;
  gap: 4px;
  padding: 16px 18px;
  min-height: 64px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.choice-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}

.choice-title {
  font-weight: 700;
  font-size: 1.08rem;
}

.choice-hint {
  font-size: 0.92rem;
  opacity: 0.85;
}

/* ------------------------------------------------------------ profiles */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.profile-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 8px;
  padding: 16px 8px;
  min-height: 140px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  text-align: center;
}

.profile-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.login-profile {
  display: grid;
  justify-items: center;
  gap: 12px;
  text-align: center;
}

/* ------------------------------------------------------------ avatar */
.avatar {
  --avatar-color: var(--primary);
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  background: var(--avatar-color);
  color: #fff;
  font-weight: 700;
  user-select: none;
}

.avatar-sm {
  width: 40px;
  height: 40px;
  font-size: 1.05rem;
}

.avatar-md {
  width: 56px;
  height: 56px;
  font-size: 1.4rem;
}

.avatar-lg {
  width: 76px;
  height: 76px;
  font-size: 2rem;
}

.avatar-empty {
  background: var(--surface-2);
  color: var(--text-muted);
}

/* ------------------------------------------------------------ cards, lists */
.card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.15rem;
}

.subtitle {
  font-size: 1rem;
  color: var(--text-muted);
}

.list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.list-item:first-child {
  border-top: none;
}

.list-main {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.list-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.list-empty {
  color: var(--text-muted);
  padding: 8px 0;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  justify-self: start;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--primary);
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.kv-key {
  color: var(--text-muted);
}

.kv-value {
  font-weight: 600;
}

.empty-state {
  justify-items: center;
  text-align: center;
  padding: 40px 16px;
}

.empty-icon {
  width: 56px;
  height: 56px;
  color: var(--primary);
}

.empty-title {
  font-size: 1.25rem;
}

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

.notice {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius-small);
  background: var(--surface-2);
}

.notice-warning {
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
}

/* ------------------------------------------------------------ forms */
.form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.fieldset {
  margin: 0;
  padding: 0;
  border: none;
}

.label {
  font-weight: 600;
}

.hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.input {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px; /* >= 16 px prevents zoom on iOS */
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

.select {
  appearance: auto;
}

.field-error,
.form-error {
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 600;
}

.form-error {
  padding: 10px 12px;
  border-radius: var(--radius-small);
  background: var(--danger-soft);
}

.field-check {
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 12px;
}

.checkbox {
  width: 26px;
  height: 26px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

.label-check {
  display: grid;
  gap: 2px;
  min-height: var(--touch);
}

.color-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.color-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.color-swatch {
  --swatch: var(--primary);
  width: var(--touch);
  height: var(--touch);
  border-radius: 50%;
  background: var(--swatch);
  border: 3px solid transparent;
  box-shadow: inset 0 0 0 3px var(--surface);
  cursor: pointer;
}

.color-input:checked + .color-swatch {
  border-color: var(--text);
}

.color-input:focus-visible + .color-swatch {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.invite-row {
  display: flex;
  gap: 8px;
}

.invite-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  text-align: center;
}

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-strong);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-link {
  background: none;
  color: var(--primary);
  padding: 10px 8px;
}

.btn-block {
  width: 100%;
}

.btn-small {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.92rem;
}

.btn-large {
  min-height: 56px;
  font-size: 1.08rem;
}

.btn-large .icon {
  width: 28px;
  height: 28px;
}

.divider-text {
  color: var(--text-muted);
  font-size: 0.92rem;
  text-align: center;
}

/* ------------------------------------------------------------ lock screen, settings sub-sections */
.layout-lock .guest-main {
  max-width: 420px;
  margin: 0 auto;
}

.screen-lock {
  padding-top: 16px;
}

.lock-profile,
.faceid-signin {
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
}

.faceid-signin {
  justify-items: stretch;
}

.settings-subsection {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.subsection-title {
  margin: 0;
  font-size: 1.02rem;
}

/* ------------------------------------------------------------ dialog, toast */
.dialog {
  width: min(92vw, 420px);
  padding: 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgb(0 0 0 / 30%);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 45%);
}

.dialog-message {
  margin-bottom: 18px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  z-index: 50;
  display: grid;
  gap: 8px;
  width: min(92vw, 480px);
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-small);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.toast-error {
  background: var(--danger);
  color: #fff;
}

.btn-on-toast {
  background: var(--bg);
  color: var(--text);
}

@media (min-width: 900px) {
  .bottom-nav {
    left: 50%;
    right: auto;
    width: 720px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .boot-spinner {
    animation: none;
  }
}
