/* ============================================
   SMMSOC Family Directory - Mobile-First Design System
   ============================================ */

/* --- CSS Custom Properties (Design Tokens) --- */
:root {
  color-scheme: light;
  /* Colors - iOS inspired */
  --color-primary: #007AFF;
  --color-primary-dark: #0056CC;
  --color-secondary: #5856D6;
  --color-success: #34C759;
  --color-warning: #FF9500;
  --color-danger: #FF3B30;
  
  /* Membership colors */
  --color-member: #34C759;
  --color-extended: #007AFF;
  --color-non-member: #FF9500;
  --color-priest: #AF52DE;
  
  /* Neutral colors */
  --color-background: #F2F2F7;
  --color-surface: #FFFFFF;
  --color-surface-secondary: #F9F9F9;
  --color-border: #E5E5EA;
  --color-border-light: #F0F0F5;
  
  /* Text colors */
  --color-text-primary: #1C1C1E;
  --color-text-secondary: #8E8E93;
  --color-text-tertiary: #AEAEB2;
  --color-text-inverse: #FFFFFF;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 16px;
  --font-size-md: 17px;
  --font-size-lg: 20px;
  --font-size-xl: 24px;
  --font-size-xxl: 28px;
  --font-size-title: 34px;
  
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  /* Spacing scale (4px base) */
  --space-xxs: 2px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-base: 16px;
  --space-lg: 20px;
  --space-xl: 24px;
  --space-xxl: 32px;
  --space-xxxl: 48px;
  
  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.16);
  
  /* Layout */
  --header-height: 56px;
  --tab-bar-height: 60px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  
  /* Touch targets */
  --touch-target-min: 44px;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Base Reset & Typography --- */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  line-height: 1.5;
  color: var(--color-text-primary);
  background-color: var(--color-background);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
}

/* Prevent iOS zoom on input focus */
input, select, textarea {
  font-size: 16px !important;
}

/* Better touch behavior */
a, button, [role="button"], .clickable {
  touch-action: manipulation;
  cursor: pointer;
}

/* --- Accessibility: Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Utility Classes --- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Highlight today's events */
#upcoming-events .today-event {
  border: 1px solid var(--color-primary);
  box-shadow: 0 0 8px 2px rgba(0, 122, 255, 0.4);
  border-radius: var(--radius-md);
}

@keyframes logoSpinPause {
  0% { transform: rotateY(0deg); }
  10% { transform: rotateY(360deg); }
  100% { transform: rotateY(360deg); }
}

.logo-spin {
  display: inline-block;
  animation: logoSpinPause 10s ease-in-out infinite;
  transform-style: preserve-3d;
}

@keyframes emojiPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.3); }
}

.pulsing-emoji {
  display: inline-block;
  animation: emojiPulse 1.2s ease-in-out infinite;
}
/* Make container fluid and responsive */
.container, .main-content {
  max-width: 100vw;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  box-sizing: border-box;
}

#filter-modal.active {
  display: flex;
}
/* ============================ */
/* Filter Modal Styles */
/* ============================ */
#filter-modal.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1002;
}
#filter-modal.hidden {
  display: none !important;
}
#filter-modal .modal-content {
  background: #fff;
  border-radius: 8px;
  padding: 25px 25px 20px 25px;
  min-width: 260px;
  max-width: 380px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 4px 18px rgba(0,0,0,0.18);
}
#filter-modal .close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #f44336;
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 1.1em;
  padding: 4px 10px;
  cursor: pointer;
}
#filter-modal .close-btn:hover {
  background: #da190b;
}
#filter-modal h3 {
  margin-top: 0;
  font-size: 1.2em;
  color: #333;
  text-align: center;
}
#filter-modal ul {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 60vh;
  overflow-y: auto;
}
#filter-modal li[data-town] {
  padding: 9px 15px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1em;
  transition: background 0.15s;
}
#filter-modal li[data-town]:hover {
  background: #f2f2f2;
  color: #2196F3;
}
#filter-modal .count {
  background: #e3e3e3;
  color: #333;
  border-radius: 1em;
  padding: 2px 10px;
  font-size: 0.92em;
  margin-left: 6px;
}

#user-dropdown li[role="link"] {
  cursor: pointer;
  padding: 8px 12px;
  outline: none;
}

#user-dropdown li[role="link"]:hover,
#user-dropdown li[role="link"]:focus {
  background-color: #f0f0f0;
  text-decoration: underline;
}
/* Hamburger and dropdown menu styles */
.hamburger-menu {
  font-size: 1.5em;
  cursor: pointer;
  padding: 10px;
  user-select: none;
}

.dropdown {
  position: absolute;
  top: 50px;
  left: 10px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 10;
}

.dropdown ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.dropdown ul li {
  padding: 10px 15px;
  cursor: pointer;
}

.dropdown ul li:hover {
  background-color: #f0f0f0;
}

/* Enhance hamburger menu li[role="link"] for accessibility and feedback */
.dropdown ul li[role="link"] {
  cursor: pointer;
  padding: 10px 15px;
  outline: none;
}

.dropdown ul li[role="link"]:hover,
.dropdown ul li[role="link"]:focus {
  background-color: #f0f0f0;
  text-decoration: underline;
}

.dropdown ul li a {
  color: #333;
  text-decoration: none;
}
/* Basic styles for the application */
.hidden {
  display: none !important; /* Ensure it overrides other styles */
}

#login-section {
  text-align: center;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute; /* Take it out of flow when visible */
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh; /* Full height only when visible */
  background-color: #fff; /* Avoid transparency issues */
  z-index: 1000; /* Above content but below modals */
}

#login-message {
  font-size: 1.2em;
  margin-bottom: 20px;
  max-width: 600px; /* Limit width for readability */
  line-height: 1.5; /* Improve readability with line spacing */
  color: #333;
}

button {
  padding: 10px 20px;
  margin: 5px;
  cursor: pointer;
}

/* Styles for the Sign In button */
#sign-in-btn {
  background-color: #2196F3;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1em;
}

#sign-in-btn:hover {
  background-color: #1976D2;
}

/* Adjust header to ensure space for all elements */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px; /* Increase padding for better spacing */
  min-height: 60px;
  height: 60px;
  background-color: #283593;
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 3;
  box-sizing: border-box; /* Ensure padding doesn't increase width */
}

.header .header-title,
.header #user-name,
.header #user-dropdown {
  color: #fff;
}

.header-left {
  display: flex;
  gap: 10px; /* Space between buttons */
}

.header-title {
  flex-grow: 1;
  text-align: center;
  margin: 0;
  font-size: 1.5em;
  color: #333;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  white-space: normal; /* Allow wrapping if needed */
  overflow: visible; /* Prevent clipping */
  text-overflow: initial; /* Disable ellipsis */
  max-width: 40%; /* Limit width to prevent overlap with title */
  padding-right: 10px; /* Add padding to avoid edge clipping */
}

/* Ensure user profile fits */
#new-family-btn,
#new-family-btn:hover,
#user-profile {
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
  max-width: 100%; /* Allow full width within parent */
}

/* New Family button styling; it may cause extra height in admin mode */
#new-family-btn {
  height: 40px;
  line-height: 40px;
  font-size: 0.9em;
  padding: 0 10px;
  white-space: nowrap;
  margin-top: 0;
}

.user-photo {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  margin-right: 10px;
}

/* Adjust user name to prevent overflow */
#user-name {
  font-size: 1em;
  color: #333;
  white-space: normal; /* Allow wrapping */
  overflow: visible;
  max-width: 150px; /* Limit width to prevent excessive stretching */
}

#user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  padding: 10px;
  z-index: 10; /* Above header */
}

#user-email {
  margin: 0 0 10px 0;
  font-size: 0.9em;
  color: #666;
}

#sign-out {
  background-color: #f44336;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1em;
  padding: 5px 10px;
  width: 100%;
}

#sign-out:hover {
  background-color: #da190b;
}

/* Styles for the search container */
.search-container {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  padding: 10px;
  gap: 10px;
  max-width: 100%;
  position: relative;
  z-index: 2;
  margin: 0 auto; /* Center the container */
  box-sizing: border-box; /* Ensure padding doesn't cause overflow */
}

/* Old fixed-width removed - now uses flex layout */
#content .search-container #search-bar {
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 0.9em; /* Slightly smaller font for mobile */
  box-sizing: border-box;
  margin-left: 0; /* Remove any left margin causing cropping */
}

/* Styles for the search button */
#search-btn {
  background-color: #4CAF50; /* Green to distinguish from other buttons */
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1em;
  padding: 10px 20px;
  flex-shrink: 0; /* Prevent button from shrinking */
}

#search-btn:hover {
  background-color: #45a049;
}

/* Styles for the family list section */
#family-list-section {
  z-index: 2;
  position: relative;
  padding: 10px 0; /* Minimal padding for top/bottom only */
}

#family-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center; /* Center cards horizontally */
  z-index: 1;
  position: relative;
  min-height: 200px;
}

.family-card {
  border: 1px solid #ccc;
  padding: 15px;
  padding-bottom: 60px; /* Reserve space for action buttons */
  margin: 0;
  border-radius: 5px;
  width: 320px;
  box-sizing: border-box;
  position: relative;
  z-index: 2; /* Above #family-list */
}

.family-photo-container {
  width: 300px;
  height: 250px;
  overflow: hidden;
  position: relative;
  display: flex; /* Use flexbox to center content */
  justify-content: center; /* Center horizontally */
  align-items: top; /* Align to top */
  padding: 0; /* Remove padding to ensure even spacing */
}

.family-photo {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center; /* Center the image */
  cursor: pointer;
  z-index: 1;
  display: block;
  margin: auto; /* Additional centering for non-flex contexts */
}

.section {
  margin-top: 10px;
}

.section h4 {
  margin: 5px 0;
  font-size: 1.1em;
  font-weight: bold;
}

.section h4.sub-heading-gray {
  color: #666;
  font-weight: normal;
}

.section h4 span {
  font-size: 0.8em;
  font-weight: normal;
  color: #666;
}

