/*
 * application.css — Family Hub design system
 * =============================================================================
 * This file holds the shared, app-wide design system. Feature stylesheets
 * (dashboard.css, todos.css, calendar.css, posts.css, links.css) should build
 * on top of these tokens and components rather than redefining them.
 *
 * Design tokens live in :root as CSS custom properties (--fh-*). Prefer using
 * them so the whole app stays visually consistent.
 *
 * Reusable component classes provided here (use these in feature views):
 *   Layout ....... .container, .site-nav, .page-header, .page-title,
 *                  .page-subtitle
 *   Surfaces ..... .card
 *   Buttons ...... .btn, .btn-primary, .btn-secondary, .btn-danger, .btn-sm
 *   Forms ........ .form, .form-group, .form-actions, .form-errors,
 *                  .field-hint  (label/input/textarea/select styled within .form)
 *   Badges ....... .badge, .badge-kid, .badge-adult, .badge-muted, .badge-accent,
 *                  .badge-removed
 *   Feedback ..... .flash, .flash-notice, .flash-alert, .empty-state
 *   Bits ......... .muted, .avatar (.avatar-sm / .avatar-lg)
 * =============================================================================
 */

:root {
  /* Palette — warm cream background with a friendly teal accent + terracotta. */
  --fh-bg: #faf6ef;
  --fh-surface: #ffffff;
  --fh-surface-muted: #f3ede2;
  --fh-border: #e7dfd1;

  --fh-text: #33302b;
  --fh-text-muted: #8a8272;

  --fh-accent: #2f8f83;         /* warm teal */
  --fh-accent-dark: #256f66;
  --fh-accent-soft: #e3f0ee;

  --fh-terracotta: #e07a5f;
  --fh-danger: #c0492f;
  --fh-danger-dark: #a03b25;
  --fh-danger-soft: #fdf0ec;         /* soft danger surface — form errors, alert flash, overdue badge */
  --fh-danger-soft-border: #f2c4b6;  /* border for the soft danger surface */

  --fh-accent-soft-border: #bfe0da;  /* border for the soft accent surface — notice flash */

  /* Ink painted on a filled theme surface (buttons, completed check). White on
     the light fills; inverts to dark ink in dark mode, where the fills lighten. */
  --fh-on-fill: #ffffff;

  /* Role badges. (The base --fh-kid/--fh-adult tokens were unused and retired;
     the kid/adult identity lives in these badge-scoped tokens.) */
  --fh-badge-kid-bg: #fbeccb;
  --fh-badge-kid-ink: #9a6a12;
  --fh-badge-adult-bg: #e4e8ec;
  --fh-badge-adult-ink: #4a5560;

  /* Typography */
  --fh-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
             Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --fh-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Spacing scale */
  --fh-space-1: 4px;
  --fh-space-2: 8px;
  --fh-space-3: 12px;
  --fh-space-4: 16px;
  --fh-space-5: 24px;
  --fh-space-6: 32px;
  --fh-space-8: 48px;

  /* Radius + shadow */
  --fh-radius: 12px;
  --fh-radius-sm: 8px;
  --fh-radius-pill: 999px;
  --fh-shadow: 0 1px 3px rgba(51, 48, 43, 0.08), 0 4px 12px rgba(51, 48, 43, 0.06);
  --fh-shadow-sm: 0 1px 2px rgba(51, 48, 43, 0.08);

  --fh-container: 1100px;

  /* Opt in to OS-follow theming: themes native date/time pickers, dropdowns,
     scrollbars, and form spinners in dark mode (the calendar/events forms use
     date/datetime-local/time inputs). No toggle, no persistence. */
  color-scheme: light dark;
}

/* -------------------------------------------------------------------------- */
/* Dark mode — OS-follow only (@media prefers-color-scheme). No toggle, no     */
/* persistence. Overrides every colour token with the locked dark palette      */
/* (issue #75); non-colour tokens (type, spacing, radius) are unchanged.        */
/* -------------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
  :root {
    /* Spine — 12 values approved in #44/#54, remapped to current token names. */
    --fh-bg: #1b1917;
    --fh-surface: #262320;
    --fh-surface-muted: #322e28;
    --fh-border: #423c34;

    --fh-text: #efe9de;
    --fh-text-muted: #a79e8e;

    --fh-accent: #3fa295;         /* warm teal */
    --fh-accent-dark: #7fd0c3;    /* INVERSION: lighter than light --fh-accent —
                                     links/hover/brand. Do NOT darken. */
    --fh-accent-soft: #23403b;

    --fh-terracotta: #e89a82;
    --fh-danger: #e08a72;
    --fh-danger-dark: #e8a892;

    /* Derived gaps + newly-tokenized surfaces (#75/#77). */
    --fh-danger-soft: #3a241f;
    --fh-danger-soft-border: #5b382f;
    --fh-accent-soft-border: #2f574f;

    /* Ink on the lightened dark fills — white would fail AA there. */
    --fh-on-fill: #1b1917;

    /* Role badges — soft dark tints. */
    --fh-badge-kid-bg: #3a3226;
    --fh-badge-kid-ink: #e9c48a;
    --fh-badge-adult-bg: #2b2f34;
    --fh-badge-adult-ink: #c2cad3;

    /* Shadow re-tinted for a dark ground (warm near-black tint reads wrong on
       dark → black, higher alpha). */
    --fh-shadow: 0 1px 3px rgba(0, 0, 0, 0.40), 0 4px 12px rgba(0, 0, 0, 0.32);
    --fh-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.40);
  }
}

