/* ===== Auth screen overlay ===== */
#auth-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #f7f1e6 0%, #efe5d3 100%);
  overflow-y: auto;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #2b2118;
}
#auth-screen.is-open { display: flex; }
body.auth-locked { overflow: hidden; }

.auth-card {
  width: 100%;
  max-width: 420px;
  background: #fffaf2;
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(74, 49, 31, 0.18), 0 2px 6px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(160, 110, 65, 0.12);
}

.auth-hero { text-align: center; margin-bottom: 24px; }
.auth-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  margin: 0 auto 14px;
  display: block;
  object-fit: contain;
  box-shadow: 0 4px 14px rgba(74, 49, 31, 0.18);
}
.auth-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 28px;
  line-height: 1.15;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  color: #2b2118;
}
.auth-tagline {
  font-size: 14px;
  color: #6b5b4a;
  margin: 0;
  line-height: 1.45;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.auth-form label {
  font-size: 12px;
  font-weight: 600;
  color: #6b5b4a;
  margin-bottom: -6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.auth-form input {
  width: 100%;
  padding: 13px 14px;
  border: 1.5px solid #e6d8c0;
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  background: #fff;
  color: #2b2118;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.auth-form input:focus {
  outline: none;
  border-color: #a35a2a;
  box-shadow: 0 0 0 3px rgba(163, 90, 42, 0.15);
}

.auth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
.auth-btn:active { transform: translateY(1px); }
.auth-btn-primary {
  background: #a35a2a;
  color: #fffaf2;
  box-shadow: 0 2px 8px rgba(163, 90, 42, 0.3);
}
.auth-btn-primary:hover { background: #8c4b21; }
.auth-btn-google {
  background: #fff;
  color: #2b2118;
  border: 1.5px solid #e6d8c0;
}
.auth-btn-google:hover { background: #fff5e8; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 8px;
  color: #a59281;
  font-size: 12px;
  font-weight: 500;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e6d8c0;
}

.auth-toggle {
  margin-top: 18px;
  text-align: center;
  font-size: 14px;
  color: #6b5b4a;
}
.auth-toggle button {
  background: none;
  border: none;
  color: #a35a2a;
  font-weight: 600;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
}
.auth-toggle button:hover { text-decoration: underline; }

.auth-error {
  display: none;
  background: #fdecea;
  color: #b3261e;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  margin-top: 4px;
}
.auth-error.is-visible { display: block; }

.auth-footer {
  margin-top: 22px;
  text-align: center;
  border-top: 1px solid #f0e3cf;
  padding-top: 16px;
}
.auth-guest-link {
  background: none;
  border: none;
  color: #8a7660;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 10px;
}
.auth-guest-link:hover { color: #2b2118; }

/* Guest empty state cards rendered into existing sections */
.guest-empty-card {
  margin: 24px auto;
  max-width: 520px;
  background: #fffaf2;
  border: 1px dashed #d9c4a3;
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
  font-family: 'Inter', sans-serif;
  color: #2b2118;
}
.guest-empty-icon { font-size: 36px; margin-bottom: 10px; }
.guest-empty-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 6px;
}
.guest-empty-sub {
  font-size: 14px;
  color: #6b5b4a;
  margin: 0 0 16px;
}
.guest-empty-btn {
  background: #a35a2a;
  color: #fffaf2;
  border: none;
  border-radius: 12px;
  padding: 11px 20px;
  font-weight: 600;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.guest-empty-btn:hover { background: #8c4b21; }

/* Sidebar account dropdown */
.account-menu {
  position: fixed;
  z-index: 9000;
  background: #fffaf2;
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(74, 49, 31, 0.18);
  border: 1px solid rgba(160, 110, 65, 0.12);
  min-width: 220px;
  padding: 6px;
  font-family: 'Inter', sans-serif;
  display: none;
}
.account-menu.is-open { display: block; }
.account-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: #2b2118;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.account-menu-item:hover { background: #fff5e8; }
.account-menu-item.danger { color: #b3261e; }
.account-menu-divider {
  height: 1px;
  background: #f0e3cf;
  margin: 4px 6px;
}
.account-menu-header {
  padding: 10px 12px 6px;
  font-size: 12px;
  color: #8a7660;
  font-weight: 500;
}

@media (max-width: 480px) {
  .auth-card { padding: 26px 20px; border-radius: 20px; }
  .auth-title { font-size: 24px; }
}

/* ===== Stage 1: Welcome screen ===== */
#welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(160deg, #f7f1e6 0%, #efe5d3 60%, #e8d9bd 100%);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #2b2118;
  overflow: hidden;
}
#welcome-screen.is-open { display: flex; }
.welcome-inner {
  width: 100%;
  max-width: 440px;
  text-align: center;
  will-change: transform, opacity;
}
.welcome-logo {
  width: 88px; height: 88px;
  border-radius: 22px;
  margin: 0 auto 20px;
  display: block;
  object-fit: contain;
  box-shadow: 0 12px 30px rgba(74, 49, 31, 0.22);
  opacity: 0;
  transform: scale(0.85);
  animation: welcomeLogoIn 900ms cubic-bezier(.2,.7,.2,1) 100ms forwards;
}
.welcome-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 44px;
  line-height: 1.05;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
  color: #2b2118;
  opacity: 0;
  transform: translateY(14px);
  animation: welcomeRise 700ms cubic-bezier(.2,.7,.2,1) 500ms forwards;
}
.welcome-tagline {
  font-size: 16px;
  color: #6b5b4a;
  margin: 0 0 36px;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(14px);
  animation: welcomeRise 700ms cubic-bezier(.2,.7,.2,1) 700ms forwards;
}
.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 0;
  transform: translateY(14px);
  animation: welcomeRise 700ms cubic-bezier(.2,.7,.2,1) 950ms forwards;
}
.welcome-btn {
  width: 100%;
  padding: 15px 18px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
.welcome-btn:active { transform: translateY(1px); }
.welcome-btn-primary {
  background: #a35a2a;
  color: #fffaf2;
  box-shadow: 0 4px 14px rgba(163, 90, 42, 0.32);
}
.welcome-btn-primary:hover { background: #8c4b21; }
.welcome-btn-secondary {
  background: transparent;
  color: #2b2118;
  border: 1.5px solid rgba(74, 49, 31, 0.18);
}
.welcome-btn-secondary:hover { background: rgba(255, 250, 242, 0.6); }
/* Skip animation when class added */
#welcome-screen.no-anim .welcome-logo,
#welcome-screen.no-anim .welcome-title,
#welcome-screen.no-anim .welcome-tagline,
#welcome-screen.no-anim .welcome-actions {
  animation: none;
  opacity: 1;
  transform: none;
}

@keyframes welcomeLogoIn {
  0%   { opacity: 0; transform: scale(0.85); }
  60%  { opacity: 1; transform: scale(1.04); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes welcomeRise {
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ===== Stage 4: Profile picker ===== */
#profile-picker-screen {
  position: fixed;
  inset: 0;
  z-index: 9997;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background: linear-gradient(180deg, #f7f1e6 0%, #efe5d3 100%);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #2b2118;
  overflow-y: auto;
}
#profile-picker-screen.is-open { display: flex; }

.pp-inner {
  width: 100%;
  max-width: 720px;
  text-align: center;
  animation: ppFadeIn 350ms ease-out;
}
@keyframes ppFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.pp-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 32px;
  line-height: 1.1;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
}
.pp-sub {
  font-size: 14px;
  color: #6b5b4a;
  margin: 0 0 28px;
}
.pp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
}
.pp-card {
  position: relative;
  background: #fffaf2;
  border: 1.5px solid rgba(160, 110, 65, 0.14);
  border-radius: 18px;
  padding: 18px 12px 14px;
  cursor: pointer;
  font-family: inherit;
  color: #2b2118;
  transition: transform 0.15s ease, box-shadow 0.18s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.pp-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 32px rgba(74, 49, 31, 0.16);
  border-color: rgba(163, 90, 42, 0.4);
}
.pp-card:active { transform: translateY(-1px); }
.pp-avatar {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 4px;
}
.pp-name {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.pp-role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a7660;
}
.pp-card.is-admin .pp-role { color: #a35a2a; }
.pp-lock {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px; height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  background: rgba(163, 90, 42, 0.12);
  color: #a35a2a;
  border-radius: 50%;
}

.pp-footer {
  margin-top: 28px;
  display: flex;
  justify-content: flex-end;
  padding: 0 8px;
}
.pp-manage-link {
  background: none;
  border: none;
  color: #8a7660;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
}
.pp-manage-link:hover { color: #2b2118; background: rgba(255, 250, 242, 0.6); }

/* PIN sheet */
.pp-pin-sheet, .pp-manage-sheet {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(43, 33, 24, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.pp-pin-sheet.is-open, .pp-manage-sheet.is-open { display: flex; }

.pp-pin-card, .pp-manage-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: #fffaf2;
  border-radius: 22px;
  padding: 28px 24px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  animation: ppSheetIn 220ms cubic-bezier(.2,.7,.2,1);
}
.pp-manage-card { max-width: 420px; text-align: left; }
@keyframes ppSheetIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.pp-pin-card.shake { animation: ppShake 380ms cubic-bezier(.36,.07,.19,.97); }
@keyframes ppShake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.pp-pin-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.08);
  background: #fff;
  font-size: 18px;
  cursor: pointer;
  color: #2b2118;
  line-height: 1;
}
.pp-pin-avatar { font-size: 56px; line-height: 1; margin-bottom: 6px; }
.pp-pin-name {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}
.pp-pin-hint {
  font-size: 13px;
  color: #6b5b4a;
  margin: 0 0 16px;
}
.pp-pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 14px;
}
.pp-pin-dots span {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #efe5d3;
  border: 1.5px solid #d9c4a3;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}
.pp-pin-dots span.filled {
  background: #a35a2a;
  border-color: #a35a2a;
  transform: scale(1.08);
}
#pp-pin-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}
.pp-pin-err {
  display: none;
  color: #b3261e;
  font-size: 13px;
  margin-top: 6px;
}
.pp-pin-err.is-visible { display: block; }

/* Manage profiles list */
.pp-manage-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
}
.pp-manage-sub {
  font-size: 13px;
  color: #6b5b4a;
  margin: 0 0 16px;
}
.pp-manage-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid #f0e3cf;
}
.pp-manage-row:first-child { border-top: none; }
.pp-manage-avatar { font-size: 28px; }
.pp-manage-name { flex: 1; font-weight: 600; font-size: 15px; }
.pp-manage-status { font-size: 12px; color: #8a7660; margin-right: 8px; }
.pp-manage-btn {
  background: #a35a2a;
  color: #fffaf2;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.pp-manage-btn.ghost {
  background: transparent;
  color: #b3261e;
  border: 1px solid rgba(179, 38, 30, 0.25);
}
.pp-manage-pin-input {
  width: 90px;
  padding: 8px 10px;
  border: 1.5px solid #e6d8c0;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  letter-spacing: 0.2em;
  margin-right: 6px;
}

@media (max-width: 480px) {
  .welcome-title { font-size: 36px; }
  .welcome-logo { width: 76px; height: 76px; }
  .pp-title { font-size: 26px; }
  .pp-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .pp-avatar { font-size: 48px; }
  .pp-card { padding: 16px 8px 12px; }
}

/* ===== Family name line under user chip / drawer ===== */
.sidebar-user-family,
.msd-user-family {
  display: block;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: #8a7a66;
  letter-spacing: 0.01em;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Invite sheet ===== */
.invite-sheet {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(43, 33, 24, 0.55);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: #2b2118;
  overflow-y: auto;
}
.invite-sheet.is-open { display: flex; }

.invite-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: #fffaf2;
  border-radius: 24px;
  padding: 28px 24px 22px;
  box-shadow: 0 20px 60px rgba(74, 49, 31, 0.28), 0 2px 6px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(160, 110, 65, 0.14);
}
.invite-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.08);
  background: #fff;
  font-size: 20px;
  cursor: pointer;
  color: #1a1d24;
  line-height: 1;
}
.invite-hero { text-align: center; margin-bottom: 18px; }
.invite-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 24px;
  margin: 0 0 6px;
  color: #2b2118;
  letter-spacing: -0.01em;
}
.invite-title #invite-family-name { color: #a35a2a; }
.invite-sub {
  margin: 0;
  font-size: 13px;
  color: #6b5b4a;
  line-height: 1.45;
}

.invite-slots {
  display: grid;
  gap: 8px;
  margin: 16px 0 16px;
}
.invite-slot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1.5px solid #e6d8c0;
  border-radius: 12px;
  background: #fffdf8;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: #2b2118;
  text-align: left;
  width: 100%;
  transition: border-color .15s ease, background .15s ease;
}
.invite-slot:hover { border-color: #c8a97e; }
.invite-slot.is-selected {
  border-color: #a35a2a;
  background: #fbf0e0;
}
.invite-slot-avatar { font-size: 26px; line-height: 1; }
.invite-slot-meta { flex: 1; min-width: 0; }
.invite-slot-name { font-weight: 600; font-size: 14px; }
.invite-slot-status { font-size: 11px; color: #8a7a66; margin-top: 1px; }
.invite-slot.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.invite-error {
  font-size: 12px;
  color: #b3261e;
  margin-top: 8px;
  min-height: 1em;
}

.invite-recent {
  margin-top: 18px;
  border-top: 1px solid rgba(160,110,65,.14);
  padding-top: 14px;
}
.invite-recent-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 8px;
  color: #2b2118;
}
.invite-recent-list {
  display: grid;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.invite-recent-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f7efe0;
  border-radius: 10px;
  font-size: 12px;
}
.invite-recent-meta { flex: 1; min-width: 0; }
.invite-recent-for { font-weight: 600; color: #2b2118; }
.invite-recent-status {
  font-size: 11px;
  color: #8a7a66;
}
.invite-recent-status.is-used { color: #4d8a4a; }
.invite-recent-status.is-revoked { color: #b3261e; }
.invite-recent-btn {
  background: transparent;
  border: 1px solid rgba(160,110,65,.25);
  color: #a35a2a;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.invite-recent-btn.danger { color: #b3261e; border-color: rgba(179,38,30,.25); }
.invite-recent-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Manage-profiles invite button */
.pp-manage-invite-btn {
  background: transparent;
  color: #a35a2a;
  border: 1px solid rgba(160,110,65,.3);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-left: 6px;
}

/* Toast (reuse points-toast look but generic) */
.afh-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(20px);
  background: #2b2118;
  color: #fffaf2;
  padding: 12px 20px;
  border-radius: 14px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 10100;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.afh-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.afh-toast.is-error { background: #6e1f1a; }