.sub-heading {
  display: block;
  margin-top: 5px;
  font-weight: normal;
  font-size: 0.9em;
}

.section ul,
.section p {
  margin-left: 20px;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  margin: 5px 0;
}

/* Ribbon styles */
.ribbon {
  position: absolute;
  bottom: 10px; /* Slightly above the bottom edge for better spacing */
  right: 10px;
  padding: 5px 10px;
  color: white;
  font-size: 0.9em; /* Slightly larger for readability */
  font-weight: bold;
  border-radius: 3px;
  z-index: 10; /* Above the photo */
  background-color: rgba(0, 0, 0, 0.7); /* Semi-transparent black background */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); /* Subtle shadow for depth */
}

.member-ribbon {
  background-color: #4CAF50; /* Green for Member */
}

.extended-member-ribbon {
  background-color: #2196F3; /* Blue for Extended Member */
}

.non-member-ribbon {
  background-color: #FFC107; /* Yellow for Non Member */
}

.priest-ribbon {
  background-color: #9C27B0; /* Purple for Priest */
}

/* ============================ */
/* Styles for the edit family modal (Polished Version) */
/* ============================ */

/* Add a fade-in and scale animation */
@keyframes fadeInModal {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

#edit-family-section {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20; /* Above family cards */
  animation: fadeInModal 0.3s ease;
}

#edit-family-section .modal-content {
  background: white;
  padding: 30px;
  border-radius: 8px;
  width: 70vw; /* At least 70% of viewport width */
  max-width: 600px; /* Cap at 600px for large screens */
  max-height: 90%;
  overflow-y: auto;
  position: relative;
  z-index: 3; /* Above modal overlay and family list */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Polished modal title bar & close button */
.modal-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #eaeaea;
  margin-bottom: 20px;
  padding-bottom: 10px;
}

.modal-title-bar h2 {
  font-size: 1.5em;
  color: #333;
  margin: 0;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.2em;
  cursor: pointer;
  padding: 5px 10px;
  color: #aaa;
  transition: color 0.2s ease;
}

.close-btn:hover {
  color: #333;
}

/* Enhanced form element styling within the edit modal */
.edit-modal-body input[type="text"],
.edit-modal-body input[type="date"],
.edit-modal-body input[type="email"],
.edit-modal-body input[type="url"],
.edit-modal-body input[type="tel"],
.edit-modal-body select,
#json-editor {
  width: 100%;
  max-width: 300px;
  padding: 10px;
  margin-top: 5px;
  margin-bottom: 15px;
  border: 1px solid #ccc;
  border-radius: 4px;
  transition: border-color 0.3s ease;
}

.edit-modal-body input:focus,
.edit-modal-body select:focus,
#json-editor:focus {
  border-color: #66afe9;
  outline: none;
}

/* Updated button styles within the edit modal */
.add-field,
.remove-field,
#save-changes,
#edit-json-btn,
#delete-family-btn,
#save-json-btn,
#cancel-json-btn {
  padding: 10px 20px;
  margin: 10px 5px 10px 0;
  border: none;
  border-radius: 4px;
  font-size: 1em;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.add-field,
#edit-json-btn,
#save-json-btn {
  background-color: #2196F3;
  color: #fff;
}

.add-field:hover,
#edit-json-btn:hover,
#save-json-btn:hover {
  background-color: #1976D2;
}

.remove-field,
#delete-family-btn,
#cancel-json-btn {
  background-color: #f44336;
  color: #fff;
}

.remove-field:hover,
#delete-family-btn:hover,
#cancel-json-btn:hover {
  background-color: #da190b;
}

/* ============================ */
/* End of Polished Edit Modal Styles */
/* ============================ */



.edit-modal-body {
  position: relative;
  max-height: 80vh;
  overflow-y: auto;
}

.edit-modal-body label {
  display: block;
  margin: 5px 0;
}

/* Styles for additional buttons within the edit modal */
.add-field,
.remove-field {
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 5px;
  margin: 5px 0;
}

.add-field:hover,
.remove-field:hover {
  background: #1976D2;
}

.delete-btn {
  background: #f44336;
  color: white;
  border: none;
  border-radius: 5px;
  margin: 5px;
  padding: 10px 20px;
  font-size: 1em;
}

.delete-btn:hover {
  background: #da190b;
}

.field-group,
.child-section,
.other-member-section {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
}

#save-changes {
  background: #4CAF50;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 10px 20px;
  margin-top: 10px;
}

#save-changes:hover {
  background: #45a049;
}

.success {
  color: green;
}

.error {
  color: red;
}

/* Loading section */
#loading-section {
  text-align: center;
  padding: 20px;
  font-size: 1.2em;
  color: #666;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background-color: #fff;
  z-index: 1001; /* Above content but below modals */
}

/* Ensure content takes full space when shown */
#content {
  min-height: 100vh;
  position: relative;
  z-index: 1; /* Below login/loading/modals */
  padding-top: 60px; /* Space for fixed header only */
}

/* When notification bar is visible, push content down */
#notification-bar.notification-bar:not(.hidden) + #content {
  padding-top: 108px; /* Header + notification bar */
}

/* Notification bar above the header */
#notification-bar.notification-bar {
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  z-index: 4;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px 20px;
  background-color: #ffeb3b;
  color: #000;
  border-bottom: 1px solid #ccc;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
}

/* Centered inner container with max width */
.notification-container {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

/* Notification bar buttons */
#notification-bar .notification-btn {
  background-color: #2196F3;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 0.95em;
  cursor: pointer;
  margin-right: 10px;
  transition: background-color 0.2s ease;
}
#notification-bar .notification-btn:hover {
  background-color: #1976D2;
}
#notification-bar .close-btn {
  background-color: #f44336;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 1.2em;
  margin-left: 0;
  cursor: pointer;
  transition: background-color 0.2s ease;
}
#notification-bar .close-btn:hover {
  background-color: #da190b;
}

/* Styles for JSON editor */
#json-editor {
  font-family: monospace;
  font-size: 1em;
  border: 1px solid #ccc;
  border-radius: 5px;
  padding: 10px;
  resize: vertical; /* Allow vertical resizing only */
}

.json-editor-buttons {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

/* Styles for admin buttons container */
.admin-buttons {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

/* Ensure Edit JSON button is visible */
#edit-json-btn.add-field {
  display: block !important;
  margin: 0;
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 10px 20px;
  cursor: pointer;
}

#edit-json-btn.add-field:hover {
  background: #1976D2;
}

/* Styles for field instructions */
.field-instruction {
  font-size: 0.9em;
  color: #666;
  margin: 5px 0;
}

.dropdown-separator {
  margin: 10px 0;
  border: 0;
  border-top: 1px solid Orgba(0, 0, 0, 0.1);
}

.dropdown-label {
  font-size: 0.9em;
  color: #666;
  margin: 5px 0;
  font-weight: bold;
}

/* Label used for notification messages */
.notif-label {
  font-size: 0.85em;
  color: #f44336;
}

#my-families-list {
  list-style: none;
  padding: 0;
  margin: 0 0 10px 0;
}

#my-families-list li {
  padding: 5px 0;
  cursor: pointer;
  font-size: 0.9em;
  color: #2196F3;
}

#my-families-list li:hover {
  text-decoration: underline;
}

#upcoming-events {
  background-color: #f9f9f9;
  padding: 15px;
  margin: 10px auto;
  border-radius: 8px;
  max-width: 2000px;
  width: 100%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

#upcoming-events h3 {
  margin-bottom: 10px;
}

.event-group h4 {
  margin-top: 10px;
  font-weight: bold;
}

.event-group ul {
  list-style: none;
  padding: 0;
}

.event-group li h4 {
  margin: 0;
}

.event-group li h4 span {
  font-size: 0.8em;
  font-weight: normal;
  color: #666;
}

.note {
  font-size: 0.8em;
  color: #666;
  font-style: italic;
}

/* ─────────────────────────────────────────────────────
  Reduce font sizes inside the Upcoming Events panel
  ───────────────────────────────────────────────────── */
#upcoming-events {
  font-size: 0.9em; /* base reduction for all text */
}

#upcoming-events h3 {
  font-size: 1.2em; /* section title */
}

#upcoming-events .event-group h4 {
  font-size: 1em;   /* group headings ("Birthdays", "Anniversaries") */
}

#upcoming-events .event-group li h4 {
  font-size: 0.9em; /* individual event lines */
}

#upcoming-events .note,
#upcoming-events span {
  font-size: 0.8em; /* c/o notes and date spans */
}

@media (max-width: 600px) {
  /* Ensure that the container for the user dropdown does not clip its children */
  #user-profile {
    overflow: visible;
    z-index: 1000;
  }
  
  /* Raise the drop-down's stacking order so it appears above other elements */
  #user-dropdown {
    z-index: 1001;
  }
  
  /* (Retain your existing mobile adjustments below) */
  .header {
    flex-direction: row;
    height: 60px;
    padding: 5px 10px;
  }
  /* Shrink New Family button for mobile admin */
  #new-family-btn {
    font-size: 0.8em;
    padding: 5px 8px;
    margin: 0;
    height: auto;
    line-height: normal;
  }
  .header-title {
    font-size: 1.2em;
    margin: 0;
    flex-grow: 1;
    text-align: center;
  }
  .header-right {
    font-size: 0.8em;
    max-width: 35%;
  }
  .search-container {
    padding: 5px;
    gap: 5px;
  }
  #content .search-container #search-bar {
    font-size: 0.85em;
  }
  /* Remove extra top margin on mobile */
  /* #upcoming-events {
    margin-top: 0;
    padding-top: 8px; 
  } */
}

@media (max-width: 600px) {
  /* When notification bar is visible on mobile, push content down */
  #notification-bar.notification-bar:not(.hidden) + #content {
    padding-top: 108px; /* Header + notification bar */
  }
}


/* === Family Edit Screen Enhancements === */

/* 1. Field Group Spacing and Alignment */
.field-group label,
.child-section label,
.other-member-section label {
  display: block;
  margin: 5px 0;
}
.field-group,
.child-section,
.other-member-section {
  margin-bottom: 15px;
}

