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

html { font-family: var(--font-sans); background: var(--bg-canvas); color: var(--text-body); }
body { margin: 0; min-height: 100vh; background: var(--bg-canvas); color: var(--text-body); font-size: var(--text-md); line-height: var(--leading-normal); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.h1,.h2,.h3,.h4 { color: var(--text-strong); margin: 0; line-height: var(--leading-tight); }
.h1 { font-size: var(--text-3xl); font-weight: var(--weight-bold); letter-spacing: -.03em; }
.h2 { font-size: var(--text-2xl); font-weight: var(--weight-bold); letter-spacing: -.02em; }
.h3 { font-size: var(--text-xl); font-weight: var(--weight-semibold); }
.h4 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--bg-canvas);
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
}
.app-main { min-width: 0; }
.app-content {
  width: min(100%, var(--content-max));
  margin: 0 auto;
  padding: var(--space-4);
}
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  min-height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding: calc(var(--space-3) + env(safe-area-inset-top)) var(--space-4) var(--space-3);
  background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.topbar__title { flex: 1; min-width: 0; }
.topbar__eyebrow { font-size: var(--text-xs); color: var(--text-muted); }
.sidebar {
  display: none;
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: calc(var(--space-5) + env(safe-area-inset-top)) var(--space-4) var(--space-5);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
}
.sidebar__brand { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-8); }
.sidebar__nav { display: grid; gap: var(--space-1); }
.nav-item {
  min-height: var(--tap-target);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: var(--weight-medium);
}
.nav-item:hover { background: var(--bg-subtle); color: var(--text-strong); }
.nav-item--active { background: var(--color-brand-50); color: var(--color-brand-700); }
.theme-dark .nav-item--active { background: var(--area-personal-tint); color: var(--color-brand-300); }

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-nav);
  min-height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  padding: var(--space-2) var(--space-2) calc(var(--space-2) + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.bottom-nav__item {
  min-height: 54px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  font-size: 12px;
  font-weight: var(--weight-medium);
}
.bottom-nav__item--active { color: var(--color-brand-600); }

.fab {
  position: fixed;
  z-index: var(--z-fab);
  right: max(var(--space-4), env(safe-area-inset-right));
  bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom) + var(--space-4));
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: 0;
  background: var(--color-brand-600);
  color: var(--color-white);
  box-shadow: var(--shadow-lg);
  display: grid;
  place-items: center;
}

.grid { display: grid; gap: var(--space-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: grid; gap: var(--space-3); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.section { margin-block: var(--space-6); }

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}
.card__header { padding: var(--space-4) var(--space-4) var(--space-2); display:flex; gap:var(--space-3); align-items:flex-start; }
.card__body { padding: var(--space-4); }
.card__header + .card__body { padding-top: var(--space-2); }
.card__title { color: var(--text-strong); font-weight: var(--weight-semibold); }
.card__meta { color: var(--text-muted); font-size: var(--text-sm); }
.card--interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }

.btn {
  min-height: var(--tap-target);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0 var(--space-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-weight: var(--weight-semibold);
  transition: background var(--duration-base) var(--ease-standard), border-color var(--duration-base) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--color-brand-600); color: var(--color-white); }
.btn--primary:hover { background: var(--color-brand-700); }
.btn--secondary { background: var(--bg-surface); color: var(--text-strong); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--bg-subtle); }
.btn--ghost { background: transparent; color: var(--text-body); }
.btn--ghost:hover { background: var(--bg-subtle); }
.btn--danger { background: var(--danger-solid); color: var(--color-white); }
.btn--icon { width: var(--tap-target); padding: 0; }

.input,
.select,
.textarea,
.search {
  width: 100%;
  min-height: var(--tap-target);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-strong);
  padding: 0 var(--space-3);
}
.textarea { min-height: 112px; padding-block: var(--space-3); resize: vertical; }
.input::placeholder,.textarea::placeholder { color: var(--text-faint); }
.field { display: grid; gap: var(--space-2); }
.field__label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-strong); }
.field__hint { color: var(--text-muted); font-size: var(--text-xs); }
.search { padding-left: 2.5rem; background: var(--bg-subtle); border-color: var(--border-subtle); }

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}
.segmented__item {
  min-height: 38px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-weight: var(--weight-medium);
}
.segmented__item--active { background: var(--bg-surface); color: var(--text-strong); box-shadow: var(--shadow-xs); }