/* -------------------------------------------------------------------------- */
/* Base                                                                       */
/* -------------------------------------------------------------------------- */

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

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

body {
  margin: 0;
  font-family: var(--fh-font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--fh-text);
  background-color: var(--fh-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--fh-accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--fh-space-3); }

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

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

.container {
  max-width: var(--fh-container);
  margin: 0 auto;
  padding: var(--fh-space-6) var(--fh-space-5);
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--fh-space-4);
  margin-bottom: var(--fh-space-5);
}

.page-title { font-size: 1.75rem; margin: 0; }
.page-subtitle { margin: var(--fh-space-1) 0 0; color: var(--fh-text-muted); }

/* -------------------------------------------------------------------------- */
/* Top navigation                                                             */
/* -------------------------------------------------------------------------- */

.site-nav {
  background: var(--fh-surface);
  border-bottom: 1px solid var(--fh-border);
  box-shadow: var(--fh-shadow-sm);
}

.site-nav-inner {
  max-width: var(--fh-container);
  margin: 0 auto;
  padding: var(--fh-space-3) var(--fh-space-5);
  display: flex;
  align-items: center;
  gap: var(--fh-space-5);
}

.brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--fh-accent-dark);
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--fh-space-1);
  flex: 1;
  flex-wrap: wrap;
}

.nav-link {
  padding: var(--fh-space-2) var(--fh-space-3);
  border-radius: var(--fh-radius-sm);
  color: var(--fh-text);
  font-weight: 500;
  font-size: 0.95rem;
}
.nav-link:hover { background: var(--fh-surface-muted); text-decoration: none; }
.nav-link-active {
  background: var(--fh-accent-soft);
  color: var(--fh-accent-dark);
  font-weight: 600;
}

.nav-user { display: flex; align-items: center; gap: var(--fh-space-3); }
.nav-user-link {
  display: flex; align-items: center; gap: var(--fh-space-2);
  color: var(--fh-text);
}
.nav-user-link:hover { text-decoration: none; }
.nav-user-name { font-weight: 600; font-size: 0.95rem; }

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

.card {
  background: var(--fh-surface);
  border: 1px solid var(--fh-border);
  border-radius: var(--fh-radius);
  box-shadow: var(--fh-shadow);
  padding: var(--fh-space-5);
}

/* -------------------------------------------------------------------------- */
/* Buttons                                                                    */
/* -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--fh-space-2);
  padding: var(--fh-space-3) var(--fh-space-4);
  border: 1px solid transparent;
  border-radius: var(--fh-radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  background: var(--fh-surface-muted);
  color: var(--fh-text);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--fh-accent); color: var(--fh-on-fill); }
.btn-primary:hover { background: var(--fh-accent-dark); }

.btn-secondary {
  background: var(--fh-surface);
  color: var(--fh-text);
  border-color: var(--fh-border);
}
.btn-secondary:hover { background: var(--fh-surface-muted); }

.btn-danger { background: var(--fh-danger); color: var(--fh-on-fill); }
.btn-danger:hover { background: var(--fh-danger-dark); }

.btn-sm { padding: var(--fh-space-2) var(--fh-space-3); font-size: 0.85rem; }

/* button_to renders a <form>; keep it inline so buttons sit alongside links. */
.nav-user form, form.button_to { display: inline; margin: 0; }

/* -------------------------------------------------------------------------- */
/* Forms                                                                      */
/* -------------------------------------------------------------------------- */

.form { display: block; }

.form-group { margin-bottom: var(--fh-space-4); }

.form label,
.form .form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: var(--fh-space-2);
  color: var(--fh-text);
}

.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form input[type="date"],
.form input[type="datetime-local"],
.form input[type="time"],
.form input[type="url"],
.form input[type="search"],
.form textarea,
.form select {
  width: 100%;
  padding: var(--fh-space-3);
  border: 1px solid var(--fh-border);
  border-radius: var(--fh-radius-sm);
  font-family: inherit;
  font-size: 1rem;
  color: var(--fh-text);
  background: var(--fh-surface);
}
.form textarea { min-height: 120px; resize: vertical; }