/* 2. Headings Hierarchy and Readability */
.edit-modal-body h3 {
  font-size: 1.3em;
  margin-top: 20px;
  color: #444;
}
.edit-modal-body h4 {
  font-size: 1.1em;
  margin-top: 10px;
  color: #555;
}

/* 3. Form Field Width and Responsiveness */
.edit-modal-body input,
.edit-modal-body select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* 4. Buttons Styling Consistency */
.add-field,
.remove-field {
  display: inline-block;
  margin-top: 5px;
  margin-right: 10px;
}

/* 5. Visual Grouping */
.child-section,
.other-member-section {
  background: #fafafa;
  padding: 15px;
  border: 1px solid #ddd;
  border-radius: 5px;
}

/* 6. Modal Scroll Behavior */
.edit-modal-body {
  padding-right: 10px;
}

/* 7. Mobile Responsiveness */
@media (max-width: 600px) {
  #content .search-container #search-bar {
    font-size: 16px; /* prevent iOS zoom */
  }
}
@media (max-width: 600px) {
  .modal-content {
    width: 90vw;
    padding: 15px;
  }

  .edit-modal-body label {
    font-size: 0.9em;
  }

  .add-field,
  .remove-field {
    font-size: 0.9em;
    padding: 8px 15px;
  }
}

/* --- Collapsible Details/Summary for Modal Sections --- */
.edit-modal-body details {
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  margin-bottom: 18px;
  background: #fafbfc;
  padding: 0 0 8px 0;
  transition: box-shadow 0.2s;
}
.edit-modal-body details[open] {
  box-shadow: 0 2px 6px rgba(0,0,0,0.03);
}
.edit-modal-body summary {
  font-weight: 600;
  font-size: 1.15em;
  padding: 10px 0 10px 6px;
  margin-bottom: 6px;
  outline: none;
  cursor: pointer;
  user-select: none;
}
.edit-modal-body details:not([open]) summary {
  border-bottom: 1px solid #e0e0e0;
}
.edit-modal-body summary::-webkit-details-marker {
  display: none;
}
.edit-modal-body summary:before {
  content: "▶";
  display: inline-block;
  margin-right: 6px;
  font-size: 0.95em;
  transition: transform 0.2s;
}
.edit-modal-body details[open] summary:before {
  content: "▼";
  transform: rotate(0deg);
}

.show-link-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background-color: #03A9F4;
  color: white;
  border: none;
  border-radius: 5px;
  padding: 8px 12px;
  cursor: pointer;
}

.show-link-btn:hover {
  background-color: #0288D1;
}


.inline-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 5px 0;
  white-space: nowrap; /* <-- this prevents the label text from wrapping */
}

/* Override block display for inline-label inside edit-modal-body */
.edit-modal-body label.inline-label {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  margin: 5px 0;
}

@media (max-width: 600px) {
  .edit-modal-body summary {
    font-size: 1em;
    padding: 8px 0 8px 4px;
  }
  .edit-modal-body details {
    margin-bottom: 10px;
  }
}
/* Recent Users Modal */
.modal.recent-users-modal {
  position: fixed;
  top: 60px;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
}

.recent-users-modal .modal-content {
  background: #fff;
  border-radius: 8px;
  width: 90vw;
  max-width: 600px;
  padding: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  position: relative;
  overflow-y: auto;
  max-height: 90vh;
}

.recent-users-modal .modal-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.recent-users-modal .modal-title-bar h2 {
  margin: 0;
  font-size: 1.4em;
}


.recent-users-modal .modal-body {
  font-size: 0.95em;
}

.recent-users-modal .modal-body ul {
  list-style: none;
  padding: 0;
}

.recent-users-modal .modal-body li {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.recent-users-modal .send-msg-btn {
  margin-top: 5px;
  background: #2196F3;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
}

.recent-users-modal .send-msg-btn:hover {
  background: #1976D2;
}

/* Notification label next to user name */
.notif-label {
  color: green;
  margin-left: 4px;
}
/* Fade-in and fade-out transitions for dropdowns */
.dropdown,
#user-dropdown {
  transition: opacity 0.2s ease, visibility 0.2s ease;
  opacity: 1;
  visibility: visible;
}

.dropdown.hidden,
#user-dropdown.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
/* Highlight the logged-in user's family card */
.highlight-user-family {
  border: 2px solid #FF9800;
  box-shadow: 0 0 10px rgba(255, 152, 0, 0.4);
}
/* Ensure dropdown menu links are visible and styled properly */
.dropdown ul li[role="link"] {
  color: #333;
  font-size: 1em;
  text-decoration: none;
}
/* --- Family details toggle styles --- */
.family-details.hidden {
  display: none;
}

.toggle-details-bar {
  text-align: center;
  padding: 8px;
  background-color: #f0f0f0;
  cursor: pointer;
  font-weight: bold;
  border-top: 1px solid #ccc;
  user-select: none;
  transition: background 0.2s;
}

.toggle-details-bar:hover {
  background-color: #e0e0e0;
}
#upcoming-events .event-group ul {
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  gap: 12px 32px;
  margin-bottom: 16px;
}

@media (min-width: 600px) {
  #upcoming-events .event-group ul {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 900px) {
  #upcoming-events .event-group ul {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (min-width: 1200px) {
  #upcoming-events .event-group ul {
    grid-template-columns: repeat(4, 1fr);
  }
}
@media (min-width: 1600px) {
  #upcoming-events .event-group ul {
    grid-template-columns: repeat(5, 1fr);
  }
}
@media (min-width: 2000px) {
  #upcoming-events .event-group ul {
    grid-template-columns: repeat(6, 1fr);
  }
}

#upcoming-events .event-group li {
  break-inside: avoid;
  background: #fff;
  margin-bottom: 8px;
  border-radius: 5px;
  padding: 6px 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
/* ============================ */
/* Filter Button Styles */
/* ============================ */
#filter-btn {
  background-color: #2196F3;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1em;
  padding: 10px 20px;
  height: 42px;
  min-width: 90px;
  margin-left: 0;
  flex-shrink: 0;
}

#filter-btn:hover {
  background-color: #1976D2;
}

@media (max-width: 600px) {
  #filter-btn {
    font-size: 1em;
    padding: 10px 14px;
    height: 40px;
    min-width: 80px;
  }
}
#upcoming-events .event-group {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(60,90,120,0.08);
  margin-bottom: 32px;
  padding: 22px 18px 16px 18px;
  min-width: 0;
}

#upcoming-events .event-group h4 {
  font-size: 1.25em;
  margin-bottom: 10px;
  font-weight: 700;
  color: #263fa0;
  letter-spacing: 0.01em;
  border-left: 4px solid #2196F3;
  padding-left: 8px;
  background: linear-gradient(90deg, #f3f8ff 80%, #fff 100%);
  border-radius: 4px 0 0 4px;
  display: inline-block;
}

#upcoming-events .event-group ul {
  margin-top: 10px;
}

#upcoming-events .event-group:not(:last-child) {
  margin-bottom: 36px;
}

#upcoming-events .event-group li {
  margin-bottom: 8px;
  background: #f9fbff;
  border: 1px solid #e3e9f3;
  border-radius: 7px;
  padding: 9px 14px;
  box-shadow: 0 1px 3px rgba(80,120,180,0.03);
}

#upcoming-events .event-group li h4 {
  font-size: 1em;
  margin: 0;
  font-weight: 500;
  color: #222;
}

#upcoming-events .event-group li h4 span,
#upcoming-events .event-group li .note {
  font-size: 0.9em;
  color: #446;
}
/* Mobile-specific adjustments for upcoming events and main container */
@media (max-width: 900px) {
  #upcoming-events {
    max-width: 100vw;
    width: 100vw;
    margin-left: 0;
    margin-right: 0;
    border-radius: 0;
    padding-left: 8px;
    padding-right: 8px;
  }
  .container, .main-content {
    max-width: 100vw;
    width: 100vw;
    padding-left: 8px;
    padding-right: 8px;
  }
}

/* Today's public events override to ensure visibility */
#upcoming-events .event-group li.today-event {
  border: 1px solid #2196F3;
  box-shadow: 0 0 8px 2px rgba(33, 150, 243, 0.7);
  background-color: #fff !important;
}

/* Fullscreen overlay for AI Chat modal */
/* ========================================= */
/* iOS-Style AI Chat                         */
/* ========================================= */

#ai-chat-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(60px + env(safe-area-inset-bottom, 0px)); /* Above tab bar */
  z-index: 99; /* Below tab bar (100) */
}

#ai-chat-modal.hidden {
  display: none;
}

.ios-chat-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.3);
  animation: fadeIn 0.2s ease;
}

.ios-chat-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  top: calc(44px + env(safe-area-inset-top, 0px));
  background: var(--color-background, #F2F2F7);
  border-radius: 12px 12px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
  overflow: hidden;
}

.ios-chat-handle {
  width: 36px;
  height: 5px;
  background: #C7C7CC;
  border-radius: 3px;
  margin: 8px auto 0;
  flex-shrink: 0;
}

.ios-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 12px;
  background: var(--color-surface, #fff);
  border-bottom: 0.5px solid var(--color-border-light, #E5E5EA);
  flex-shrink: 0;
}

.ios-chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ios-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.ios-chat-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
}