.toggle {
  width: 48px;
  height: 28px;
  padding: 3px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--neutral-300);
}
.toggle::after {
  content: "";
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-white);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-base) var(--ease-standard);
}
.toggle--on { background: var(--color-brand-600); }
.toggle--on::after { transform: translateX(20px); }

.tag,.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  white-space: nowrap;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}
.tag { padding: 4px 9px; background: var(--bg-subtle); color: var(--text-body); }
.badge { padding: 4px 8px; }
.badge--overdue { background: var(--status-overdue-tint); color: var(--status-overdue-text); }
.badge--today { background: var(--status-today-tint); color: var(--status-today-text); }
.badge--upcoming { background: var(--status-upcoming-tint); color: var(--status-upcoming-text); }
.badge--done { background: var(--status-done-tint); color: var(--status-done-text); }
.badge--expiring { background: var(--status-expiring-tint); color: var(--status-expiring-text); }
.badge--expired { background: var(--status-expired-tint); color: var(--status-expired-text); }

.visibility {
  display: inline-flex; align-items:center; gap:6px;
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  padding: 5px 8px; border-radius: var(--radius-pill);
}
.visibility--private { background:var(--visibility-private-tint); color: var(--visibility-private-text); }
.visibility--household { background:var(--visibility-household-tint); color: var(--visibility-household-text); }
.visibility--specific { background:var(--visibility-specific-tint); color: var(--visibility-specific-text); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: inline-grid; place-items:center;
  color: var(--color-white);
  font-weight: var(--weight-bold);
  border: 2px solid var(--bg-surface);
}
.avatar--sm { width: 28px; height:28px; font-size:var(--text-xs); }
.avatar--lg { width:48px; height:48px; }
.avatar-stack { display:flex; }
.avatar-stack .avatar + .avatar { margin-left:-8px; }

.area-dot { width:10px; height:10px; border-radius:50%; flex:0 0 auto; }
.area-tag { display:inline-flex; gap:6px; align-items:center; padding:4px 8px; border-radius:var(--radius-pill); font-size:var(--text-xs); font-weight:var(--weight-semibold); }
.area-personal { --area:var(--area-personal); --area-tint:var(--area-personal-tint); --area-text:var(--area-personal-text); }
.area-home { --area:var(--area-home); --area-tint:var(--area-home-tint); --area-text:var(--area-home-text); }
.area-vehicles { --area:var(--area-vehicles); --area-tint:var(--area-vehicles-tint); --area-text:var(--area-vehicles-text); }
.area-finance { --area:var(--area-finance); --area-tint:var(--area-finance-tint); --area-text:var(--area-finance-text); }
.area-health { --area:var(--area-health); --area-tint:var(--area-health-tint); --area-text:var(--area-health-text); }
.area-family { --area:var(--area-family); --area-tint:var(--area-family-tint); --area-text:var(--area-family-text); }
.area-work { --area:var(--area-work); --area-tint:var(--area-work-tint); --area-text:var(--area-work-text); }
.area-racers { --area:var(--area-racers); --area-tint:var(--area-racers-tint); --area-text:var(--area-racers-text); }
.area-midas { --area:var(--area-midas); --area-tint:var(--area-midas-tint); --area-text:var(--area-midas-text); }
.area-events { --area:var(--area-events); --area-tint:var(--area-events-tint); --area-text:var(--area-events-text); }
.area-admin { --area:var(--area-admin); --area-tint:var(--area-admin-tint); --area-text:var(--area-admin-text); }
.area-travel { --area:var(--area-travel); --area-tint:var(--area-travel-tint); --area-text:var(--area-travel-text); }
.area-tag,[class*="area-"] .area-chip { background:var(--area-tint); color:var(--area-text); }
.area-dot { background:var(--area); }

.task-row {
  min-height: 60px;
  display:grid;
  grid-template-columns:auto 1fr auto;
  gap:var(--space-3);
  align-items:center;
  padding:var(--space-3);
  border-bottom:1px solid var(--border-subtle);
}
.task-row:last-child { border-bottom:0; }
.task-row__check {
  width:24px; height:24px; border-radius:8px;
  border:2px solid var(--border-strong);
  background:var(--bg-surface);
}
.task-row__title { color:var(--text-strong); font-weight:var(--weight-medium); }
.task-row__meta { display:flex; flex-wrap:wrap; gap:var(--space-2); color:var(--text-muted); font-size:var(--text-xs); margin-top:3px; }
.task-row--done .task-row__title { color:var(--text-faint); text-decoration:line-through; }
.priority { width:8px; height:8px; border-radius:50%; background:var(--text-faint); }
.priority--high { background:var(--danger-solid); }
.priority--medium { background:var(--warning-solid); }
.priority--low { background:var(--info-solid); }

