/* ── Fonts ─────────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300..900;1,9..144,300..900&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap');

/* ── Variables (Light) ─────────────────────────────────────────────────────── */
:root {
  --bg:           #FBF5EE;
  --surface:      #FFFFFF;
  --surface-2:    #F5EBDF;
  --surface-3:    #EDE0D3;
  --border:       #E0CFC2;
  --border-s:     #C5B09E;

  --text:         #1E0F05;
  --text-2:       #7A5A46;
  --text-3:       #B09080;

  --accent:       #C85A1A;
  --accent-h:     #A04412;
  --accent-l:     #FDEEE6;
  --gold:         #D4943A;

  --c-family:     #D4622A;
  --c-health:     #3D8A58;
  --c-work:       #2A5F96;
  --c-other:      #7A6A5A;

  --c-family-bg:  #FEF0E8;
  --c-health-bg:  #E8F5EC;
  --c-work-bg:    #E8EFF8;
  --c-other-bg:   #F0EDE8;

  --r:            14px;
  --r-sm:         8px;
  --r-lg:         24px;
  --r-xl:         32px;

  --shadow-sm:    0 1px 4px rgba(30,15,5,.06);
  --shadow:       0 2px 12px rgba(30,15,5,.08);
  --shadow-lg:    0 8px 32px rgba(30,15,5,.12);
  --shadow-xl:    0 16px 48px rgba(30,15,5,.16);

  --nav-h:        72px;
  --header-h:     60px;
  --safe-b:       env(safe-area-inset-bottom, 0px);

  --ease:         cubic-bezier(.4,0,.2,1);
  --spring:       cubic-bezier(.34,1.56,.64,1);
  --t:            240ms;
}

/* ── Variables (Dark) ──────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:           #120A05;
  --surface:      #1D1108;
  --surface-2:    #271810;
  --surface-3:    #331F14;
  --border:       #3D2418;
  --border-s:     #503020;

  --text:         #F0E4D8;
  --text-2:       #9A7060;
  --text-3:       #6A5045;

  --accent:       #E8682A;
  --accent-h:     #FF7835;
  --accent-l:     #3A2010;
  --gold:         #E0A848;

  --c-family-bg:  #2A1A10;
  --c-health-bg:  #0E2018;
  --c-work-bg:    #101828;
  --c-other-bg:   #201A14;

  --shadow-sm:    0 1px 4px rgba(0,0,0,.3);
  --shadow:       0 2px 12px rgba(0,0,0,.35);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.45);
  --shadow-xl:    0 16px 48px rgba(0,0,0,.55);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ── Grain overlay ─────────────────────────────────────────────────────────── */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 9999;
  opacity: .028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 300px;
}
[data-theme="dark"] .grain { opacity: .06; }

/* ── Typography ────────────────────────────────────────────────────────────── */
.font-display { font-family: 'Fraunces', Georgia, serif; }
h1,h2,h3 { font-family: 'Fraunces', Georgia, serif; line-height: 1.2; }
h1 { font-size: clamp(2rem, 5vw, 2.8rem); font-weight: 600; }
h2 { font-size: clamp(1.4rem, 3.5vw, 1.8rem); font-weight: 500; }
h3 { font-size: 1.15rem; font-weight: 500; }

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.header-brand {
  display: flex; align-items: center; gap: 10px;
}
.brand-icon {
  width: 32px; height: 32px; color: var(--accent);
  flex-shrink: 0;
}
.brand-name {
  font-family: 'Fraunces', serif;
  font-size: .82rem; font-weight: 600;
  font-style: italic;
  color: var(--text);
  letter-spacing: -.01em;
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.btn-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  background: transparent;
  transition: background var(--t) var(--ease), color var(--t) var(--ease), transform .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon:active { transform: scale(.9); }
.btn-icon svg { width: 20px; height: 20px; }
.user-chip {
  display: flex; align-items: center;
  height: 34px; padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .82rem; font-weight: 600;
  color: var(--text-2);
  gap: 6px;
  transition: background var(--t) var(--ease);
}
.user-chip svg { width: 14px; height: 14px; }

/* ── Main content ──────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  padding-bottom: calc(var(--nav-h) + var(--safe-b));
  position: relative;
}

/* ── Views ─────────────────────────────────────────────────────────────────── */
.view {
  display: none;
  padding: 24px 20px;
  animation: viewIn var(--t) var(--ease) both;
}
.view.active { display: block; }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Bottom navigation ─────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 640px;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; align-items: flex-start;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  transition: background var(--t) var(--ease);
}
.nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  height: var(--nav-h);
  padding-top: 10px;
  color: var(--text-3);
  font-size: .72rem; font-weight: 600;
  letter-spacing: .02em; text-transform: uppercase;
  border-radius: 0;
  transition: color var(--t) var(--ease);
  position: relative;
  min-width: 44px;
}
.nav-item svg { width: 22px; height: 22px; transition: transform .2s var(--spring); }
.nav-item:active svg { transform: scale(.85); }
.nav-item.active { color: var(--accent); }
.nav-item.active::before {
  content: '';
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 32px; height: 3px;
  background: var(--accent);
  border-radius: 0 0 3px 3px;
}
.nav-item span { transition: color var(--t) var(--ease); }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow); }
.card + .card, .card + * { margin-top: 12px; }