.ios-chat-status {
  font-size: 12px;
  color: var(--color-text-secondary, #8E8E93);
}

.ios-chat-close,
.ios-chat-reset {
  font-size: 15px;
  font-weight: 500;
  color: var(--color-primary, #007AFF);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  min-width: 70px;
}

.ios-chat-close {
  text-align: right;
  font-weight: 600;
}

.ios-chat-reset {
  text-align: left;
}

.ios-chat-close:active {
  opacity: 0.5;
}

/* Messages area */
.ios-chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Bubble rows */
.ios-bubble-row {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.ios-bubble-left {
  justify-content: flex-start;
}

.ios-bubble-right {
  justify-content: flex-end;
}

/* Bubbles */
.ios-bubble {
  max-width: 80%;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.4;
  word-wrap: break-word;
}

.ios-bubble p {
  margin: 0 0 6px;
}

.ios-bubble p:last-child {
  margin-bottom: 0;
}

.ios-bubble-ai {
  background: var(--color-surface, #fff);
  color: var(--color-text-primary, #000);
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.ios-bubble-user {
  background: var(--color-primary, #007AFF);
  color: white;
  border-radius: 18px 18px 4px 18px;
}

/* AI bubble content styling */
.ios-bubble-ai table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 14px;
  width: 100%;
}

.ios-bubble-ai th, .ios-bubble-ai td {
  border: 1px solid var(--color-border-light, #E5E5EA);
  padding: 6px 10px;
  text-align: left;
}

.ios-bubble-ai th {
  background: var(--color-background, #F2F2F7);
  font-weight: 600;
}

.ios-bubble-ai ul, .ios-bubble-ai ol {
  padding-left: 20px;
  margin: 4px 0;
}

.ios-bubble-ai li {
  margin: 2px 0;
}

.ios-bubble-ai a {
  color: var(--color-primary, #007AFF);
}

/* Typing indicator */
.ios-typing {
  padding: 14px 18px;
}

.typing-indicator .typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-indicator .typing-dots span {
  width: 8px;
  height: 8px;
  background: #8E8E93;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator .typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Input bar */
.ios-chat-input-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--color-surface, #fff);
  border-top: 0.5px solid var(--color-border-light, #E5E5EA);
  gap: 8px;
  flex-shrink: 0;
}

.ios-chat-input {
  flex: 1;
  padding: 10px 16px;
  font-size: 16px !important;
  border: 1px solid var(--color-border, #D1D1D6);
  border-radius: 20px;
  background: var(--color-background, #F2F2F7);
  color: var(--color-text-primary, #000);
  outline: none;
  font-family: inherit;
  min-height: 20px;
}

.ios-chat-input:focus {
  border-color: var(--color-primary, #007AFF);
  background: var(--color-surface, #fff);
}

.ios-chat-input::placeholder {
  color: var(--color-text-tertiary, #C7C7CC);
}

.ios-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary, #007AFF);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.ios-chat-send:active {
  opacity: 0.7;
}

.ios-chat-send svg {
  margin-left: 2px;
}

/* Suggestion chips */
.ios-chat-suggestions {
  padding: 8px 16px 12px;
  flex-shrink: 0;
}

.ios-suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ios-suggestion-chip {
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 400;
  color: var(--color-primary, #007AFF);
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-primary, #007AFF);
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.ios-suggestion-chip:active {
  background: var(--color-primary, #007AFF);
  color: white;
}

/* Responsive adjustments */
@media (min-width: 768px) {
  .ios-chat-sheet {
    top: auto;
    left: 50%;
    right: auto;
    bottom: 0;
    width: 420px;
    height: 75vh;
    transform: translateX(-50%);
    border-radius: 12px 12px 0 0;
  }
}

.family-results {
  margin-top: 10px;
}

.family-result-item {
  background: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.family-result-item h4 {
  margin: 0 0 5px 0;
  color: #333;
}

.family-result-item p {
  margin: 3px 0;
  font-size: 0.9em;
  color: #666;
}

@media (max-width: 600px) {
  .ios-bubble {
    max-width: 85%;
  }
}

/* ============================================
   MOBILE-FIRST REDESIGN STYLES
   ============================================ */

/* --- Loading Screen --- */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  z-index: 9999;
}

.loading-content {
  text-align: center;
}

.loading-logo {
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-lg);
  animation: pulse 2s ease-in-out infinite;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto var(--space-md);
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.95); opacity: 0.8; }
}

.loading-screen p {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

/* --- Login Screen --- */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--color-surface) 0%, var(--color-background) 100%);
  z-index: 1000;
  padding: var(--space-xl);
}

.login-content {
  text-align: center;
  max-width: 320px;
}

.login-logo {
  width: 100px;
  height: 100px;
  margin-bottom: var(--space-lg);
}

.login-content h1 {
  font-size: var(--font-size-title);
  font-weight: var(--font-weight-bold);
  margin: 0 0 var(--space-sm);
  color: var(--color-text-primary);
}

.login-content #login-message {
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-xxl);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: var(--touch-target-min);
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-background);
  color: var(--color-text-primary);
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-text-inverse);
}

.btn-lg {
  padding: var(--space-base) var(--space-xl);
  font-size: var(--font-size-md);
  border-radius: var(--radius-lg);
  min-height: 52px;
}

.btn-sm {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  min-height: 36px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  color: var(--color-text-secondary);
  font-size: 24px;
}

.btn-icon:active {
  background: var(--color-border-light);
}

/* --- App Container --- */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-background);
}

/* --- App Header --- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-border-light);
  padding-top: var(--safe-area-top);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--space-base);
}

.header-logo {
  width: 32px;
  height: 32px;
}

.header-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0;
}

.header-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-border);
}

/* --- Tab Views --- */
.tab-views {
  flex: 1;
  padding-top: calc(var(--header-height) + var(--safe-area-top));
  padding-bottom: calc(var(--tab-bar-height) + var(--safe-area-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-view {
  display: none !important;
  padding: var(--space-base);
  animation: fadeIn 0.2s ease;
}

.tab-view.active {
  display: block !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.tab-title {
  font-size: var(--font-size-xxl);
  font-weight: var(--font-weight-bold);
  margin: 0 0 var(--space-base);
  color: var(--color-text-primary);
}

/* --- Bottom Tab Bar --- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--tab-bar-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--color-border-light);
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  color: #8E8E93;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: var(--space-sm) 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.tab-item:active {
  opacity: 0.7;
}

.tab-item.active {
  color: #007AFF;
}

.tab-emoji {
  font-size: 22px;
  line-height: 1;
  filter: grayscale(100%);
  opacity: 0.6;
}

.tab-item.active .tab-emoji {
  filter: none;
  opacity: 1;
}

.tab-label {
  font-size: 10px;
  font-weight: var(--font-weight-medium);
}

/* --- Search Components --- */
.search-container {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  align-items: center;
}

.search-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: var(--space-md);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: var(--space-md) var(--space-md) var(--space-md) 44px;
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  border: none;
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text-primary);
  box-shadow: var(--shadow-sm);
}

.search-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.2);
}

.search-input::placeholder {
  color: var(--color-text-tertiary);
}

.search-ai-btn {
  position: absolute;
  right: var(--space-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text-inverse);
  cursor: pointer;
}

.search-ai-btn:active {
  transform: scale(0.95);
}

.search-full {
  margin-bottom: var(--space-base);
}

.search-input-wrapper.large .search-input {
  padding: var(--space-base) var(--space-base) var(--space-base) 52px;
  font-size: var(--font-size-md);
  border-radius: var(--radius-xl);
}

.search-input-wrapper.large .search-icon {
  left: var(--space-base);
}

.search-clear {
  position: absolute;
  right: var(--space-md);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-text-tertiary);
  color: var(--color-surface);
  border: none;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}

/* --- Filter Chips --- */
.filter-chips {
  display: flex;
  gap: var(--space-sm);
  padding: var(--space-sm) 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.filter-chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-base);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  font-family: var(--font-family);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip.active {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}

.chip:active {
  transform: scale(0.97);
}

/* --- Search Results --- */
.search-results {
  margin-top: var(--space-base);
}

.search-placeholder {
  text-align: center;
  color: var(--color-text-tertiary);
  padding: var(--space-xxl);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-sm);
  box-shadow: var(--shadow-sm);
}

.search-result-photo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  object-fit: cover;
  background: var(--color-background);
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 2px;
}

.search-result-address {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-badge {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  color: var(--color-text-inverse);
}

.search-result-badge.member { background: var(--color-member); }
.search-result-badge.extended { background: var(--color-extended); }
.search-result-badge.non-member { background: var(--color-non-member); }
.search-result-badge.priest { background: var(--color-priest); }

/* --- Family Grid --- */
.family-grid-section {
  padding-top: var(--space-base);
}

.family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-base);
}

@media (min-width: 768px) {
  .family-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* --- Family Card (Redesigned) --- */
.family-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: none;
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  padding: 0;
  width: auto;
  margin: 0;
}

.family-card:active {
  transform: scale(0.98);
}

.family-photo-container {
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-background);
  height: auto;
  padding: 0;
}

.family-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.family-card-content {
  padding: var(--space-md);
}

.family-card-name {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0;
  line-height: 1.3;
}

.family-card-initials {
  font-size: 48px;
  font-weight: var(--font-weight-bold);
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* --- Ribbons / Badges (Redesigned) --- */
.ribbon {
  position: absolute;
  bottom: var(--space-sm);
  right: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  color: var(--color-text-inverse);
  z-index: 5;
  background: rgba(0, 0, 0, 0.6);
  box-shadow: none;
}

.member-ribbon { background: var(--color-member); }
.extended-member-ribbon { background: var(--color-extended); }
.non-member-ribbon { background: var(--color-non-member); }
.priest-ribbon { background: var(--color-priest); }

/* --- Events Section --- */
.events-section {
  margin-bottom: var(--space-base);
}

.events-tab-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-base);
}

.events-date-range {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.events-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* --- Menu Section --- */
.menu-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.menu-section-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--space-sm) var(--space-base);
}

.menu-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  width: 100%;
  padding: var(--space-md) var(--space-base);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--color-border-light);
  text-decoration: none;
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-family: var(--font-family);
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:active {
  background: var(--color-background);
}

.menu-icon {
  font-size: 20px;
  width: 28px;
  text-align: center;
}

.menu-label {
  flex: 1;
}

.menu-external,
.menu-chevron {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-md);
}

.admin-only.hidden {
  display: none;
}

/* --- Profile Section --- */
.profile-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-xl) 0;
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-background);
  margin-bottom: var(--space-md);
}

.profile-name {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin: 0 0 var(--space-xs);
  color: var(--color-text-primary);
}

.profile-email {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: 0;
}