.record-card { padding:var(--space-4); display:grid; gap:var(--space-3); }
.record-card__top { display:flex; justify-content:space-between; gap:var(--space-3); align-items:flex-start; }
.record-card__icon { width:42px; height:42px; border-radius:var(--radius-sm); display:grid; place-items:center; background:var(--bg-subtle); }
.record-card__title { color:var(--text-strong); font-weight:var(--weight-semibold); }
.record-card__meta { color:var(--text-muted); font-size:var(--text-sm); }

.calendar {
  background:var(--bg-surface);
  border:1px solid var(--border-subtle);
  border-radius:var(--radius-md);
  overflow:hidden;
}
.calendar__header {
  display:grid; grid-template-columns:repeat(7,1fr);
  background:var(--bg-subtle);
  border-bottom:1px solid var(--border-subtle);
}
.calendar__dow { padding:10px 6px; text-align:center; color:var(--text-muted); font-size:var(--text-xs); font-weight:var(--weight-semibold); }
.calendar__month {
  display:grid; grid-template-columns:repeat(7,1fr);
}
.calendar__day {
  min-width:0; min-height:96px;
  padding:6px;
  border-right:1px solid var(--border-subtle);
  border-bottom:1px solid var(--border-subtle);
  background:var(--bg-surface);
}
.calendar__day:nth-child(7n) { border-right:0; }
.calendar__date {
  width:28px; height:28px; display:grid; place-items:center;
  border-radius:50%; color:var(--text-body); font-size:var(--text-sm); font-weight:var(--weight-medium);
}
.calendar__date--today { background:var(--color-brand-600); color:var(--color-white); }
.calendar__events { display:grid; gap:3px; margin-top:4px; }
.event-chip {
  min-width:0;
  border-radius:6px;
  padding:3px 6px;
  background:var(--area-tint, var(--info-tint));
  color:var(--area-text, var(--info-text));
  border-left:3px solid var(--area, var(--info-solid));
  font-size:12px;
  font-weight:var(--weight-semibold);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.event-chip--person {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--person-color) 70%, transparent);
}
.calendar__more { color:var(--text-muted); font-size:12px; padding-left:4px; }

.week {
  display:grid;
  grid-template-columns:56px repeat(7,minmax(130px,1fr));
  overflow:auto;
  background:var(--bg-surface);
  border:1px solid var(--border-subtle);
  border-radius:var(--radius-md);
}
.week__time,.week__cell { min-height:56px; border-right:1px solid var(--border-subtle); border-bottom:1px solid var(--border-subtle); }
.week__time { color:var(--text-faint); font-size:12px; padding:4px; text-align:right; }
.week__cell { position:relative; }

.filter-bar {
  display:flex; gap:var(--space-2); overflow:auto; padding-bottom:2px; scrollbar-width:none;
}
.filter-bar::-webkit-scrollbar { display:none; }
.filter {
  min-height:38px; border:1px solid var(--border-subtle); background:var(--bg-surface); color:var(--text-muted);
  border-radius:var(--radius-pill); padding:0 var(--space-3); white-space:nowrap; font-weight:var(--weight-medium);
}
.filter--active { border-color:var(--color-brand-300); background:var(--color-brand-50); color:var(--color-brand-700); }

.sheet {
  background:var(--bg-elevated);
  border-radius:var(--radius-xl) var(--radius-xl) 0 0;
  padding:var(--space-4) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom));
  box-shadow:var(--shadow-lg);
}
.sheet__handle { width:42px; height:5px; border-radius:var(--radius-pill); background:var(--border-strong); margin:0 auto var(--space-4); }
.modal {
  width:min(560px, calc(100vw - 32px));
  background:var(--bg-elevated);
  border:1px solid var(--border-subtle);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow-lg);
  padding:var(--space-5);
}
.toast {
  display:flex; align-items:center; gap:var(--space-3);
  padding:var(--space-3) var(--space-4);
  border-radius:var(--radius-sm);
  background:var(--bg-inverse); color:var(--text-inverse);
  box-shadow:var(--shadow-md);
}
.offline-banner {
  padding:var(--space-2) var(--space-3);
  background:var(--warning-tint); color: var(--warning-text);
  font-size:var(--text-sm); font-weight:var(--weight-semibold); text-align:center;
}
.skeleton {
  min-height:14px;
  border-radius:var(--radius-xs);
  background:linear-gradient(90deg,var(--bg-subtle),var(--border-subtle),var(--bg-subtle));
  background-size:200% 100%;
}