/* ── Section heading ───────────────────────────────────────────────────────── */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-title {
  font-family: 'Fraunces', serif;
  font-size: 1.1rem; font-weight: 600;
  color: var(--text);
  letter-spacing: -.02em;
}
.section-action {
  font-size: .8rem; font-weight: 600;
  color: var(--accent);
  padding: 4px 0;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px;
  border-radius: var(--r-sm);
  font-size: .9rem; font-weight: 600;
  transition: background var(--t) var(--ease), color var(--t) var(--ease),
              transform .15s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px rgba(200,90,26,.3);
}
.btn-primary:hover { background: var(--accent-h); box-shadow: 0 4px 16px rgba(200,90,26,.4); }
.btn-secondary {
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-lg { height: 52px; font-size: 1rem; border-radius: var(--r); }
.btn-sm { height: 36px; font-size: .82rem; padding: 0 14px; }
.btn-full { width: 100%; }
.btn svg { width: 18px; height: 18px; }

/* ── FAB ───────────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 20px);
  right: 20px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(200,90,26,.4);
  z-index: 40;
  transition: transform .2s var(--spring), box-shadow .2s;
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(200,90,26,.5); }
.fab:active { transform: scale(.94); }
.fab svg { width: 24px; height: 24px; }

/* ── Form fields ───────────────────────────────────────────────────────────── */
.field { margin-bottom: 18px; }
.field-label {
  display: block;
  font-size: .82rem; font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
  letter-spacing: .02em; text-transform: uppercase;
}
.field-wrap { position: relative; }
.field-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--text-3);
  pointer-events: none;
}
.field-input, .field-select, .field-textarea {
  width: 100%;
  height: 50px;
  padding: 0 16px 0 44px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: .95rem; color: var(--text);
  appearance: none;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.field-input.no-icon {
  padding-left: 16px;
}
.field-select { padding-left: 16px; cursor: pointer; }
.field-textarea {
  height: auto; min-height: 90px;
  padding: 14px 16px; resize: vertical; line-height: 1.5;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-l);
}
.field-toggle {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); border-radius: var(--r-sm);
}
.field-toggle:hover { color: var(--text-2); }
.field-toggle svg { width: 18px; height: 18px; }

/* Color selector */
.color-select {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.color-opt {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: .82rem; font-weight: 600;
  color: var(--text-2);
  background: var(--surface-2);
  cursor: pointer;
  transition: all .15s;
}
.color-opt:hover { border-color: var(--border-s); }
.color-opt.selected { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: var(--c); }
.color-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--c);
}

