/*
 * Frigga base styles. Phone-first, no framework. Every file in
 * app/assets/stylesheets is included (stylesheet_link_tag :app), so feature
 * styles live in their own files (map.css, places.css, settings.css, ...).
 *
 * Building blocks: .page, .stack, .card, .row, .btn (+ --primary, --danger,
 * --quiet, --small), .field, .badge (+ --ok, --warn, --danger, --muted),
 * .list (+ .list__item), .muted, .empty, .section-title, .flash.
 */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --border: #e3e5e8;
  --primary: #1d3557;
  --primary-text: #ffffff;
  --accent: #2f9e44;
  --warn: #e8590c;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --radius: 14px;
  --gap: 0.75rem;
  --tabbar-height: 3.6rem;
  --topbar-height: 3rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #1a1f26;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --border: #2a313a;
    --primary: #4c7ad1;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}

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

/* --- Top bar and tab bar ------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 0.5rem;
  min-height: calc(var(--topbar-height) + var(--safe-top));
  padding: var(--safe-top) 1rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar__title { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 650; }
.topbar a { text-decoration: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; /* 4 tabs for parents, 2 for a child */
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.1rem; font-size: 0.75rem; color: var(--muted); text-decoration: none;
}
.tabbar__item.is-active { color: var(--primary); font-weight: 600; }
.tabbar__icon { font-size: 1.2rem; line-height: 1; }

.page {
  max-width: 44rem; margin: 0 auto;
  padding: 1rem 1rem calc(var(--tabbar-height) + var(--safe-bottom) + 1.5rem);
}
body:not(.signed-in) .page { padding-bottom: 2rem; }

/* --- Layout helpers ----------------------------------------------------- */
.stack > * + * { margin-top: var(--gap); }
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.section-title { margin: 1.5rem 0 0.5rem; font-size: 0.8rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

/* --- Cards and lists ---------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.card h2, .card h3 { margin: 0 0 0.25rem; font-size: 1.05rem; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list__item { display: flex; align-items: center; gap: 0.75rem; padding: 0.8rem 1rem; border-top: 1px solid var(--border); color: inherit; text-decoration: none; }
.list__item:first-child { border-top: 0; }
.list__item > .grow { flex: 1; min-width: 0; }
a.list__item::after { content: "›"; color: var(--muted); font-size: 1.2rem; }

/* --- Buttons ------------------------------------------------------------ */
.btn, button, input[type="submit"] {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-height: 2.75rem; padding: 0 1rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn--primary, input[type="submit"].btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn--danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn--quiet { border-color: transparent; background: transparent; color: var(--primary); }
.btn--small { min-height: 2.1rem; padding: 0 0.8rem; font-size: 0.875rem; }
.btn--block { width: 100%; }
button[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: default; }
form.button_to { display: inline; }

/* --- Forms -------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field + .field { margin-top: 0.9rem; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field .hint { font-size: 0.8rem; color: var(--muted); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="time"], input[type="url"], input[type="search"], select, textarea {
  width: 100%; min-height: 2.75rem; padding: 0.5rem 0.75rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
.checkbox { display: flex; align-items: center; gap: 0.5rem; }
.form-errors { color: var(--danger); }
.form-actions { display: flex; gap: 0.5rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* --- Badges ------------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--border); color: var(--text); white-space: nowrap; }
.badge--ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge--warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge--danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge--muted { color: var(--muted); }

/* --- Avatars ------------------------------------------------------------ */
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; border-radius: 50%; color: #fff; font-weight: 700; font-size: 0.85rem; flex: none; background: var(--muted); object-fit: cover; }

/* --- Flash -------------------------------------------------------------- */
.flash-stack { max-width: 44rem; margin: 0 auto; padding: 0 1rem; }
.flash { margin-top: 0.75rem; padding: 0.7rem 1rem; border-radius: 10px; background: color-mix(in srgb, var(--ok) 15%, var(--surface)); }
.flash--alert { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); }
.banner { max-width: 44rem; margin: 0.75rem auto 0; padding: 0.7rem 1rem; border-radius: 10px; background: color-mix(in srgb, var(--warn) 18%, var(--surface)); }

/* --- Map markers (lib/map_base.js) -------------------------------------- */
.person-marker { background: none; border: 0; }
.person-marker__dot { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); color: #fff; font: 700 12px/1 system-ui, sans-serif; }
.person-marker__dot.is-stale { opacity: 0.55; }

/* --- Shared utilities ---------------------------------------------------- */
.topbar__back { display: inline-flex; align-items: center; min-height: 2.75rem; padding-right: 0.25rem; font-weight: 600; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Leaflet draws on an inner canvas owned by one map (lib/map_base.js createMap). */
.map-canvas { width: 100%; height: 100%; }
