/* Shared design system for every app under famhub.no. Link this BEFORE your
   app's own stylesheet:
     <link rel="stylesheet" href="/shared/tokens.css">
     <link rel="stylesheet" href="style.css">
   Your app's own CSS should build on these tokens (var(--accent), var(--space-4),
   etc.) rather than hardcoding colors/sizes - that's what keeps every app
   looking and behaving consistently, and keeps dark mode/responsiveness
   working everywhere for free. See CLAUDE.md for the full contract. */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* ---- Color ---- */
  --accent: #4361ee;
  --accent-dark: #3348c4;
  --accent-soft: #edf0ff;
  --text: #1a1a2e;
  --text-muted: #6b7086;
  --bg: #f7f8fc;
  --card-bg: #ffffff;
  --border: #e3e5f0;
  --danger: #c0392b;
  --shadow: rgba(20, 20, 35, 0.06);

  /* ---- Spacing scale (4px base) - use these instead of one-off px values ---- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* ---- Type scale - fluid (clamp), so text scales smoothly between phone
     and laptop instead of jumping at breakpoints ---- */
  --text-xs: clamp(0.72rem, 0.69rem + 0.15vw, 0.8rem);
  --text-sm: clamp(0.85rem, 0.82rem + 0.15vw, 0.92rem);
  --text-base: clamp(0.95rem, 0.92rem + 0.2vw, 1.05rem);
  --text-lg: clamp(1.1rem, 1.02rem + 0.4vw, 1.3rem);
  --text-xl: clamp(1.4rem, 1.2rem + 1vw, 1.8rem);
  --text-2xl: clamp(1.8rem, 1.5rem + 1.6vw, 2.4rem);

  /* ---- Radii ---- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* ---- Shell width - the centered column every app's shell should use.
     Widens at tablet/laptop instead of staying pinned to a phone-width
     column with wasted grey margins. See CLAUDE.md before adding any new
     fixed-position element (FAB, bottom nav) - there's a centering trick
     needed for those, already used by the hub and by calendar. ---- */
  --shell-max: 640px;
}

/* Tablet */
@media (min-width: 700px) {
  :root { --shell-max: 820px; }
}

/* Laptop / desktop */
@media (min-width: 1100px) {
  :root { --shell-max: 960px; }
}

/* A phone rotated to landscape is wide but short - unlike an actual laptop
   window, so it should use most of that width instead of sitting in a
   phone-width column with grey bars either side. */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --shell-max: min(96vw, 1100px); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #5b76f7;
    --accent-dark: #7891ff;
    --accent-soft: rgba(91, 118, 247, 0.22);
    --text: #e8e9f3;
    --text-muted: #9a9fbd;
    --bg: #121319;
    --card-bg: #1c1e2b;
    --border: #333650;
    --danger: #ff7a7a;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; color: inherit; }
a { color: inherit; }

/* ---------- Shell: the centered app column every app page uses ---------- */

.shell {
  min-height: 100vh;
  max-width: var(--shell-max);
  margin: 0 auto;
  position: relative;
}

@media (min-width: 700px) {
  .shell { background: var(--card-bg); box-shadow: 0 0 40px var(--shadow); }
}

/* ---------- Avatar - the person-identity atom used everywhere ---------- */

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  color: #fff;
  font-weight: 700;
  background: var(--accent);
  flex-shrink: 0;
}

.avatar-sm { width: 36px; height: 36px; font-size: var(--text-sm); }
.avatar-md { width: 56px; height: 56px; font-size: var(--text-lg); }
.avatar-lg { width: 72px; height: 72px; font-size: clamp(1.4rem, 1.2rem + 1vw, 1.7rem); margin: 0 auto var(--space-2); }

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

.btn-primary, .btn-secondary, .btn-text, .btn-danger {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  border: none;
  font-weight: 600;
  font-size: var(--text-base);
  min-height: 44px; /* touch target */
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-text { background: none; color: var(--text-muted); }
.btn-danger { background: none; color: var(--danger); border: 1px solid var(--danger); }

button:disabled { opacity: 0.6; cursor: default; }

/* ---------- Overlay / modal card - reusable for any app's dialogs ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 35, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

@media (min-width: 560px) { .overlay { align-items: center; } }
.overlay[hidden] { display: none; }

.card {
  background: var(--card-bg);
  width: 100%;
  max-width: 420px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-5);
  position: relative;
}

@media (min-width: 560px) {
  .card { border-radius: var(--radius-lg); }
}

/* Centered menu/confirm-dialog pattern: a title, stacked full-width
   buttons. Used for the hub's account menu and any app's confirm dialogs. */
.menu-card { text-align: center; }
.menu-name { font-weight: 700; font-size: var(--text-lg); margin-bottom: var(--space-4); }
.menu-card button { display: block; width: 100%; margin-top: var(--space-3); }

/* ---------- PIN pad components (hub login + any app's own PIN prompts) ---------- */

.pin-dots {
  display: flex;
  justify-content: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  min-height: 16px;
}

.pin-dots span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  display: inline-block;
}

.pin-dots span.filled { background: var(--accent); }

.pin-error {
  color: var(--danger);
  font-size: var(--text-sm);
  min-height: 20px;
  margin-bottom: var(--space-2);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  max-width: 280px;
  margin: 0 auto;
}

.keypad button {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 1.3rem;
  font-weight: 600;
  min-height: 44px;
}

.keypad button:active { background: var(--bg); }
.keypad button.keypad-empty { visibility: hidden; }

/* ---------- Form-sheet building blocks (any app's add/edit forms) ---------- */

.sheet form label {
  display: block;
  font-weight: 600;
  font-size: var(--text-sm);
  margin-top: var(--space-4);
  margin-bottom: var(--space-2);
}

.sheet form label:first-of-type { margin-top: 0; }

.sheet input[type="text"],
.sheet input[type="date"],
.sheet input[type="number"] {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--card-bg);
  color: var(--text);
}

.field-label { font-weight: 600; font-size: var(--text-sm); margin-top: var(--space-4); margin-bottom: var(--space-2); }

.people-toggle { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.people-toggle button {
  border: 2px solid var(--border);
  background: var(--card-bg);
  border-radius: 20px;
  padding: 6px var(--space-4);
  font-weight: 600;
  font-size: var(--text-sm);
}

.people-toggle button.selected { border-color: currentColor; color: #fff; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--text-sm);
  margin-top: var(--space-4);
}

.checkbox-label[hidden] { display: none; }
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }

.add-error { color: var(--danger); font-size: var(--text-sm); min-height: 20px; margin-top: var(--space-2); }

.sheet-actions { display: flex; gap: var(--space-2); margin-top: var(--space-5); }
.sheet-actions button { flex: 1; }

/* ---------- Small utilities ---------- */

.empty-note { color: var(--text-muted); text-align: center; padding: var(--space-6) 0; }