/* ── Tags / Badges ─────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 10px;
  border-radius: 999px;
  font-size: .75rem; font-weight: 600;
  letter-spacing: .03em;
}
.tag-family  { background: var(--c-family-bg);  color: var(--c-family); }
.tag-health  { background: var(--c-health-bg);  color: var(--c-health); }
.tag-work    { background: var(--c-work-bg);    color: var(--c-work); }
.tag-other   { background: var(--c-other-bg);   color: var(--c-other); }
.tag-dot {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}

/* ── Alert ─────────────────────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px;
  border-radius: var(--r-sm);
  font-size: .88rem; font-weight: 500;
  margin-bottom: 18px;
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-error { background: #FEE2E2; color: #B91C1C; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: calc(var(--nav-h) + var(--safe-b) + 12px); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 9000; width: 90%; max-width: 400px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  background: var(--text); color: var(--bg);
  border-radius: var(--r);
  font-size: .88rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toastIn .3s var(--spring) both;
}
.toast.out { animation: toastOut .25s var(--ease) both; }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }
.toast-ok   { background: #1a3a28; color: #a7f3d0; }
.toast-err  { background: #3a1a1a; color: #fca5a5; }
@keyframes toastIn  { from { opacity:0; transform:translateY(16px) scale(.95); } to { opacity:1; transform:none; } }
@keyframes toastOut { to   { opacity:0; transform:translateY(-8px) scale(.95); } }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0);
  backdrop-filter: blur(0px);
  z-index: 200;
  transition: background .25s var(--ease), backdrop-filter .25s;
  pointer-events: none;
}
.modal-backdrop.open {
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  pointer-events: all;
}
.modal-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 201; pointer-events: none;
}
.modal {
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  width: 100%; max-width: 640px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 8px 24px calc(28px + var(--safe-b));
  box-shadow: var(--shadow-xl);
  transform: translateY(100%);
  transition: transform .35s var(--spring);
  pointer-events: all;
  overscroll-behavior: contain;
}
.modal.open { transform: translateY(0); }
.modal-pill {
  width: 40px; height: 4px;
  background: var(--border-s); border-radius: 2px;
  margin: 0 auto 20px;
}
.modal-title {
  font-family: 'Fraunces', serif;
  font-size: 1.4rem; font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
  letter-spacing: -.02em;
}
.modal-actions {
  display: flex; gap: 10px; margin-top: 8px;
}
.modal-actions .btn { flex: 1; }

/* ── Home view ─────────────────────────────────────────────────────────────── */
.home-hero {
  margin-bottom: 28px;
}
.home-date {
  font-size: .82rem; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3);
  margin-bottom: 6px;
}
.home-greeting {
  font-family: 'Fraunces', serif;
  font-size: clamp(1.8rem,5vw,2.4rem); font-weight: 600;
  line-height: 1.15; color: var(--text);
  letter-spacing: -.03em;
}
.home-greeting em { font-style: italic; color: var(--accent); }
.home-stats {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.stat-number {
  font-family: 'Fraunces', serif;
  font-size: 2.2rem; font-weight: 700; line-height: 1;
  color: var(--accent); margin-bottom: 4px;
}
.stat-label { font-size: .78rem; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.event-list-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.event-list-item:last-child { border-bottom: none; }
.event-color-bar {
  width: 3px; align-self: stretch; border-radius: 2px; flex-shrink: 0;
  min-height: 36px;
}
.event-color-bar.family { background: var(--c-family); }
.event-color-bar.health { background: var(--c-health); }
.event-color-bar.work   { background: var(--c-work); }
.event-color-bar.other  { background: var(--c-other); }
.event-info { flex: 1; min-width: 0; }
.event-title { font-size: .92rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.event-meta  { font-size: .78rem; color: var(--text-3); margin-top: 2px; }
.event-date-badge {
  font-size: .72rem; font-weight: 700;
  color: var(--text-3);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 4px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.empty-state {
  text-align: center; padding: 32px 20px; color: var(--text-3);
}
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ── Calendar ──────────────────────────────────────────────────────────────── */
.cal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.cal-month-label {
  font-family: 'Fraunces', serif;
  font-size: 1.3rem; font-weight: 600;
  color: var(--text); letter-spacing: -.02em;
}
.cal-nav { display: flex; gap: 6px; }
.cal-nav-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
  transition: all .15s;
}
.cal-nav-btn:hover { background: var(--surface-3); }
.cal-nav-btn:active { transform: scale(.93); }
.cal-nav-btn svg { width: 18px; height: 18px; }
.cal-grid-head {
  display: grid; grid-template-columns: repeat(7, 1fr);
  margin-bottom: 6px;
}
.cal-day-name {
  text-align: center;
  font-size: .7rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-3);
  padding: 4px 0;
}
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start;
  padding: 6px 2px 4px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .15s;
  position: relative;
  min-height: 44px;
}
.cal-cell:hover { background: var(--surface-2); }
.cal-cell.empty { cursor: default; pointer-events: none; }
.cal-cell.today {
  background: var(--accent-l);
}
.cal-cell.today .cal-day-num { color: var(--accent); font-weight: 700; }
.cal-cell.today::after {
  content: '';
  position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent);
}
.cal-day-num {
  font-size: .88rem; font-weight: 500; color: var(--text); line-height: 1;
}
.cal-dots {
  display: flex; gap: 2px; flex-wrap: wrap;
  justify-content: center; margin-top: 3px;
}
.cal-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
}
.cal-dot.family           { background: var(--c-family); }
.cal-dot.health           { background: var(--c-health); }
.cal-dot.work             { background: var(--c-work); }
.cal-dot.other            { background: var(--c-other); }
.cal-dot.birthday         { background: var(--gold); width: 6px; height: 6px; }
.cal-dot.death_anniversary{ background: var(--text-3); width: 5px; height: 5px; border-radius: 2px; }