.profile-section-title {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--space-sm) var(--space-base);
}

.profile-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.profile-families {
  list-style: none;
  padding: 0;
  margin: 0;
}

.profile-families li {
  padding: var(--space-md) var(--space-base);
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-primary);
  cursor: pointer;
}

.profile-families li:last-child {
  border-bottom: none;
}

.profile-toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-base);
}

/* --- Toggle Switch --- */
.toggle-switch {
  position: relative;
  width: 51px;
  height: 31px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--color-border);
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 27px;
  height: 27px;
  left: 2px;
  bottom: 2px;
  background: var(--color-surface);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--color-success);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* --- Notification Bar --- */
.notification-bar {
  position: fixed;
  top: calc(var(--header-height) + var(--safe-area-top));
  left: 0;
  right: 0;
  z-index: 99;
  padding: var(--space-md) var(--space-base);
  background: #FFF3CD;
  border-bottom: 1px solid #FFECB5;
}

.notification-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  max-width: 600px;
  margin: 0 auto;
  font-size: var(--font-size-sm);
}

/* --- Modal Sheet (iOS Style) --- */
.modal-sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-sheet:not(.hidden) {
  opacity: 1;
  visibility: visible;
}

.modal-sheet .modal-content {
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  background: var(--color-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow: hidden;
  transform: translateY(100%);
  transition: transform var(--transition-slow);
  padding-bottom: var(--safe-area-bottom);
}

.modal-sheet:not(.hidden) .modal-content {
  transform: translateY(0);
}

/* Modal drag handle */
.modal-sheet .modal-content::before {
  content: '';
  display: block;
  width: 36px;
  height: 5px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  margin: var(--space-sm) auto var(--space-md);
}

/* --- Highlight User Family --- */
.highlight-user-family {
  box-shadow: 0 0 0 3px var(--color-primary), var(--shadow-lg) !important;
}

/* --- Upcoming Events Overrides --- */
#upcoming-events {
  background: transparent;
  padding: 0;
  margin: 0;
  box-shadow: none;
  max-width: none;
  width: 100%;
}

#upcoming-events h3 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: var(--space-md);
}

#upcoming-events .event-group {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-base);
  margin-bottom: var(--space-base);
  box-shadow: var(--shadow-sm);
}

#upcoming-events .event-group h4 {
  font-size: var(--font-size-base);
  color: var(--color-primary);
  margin-bottom: var(--space-sm);
  padding-left: var(--space-sm);
  border-left: 3px solid var(--color-primary);
  background: transparent;
  display: block;
}

#upcoming-events .event-group li {
  background: var(--color-background);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-xs);
}

/* --- Hide Legacy Elements --- */
#hamburger-menu,
#dropdown-menu,
.header-left,
.header-right,
.header:not(.app-header) {
  display: none !important;
}

/* Legacy #content padding override */
#content.app-container {
  padding-top: 0;
}

/* --- Responsive Adjustments --- */
@media (min-width: 768px) {
  .tab-views {
    max-width: 1200px;
    margin: 0 auto;
    padding-left: var(--space-xl);
    padding-right: var(--space-xl);
  }
  
  .family-grid {
    gap: var(--space-lg);
  }
}

@media (min-width: 1024px) {
  /* On larger screens, tab bar could become a sidebar */
  /* For now, keep bottom tab bar */
}

/* --- Skeleton Loading --- */
.skeleton {
  background: linear-gradient(90deg, 
    var(--color-background) 25%, 
    var(--color-surface) 50%, 
    var(--color-background) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.skeleton-photo {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--color-background);
}

.skeleton-text {
  height: 16px;
  margin: var(--space-md);
  border-radius: var(--radius-sm);
}

.skeleton-text.short {
  width: 60%;
}

/* --- Empty State --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-xxxl) var(--space-xl);
  text-align: center;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: var(--space-lg);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-sm);
}

.empty-state-text {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  margin: 0;
}

/* --- Pull to Refresh Indicator --- */
.pull-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-base);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

/* --- Staggered Animation for Cards --- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .family-card {
    animation: fadeInUp 0.3s ease-out backwards;
  }
  
  .family-card:nth-child(1) { animation-delay: 0.05s; }
  .family-card:nth-child(2) { animation-delay: 0.1s; }
  .family-card:nth-child(3) { animation-delay: 0.15s; }
  .family-card:nth-child(4) { animation-delay: 0.2s; }
  .family-card:nth-child(5) { animation-delay: 0.25s; }
  .family-card:nth-child(6) { animation-delay: 0.3s; }
  .family-card:nth-child(7) { animation-delay: 0.35s; }
  .family-card:nth-child(8) { animation-delay: 0.4s; }
}

/* --- Search Result Cards (Search Tab) --- */
.search-result-card {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-base);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  gap: var(--space-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  min-height: var(--touch-target-min);
}

.search-result-card:active {
  background: var(--color-surface-secondary);
}

.search-result-photo {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-surface-secondary);
}

.search-result-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.search-result-initials {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary) 0%, #5856D6 100%);
  color: white;
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-md);
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-md);
  color: var(--color-text-primary);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-type {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  display: inline-block;
  margin-top: 2px;
}

.search-result-detail {
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
  margin: 2px 0 0;
}

.search-result-chevron {
  flex-shrink: 0;
  color: var(--color-text-tertiary);
}

.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-base);
}

.empty-state-text {
  color: var(--color-text-secondary);
  font-size: var(--font-size-md);
}

.search-placeholder {
  color: var(--color-text-secondary);
  text-align: center;
  padding: var(--space-xl) var(--space-base);
  font-size: var(--font-size-md);
}

.search-results-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary, #8E8E93);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px 4px 12px;
}

/* --- Profile Tab Styles --- */
.profile-content {
  padding: 0;
}

.profile-header {
  text-align: center;
  padding: var(--space-lg) 0;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  object-fit: cover;
  margin-bottom: var(--space-sm);
  border: 3px solid var(--color-primary);
}

.profile-name {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  margin: 0;
}

.profile-email {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: var(--space-xxs) 0 0;
}

.profile-section {
  margin-bottom: var(--space-lg);
}

.profile-section-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--space-xs);
  padding: 0 var(--space-xs);
}

.profile-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-sm) var(--space-base);
}

.profile-families {
  list-style: none;
  padding: 0;
  margin: 0;
}

.profile-families li {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-primary);
  cursor: pointer;
  font-weight: var(--font-weight-medium);
}

.profile-families li:last-child {
  border-bottom: none;
}

.profile-toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-xs) 0;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #E5E5EA;
  border-radius: 31px;
  transition: 0.3s;
  cursor: pointer;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: 27px;
  height: 27px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: #34C759;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.btn-danger {
  background: #FF3B30;
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-base);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: background var(--transition-fast);
  min-height: var(--touch-target-min);
}

.btn-danger:active {
  background: #D32F2F;
}

.btn-block {
  display: block;
  width: 100%;
  text-align: center;
}

/* --- Menu Tab Styles --- */
.menu-content {
  padding: 0;
}

.menu-section {
  margin-bottom: var(--space-lg);
}

.menu-section-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--space-xs);
  padding: 0 var(--space-xs);
}

.menu-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-base);
  text-decoration: none;
  color: var(--color-text-primary);
  border-bottom: 1px solid var(--color-border-light);
  min-height: var(--touch-target-min);
  transition: background var(--transition-fast);
  cursor: pointer;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:active {
  background: var(--color-surface-secondary);
}

.menu-icon {
  font-size: 20px;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.menu-label {
  flex: 1;
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-medium);
}

.menu-external {
  color: var(--color-text-tertiary);
  font-size: var(--font-size-sm);
}

/* --- Filter Chips --- */
.filter-chips {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-sm) 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chip {
  padding: var(--space-xs) var(--space-base);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 32px;
}

.chip.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.chip:active {
  transform: scale(0.95);
}

/* --- Loading & Login Screens --- */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--color-background);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading-screen.hidden {
  display: none;
}

.loading-content {
  text-align: center;
}

.loading-logo {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-base);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: var(--space-base) auto;
}

.login-screen {
  position: fixed;
  inset: 0;
  background: var(--color-background);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

.login-screen.hidden {
  display: none;
}

.login-content {
  text-align: center;
  padding: var(--space-xl);
}

.login-logo {
  width: 100px;
  height: 100px;
  border-radius: var(--radius-xl);
  margin-bottom: var(--space-lg);
}

.login-content h1 {
  font-size: var(--font-size-xxl);
  font-weight: var(--font-weight-bold);
  margin: 0 0 var(--space-xs);
}

.login-content #login-message {
  color: var(--color-text-secondary);
  margin-bottom: var(--space-xl);
}

.btn-lg {
  padding: var(--space-sm) var(--space-xl);
  font-size: var(--font-size-md);
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
}

/* --- Tab Title Styles --- */
.tab-title {
  font-size: var(--font-size-xxl);
  font-weight: var(--font-weight-bold);
  margin: 0 0 var(--space-sm);
}

/* --- Notification Bar --- */
.notification-bar {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  z-index: 99;
  background: var(--color-primary);
  color: white;
  padding: var(--space-sm) var(--space-base);
}

.notification-bar.hidden {
  display: none;
}

.notification-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.btn-sm {
  padding: var(--space-xxs) var(--space-sm);
  font-size: var(--font-size-sm);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.2);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  cursor: pointer;
}

.btn-icon {
  background: none;
  border: none;
  color: white;
  font-size: var(--font-size-lg);
  cursor: pointer;
  padding: var(--space-xxs);
}

/* ========================================= */
/* iOS-Style Edit Form / Bottom Sheet        */
/* ========================================= */

/* Backdrop overlay */
.ios-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
  animation: fadeIn 0.2s ease;
}

/* The sheet itself */
.ios-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  top: 40px;
  background: var(--color-background, #F2F2F7);
  border-radius: 12px 12px 0 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
  overflow: hidden;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Drag handle */
.ios-sheet-handle {
  width: 36px;
  height: 5px;
  background: #C7C7CC;
  border-radius: 3px;
  margin: 8px auto 0;
  flex-shrink: 0;
}

/* Header bar with Cancel / Title / Save */
.ios-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--color-border-light, #E5E5EA);
}

