:root {
  color-scheme: light;
  /* Semantic, adaptive colors. Apple ships these as adaptive system colors
     (systemBlue, label, systemBackground...) that shift for light/dark/contrast.
     The hex values below are community-measured approximations, not Apple spec. */
  --blue: #007aff;
  --blue-pressed: #0051d5;
  --blue-tint: rgba(0, 122, 255, 0.12);
  --blue-tint-pressed: rgba(0, 122, 255, 0.20);
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;

  --label: #000000;
  --secondary-label: rgba(60, 60, 67, 0.60);
  --tertiary-label: rgba(60, 60, 67, 0.30);
  --muted: #8e8e93;
  --separator: rgba(60, 60, 67, 0.29);
  --separator-opaque: #c6c6c8;
  --background: #f2f2f7;
  --card: #ffffff;
  --card-elevated: #ffffff;
  --card-secondary: #f2f2f7;
  --system-gray6: #f2f2f7;
  --border: rgba(60, 60, 67, 0.12);
  --shadow: 0 0 0 0.5px var(--border);
  --fill: rgba(120, 120, 128, 0.12);
  --fill-hover: rgba(120, 120, 128, 0.20);
  --fill-pressed: rgba(120, 120, 128, 0.28);
  --accent: var(--blue);
  --accent-hover: var(--blue-pressed);
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  margin: 0;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  background: var(--background);
  color: var(--label);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 16px);
  overscroll-behavior-y: none;
}

::selection {
  background: rgba(0, 122, 255, 0.20);
}

/* ── Navigation bar (Liquid Glass) ───────────────────────────── */

.bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px 6px;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid transparent;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: border-color 0.2s ease;
}
.bar.scrolled {
  border-bottom-color: var(--separator);
}
.bar-title {
  flex: 1;
  min-width: 0;
}
.bar h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.37px;
  line-height: 1.07;
  color: var(--label);
}
.bar h1 a {
  color: var(--label);
  text-decoration: none;
}
.bar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-bottom: 4px;
  flex-shrink: 0;
}
.bar-actions a,
.bar-actions .logout-btn {
  color: var(--blue);
  text-decoration: none;
  font-size: 17px;
  font-weight: 400;
  padding: 6px 8px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.1s;
}
.bar-actions a:active,
.bar-actions .logout-btn:active {
  opacity: 0.4;
}

/* ── Layout ─────────────────────────────────────────────────── */

main {
  max-width: 600px;
  margin: 0 auto;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
}

/* ── Section headers (iOS footnote-style) ────────────────────── */

.section-header {
  font-size: 13px;
  font-weight: 400;
  color: var(--secondary-label);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 16px 6px;
  margin-top: 24px;
}
.section-header:first-child { margin-top: 8px; }

/* ── Grouped inset cards ─────────────────────────────────────── */

.card,
section#add, section#add-contact, #filter,
#list-container, #contact-list,
#upcoming, .dates-section, .links-section, .edit-section {
  background: var(--card);
  border-radius: 12px;
  padding: 0;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#filter { padding: 14px 16px; }
#upcoming { padding: 14px 16px; }
.dates-section, .links-section, .edit-section { padding: 14px 16px; }
section#add, section#add-contact { padding: 14px 16px; }
#list-container, #contact-list { padding: 0; }

/* ── Forms: grouped field rows ───────────────────────────────── */

.form-group {
  background: var(--card-secondary);
  border-radius: 10px;
  overflow: hidden;
}
.field {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-bottom: 0.5px solid var(--separator);
}
.field:last-child { border-bottom: none; }
.field label {
  flex-shrink: 0;
  width: 90px;
  margin: 0;
  font-size: 17px;
  font-weight: 400;
  color: var(--label);
  text-transform: none;
  letter-spacing: 0;
  line-height: 44px;
}
.field input,
.field textarea,
.field select {
  flex: 1;
  min-height: 44px;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 10px 0;
  box-shadow: none;
  font: inherit;
  font-size: 17px;
  color: var(--label);
}
.field input::placeholder,
.field textarea::placeholder { color: var(--tertiary-label); }
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  box-shadow: none;
}
.field input[type="date"] { min-height: 44px; }

/* Stacked fields (label above input) */
label {
  display: block;
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--secondary-label);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

input, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 0.5px solid var(--separator-opaque);
  background: var(--card-secondary);
  color: var(--label);
  font: inherit;
  font-size: 17px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--tertiary-label); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-tint);
}
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 0.5px solid var(--separator-opaque);
  background: var(--card-secondary);
  color: var(--label);
  font: inherit;
  font-size: 17px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%238e8e93'%3E%3Cpath d='M7 10L2 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}
select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-tint);
}
select[multiple] {
  height: auto;
  min-height: 48px;
  max-height: 120px;
  background-image: none;
  padding-right: 12px;
}
select option {
  background: var(--card-elevated);
  color: var(--label);
  padding: 8px;
}