/* ── Birthday / Anniversary items ─────────────────────────────── */
.bday-card { margin-bottom: 12px; }
.bday-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.bday-item:last-child { border-bottom: none; }
.bday-item.is-today {
  background: var(--accent-l);
  margin: 0 -20px; padding: 10px 20px;
  border-radius: var(--r-sm);
  border-bottom: none;
}
.bday-icon { font-size: 1.4rem; flex-shrink: 0; width: 34px; text-align: center; line-height: 1; }
.bday-info { flex: 1; min-width: 0; }
.bday-name { font-size: .9rem; font-weight: 600; color: var(--text); }
.bday-meta { font-size: .75rem; color: var(--text-3); margin-top: 2px; }
.bday-badge {
  font-size: .72rem; font-weight: 700; white-space: nowrap;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-3);
  border: 1px solid var(--border);
}
.bday-badge.today-badge { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Calendar birthday event item */
.cal-bday-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 8px;
  border-left-width: 3px;
}
.cal-bday-icon { font-size: 1.2rem; line-height: 1; flex-shrink: 0; }
.cal-bday-body { flex: 1; }
.cal-bday-name { font-size: .88rem; font-weight: 600; color: var(--text); }
.cal-bday-meta { font-size: .75rem; color: var(--text-3); margin-top: 2px; }

.cal-events-panel {
  margin-top: 20px;
}
.cal-event-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 8px;
  transition: background var(--t) var(--ease);
  cursor: pointer;
}
.cal-event-item:hover { background: var(--surface-2); }
.cal-event-body { flex: 1; min-width: 0; }
.cal-event-name { font-size: .92rem; font-weight: 600; color: var(--text); }
.cal-event-desc { font-size: .8rem; color: var(--text-2); margin-top: 2px; }
.cal-event-by   { font-size: .74rem; color: var(--text-3); margin-top: 4px; }
.cal-event-actions { display: flex; gap: 6px; }
.cal-event-actions .btn-icon { width: 32px; height: 32px; }
.cal-selected-label {
  font-size: .78rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-3);
  margin-bottom: 12px;
}

