:root {
  color-scheme: light dark;
  --system-blue: #007aff;
  --system-green: #34c759;
  --system-red: #ff3b30;
  --system-orange: #ff9500;
  --system-yellow: #ffcc00;
  --system-purple: #af52de;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --separator: rgba(60, 60, 67, 0.17);
  --label: #111111;
  --secondary-label: rgba(60, 60, 67, 0.72);
  --tertiary-label: rgba(60, 60, 67, 0.36);
  --tab-bg: rgba(248, 248, 248, 0.84);
  --danger-soft: rgba(255, 59, 48, 0.12);
  --blue-soft: rgba(0, 122, 255, 0.12);
  --green-soft: rgba(52, 199, 89, 0.14);
  --shadow: 0 16px 46px rgba(0, 0, 0, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --touch: 44px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-elevated: #2c2c2e;
    --separator: rgba(84, 84, 88, 0.62);
    --label: #f5f5f7;
    --secondary-label: rgba(235, 235, 245, 0.72);
    --tertiary-label: rgba(235, 235, 245, 0.38);
    --tab-bg: rgba(28, 28, 30, 0.86);
    --danger-soft: rgba(255, 69, 58, 0.18);
    --blue-soft: rgba(10, 132, 255, 0.2);
    --green-soft: rgba(48, 209, 88, 0.2);
    --shadow: 0 18px 54px rgba(0, 0, 0, 0.44);
  }
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--label);
}

* {
  box-sizing: border-box;
}

body {
  -webkit-font-smoothing: antialiased;
  font-size: 17px;
  line-height: 1.38;
  overscroll-behavior-y: contain;
  touch-action: manipulation;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  background: var(--bg);
  color: var(--label);
}

.nav-large {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: calc(12px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
}

.nav-large h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.04;
  letter-spacing: 0;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--secondary-label);
  font-size: 13px;
  line-height: 1.2;
  font-weight: 600;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 2px;
}

.icon-button,
.tab-button,
.chip,
.primary-action,
.secondary-action,
.danger-action,
.list-check,
.swipe-delete,
.calendar-day,
.segment-button,
.add-button {
  min-width: var(--touch);
  min-height: var(--touch);
  border: 0;
  border-radius: 999px;
  color: var(--label);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 180ms ease, color 180ms ease, opacity 180ms ease, transform 180ms ease;
}

.icon-button {
  background: color-mix(in srgb, var(--surface) 76%, transparent);
  border: 1px solid var(--separator);
}

.icon-button:active,
.tab-button:active,
.primary-action:active,
.secondary-action:active,
.danger-action:active,
.calendar-day:active,
.list-check:active,
.add-button:active {
  transform: scale(0.97);
}

.content {
  padding: 8px 16px calc(92px + var(--safe-bottom));
}

.content:focus {
  outline: none;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 180ms ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-card,
.member-card,
.calendar-card,
.list-card,
.family-card,
.empty-state,
.search-result {
  background: var(--surface);
  border: 1px solid var(--separator);
  border-radius: 12px;
}

.hero-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 16px;
  margin-bottom: 16px;
}

.date-title {
  margin: 0;
  color: var(--secondary-label);
  font-size: 15px;
  font-weight: 500;
}

.weather-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 22px;
  color: var(--system-blue);
  background: var(--blue-soft);
  font-weight: 600;
  white-space: nowrap;
}

.summary-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.chip {
  min-height: 34px;
  padding: 0 12px;
  background: color-mix(in srgb, var(--surface-elevated) 88%, var(--bg));
  border: 1px solid var(--separator);
  font-size: 14px;
  font-weight: 600;
  color: var(--secondary-label);
}