/* ── Buttons ─────────────────────────────────────────────────── */

button {
  width: 100%;
  min-height: 50px;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 17px;
  margin-top: 16px;
  cursor: pointer;
  transition: opacity 0.1s, background 0.15s;
}
button:active { opacity: 0.7; }

/* Gray button (secondary action) */
.btn-gray {
  background: var(--card-secondary);
  color: var(--label);
  box-shadow: var(--shadow);
}
.btn-gray:active { background: var(--fill-pressed); opacity: 1; }

/* Tinted button */
.btn-tinted {
  background: var(--blue-tint);
  color: var(--blue);
}
.btn-tinted:active { background: var(--blue-tint-pressed); opacity: 1; }

/* Plain button (bar / inline) */
.btn-plain {
  background: transparent;
  color: var(--blue);
  font-weight: 400;
  font-size: 17px;
  min-height: 44px;
  width: auto;
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
}
.btn-plain:active { opacity: 0.4; }

.remember-btn {
  width: 100%;
  min-height: 50px;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--blue-tint);
  color: var(--blue);
  font: inherit;
  font-weight: 600;
  font-size: 17px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s;
}
.remember-btn:active { background: var(--blue-tint-pressed); }

/* ── Filter labels / section labels ─────────────────────────── */

.filter-label,
.upcoming-header > span {
  font-size: 13px;
  color: var(--secondary-label);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
}

/* ── Segmented control ──────────────────────────────────────── */

.segmented {
  display: flex;
  background: var(--card-secondary);
  border-radius: 9px;
  padding: 2px;
  gap: 0;
}
.segmented a {
  flex: 1;
  text-align: center;
  padding: 7px 10px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  color: var(--label);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.segmented a:active { background: var(--fill); }
.segmented a.active {
  background: var(--card);
  color: var(--label);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0 0 0.5px var(--border);
}

/* ── Person pills (capsule filter) ──────────────────────────── */

.person-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.person-pill {
  padding: 7px 14px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: 100px;
  background: var(--card-secondary);
  color: var(--label);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  border: none;
  transition: background 0.1s, color 0.1s;
}
.person-pill:active { background: var(--fill-pressed); }
.person-pill.active {
  background: var(--blue);
  color: #fff;
}

/* ── Disclosure chevron ──────────────────────────────────────── */

.chevron {
  flex-shrink: 0;
  width: 8px;
  height: 14px;
  margin-left: auto;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='14' viewBox='0 0 8 14' fill='none' stroke='%23c6c6c8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l6 6-6 6'/%3E%3C/svg%3E") no-repeat center;
  background-size: contain;
}

/* ── Observations list ──────────────────────────────────────── */

ul#list { list-style: none; padding: 0; margin: 0; }
.obs-card {
  background: var(--card);
  border-radius: 0;
  padding: 16px;
  margin: 0;
  border-bottom: 0.5px solid var(--separator);
  box-shadow: none;
}
.obs-card:first-child {
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}
.obs-card:last-child {
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  border-bottom: none;
}
.obs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.obs-header time {
  color: var(--secondary-label);
  font-size: 13px;
  font-weight: 400;
}
.obs-header .persons {
  color: var(--label);
  font-weight: 600;
  font-size: 15px;
}
.obs-header .persons a {
  color: var(--label);
  font-weight: 600;
  text-decoration: none;
}
.obs-header .persons a:active { opacity: 0.4; }
.obs-header-right { display: flex; gap: 4px; align-items: center; }
.obs-edit-btn {
  width: auto;
  min-height: 36px;
  margin: 0;
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  cursor: pointer;
}
.obs-edit-btn:active { opacity: 0.4; }
.obs-edit-form { margin-top: 10px; }
.obs-edit-form button { width: auto; margin: 0; padding: 10px 18px; }
.obs-edit-form button[type="button"] {
  background: var(--card-secondary);
  color: var(--label);
  margin-left: 8px;
  box-shadow: var(--shadow);
}
.obs-edit-form button[type="button"]:active {
  background: var(--fill-pressed);
  opacity: 1;
}
.obs-card .content {
  margin: 0;
  color: var(--label);
  font-size: 17px;
  line-height: 1.45;
}

/* ── Empty / muted text ─────────────────────────────────────── */

.muted {
  color: var(--secondary-label);
  text-align: center;
  padding: 24px 0;
  font-size: 15px;
  margin: 0;
}

/* ── Upcoming events ────────────────────────────────────────── */

.upcoming-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 12px;
  gap: 8px;
}
.upcoming-header > span {
  margin: 0;
  flex-shrink: 0;
}
.range-pills { display: flex; gap: 4px; }
.range-pill {
  padding: 6px 12px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 100px;
  background: transparent;
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border: none;
}
.range-pill:active { opacity: 0.4; }
.range-pill.active {
  background: var(--blue-tint);
  color: var(--blue);
  font-weight: 600;
}
ul#events-list { list-style: none; padding: 0; margin: 0; }
.event-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
  text-decoration: none;
}
.event-item:last-child { border-bottom: none; }
.event-item:active { background: var(--fill); }
.event-date {
  color: var(--secondary-label);
  font-size: 13px;
  width: 84px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.event-name {
  color: var(--label);
  font-weight: 400;
  text-decoration: none;
  font-size: 17px;
  flex: 1;
  min-width: 0;
}
.event-label {
  color: var(--blue);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

/* ── Contact dates ──────────────────────────────────────────── */

.dates-section h3,
.links-section h3,
.edit-section h3 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 600;
  color: var(--label);
}
ul#dates-list { list-style: none; padding: 0; margin: 0 0 16px; }
.date-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 0.5px solid var(--separator);
  min-height: 44px;
}
.date-item:last-child { border-bottom: none; }
.date-label {
  color: var(--label);
  font-weight: 400;
  font-size: 17px;
  text-transform: capitalize;
}
.date-value {
  color: var(--secondary-label);
  font-size: 15px;
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* ── Tag input (contact selector) ──────────────────────────── */

.tag-input { position: relative; }
.tag-box {
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 0.5px solid var(--separator-opaque);
  background: var(--card-secondary);
  color: var(--label);
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tag-box:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-tint);
}
.tag-placeholder { color: var(--tertiary-label); font-size: 17px; }
.tag-list { display: contents; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 100px;
  background: var(--blue);
  color: #fff;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.4;
}
.tag-remove { cursor: pointer; opacity: 0.6; font-size: 16px; line-height: 1; }
.tag-remove:hover { opacity: 1; }
.tag-ids { display: none; }
.tag-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--card-elevated);
  border: 0.5px solid var(--separator-opaque);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 0 0 0.5px var(--border);
  z-index: 100;
  max-height: 240px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tag-option {
  padding: 0 16px;
  cursor: pointer;
  color: var(--label);
  font-size: 17px;
  min-height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 0.5px solid var(--separator);
}
.tag-option:last-child { border-bottom: none; }
.tag-option:active { background: var(--fill); }
.tag-option-muted { padding: 14px 16px; color: var(--tertiary-label); font-size: 15px; }