/* ── Shopping ──────────────────────────────────────────────────────────────── */
.shop-category {
  margin-bottom: 20px;
}
.shop-cat-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-3);
  padding: 0 4px;
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 8px;
}
.shop-cat-label::after {
  content: ''; flex: 1; height: 1px;
  background: var(--border);
}
.shop-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  margin-bottom: 6px;
  transition: background var(--t) var(--ease), opacity .3s, border-color var(--t) var(--ease);
}
.shop-item.done {
  opacity: .55;
  background: var(--surface-2);
}
.shop-check {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--border-s);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
  transition: all .2s var(--spring);
  color: transparent;
}
.shop-check:hover { border-color: var(--accent); }
.shop-check.checked {
  background: var(--c-health); border-color: var(--c-health); color: #fff;
}
.shop-check svg { width: 13px; height: 13px; }
.shop-info { flex: 1; min-width: 0; }
.shop-name {
  font-size: .92rem; font-weight: 600; color: var(--text);
  transition: color .3s;
  position: relative; display: inline-block;
}
.shop-item.done .shop-name {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: var(--text-3);
}
.shop-qty  { font-size: .78rem; color: var(--text-3); margin-top: 1px; }
.shop-del  {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); flex-shrink: 0;
  transition: all .15s; opacity: 0;
}
.shop-item:hover .shop-del { opacity: 1; }
.shop-del:hover { background: #fee2e2; color: #b91c1c; }
.shop-del svg { width: 16px; height: 16px; }
.shop-add-row {
  display: flex; gap: 8px; margin-bottom: 20px;
}
.shop-add-row .field-input { padding-left: 16px; }
.shop-filters {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px;
  margin-bottom: 16px; scrollbar-width: none;
}
.shop-filters::-webkit-scrollbar { display: none; }
.filter-chip {
  display: flex; align-items: center; gap: 5px;
  height: 34px; padding: 0 14px;
  border-radius: 999px;
  font-size: .8rem; font-weight: 600;
  white-space: nowrap; flex-shrink: 0;
  background: var(--surface-2); color: var(--text-2);
  border: 1px solid var(--border);
  transition: all .15s;
}
.filter-chip:hover { border-color: var(--border-s); }
.filter-chip.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}

/* ── Install bottom sheet ───────────────────────────────────────────────────── */
.install-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 250;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border-top: 1px solid var(--border);
  padding: 8px 24px calc(28px + var(--safe-b));
  box-shadow: var(--shadow-xl);
  /* Sprečava selekciju teksta na tapkanju */
  user-select: none;
  -webkit-user-select: none;
  animation: slideUp .35s var(--spring) both;
  max-width: 640px;
  margin: 0 auto;
}
.install-sheet[hidden] { display: none; }
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.install-sheet-pill {
  width: 40px; height: 4px;
  background: var(--border-s); border-radius: 2px;
  margin: 0 auto 18px;
}
.install-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.install-sheet-brand {
  display: flex; align-items: center; gap: 12px;
}
.install-sheet-title {
  font-family: 'Fraunces', serif;
  font-size: 1.15rem; font-weight: 700;
  color: var(--text); letter-spacing: -.02em;
  font-style: italic;
}
.install-sheet-sub {
  font-size: .78rem; color: var(--text-3); margin-top: 1px;
}
.install-sheet-close {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); flex-shrink: 0;
  transition: background .15s;
}
.install-sheet-close:hover { background: var(--surface-2); color: var(--text-2); }
.install-sheet-desc {
  font-size: .88rem; color: var(--text-2);
  line-height: 1.5; margin-bottom: 18px;
}
/* Backdrop za sheet */
.install-sheet::before {
  content: '';
  position: fixed;
  inset: 0; bottom: 100%;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(3px);
  z-index: -1;
  pointer-events: none;
}