.section-label {
  margin: 20px 4px 8px;
  color: var(--secondary-label);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.member-card {
  overflow: hidden;
  margin-bottom: 12px;
}

.member-head {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 11px;
  min-height: 62px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.avatar.yellow {
  color: #2b2200;
}

.member-name {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.member-meta,
.event-meta,
.list-meta,
.family-meta,
.sheet-meta {
  color: var(--secondary-label);
  font-size: 13px;
}

.count-badge {
  min-width: 30px;
  height: 30px;
  border-radius: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--secondary-label);
  background: color-mix(in srgb, var(--surface-elevated) 88%, var(--bg));
  font-size: 13px;
  font-weight: 700;
}

.event-row {
  width: 100%;
  min-height: 58px;
  border: 0;
  border-bottom: 1px solid var(--separator);
  background: transparent;
  color: var(--label);
  display: grid;
  grid-template-columns: 54px 32px 1fr;
  gap: 8px;
  align-items: center;
  padding: 9px 12px;
  text-align: left;
}

.event-row:last-child {
  border-bottom: 0;
}

.event-row:focus-visible,
.icon-button:focus-visible,
.tab-button:focus-visible,
.calendar-day:focus-visible,
.list-check:focus-visible,
.primary-action:focus-visible,
.secondary-action:focus-visible,
.danger-action:focus-visible,
.form-field input:focus-visible,
.form-field textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--system-blue) 55%, transparent);
  outline-offset: 2px;
}

.time {
  color: var(--secondary-label);
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.event-icon {
  width: 30px;
  height: 30px;
  border-radius: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--system-blue);
  background: var(--blue-soft);
}

.event-icon.medical { color: var(--system-green); background: var(--green-soft); }
.event-icon.alert { color: var(--system-red); background: var(--danger-soft); }
.event-icon.work { color: var(--system-purple); background: color-mix(in srgb, var(--system-purple) 18%, transparent); }
.event-icon.shop { color: var(--system-orange); background: color-mix(in srgb, var(--system-orange) 18%, transparent); }

.event-title {
  margin: 0;
  font-size: 16px;
  font-weight: 560;
}

.event-subtitle {
  margin-top: 2px;
  color: var(--secondary-label);
  font-size: 13px;
}

.tab-bar {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 10px calc(6px + var(--safe-bottom));
  background: var(--tab-bg);
  border-top: 1px solid var(--separator);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
}

.tab-button {
  min-height: 52px;
  flex-direction: column;
  gap: 2px;
  color: var(--secondary-label);
  font-size: 11px;
  font-weight: 650;
}

.tab-button.active {
  color: var(--system-blue);
}

.calendar-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  min-height: 40px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-elevated) 84%, var(--bg));
  border: 1px solid var(--separator);
}

.segment-button {
  min-height: 36px;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 650;
  color: var(--secondary-label);
}