.form input:focus,
.form textarea:focus,
.form select:focus {
  outline: none;
  border-color: var(--fh-accent);
  box-shadow: 0 0 0 3px var(--fh-accent-soft);
}

.field-hint { font-size: 0.85rem; margin: var(--fh-space-1) 0 0; }

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--fh-space-3);
  margin-top: var(--fh-space-5);
}

.form-errors {
  background: var(--fh-danger-soft);
  border: 1px solid var(--fh-danger-soft-border);
  border-radius: var(--fh-radius-sm);
  padding: var(--fh-space-4);
  margin-bottom: var(--fh-space-4);
  color: var(--fh-danger-dark);
}
.form-errors-title { font-weight: 700; margin: 0 0 var(--fh-space-2); }
.form-errors ul { margin: 0; padding-left: var(--fh-space-5); }

/* -------------------------------------------------------------------------- */
/* Badges                                                                     */
/* -------------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 2px var(--fh-space-3);
  border-radius: var(--fh-radius-pill);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--fh-surface-muted);
  color: var(--fh-text-muted);
}
.badge-kid { background: var(--fh-badge-kid-bg); color: var(--fh-badge-kid-ink); }
.badge-adult { background: var(--fh-badge-adult-bg); color: var(--fh-badge-adult-ink); }
.badge-muted { background: var(--fh-surface-muted); color: var(--fh-text-muted); }
.badge-accent { background: var(--fh-accent-soft); color: var(--fh-accent-dark); }
/* Marks a byline whose member has been removed from the family. Rendered by
   member_name, never written into a view directly. */
.badge-removed { background: var(--fh-surface-muted); color: var(--fh-text-muted); }

/* -------------------------------------------------------------------------- */
/* Flash + empty states                                                       */
/* -------------------------------------------------------------------------- */

.flash {
  padding: var(--fh-space-3) var(--fh-space-4);
  border-radius: var(--fh-radius-sm);
  margin-bottom: var(--fh-space-5);
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-notice {
  background: var(--fh-accent-soft);
  color: var(--fh-accent-dark);
  border-color: var(--fh-accent-soft-border);
}
.flash-alert {
  background: var(--fh-danger-soft);
  color: var(--fh-danger-dark);
  border-color: var(--fh-danger-soft-border);
}

.empty-state {
  text-align: center;
  padding: var(--fh-space-8) var(--fh-space-5);
  background: var(--fh-surface);
  border: 1px dashed var(--fh-border);
  border-radius: var(--fh-radius);
  color: var(--fh-text-muted);
}
.empty-state p { margin: 0 0 var(--fh-space-4); }

/* -------------------------------------------------------------------------- */
/* Avatar                                                                     */
/* -------------------------------------------------------------------------- */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1;
  flex: none;
  user-select: none;
}
.avatar-sm { width: 30px; height: 30px; font-size: 0.75rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.2rem; }
/* A removed member's avatar, at the sites where the avatar is the only thing
   naming them. Set by avatar_tag, not by hand. */
.avatar-removed { opacity: 0.45; filter: grayscale(0.7); }

/* -------------------------------------------------------------------------- */
/* Auth (login) page                                                          */
/* -------------------------------------------------------------------------- */

.auth-card {
  max-width: 400px;
  margin: var(--fh-space-8) auto;
}
.auth-title { font-size: 1.6rem; margin-bottom: var(--fh-space-1); }
.auth-subtitle { margin-top: 0; margin-bottom: var(--fh-space-5); }

/* -------------------------------------------------------------------------- */
/* Family (users) page                                                        */
/* -------------------------------------------------------------------------- */

.form-card { max-width: 520px; }

.member-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--fh-space-4);
}
.member-card { display: flex; align-items: center; gap: var(--fh-space-4); }
.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 700; margin: 0; }
.member-email { margin: 0 0 var(--fh-space-2); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; }
.member-actions { display: flex; flex-direction: column; gap: var(--fh-space-2); flex: none; }

.former-members { margin-top: var(--fh-space-8); }
.former-members-title { font-size: 1.1rem; margin: 0 0 var(--fh-space-1); }
.former-members .muted { margin: 0 0 var(--fh-space-4); font-size: 0.9rem; }
.member-card-removed { opacity: 0.75; }

/* -------------------------------------------------------------------------- */
/* Responsive                                                                 */
/* -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .site-nav-inner { flex-wrap: wrap; gap: var(--fh-space-3); }
  .nav-links { order: 3; width: 100%; }
  .page-header { flex-direction: column; }
}