/* ── Login page ────────────────────────────────────────────────────────────── */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh;
  padding: 24px 20px calc(24px + var(--safe-b));
  overflow: hidden;
}
.login-wrap {
  width: 100%; max-width: 420px;
  position: relative;
}
.login-deco {
  position: absolute; top: -60px; right: -40px;
  width: 240px; height: 240px;
  pointer-events: none; z-index: 0;
}
.login-deco-inner { position: relative; width: 100%; height: 100%; }
.deco-circle {
  position: absolute; border-radius: 50%;
  background: var(--accent); opacity: .08;
}
.deco-c1 { width: 180px; height: 180px; top: 0; right: 0; }
.deco-c2 { width: 120px; height: 120px; top: 40px; right: 80px; background: var(--gold); opacity: .12; }
.deco-c3 { width: 70px; height: 70px; top: 10px; right: 30px; opacity: .2; }
.deco-icon {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 80px; height: 80px; color: var(--accent); opacity: .25;
}
.deco-icon svg { width: 100%; height: 100%; }
.login-card {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-xl);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.login-header { margin-bottom: 28px; }
.login-title {
  font-family: 'Fraunces', serif;
  font-size: 2.2rem; font-weight: 700;
  color: var(--text); letter-spacing: -.04em;
  font-style: italic;
  line-height: 1.1; margin-bottom: 6px;
}
.login-subtitle { font-size: .92rem; color: var(--text-2); }
.login-hint {
  text-align: center; margin-top: 20px;
  font-size: .78rem; color: var(--text-3);
}
.login-hint code {
  background: var(--surface-2); color: var(--text-2);
  padding: 2px 6px; border-radius: 4px;
  font-family: 'Courier New', monospace; font-size: .78rem;
}
.theme-toggle-login {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: background .15s, color .15s;
}
.theme-toggle-login:hover { background: var(--surface-2); color: var(--text-2); }
.theme-toggle-login svg { width: 18px; height: 18px; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"]  .icon-sun  { display: none; }

/* ── Divider ───────────────────────────────────────────────────────────────── */
.divider {
  height: 1px; background: var(--border);
  margin: 20px 0;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-s); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ── Focus ─────────────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: .82rem; }
.text-muted { color: var(--text-3); }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Brand family name ──────────────────────────────────────────────────────── */
.brand-text { display: flex; flex-direction: column; gap: 0; }
.brand-family {
  font-size: .68rem; font-weight: 600;
  color: var(--accent); letter-spacing: .03em;
  text-transform: uppercase; line-height: 1;
  margin-top: 1px;
}
.user-chip-badge {
  background: var(--accent-l); color: var(--accent);
  border-radius: 999px; padding: 1px 6px;
  font-size: .65rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  margin-left: 2px;
}