.ios-sheet-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
  margin: 0;
  text-align: center;
}

.ios-sheet-cancel,
.ios-sheet-done {
  font-size: 17px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  min-width: 60px;
}

.ios-sheet-cancel {
  color: var(--color-primary, #007AFF);
  text-align: left;
  font-weight: 400;
}

.ios-sheet-done {
  color: var(--color-primary, #007AFF);
  text-align: right;
  font-weight: 600;
}

.ios-sheet-done:active,
.ios-sheet-cancel:active {
  opacity: 0.5;
}

/* Scrollable body */
.ios-sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px 40px;
}

/* Section with details/summary */
.ios-section {
  margin-bottom: 8px;
}

.ios-section > summary {
  list-style: none;
}

.ios-section > summary::-webkit-details-marker {
  display: none;
}

.ios-section-summary {
  font-size: 13px;
  font-weight: 600;
  color: #6D6D72;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 24px 16px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ios-section-summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid #C7C7CC;
  border-bottom: 2px solid #C7C7CC;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.ios-section[open] > .ios-section-summary::after {
  transform: rotate(-135deg);
}

.ios-section-header {
  font-size: 13px;
  font-weight: 600;
  color: #6D6D72;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 16px 8px;
}

/* Form card (grouped table-view style) */
.ios-form-card {
  background: var(--color-surface, #FFFFFF);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 4px;
}

.ios-dynamic-card {
  margin: 8px 0;
  border-radius: 10px;
}

/* Form row: label on left, input on right */
.ios-form-row {
  display: flex;
  align-items: center;
  padding: 0 16px;
  min-height: 44px;
  border-bottom: 0.5px solid var(--color-border-light, #E5E5EA);
}

.ios-form-row-last {
  border-bottom: none;
}

.ios-form-row-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ios-form-label {
  font-size: 16px;
  color: var(--color-text-primary, #000);
  flex-shrink: 0;
  min-width: 100px;
  padding: 12px 0;
  font-weight: 400;
}

.ios-form-input {
  flex: 1;
  font-size: 16px !important;
  color: var(--color-text-primary, #000);
  border: none;
  background: transparent;
  padding: 12px 0;
  text-align: right;
  outline: none;
  min-width: 0;
  font-family: inherit;
}

.ios-form-input::placeholder {
  color: #C7C7CC;
}

.ios-form-input:focus {
  color: var(--color-primary, #007AFF);
}

.ios-form-select {
  flex: 1;
  font-size: 16px !important;
  color: var(--color-text-primary, #000);
  border: none;
  background: transparent;
  padding: 12px 0;
  text-align: right;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  direction: rtl;
  font-family: inherit;
  cursor: pointer;
}

.ios-form-hint {
  font-size: 12px;
  color: #8E8E93;
  padding: 2px 16px 8px;
  line-height: 1.3;
}

/* Add / Remove buttons */
.ios-form-row-action {
  padding: 8px 16px;
}

.ios-add-btn {
  font-size: 15px;
  color: var(--color-primary, #007AFF);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  font-weight: 400;
  font-family: inherit;
}

.ios-add-btn:active {
  opacity: 0.5;
}

.ios-remove-btn {
  font-size: 15px;
  color: #FF3B30;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  font-weight: 400;
  font-family: inherit;
}

.ios-remove-btn:active {
  opacity: 0.5;
}

/* Admin action buttons */
.ios-admin-actions {
  display: flex;
  gap: 8px;
  padding: 8px 0 16px;
}

.ios-action-btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
}

.ios-action-blue {
  background: var(--color-primary, #007AFF);
  color: white;
}

.ios-action-red {
  background: #FF3B30;
  color: white;
}

.ios-action-secondary {
  background: var(--color-surface-secondary, #E5E5EA);
  color: var(--color-text-primary, #000);
}

.ios-action-btn:active {
  opacity: 0.7;
}

/* Status message */
.ios-message:empty {
  display: none;
}

.ios-message {
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin: 8px 0;
  text-align: center;
}

.ios-message.success {
  background: #E8F5E9;
  color: #2E7D32;
}

.ios-message.error {
  background: #FFEBEE;
  color: #C62828;
}

/* JSON editor */
.ios-json-editor {
  width: 100%;
  box-sizing: border-box;
  font-family: 'SF Mono', 'Menlo', 'Monaco', monospace;
  font-size: 13px;
  border: none;
  background: var(--color-surface, #fff);
  padding: 12px;
  resize: vertical;
  outline: none;
  border-radius: 10px;
  line-height: 1.4;
}

/* Dynamic section containers */
.ios-dynamic-fields {
  margin: 0;
}

.ios-dynamic-sections {
  margin: 0;
}

/* Bottom spacer for safe area */
.ios-sheet-bottom-spacer {
  height: 60px;
}

/* Override the old modal styles when the new sheet is present */
#edit-family-section:not(.hidden) {
  position: fixed;
  inset: 0;
  z-index: 998;
  display: block;
}

/* Hide old modal classes that might conflict */
#edit-family-section .modal,
#edit-family-section .modal-content,
#edit-family-section .modal-title-bar,
#edit-family-section .edit-modal-body {
  all: unset;
}

/* ========================================= */
/* HOME SCREEN - iOS Polish Overrides        */
/* ========================================= */

/* --- Events Section (iOS Card Style) --- */
#tab-home .events-section {
  margin-bottom: 16px;
}

#tab-home .events-section details.section {
  background: var(--color-surface, #fff);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border: none;
  margin: 0;
}

#tab-home .events-section details.section > summary {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
  padding: 14px 16px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid transparent;
}

#tab-home .events-section details.section[open] > summary {
  border-bottom-color: var(--color-border-light, #E5E5EA);
}

#tab-home .events-section details.section > summary::-webkit-details-marker {
  display: none;
}

#tab-home .events-section details.section > summary::after {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 2px solid #C7C7CC;
  border-bottom: 2px solid #C7C7CC;
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

#tab-home .events-section details.section[open] > summary::after {
  transform: rotate(-135deg);
}

/* Inner event groups */
#tab-home .events-section .event-group {
  border: none;
  margin: 0;
  padding: 0;
}

#tab-home .events-section .event-group > summary {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary, #007AFF);
  padding: 10px 16px;
  list-style: none;
  cursor: pointer;
  border-bottom: 0.5px solid var(--color-border-light, #E5E5EA);
}

#tab-home .events-section .event-group > summary::-webkit-details-marker {
  display: none;
}

#tab-home .events-section .event-group > summary h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-primary, #007AFF);
}

/* Event list items */
#tab-home .events-section .event-group ul {
  display: flex !important;
  flex-direction: column !important;
  gap: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  grid-template-columns: none !important;
}

#tab-home .events-section .event-group li {
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--color-border-light, #E5E5EA);
  margin: 0;
}

#tab-home .events-section .event-group li:last-child {
  border-bottom: none;
}

#tab-home .events-section .event-group li h4 {
  font-size: 15px;
  font-weight: 400;
  margin: 0;
  color: var(--color-text-primary, #000);
}

#tab-home .events-section .event-group li h4 span {
  color: var(--color-text-secondary, #8E8E93);
  font-size: 13px;
}

#tab-home .events-section .event-group li .note {
  display: block;
  font-size: 12px;
  color: var(--color-text-tertiary, #636366);
  margin-top: 2px;
}

/* Today events highlight */
#tab-home .events-section li.today-event {
  background: rgba(0, 122, 255, 0.06);
  border-color: rgba(0, 122, 255, 0.15) !important;
  border-radius: 0;
  box-shadow: none;
}

#tab-home .events-section p {
  padding: 16px;
  color: var(--color-text-secondary, #8E8E93);
  text-align: center;
  font-size: 14px;
  margin: 0;
}

/* --- Search Container (iOS Style) --- */
#tab-home .search-container {
  display: flex !important;
  align-items: center !important;
  justify-content: stretch !important;
  gap: 0 !important;
  margin-bottom: 12px !important;
  padding: 0 !important;
  flex-wrap: nowrap !important;
  width: 100% !important;
}

#tab-home .search-container .search-input-wrapper {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  position: relative;
  display: flex;
  align-items: center;
}

#tab-home .search-container .search-input,
#content #tab-home .search-container #search-bar {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  padding: 9px 32px 9px 36px !important;
  font-size: 16px !important;
  background: var(--color-surface, #fff) !important;
  border: none !important;
  border-radius: 10px 0 0 10px !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08) !important;
  color: var(--color-text-primary, #000) !important;
  outline: none !important;
  box-sizing: border-box !important;
}

#tab-home .search-container .search-input:focus {
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.3);
}

#tab-home .search-container .search-icon {
  position: absolute;
  left: 10px;
  width: 18px;
  height: 18px;
  color: #8E8E93;
  pointer-events: none;
  z-index: 1;
}

#tab-home .search-container .search-ai-btn {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary, #007AFF);
  color: white;
  border: none;
  border-radius: 7px;
  padding: 0;
  cursor: pointer;
}

#tab-home .search-container .search-ai-btn svg {
  width: 16px;
  height: 16px;
}

#tab-home .search-container .search-ai-btn:active {
  opacity: 0.7;
}

#tab-home .ios-filter-btn {
  width: 36px;
  height: 36px;
  border-radius: 0 10px 10px 0;
  background: var(--color-primary, #007AFF);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  margin-left: -1px;
  font-weight: 500;
  background: var(--color-primary, #007AFF);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

#tab-home .ios-filter-btn:active {
  opacity: 0.7;
}

/* --- Family Cards (iOS Style Override) --- */
#tab-home .family-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
}

#tab-home .family-card {
  width: 100% !important;
  border: none !important;
  border-radius: 12px !important;
  padding: 0 !important;
  background: var(--color-surface, #fff) !important;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08) !important;
  overflow: hidden !important;
  position: relative !important;
  margin: 0 !important;
}