/* ── Contacts list ─────────────────────────────────────────── */

ul#contacts-list { list-style: none; padding: 0; margin: 0; }
.contact-card {
  border-bottom: 0.5px solid var(--separator);
}
.contact-card:last-child { border-bottom: none; }
.contact-card a {
  text-decoration: none;
  color: var(--label);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  min-height: 44px;
  padding: 12px 16px;
  transition: background 0.1s;
}
.contact-card a:active { background: var(--fill); }
.contact-name { font-weight: 400; font-size: 17px; }
.contact-nicknames { color: var(--secondary-label); font-size: 15px; font-weight: 400; }
.contact-dob { color: var(--tertiary-label); font-size: 13px; }

/* ── Contact detail ────────────────────────────────────────── */

.contact-header {
  padding: 8px 0 4px;
  margin-bottom: 8px;
}
.contact-header h2 {
  margin: 0 0 2px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.23px;
  color: var(--label);
}
.contact-header .contact-nicknames { margin: 0; }
.contact-header .contact-dob { margin: 2px 0; }
.contact-header a {
  color: var(--blue);
  text-decoration: none;
  font-size: 17px;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: 6px;
}
.contact-header a:active { opacity: 0.4; }

/* ── Links list ────────────────────────────────────────────── */

ul#links-list { list-style: none; padding: 0; margin: 0 0 16px; }
.link-item {
  padding: 0 16px;
  border-bottom: 0.5px solid var(--separator);
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.link-item:last-child { border-bottom: none; }
.link-relationship {
  color: var(--secondary-label);
  font-weight: 400;
  margin-right: 4px;
  font-size: 17px;
  text-transform: capitalize;
}
.link-item a {
  color: var(--label);
  text-decoration: none;
  font-weight: 400;
  font-size: 17px;
  flex: 1;
  min-width: 0;
}
.link-item a:active { opacity: 0.4; }

/* ── Login page ────────────────────────────────────────────── */

.login-section {
  background: var(--card);
  border-radius: 14px;
  padding: 24px 16px;
  margin-top: 32px;
  box-shadow: var(--shadow);
}
.login-form .error {
  color: var(--red);
  font-size: 15px;
  margin: 8px 0;
}
.login-logo {
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.37px;
  color: var(--label);
  margin-bottom: 32px;
}

/* ── Utility ───────────────────────────────────────────────── */

.back-link {
  color: var(--blue);
  text-decoration: none;
  font-size: 17px;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.back-link:active { opacity: 0.4; }