/* ── Settings page ──────────────────────────────────────────────────────────── */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.settings-section-head {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
.settings-section-icon {
  width: 38px; height: 38px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.settings-section-icon svg { width: 20px; height: 20px; }
.si-family  { background: var(--c-family-bg);  color: var(--c-family); }
.si-users   { background: var(--c-work-bg);    color: var(--c-work); }
.si-calendar{ background: var(--accent-l);      color: var(--accent); }
.si-shop    { background: var(--c-health-bg);  color: var(--c-health); }
.si-security{ background: #FEF0E8;             color: #9A3B00; }
.si-info    { background: var(--surface-3);    color: var(--text-3); }
.settings-section-labels {}
.settings-section-title {
  font-size: .95rem; font-weight: 700; color: var(--text);
}
.settings-section-desc {
  font-size: .78rem; color: var(--text-3); margin-top: 2px;
}
.settings-section-body { padding: 4px 0; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 58px;
  transition: background .15s;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: var(--surface-2); }
.settings-row-label {}
.settings-row-title {
  font-size: .9rem; font-weight: 600; color: var(--text);
}
.settings-row-desc {
  font-size: .76rem; color: var(--text-3); margin-top: 2px;
}
.settings-row-control { flex-shrink: 0; }
.settings-row-full {
  flex-direction: column; align-items: flex-start; gap: 10px;
}
.settings-row-full .settings-row-control { width: 100%; }

/* Toggle switch */
.toggle-switch {
  width: 50px; height: 28px; border-radius: 14px;
  background: var(--border-s);
  cursor: pointer; border: none;
  position: relative;
  transition: background .2s var(--spring);
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  transition: transform .2s var(--spring);
}
.toggle-switch[aria-checked="true"] { background: var(--c-health); }
.toggle-switch[aria-checked="true"]::after { transform: translateX(22px); }

/* Inline settings input */
.settings-input {
  height: 40px; padding: 0 12px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: .9rem; color: var(--text);
  width: 100%;
  transition: border-color .2s, box-shadow .2s;
}
.settings-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-l);
}
.settings-input-sm { max-width: 100px; }
.settings-input-md { max-width: 200px; }

/* Segment/radio pills */
.seg-group {
  display: flex; border-radius: var(--r-sm); overflow: hidden;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
}
.seg-btn {
  flex: 1; height: 36px; padding: 0 14px;
  font-size: .82rem; font-weight: 600; color: var(--text-2);
  border: none; background: transparent;
  cursor: pointer; white-space: nowrap;
  transition: all .15s;
  border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active {
  background: var(--accent); color: #fff;
  box-shadow: none;
}

/* User list */
.user-list { padding: 0; }
.user-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.user-item:last-child { border-bottom: none; }
.user-item:hover { background: var(--surface-2); }
.user-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent-l); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif;
  font-size: 1rem; font-weight: 700;
  flex-shrink: 0;
}
.user-avatar.admin { background: var(--accent); color: #fff; }
.user-item-info { flex: 1; min-width: 0; }
.user-item-name {
  font-size: .92rem; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.user-item-meta { font-size: .76rem; color: var(--text-3); margin-top: 2px; }
.badge {
  display: inline-flex; align-items: center;
  height: 20px; padding: 0 8px;
  border-radius: 999px;
  font-size: .68rem; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
}
.badge-admin { background: var(--accent-l); color: var(--accent); }
.badge-user  { background: var(--surface-3); color: var(--text-3); }
.user-item-actions { display: flex; gap: 6px; }
.user-item-actions .btn { height: 32px; font-size: .78rem; padding: 0 10px; }

/* System info grid */
.sysinfo-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 1px; background: var(--border);
}
.sysinfo-item {
  padding: 14px 20px;
  background: var(--surface);
  transition: background var(--t) var(--ease);
}
.sysinfo-label { font-size: .72rem; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.sysinfo-value { font-size: .92rem; font-weight: 600; color: var(--text); font-family: 'Fraunces', serif; }

/* Family name hero on home */
.home-family-tag {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 12px;
  background: var(--accent-l);
  border-radius: 999px;
  font-size: .78rem; font-weight: 700;
  color: var(--accent); letter-spacing: .02em;
  margin-bottom: 10px;
}

/* Settings page title */
.settings-page-title {
  font-family: 'Fraunces', serif;
  font-size: 1.6rem; font-weight: 600;
  color: var(--text); letter-spacing: -.02em;
  margin-bottom: 20px;
}

/* ── Family Tree ────────────────────────────────────────────────────────────── */
.tree-view-header {
  margin-bottom: 20px;
}
.tree-view-title {
  font-family: 'Fraunces', serif;
  font-size: 1.6rem; font-weight: 700;
  color: var(--text); letter-spacing: -.02em;
  display: flex; align-items: center; gap: 10px;
}
.tree-view-meta { font-size: .82rem; color: var(--text-3); margin-top: 4px; }

.tree-scroll-wrap {
  overflow: auto;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}
.tree-scroll-wrap:active { cursor: grabbing; }

.tree-canvas {
  position: relative;
  /* width/height set via JS */
}

/* SVG lines */
.tree-svg {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  overflow: visible;
}
.tree-branch {
  stroke: var(--border-s);
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
}
[data-theme="dark"] .tree-branch { stroke: #5A3A28; }

.tree-spouse-line {
  stroke: var(--accent);
  stroke-width: 2;
  fill: none;
  stroke-dasharray: 5 3;
  stroke-linecap: round;
  opacity: .7;
}
.tree-heart {
  font-size: 12px;
  fill: var(--accent);
  user-select: none;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.2));
}

/* Generation label */
.tree-gen-label {
  position: absolute;
  left: 12px;
  display: flex; align-items: center;
  font-size: .68rem; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3);
  height: 110px;
}

/* Person node */
.tree-person {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  cursor: pointer;
  z-index: 2;
  transition: transform .18s var(--spring);
}
.tree-person:hover { transform: translateY(-4px) scale(1.04); }
.tree-person:focus { outline: 2px solid var(--accent); border-radius: 50%; }