#tab-home .family-card.highlight-user-family {
  box-shadow: 0 0 0 2px var(--color-primary, #007AFF), 0 2px 8px rgba(0,122,255,0.15) !important;
}

#tab-home .family-photo-container {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 16/10 !important;
  overflow: hidden !important;
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  padding: 0 !important;
}

#tab-home .family-photo {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center top !important;
  display: block !important;
  margin: 0 !important;
  max-width: none !important;
  max-height: none !important;
  cursor: pointer;
}

#tab-home .family-card-initials {
  font-size: 40px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
}

/* Ribbon badge - pill style */
#tab-home .ribbon {
  position: absolute !important;
  bottom: 10px !important;
  right: 10px !important;
  padding: 4px 10px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  border-radius: 20px !important;
  color: white !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 5 !important;
  letter-spacing: 0.3px;
}

#tab-home .member-ribbon { background: rgba(52, 199, 89, 0.85) !important; }
#tab-home .extended-member-ribbon { background: rgba(0, 122, 255, 0.85) !important; }
#tab-home .non-member-ribbon { background: rgba(142, 142, 147, 0.85) !important; }
#tab-home .priest-ribbon { background: rgba(175, 82, 222, 0.85) !important; }

/* Card content area below photo */
#tab-home .family-card-content {
  padding: 12px 14px;
}

#tab-home .family-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
  margin: 0;
}

/* Toggle details bar */
#tab-home .toggle-details-bar {
  text-align: center;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-primary, #007AFF);
  background: var(--color-surface, #fff) !important;
  border-top: 0.5px solid var(--color-border-light, #E5E5EA) !important;
  cursor: pointer;
  user-select: none;
}

#tab-home .toggle-details-bar:active {
  background: var(--color-surface-secondary, #F2F2F7) !important;
}

/* --- Expanded Family Details (iOS Style) --- */
#tab-home .family-details {
  background: var(--color-surface, #fff);
  padding: 0 14px 14px;
}

#tab-home .family-details .section {
  background: var(--color-background, #F2F2F7);
  border-radius: 10px;
  padding: 12px;
  margin: 8px 0;
}

#tab-home .family-details .section h4 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--color-text-primary, #000);
}

#tab-home .family-details .section h4 span {
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-secondary, #8E8E93);
}

#tab-home .family-details .section h4.sub-heading-gray {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary, #8E8E93);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

#tab-home .family-details .sub-heading {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary, #8E8E93);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin: 8px 0 4px;
  display: block;
}

#tab-home .family-details .section ul {
  margin: 0 !important;
  padding: 0;
}

#tab-home .family-details .section li {
  margin: 2px 0;
  font-size: 15px;
  color: var(--color-text-primary, #000);
}

#tab-home .family-details .section li a {
  color: var(--color-primary, #007AFF);
  text-decoration: none;
}

#tab-home .family-details .section p {
  margin: 4px 0;
  font-size: 15px;
}

#tab-home .family-details .section p a {
  color: var(--color-primary, #007AFF);
  text-decoration: none;
}