.quick-add-grid {
  display:grid; grid-template-columns:repeat(4,1fr); gap:var(--space-2);
}
.quick-add {
  min-height:84px; border:1px solid var(--border-subtle); background:var(--bg-surface);
  border-radius:var(--radius-md); color:var(--text-body); display:grid; place-items:center; align-content:center; gap:6px;
}
.quick-add__icon { width:34px; height:34px; border-radius:10px; background:var(--color-brand-50); color:var(--color-brand-700); display:grid; place-items:center; }

.comment { display:grid; grid-template-columns:auto 1fr; gap:var(--space-3); }
.comment__bubble {
  background:var(--bg-subtle); border-radius:var(--radius-md);
  padding:var(--space-3); color:var(--text-body);
}
.comment__meta { font-size:var(--text-xs); color:var(--text-muted); margin-top:4px; }
.chat { display:grid; gap:var(--space-2); }
.chat-bubble {
  max-width:78%;
  padding:10px 12px;
  border-radius:16px 16px 16px 4px;
  background:var(--bg-subtle);
  color:var(--text-strong);
}
.chat-bubble--mine {
  justify-self:end;
  background:var(--color-brand-600);
  color:var(--color-white);
  border-radius:16px 16px 4px 16px;
}
.conversation-row {
  min-height:68px; display:grid; grid-template-columns:auto 1fr auto; gap:var(--space-3);
  align-items:center; padding:var(--space-3); border-bottom:1px solid var(--border-subtle);
}
.unread {
  min-width:20px; height:20px; border-radius:10px; padding:0 6px;
  display:grid; place-items:center; background:var(--color-brand-600); color:var(--color-white);
  font-size:12px; font-weight:var(--weight-bold);
}
.activity {
  display:grid; grid-template-columns:18px 1fr; gap:var(--space-3); position:relative;
}
.activity::before {
  content:""; position:absolute; left:8px; top:20px; bottom:-12px; width:2px; background:var(--border-subtle);
}
.activity:last-child::before { display:none; }
.activity__dot { width:18px; height:18px; border-radius:50%; background:var(--color-brand-100); border:5px solid var(--color-brand-600); }

.person-toggle {
  min-height:42px;
  display:inline-flex; align-items:center; gap:8px;
  padding:0 10px; border:1px solid var(--border-subtle); border-radius:var(--radius-pill);
  background:var(--bg-surface); color:var(--text-body);
}
.person-toggle::before { content:""; width:10px; height:10px; border-radius:50%; background:var(--person-color); }
.person-toggle--active { box-shadow:inset 0 0 0 2px var(--person-color); }

.expiry-meter { height:6px; border-radius:var(--radius-pill); background:var(--bg-subtle); overflow:hidden; }
.expiry-meter__fill { height:100%; background:var(--status-expiring); width:65%; }

.empty-state {
  text-align:center; padding:var(--space-10) var(--space-6); color:var(--text-muted);
}
.empty-state__icon { width:54px; height:54px; margin:0 auto var(--space-3); border-radius:18px; background:var(--bg-subtle); display:grid; place-items:center; color:var(--text-faint); }

@media (max-width: 719px) {
  .calendar__day { min-height:72px; padding:4px; }
  .calendar__date { width:24px; height:24px; font-size:12px; }
  .event-chip { padding:2px 4px; border-left-width:2px; font-size:12px; }
  .calendar__dow { padding:8px 2px; }
  .grid--2,.grid--3 { grid-template-columns:1fr; }
}

@media (min-width: 900px) {
  .app-shell { grid-template-columns:var(--sidebar-width) minmax(0,1fr); padding-bottom:0; }
  .sidebar { display:block; }
  .bottom-nav,.fab { display:none; }
  .app-content { padding:var(--space-6) var(--space-8); }
  .topbar { padding-left:var(--space-6); padding-right:var(--space-6); }
}