.tree-medallion {
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif;
  font-size: 1.5rem; font-weight: 700;
  color: #fff;
  border: 3px solid rgba(255,255,255,.5);
  box-shadow: 0 4px 18px rgba(0,0,0,.18);
  margin-bottom: 8px;
  position: relative;
  transition: box-shadow .2s;
}
.tree-person:hover .tree-medallion { box-shadow: 0 8px 28px rgba(0,0,0,.25); }
.tree-medallion.gender-male    { background: linear-gradient(140deg,#2A5F96,#5A90CC); }
.tree-medallion.gender-female  { background: linear-gradient(140deg,#B8441A,#E07848); }
.tree-medallion.gender-other   { background: linear-gradient(140deg,#3A7A5C,#68B090); }
.tree-medallion.gender-unknown { background: linear-gradient(140deg,#7A6050,#A08878); }
.tree-medallion.deceased       { filter: grayscale(.75); opacity: .7; }
.tree-medallion.has-account::after {
  content: '●';
  position: absolute; bottom: -1px; right: -1px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--c-health);
  border: 2px solid var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; color: #fff;
  text-indent: -99em;
  box-shadow: 0 0 0 2px rgba(58,138,88,.3);
}
.tree-medallion.has-account::before {
  content: '';
  position: absolute; bottom: -1px; right: -1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--c-health);
  border: 2px solid var(--surface);
}

.tree-node-name {
  font-size: .78rem; font-weight: 700; text-align: center;
  color: var(--text); line-height: 1.2;
  max-width: 120px;
}
.tree-node-year {
  font-size: .7rem; color: var(--text-3); text-align: center;
  margin-top: 2px;
}
.tree-node-role {
  font-size: .65rem; color: var(--text-3); text-align: center;
  font-style: italic; margin-top: 1px;
  max-width: 120px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* Empty tree state */
.tree-empty {
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 20px; text-align: center; color: var(--text-3);
}
.tree-empty-icon { font-size: 4rem; margin-bottom: 16px; opacity: .5; }
.tree-empty h3 { font-family: 'Fraunces', serif; font-size: 1.2rem; color: var(--text-2); margin-bottom: 8px; }
.tree-empty p { font-size: .88rem; }

/* Person detail tooltip */
.tree-tooltip {
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  box-shadow: var(--shadow-xl);
  max-width: 240px;
  animation: toastIn .2s var(--spring) both;
  pointer-events: none;
}
.tree-tooltip-name {
  font-family: 'Fraunces', serif;
  font-size: 1rem; font-weight: 700; color: var(--text);
}
.tree-tooltip-row {
  display: flex; gap: 6px; align-items: flex-start;
  font-size: .78rem; color: var(--text-2); margin-top: 5px;
}
.tree-tooltip-row span:first-child {
  color: var(--text-3); font-weight: 600; white-space: nowrap;
  text-transform: uppercase; font-size: .65rem; min-width: 54px;
}

/* Family member settings list */
.fmember-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.fmember-item:last-child { border-bottom: none; }
.fmember-item:hover { background: var(--surface-2); }
.fmember-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Fraunces', serif;
  font-size: .95rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.fa-male    { background: linear-gradient(140deg,#2A5F96,#5A90CC); }
.fa-female  { background: linear-gradient(140deg,#B8441A,#E07848); }
.fa-other   { background: linear-gradient(140deg,#3A7A5C,#68B090); }
.fa-unknown { background: linear-gradient(140deg,#7A6050,#A08878); }
.fmember-info { flex: 1; min-width: 0; }
.fmember-name { font-size: .9rem; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.fmember-meta { font-size: .75rem; color: var(--text-3); margin-top: 2px; }
.fmember-actions { display: flex; gap: 6px; }

/* ── Admin switch banner ───────────────────────────────────────────────────── */
.switch-user-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: .82rem;
  color: var(--text-2);
}
.switch-user-banner strong { color: var(--text); }

/* ── Desktop layout ────────────────────────────────────────────────────────── */
@media (min-width: 640px) {
  .view { padding: 32px 28px; }
  .home-stats { grid-template-columns: repeat(4, 1fr); }
  .login-card { padding: 44px 40px 40px; }
}