#tab-home .family-details .edit-btn {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-weight: 500;
  color: var(--color-primary, #007AFF);
  background: var(--color-background, #F2F2F7);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 8px;
  font-family: inherit;
}

#tab-home .family-details .edit-btn:active {
  background: var(--color-border-light, #E5E5EA);
}

#tab-home .family-details .show-link-btn {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-primary, #007AFF);
  background: transparent;
  border: 1px solid var(--color-border, #D1D1D6);
  border-radius: 8px;
  cursor: pointer;
  margin-top: 6px;
  font-family: inherit;
  text-align: center;
}

#tab-home .family-details .show-link-btn:active {
  background: var(--color-surface-secondary, #F2F2F7);
}

/* Skeleton loading cards */
#tab-home .skeleton-card {
  background: var(--color-surface, #fff);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

#tab-home .skeleton-photo {
  width: 100%;
  aspect-ratio: 16/10;
  background: linear-gradient(90deg, #E5E5EA 25%, #F2F2F7 50%, #E5E5EA 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

#tab-home .skeleton-text {
  margin: 12px 14px;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, #E5E5EA 25%, #F2F2F7 50%, #E5E5EA 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

#tab-home .skeleton-text.short {
  width: 60%;
  margin-bottom: 14px;
}

/* ========================================= */
/* COMPACT FAMILY CARDS (Home Tab)           */
/* ========================================= */

.compact-family-card {
  background: var(--color-surface, #fff);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.compact-family-card.compact-card-highlight {
  box-shadow: 0 0 0 2px var(--color-primary, #007AFF), 0 1px 4px rgba(0,122,255,0.12);
}

.compact-card-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 12px;
  cursor: pointer;
  min-height: 56px;
  transition: background 0.15s ease;
}

.compact-card-header:active {
  background: rgba(0,0,0,0.03);
}

.compact-card-photo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--color-surface-secondary, #E5E5EA);
}

.compact-card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.compact-card-initials {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
  font-size: 16px;
}

.compact-card-info {
  flex: 1;
  min-width: 0;
}

.compact-card-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compact-card-meta {
  font-size: 13px;
  color: var(--color-text-secondary, #8E8E93);
  display: block;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compact-card-badge {
  display: none;
}

.compact-card-chevron {
  flex-shrink: 0;
  color: #C7C7CC;
  transition: transform 0.25s ease;
}

.compact-card-chevron.rotated {
  transform: rotate(90deg);
}

/* Expanded detail area */
.compact-card-details {
  border-top: 0.5px solid var(--color-border-light, #E5E5EA);
  padding: 12px 14px 16px;
  animation: fadeIn 0.2s ease;
}

.compact-card-details.hidden {
  display: none;
}

.compact-detail-loading {
  text-align: center;
  padding: 16px;
  color: var(--color-text-secondary, #8E8E93);
  font-size: 14px;
}

.compact-detail-photo {
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 12px;
}

.compact-detail-photo img {
  width: 100%;
  display: block;
  border-radius: 10px;
}

.compact-detail-section {
  background: var(--color-background, #F2F2F7);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
}

.compact-detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-secondary, #8E8E93);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.compact-detail-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
  margin-bottom: 4px;
}

.compact-detail-dob {
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-secondary, #8E8E93);
}

.compact-detail-fb {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 4px;
}

.compact-detail-fb svg {
  display: block;
}

.compact-detail-contact {
  display: block;
  font-size: 15px;
  color: var(--color-primary, #007AFF);
  text-decoration: none;
  padding: 3px 0;
}

.compact-detail-link {
  color: var(--color-primary, #007AFF);
  text-decoration: none;
  font-size: 15px;
}

.compact-detail-info {
  font-size: 14px;
  color: var(--color-text-secondary, #8E8E93);
  padding: 2px 0;
}

.compact-detail-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary, #8E8E93);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px 0 4px;
}

.compact-detail-edit {
  display: block !important;
  width: 100% !important;
  padding: 12px !important;
  font-size: 16px !important;
  font-weight: 500 !important;
  color: var(--color-primary, #007AFF) !important;
  background: var(--color-background, #F2F2F7) !important;
  border: none !important;
  border-radius: 10px !important;
  cursor: pointer !important;
  margin-top: 8px !important;
  font-family: inherit !important;
  text-align: center !important;
}

.compact-detail-edit:active {
  background: var(--color-border-light, #E5E5EA) !important;
}

.compact-detail-link-btn {
  display: block !important;
  width: 100% !important;
  padding: 10px 12px !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  color: var(--color-primary, #007AFF) !important;
  background: transparent !important;
  border: 1px solid var(--color-border, #D1D1D6) !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  margin-top: 6px !important;
  font-family: inherit !important;
  text-align: center !important;
}

.compact-detail-meta {
  font-size: 12px;
  color: var(--color-text-tertiary, #636366);
  margin-top: 8px;
  text-align: center;
}

/* Home tab filter chips */
#tab-home .filter-chips {
  display: flex;
  gap: 8px;
  padding: 8px 0 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Hide old family-list grid when search-results is active */
#tab-home #family-list {
  display: none !important;
}

/* Search clear button positioning fix for Home tab */
#tab-home .search-clear {
  position: absolute;
  right: 10px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #C7C7CC;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  z-index: 2;
}

#tab-home .search-clear.hidden {
  display: none;
}

/* ========================================= */
/* iOS-Style Events Tab                      */
/* ========================================= */

#tab-events {
  padding: 16px;
}

/* Week navigation bar */
.events-week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 4px 0;
}

.events-nav-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--color-surface, #fff);
  color: var(--color-primary, #007AFF);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  flex-shrink: 0;
  font-size: 24px;
  font-weight: 300;
  line-height: 1;
}

.events-nav-btn:active {
  background: var(--color-surface-secondary, #E5E5EA);
}

.events-nav-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.events-nav-range {
  font-size: 17px;
  font-weight: 600;
  color: var(--color-text-primary, #000);
}

.events-nav-today {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary, #007AFF);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 10px;
  border-radius: 12px;
  background: rgba(0, 122, 255, 0.1);
}

.events-nav-today:active {
  background: rgba(0, 122, 255, 0.2);
}

.events-nav-today.hidden {
  display: none;
}

.ios-events-section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text-primary, #000);
  padding: 16px 0 8px;
}

.ios-events-card {
  background: var(--color-surface, #fff);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 4px;
}

.ios-event-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 12px;
  border-bottom: 0.5px solid var(--color-border-light, #E5E5EA);
  transition: background 0.15s;
}

.ios-event-row-last {
  border-bottom: none;
}

/* Date badge - like Calendar app */
.ios-event-date-badge {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--color-background, #F2F2F7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ios-event-badge-month {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-secondary, #8E8E93);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1;
}

.ios-event-badge-day {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text-primary, #000);
  line-height: 1.2;
}

/* Today's date badge */
.ios-badge-today {
  background: #FF3B30;
}

.ios-badge-today .ios-event-badge-month {
  color: rgba(255,255,255,0.85);
}

.ios-badge-today .ios-event-badge-day {
  color: #fff;
}

/* Event info */
.ios-event-info {
  flex: 1;
  min-width: 0;
}

.ios-event-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-primary, #000);
  line-height: 1.3;
}

.ios-event-detail {
  font-size: 13px;
  color: var(--color-text-secondary, #8E8E93);
  margin-top: 1px;
}

/* Today highlight row */
.ios-event-today {
  background: rgba(255, 59, 48, 0.05);
}

/* TODAY label */
.ios-today-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: #FF3B30;
  background: rgba(255, 59, 48, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
  vertical-align: middle;
  margin-left: 6px;
}

/* Empty state */
.ios-events-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-secondary, #8E8E93);
  font-size: 16px;
}

/* Tappable event rows */
.ios-event-tappable {
  cursor: pointer;
}

.ios-event-tappable:active {
  background: rgba(0,0,0,0.03);
}

.ios-event-chevron {
  flex-shrink: 0;
  color: #C7C7CC;
  transition: transform 0.25s ease;
}

.ios-event-chevron.rotated {
  transform: rotate(90deg);
}

/* Inline expanded detail below event row */
.ios-event-expand {
  border-top: 0.5px solid var(--color-border-light, #E5E5EA);
  padding: 12px 14px 16px;
  animation: fadeIn 0.2s ease;
}

.ios-event-expand.hidden {
  display: none;
}

/* Events content container */
#tab-events .events-content {
  display: flex;
  flex-direction: column;
}

/* ========================================= */
/* iOS Notification Bar                      */
/* ========================================= */

.ios-notif-bar {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  z-index: 200;
  background: #FFFFFF;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  padding: 16px;
  animation: slideDown 0.3s ease;
}

.ios-notif-bar.hidden {
  display: none;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

.ios-notif-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ios-notif-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-primary, #000);
}

.ios-notif-icon {
  font-size: 20px;
}

.ios-notif-actions {
  display: flex;
  gap: 8px;
}

.ios-notif-enable {
  flex: 1;
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  color: white;
  background: var(--color-primary, #007AFF);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}

.ios-notif-enable:active {
  opacity: 0.7;
}

.ios-notif-dismiss {
  flex: 1;
  padding: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-primary, #000);
  background: var(--color-background, #F2F2F7);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}

.ios-notif-dismiss:active {
  background: var(--color-border-light, #E5E5EA);
}

/* ========================================= */
/* Recent Users (Admin) - iOS Style          */
/* ========================================= */

.ios-ru-count {
  font-size: 13px;
  font-weight: 600;
  color: #8E8E93;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 0 0 12px;
}

.ios-ru-card {
  background: #FFFFFF;
  border-radius: 12px;
  margin-bottom: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.ios-ru-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 12px;
}

.ios-ru-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.ios-ru-info {
  flex: 1;
  min-width: 0;
}

.ios-ru-name {
  font-size: 16px;
  font-weight: 600;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ios-ru-email {
  font-size: 13px;
  color: #8E8E93;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ios-ru-seen {
  font-size: 12px;
  color: #8E8E93;
  flex-shrink: 0;
  text-align: right;
}

.ios-ru-recent {
  color: #34C759;
  font-weight: 600;
}

.ios-ru-notify-toggle {
  display: block;
  width: 100%;
  padding: 10px;
  font-size: 15px;
  font-weight: 500;
  color: #007AFF;
  background: none;
  border: none;
  border-top: 0.5px solid #E5E5EA;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}

.ios-ru-notify-toggle:active {
  background: #F2F2F7;
}

.ios-ru-message-area {
  padding: 0 14px 14px;
}

.ios-ru-message-area.hidden {
  display: none;
}

.ios-ru-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid #D1D1D6;
  border-radius: 10px;
  background: #F2F2F7;
  resize: none;
  font-family: inherit;
  outline: none;
  margin-bottom: 8px;
}

.ios-ru-textarea:focus {
  border-color: #007AFF;
  background: #FFFFFF;
}

.ios-ru-send {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  color: white;
  background: #007AFF;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}

.ios-ru-send:active {
  opacity: 0.7;
}

.ios-ru-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ========================================= */
/* Chat Tab                                  */
/* ========================================= */

#tab-chat { 
  padding: 0 !important; 
  position: relative !important; 
  height: calc(100vh - 72px - 60px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
  overflow: hidden !important; 
}

/* Contacts Header */
.chat-contacts-header {
  padding: 16px 16px 8px;
}

.chat-contacts-header .tab-title {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
}

/* Contact Card */
.chat-contact-card {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 0.5px solid #E5E5EA;
}

.chat-contact-card:active {
  background: #F2F2F7;
}

.chat-contact-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.chat-contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: #E5E5EA;
}

.chat-contact-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-contact-initials {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-weight: 600;
  font-size: 16px;
}

.chat-online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #34C759;
  border-radius: 50%;
  border: 2px solid #FFFFFF;
}

.chat-contact-info {
  flex: 1;
  min-width: 0;
}

.chat-contact-name {
  font-size: 16px;
  font-weight: 600;
  color: #000;
}

.chat-ai-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: white;
  background: linear-gradient(135deg, #007AFF, #5856D6);
  padding: 1px 6px;
  border-radius: 8px;
  vertical-align: middle;
  margin-left: 4px;
}

.chat-contact-status {
  font-size: 13px;
  color: #8E8E93;
}

.chat-status-online {
  color: #34C759;
  font-weight: 500;
}

.chat-unread-badge {
  background: #FF3B30;
  color: white;
  font-size: 12px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

.chat-contact-chevron {
  flex-shrink: 0;
}

/* Conversation View - fills space between header and tab bar */
#chat-convo-view {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

#chat-convo-view.hidden {
  display: none !important;
}

.chat-convo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 0.5px solid #E5E5EA;
  background: #FFFFFF;
  flex-shrink: 0;
}

.chat-back-btn {
  font-size: 17px;
  color: #007AFF;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  min-width: 60px;
  text-align: left;
  font-family: inherit;
}

.chat-back-btn span {
  font-size: 22px;
  font-weight: 300;
  margin-right: 2px;
}

.chat-convo-title {
  text-align: center;
  flex: 1;
}

.chat-convo-name {
  font-size: 16px;
  font-weight: 600;
  color: #000;
}

.chat-convo-status {
  font-size: 12px;
  color: #8E8E93;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #F2F2F7;
}

.chat-bubble-row {
  display: flex;
}

.chat-bubble-left { justify-content: flex-start; }
.chat-bubble-right { justify-content: flex-end; }

.chat-bubble {
  max-width: 78%;
  padding: 8px 12px;
  font-size: 16px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chat-bubble-mine {
  background: #007AFF;
  color: white;
  border-radius: 18px 18px 4px 18px;
}

.chat-bubble-other {
  background: #FFFFFF;
  color: #000;
  border-radius: 18px 18px 18px 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.chat-bubble-text {
  white-space: pre-wrap;
}

.chat-bubble-meta {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.7;
  text-align: right;
}

.chat-receipt {
  font-size: 12px;
  margin-left: 4px;
  color: rgba(255,255,255,0.6);
}

.chat-receipt-read {
  color: #5AC8FA;
}

.chat-bubble-other .chat-receipt {
  color: #8E8E93;
}

.chat-bubble-other .chat-receipt-read {
  color: #007AFF;
}

/* Typing indicator */
.chat-typing {
  padding: 12px 16px;
}

/* Input bar */
.chat-input-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #FFFFFF;
  border-top: 0.5px solid #E5E5EA;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  font-size: 16px !important;
  border: 1px solid #D1D1D6;
  border-radius: 20px;
  background: #F2F2F7;
  color: #000;
  outline: none;
  font-family: inherit;
}

.chat-input:focus {
  border-color: #007AFF;
  background: #FFFFFF;
}

.chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #007AFF;
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}

.chat-send-btn:active { opacity: 0.7; }

/* New Chat button */
.chat-new-btn {
  font-size: 14px;
  font-weight: 500;
  color: #007AFF;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  min-width: 70px;
  text-align: right;
  font-family: inherit;
}

.chat-new-btn:active { opacity: 0.5; }

/* Suggestion chips in conversation */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 0;
}

.chat-suggestion-chip {
  padding: 8px 14px;
  font-size: 14px;
  color: #007AFF;
  background: #FFFFFF;
  border: 1px solid #007AFF;
  border-radius: 18px;
  cursor: pointer;
  font-family: inherit;
}

.chat-suggestion-chip:active {
  background: #007AFF;
  color: white;
}

/* ========================================= */
/* PWA Install Banner                        */
/* ========================================= */

.pwa-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  animation: slideUp 0.3s ease;
}

.pwa-banner.hidden {
  display: none;
}

.pwa-banner-card {
  background: #FFFFFF;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 -2px 20px rgba(0,0,0,0.15);
  max-width: 400px;
  margin: 0 auto;
}

.pwa-banner-card.hidden {
  display: none;
}

.pwa-banner-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.pwa-banner-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
}

.pwa-banner-title {
  font-size: 17px;
  font-weight: 700;
  color: #000;
}

.pwa-banner-subtitle {
  font-size: 13px;
  color: #8E8E93;
  margin-top: 1px;
}

/* iOS Steps */
.pwa-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.pwa-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  color: #000;
  line-height: 1.4;
}

.pwa-step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #007AFF;
  color: white;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-share-icon,
.pwa-add-icon {
  display: inline-block;
  vertical-align: middle;
  margin: 0 2px;
}

/* Bouncing arrow pointing down */
.pwa-banner-arrow {
  text-align: center;
  animation: bouncePWA 1.5s infinite;
}

@keyframes bouncePWA {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(6px); }
}

/* Android actions */
.pwa-banner-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.pwa-install-btn {
  padding: 10px 24px;
  font-size: 16px;
  font-weight: 600;
  color: white;
  background: #007AFF;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
}

.pwa-install-btn:active {
  opacity: 0.7;
}

.pwa-dismiss {
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 500;
  color: #8E8E93;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.pwa-dismiss:active {
  color: #636366;
}

/* Dark mode disabled - app always uses light theme */