.segment-button.active {
  color: var(--label);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.calendar-card {
  padding: 12px;
  margin-bottom: 12px;
}

.week-strip,
.month-grid {
  display: grid;
  gap: 8px;
}

.week-strip {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.month-grid {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.weekday {
  text-align: center;
  color: var(--secondary-label);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.calendar-day {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 54px;
  border-radius: 12px;
  flex-direction: column;
  gap: 4px;
  font-weight: 700;
}

.calendar-day.today {
  color: white;
  background: var(--system-blue);
}

.calendar-day.selected {
  background: var(--blue-soft);
  color: var(--system-blue);
}

.dot-row {
  display: flex;
  justify-content: center;
  gap: 3px;
  min-height: 6px;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.list-card {
  overflow: hidden;
  margin-bottom: 12px;
}

.list-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 60px;
  padding: 12px;
  border-bottom: 1px solid var(--separator);
}

.list-title {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.add-button {
  background: var(--blue-soft);
  color: var(--system-blue);
}

.swipe-wrap {
  position: relative;
  overflow: hidden;
  background: var(--surface);
}

.swipe-delete {
  position: absolute;
  inset: 1px 0 1px auto;
  width: 86px;
  border-radius: 0;
  background: var(--system-red);
  color: white;
  font-weight: 700;
}

.list-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 7px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--separator);
  transition: transform 200ms ease;
  touch-action: pan-y;
}

.swipe-wrap:last-child .list-row {
  border-bottom: 0;
}

.list-row.open {
  transform: translateX(-86px);
}

.list-check {
  border: 2px solid var(--separator);
  color: transparent;
}

.list-check.checked {
  color: white;
  border-color: var(--system-green);
  background: var(--system-green);
}

.list-item-title {
  margin: 0;
  font-weight: 560;
}

.list-row.done .list-item-title {
  color: var(--secondary-label);
  text-decoration: line-through;
}

.family-grid {
  display: grid;
  gap: 12px;
}

.family-card {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 12px;
}

.privacy-pill {
  min-height: 32px;
  border-radius: 16px;
  padding: 6px 10px;
  color: var(--secondary-label);
  background: color-mix(in srgb, var(--surface-elevated) 86%, var(--bg));
  font-size: 12px;
  font-weight: 700;
}

.empty-state {
  padding: 24px 16px;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.empty-state p {
  margin: 0;
  color: var(--secondary-label);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.32);
}

.sheet {
  position: fixed;
  z-index: 50;
  left: 8px;
  right: 8px;
  bottom: 0;
  max-height: min(84vh, 720px);
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateY(110%);
  transition: transform 260ms cubic-bezier(0.2, 0.9, 0.2, 1);
  padding-bottom: var(--safe-bottom);
  overflow: hidden;
}

.sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 999px;
  margin: 9px auto 4px;
  background: var(--tertiary-label);
}

.sheet-content {
  padding: 12px 16px 20px;
  overflow: auto;
  max-height: calc(min(84vh, 720px) - 24px);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.sheet h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.detail-top {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.detail-list {
  border: 1px solid var(--separator);
  border-radius: 12px;
  overflow: hidden;
  margin: 14px 0;
}

.detail-line {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 10px;
  min-height: 48px;
  padding: 12px;
  border-bottom: 1px solid var(--separator);
}

.detail-line:last-child {
  border-bottom: 0;
}

.detail-key {
  color: var(--secondary-label);
  font-size: 14px;
  font-weight: 650;
}

.detail-value {
  font-weight: 560;
}

.edit-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  margin: 14px 0;
  border: 1px solid var(--separator);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-elevated) 82%, var(--bg));
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.form-field {
  display: grid;
  gap: 6px;
  color: var(--secondary-label);
  font-size: 13px;
  font-weight: 700;
}

.form-field input,
.form-field textarea {
  width: 100%;
  min-height: var(--touch);
  border: 1px solid var(--separator);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--label);
  background: var(--surface);
  outline: 0;
  font-size: 16px;
}

.form-field textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.38;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.primary-action,
.secondary-action,
.danger-action {
  width: 100%;
  border-radius: 12px;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.primary-action {
  color: white;
  background: var(--system-blue);
}

.secondary-action {
  color: var(--system-blue);
  background: var(--blue-soft);
}

.danger-action {
  color: var(--system-red);
  background: var(--danger-soft);
}

.primary-action:disabled,
.secondary-action:disabled,
.danger-action:disabled {
  cursor: wait;
  opacity: 0.58;
}

.search-field {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  min-height: 48px;
  padding: 0 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-elevated) 88%, var(--bg));
  border: 1px solid var(--separator);
  color: var(--secondary-label);
}

.search-field input {
  width: 100%;
  min-height: 44px;
  border: 0;
  outline: 0;
  color: var(--label);
  background: transparent;
}

.search-results {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.search-result {
  width: 100%;
  min-height: 62px;
  padding: 12px;
  text-align: left;
}

.pull-indicator {
  position: fixed;
  z-index: 10;
  top: calc(8px + var(--safe-top));
  left: 50%;
  transform: translate(-50%, -140%);
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 17px;
  background: var(--surface);
  border: 1px solid var(--separator);
  color: var(--secondary-label);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 180ms ease;
}

.pull-indicator.visible {
  transform: translate(-50%, 0);
}

svg {
  width: 21px;
  height: 21px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (min-width: 700px) {
  .app-shell {
    max-width: 620px;
    margin: 0 auto;
    min-height: 100vh;
    border-left: 1px solid var(--separator);
    border-right: 1px solid var(--separator);
  }

  .tab-bar,
  .nav-large {
    max-width: 620px;
    margin: 0 auto;
  }

  .sheet {
    left: 50%;
    right: auto;
    width: min(620px, calc(100vw - 24px));
    transform: translate(-50%, 110%);
  }

  .sheet.open {
    transform: translate(-50%, 0);
  }
}

@media (max-width: 430px) {
  .field-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-grid .form-field:first-child {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
