/* ========================================================
   FAMILY OS - Android Native SPA Styling (Material Design 3)
   ======================================================== */

:root {
  --md-sys-color-primary: #006c4c;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #89f8ca;
  --md-sys-color-on-primary-container: #002114;
  --md-sys-color-secondary: #4d6356;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #cfe9d7;
  --md-sys-color-tertiary: #3e6374;
  --md-sys-color-tertiary-container: #c1e8fb;
  --md-sys-color-surface: #f7fbf6;
  --md-sys-color-surface-dim: #d8dbd5;
  --md-sys-color-surface-container: #edf1ec;
  --md-sys-color-surface-container-high: #e7ebe6;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-on-surface: #191c1a;
  --md-sys-color-on-surface-variant: #404943;
  --md-sys-color-outline: #707972;
  --md-sys-color-outline-variant: #bfc9c1;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-success: #059669;
  --md-sys-color-warning: #d97706;

  --elevation-1: 0 1px 3px 1px rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.12);
  --elevation-2: 0 2px 6px 2px rgba(0, 0, 0, 0.08), 0 1px 2px 0 rgba(0, 0, 0, 0.12);
  --elevation-3: 0 4px 8px 3px rgba(0, 0, 0, 0.1), 0 1px 3px 0 rgba(0, 0, 0, 0.14);
  --elevation-4: 0 6px 10px 4px rgba(0, 0, 0, 0.12), 0 2px 3px 0 rgba(0, 0, 0, 0.16);

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  --font-family: -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", system-ui, sans-serif;
  --transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: #0f172a;
  color: var(--md-sys-color-on-surface);
  line-height: 1.5;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
}

/* Device Frame Wrapper for Desktop/Tablet View */
.device-container {
  width: 100%;
  max-width: 440px;
  height: 920px;
  max-height: 96vh;
  background-color: var(--md-sys-color-surface);
  border-radius: 44px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.6), 0 0 0 10px #1e293b, 0 0 0 12px #334155;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-width 0.3s ease;
}

@media (max-width: 600px) {
  body {
    background-color: var(--md-sys-color-surface);
  }
  .device-container {
    max-width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}

/* Responsive toggle button on desktop */
.desktop-preview-bar {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 9999;
}
@media (max-width: 600px) {
  .desktop-preview-bar {
    display: none;
  }
}
.preview-btn {
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}
.preview-btn:hover {
  background: #334155;
}

/* 1. Android Status Bar */
.android-status-bar {
  height: 38px;
  padding: 8px 20px 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  z-index: 50;
  background-color: transparent;
  flex-shrink: 0;
}
.status-icons {
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-icon {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

/* 2. Android Material Top App Bar */
.top-app-bar {
  padding: 6px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--md-sys-color-surface);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
  z-index: 40;
}
.app-brand-area {
  display: flex;
  align-items: center;
  gap: 10px;
}
.family-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--md-sys-color-surface-container);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: var(--transition);
}
.family-badge:hover {
  background: var(--md-sys-color-surface-container-high);
}
.family-badge .fam-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.family-icon {
  width: 16px;
  height: 16px;
  fill: var(--md-sys-color-primary);
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  position: relative;
  transition: var(--transition);
}
.icon-btn:hover {
  background-color: var(--md-sys-color-surface-container);
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.badge-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 8px;
  height: 8px;
  background: var(--md-sys-color-error);
  border-radius: 50%;
  border: 2px solid var(--md-sys-color-surface);
}

/* 3. Main Screen Viewport (Scrollable Content) */
.screen-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  padding-bottom: 90px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.screen-viewport::-webkit-scrollbar {
  width: 4px;
}
.screen-viewport::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline-variant);
  border-radius: 4px;
}

/* View Pages */
.view-page {
  display: none;
  padding: 16px;
  animation: fadeIn 0.25s ease-out;
}
.view-page.active {
  display: block;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Section Titles & Cards */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 18px 0 10px;
}
.section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  letter-spacing: -0.2px;
}
.section-link {
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-primary);
  text-decoration: none;
  cursor: pointer;
}

/* Material 3 Surface Card */
.m3-card {
  background-color: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--elevation-1);
  border: 1px solid rgba(0, 0, 0, 0.04);
  transition: var(--transition);
}
.m3-card:hover {
  box-shadow: var(--elevation-2);
}

/* Net Worth Killer Card */
.net-worth-card {
  background: linear-gradient(135deg, #004d35 0%, #006c4c 50%, #0d9467 100%);
  color: #ffffff;
  border-radius: var(--radius-xl);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--elevation-3);
  position: relative;
  overflow: hidden;
}
.net-worth-card::after {
  content: "";
  position: absolute;
  top: -30%;
  right: -20%;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0) 70%);
  border-radius: 50%;
  pointer-events: none;
}
.nw-subtitle {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 6px;
}
.nw-amount {
  font-size: 28px;
  font-weight: 800;
  margin: 6px 0 14px;
  letter-spacing: -0.5px;
}
.nw-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}
.nw-sub-item .label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
}
.nw-sub-item .val {
  font-size: 15px;
  font-weight: 700;
  margin-top: 2px;
}

/* Cashflow Card */
.cashflow-banner {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  background: var(--md-sys-color-surface-container);
  padding: 12px;
  border-radius: var(--radius-lg);
  margin-bottom: 14px;
  text-align: center;
}
.cf-col .cf-label {
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
}
.cf-col .cf-val {
  font-size: 13px;
  font-weight: 700;
  margin-top: 2px;
}
.cf-in { color: var(--md-sys-color-success); }
.cf-out { color: var(--md-sys-color-error); }
.cf-surplus { color: var(--md-sys-color-primary); }

/* Finance Subnav Tabs */
.fin-subnav-bar {
  display: flex;
  background: var(--md-sys-color-surface-container);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 14px;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.fin-subnav-bar::-webkit-scrollbar {
  display: none;
}
.fin-subnav-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  text-align: center;
}
.fin-subnav-btn.active {
  background: #ffffff;
  color: var(--md-sys-color-primary);
  box-shadow: var(--elevation-1);
}

/* Period Filter Bar */
.period-filter-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.period-filter-scroll::-webkit-scrollbar {
  display: none;
}
.period-filter-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}
.period-filter-chip.active {
  background: var(--md-sys-color-primary);
  color: #ffffff;
  border-color: var(--md-sys-color-primary);
  box-shadow: var(--elevation-1);
}

/* Cashflow Health Card */
.cashflow-health-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--elevation-2);
  border: 1.5px solid rgba(0, 0, 0, 0.06);
  margin-bottom: 14px;
  transition: var(--transition);
}
.cf-health-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}
.cf-health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2px;
}
.cf-health-badge.healthy {
  color: #065f46;
}
.cf-health-badge.danger {
  color: #b91c1c;
}
.cf-health-badge.warning {
  color: #b45309;
}
.cf-health-badge.neutral {
  color: #475569;
}

.cf-health-numbers {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  text-align: center;
  margin-bottom: 12px;
}
.cf-health-col .lbl {
  font-size: 11px;
  color: #64748b;
  font-weight: 600;
}
.cf-health-col .val {
  font-size: 13.5px;
  font-weight: 800;
  margin-top: 2px;
}
.cf-health-col .val.in { color: #059669; }
.cf-health-col .val.out { color: #dc2626; }
.cf-health-col .val.surplus { color: #006c4c; }
.cf-health-col .val.deficit { color: #b91c1c; }

.cf-meter-box {
  background: #f8fafc;
  padding: 8px 12px;
  border-radius: 12px;
  margin-bottom: 10px;
}
.cf-diagnosis-text {
  font-size: 12px;
  color: #334155;
  background: #f1f5f9;
  padding: 8px 12px;
  border-radius: 10px;
  line-height: 1.45;
  border-left: 3px solid var(--md-sys-color-primary);
}

/* Subscription, PWA & Admin Styling */
.sub-status-chip {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid transparent;
  transition: var(--transition);
}
.sub-status-chip.premium {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
  border-color: #f59e0b;
}
.sub-status-chip.trial {
  background: #ecfdf5;
  color: #065f46;
  border-color: #6ee7b7;
}
.sub-status-chip.expired {
  background: #fee2e2;
  color: #991b1b;
  border-color: #f87171;
}

.offline-top-banner {
  background: #dc2626;
  color: #ffffff;
  padding: 6px 12px;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  z-index: 100;
}

.plan-card {
  border-radius: 20px;
  border: 2px solid #e2e8f0;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  background: #ffffff;
}
.plan-card.selected {
  border-color: var(--md-sys-color-primary);
  background: #f0fdf4;
}
.plan-card .plan-tag {
  position: absolute;
  top: -10px;
  right: 14px;
  background: #f59e0b;
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  letter-spacing: 0.3px;
}

.unique-code-box {
  background: #fefce8;
  border: 2px dashed #eab308;
  padding: 14px;
  border-radius: 16px;
  text-align: center;
  margin: 14px 0;
}
.unique-code-num {
  font-size: 26px;
  font-weight: 900;
  color: #a16207;
  letter-spacing: 1px;
  margin: 4px 0;
}

.server-node-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  margin-bottom: 10px;
  box-shadow: var(--elevation-1);
}
.server-capacity-meter {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0 4px;
}
.server-capacity-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.admin-grid-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.admin-stat-item {
  background: #ffffff;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  text-align: center;
}
.admin-stat-item .val {
  font-size: 20px;
  font-weight: 800;
  color: #0f172a;
  margin-top: 2px;
}
.admin-stat-item .lbl {
  font-size: 11px;
  color: #64748b;
}

/* Auth Screen (Login / Register / Google Sign-In) */
.auth-screen-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--md-sys-color-surface);
  z-index: 850;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 36px;
  overflow-y: auto;
  box-sizing: border-box;
}

.auth-header {
  text-align: center;
  margin-bottom: 20px;
  padding-top: 10px;
}
.auth-logo-icon {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: linear-gradient(135deg, #006c4c, #059669);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin: 0 auto 10px;
  box-shadow: var(--elevation-2);
}
.auth-title {
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.4px;
}
.auth-subtitle {
  font-size: 12.5px;
  color: #64748b;
  margin-top: 2px;
}

.auth-tab-bar {
  display: flex;
  background: var(--md-sys-color-surface-container);
  padding: 4px;
  border-radius: 14px;
  margin-bottom: 18px;
}
.auth-tab-btn {
  flex: 1;
  padding: 9px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}
.auth-tab-btn.active {
  background: #ffffff;
  color: var(--md-sys-color-primary);
  box-shadow: var(--elevation-1);
}

.google-signin-btn {
  width: 100%;
  padding: 13px 16px;
  border-radius: var(--radius-full);
  background: #ffffff;
  color: #1f2937;
  border: 1.5px solid #e2e8f0;
  font-size: 13.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: var(--elevation-1);
  transition: var(--transition);
}
.google-signin-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  box-shadow: var(--elevation-2);
}
.google-signin-btn:active {
  transform: scale(0.98);
}
.google-icon-svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  margin: 16px 0;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 700;
}
.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}
.auth-divider span {
  padding: 0 10px;
  letter-spacing: 0.5px;
}

.demo-login-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
}
.demo-login-chip {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 8px 4px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}
.demo-login-chip:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Trial Expired Lock Overlay */
.trial-expired-overlay {
  position: absolute;
  top: 38px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(8px);
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  animation: fadeIn 0.25s ease-out;
}

.trial-lock-card {
  background: #ffffff;
  border-radius: 28px;
  padding: 30px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--elevation-4);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.trial-lock-icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: #fee2e2;
  color: #dc2626;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  border: 1px solid #fca5a5;
}

.trial-lock-badge {
  display: inline-block;
  background: #fee2e2;
  color: #991b1b;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.trial-lock-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.trial-lock-desc {
  font-size: 13px;
  color: #475569;
  line-height: 1.55;
  margin-bottom: 20px;
}

/* Quick Action Chips */
.chip-scroller {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 14px;
  scrollbar-width: none;
}
.chip-scroller::-webkit-scrollbar {
  display: none;
}
.m3-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
}
.m3-chip:hover, .m3-chip.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: rgba(0, 108, 76, 0.2);
}
.m3-chip svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* List Items */
.m3-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  box-shadow: var(--elevation-1);
  cursor: pointer;
  transition: var(--transition);
}
.m3-list-item:hover {
  background: var(--md-sys-color-surface-container);
}
.list-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar-icon-box {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-primary);
  flex-shrink: 0;
}
.avatar-icon-box svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.list-text .title {
  font-size: 14px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}
.list-text .subtitle {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 1px;
}
.list-right {
  text-align: right;
}
.list-right .amount {
  font-size: 14px;
  font-weight: 700;
}
.list-right .badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-top: 3px;
  font-weight: 600;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}
.badge-paid {
  background: #d1fae5;
  color: #065f46;
}

/* 4. Android Bottom Navigation Bar (Material You) */
.bottom-nav-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72px;
  background-color: var(--md-sys-color-surface-container);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 4px;
  z-index: 60;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 1;
  padding: 6px 0;
  color: var(--md-sys-color-on-surface-variant);
  transition: var(--transition);
  text-decoration: none;
}
.nav-pill {
  width: 52px;
  height: 30px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.nav-pill svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.nav-label {
  font-size: 11px;
  font-weight: 600;
  margin-top: 3px;
  letter-spacing: 0.1px;
}
.nav-item.active {
  color: var(--md-sys-color-on-surface);
}
.nav-item.active .nav-pill {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}
.nav-item.active .nav-label {
  font-weight: 700;
  color: var(--md-sys-color-primary);
}

/* Android Home Gesture Indicator */
.android-home-bar {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 108px;
  height: 4px;
  background-color: var(--md-sys-color-on-surface);
  opacity: 0.25;
  border-radius: 2px;
  pointer-events: none;
  z-index: 70;
}

/* 5. Android Floating Action Button (FAB) */
.m3-fab {
  position: absolute;
  bottom: 84px;
  right: 18px;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--elevation-3);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  z-index: 65;
  transition: var(--transition);
}
.m3-fab:hover {
  box-shadow: var(--elevation-4);
  transform: scale(1.05);
}
.m3-fab:active {
  transform: scale(0.94);
}
.m3-fab svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

/* Speed Dial Menu */
.speed-dial-menu {
  position: absolute;
  bottom: 148px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  z-index: 64;
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  pointer-events: none;
  transition: var(--transition);
}
.speed-dial-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.speed-item {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.speed-label {
  background: rgba(30, 41, 59, 0.9);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--elevation-2);
}
.speed-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  box-shadow: var(--elevation-2);
  transition: var(--transition);
}
.speed-btn:hover {
  background: var(--md-sys-color-primary-container);
}
.speed-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* 6. Android Bottom Sheet (Modal Bottom Sheet) */
.bottom-sheet-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.bottom-sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.bottom-sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85%;
  background-color: var(--md-sys-color-surface-container-lowest);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 12px 20px 24px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.1, 0.9, 0.2, 1);
  overflow-y: auto;
  z-index: 101;
}
.bottom-sheet-overlay.open .bottom-sheet-content {
  transform: translateY(0);
}
.sheet-drag-handle {
  width: 40px;
  height: 4px;
  background-color: var(--md-sys-color-outline-variant);
  border-radius: 2px;
  margin: 4px auto 14px;
}
.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.sheet-title {
  font-size: 18px;
  font-weight: 700;
}

/* Form Styles inside Bottom Sheet */
.form-group {
  margin-bottom: 14px;
}
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--md-sys-color-outline-variant);
  background-color: var(--md-sys-color-surface);
  font-family: inherit;
  font-size: 14px;
  color: var(--md-sys-color-on-surface);
  outline: none;
  transition: var(--transition);
}
.form-control:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 3px rgba(0, 108, 76, 0.12);
}
.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-full);
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: var(--elevation-1);
  transition: var(--transition);
}
.btn-primary:active {
  transform: scale(0.98);
}
.btn-secondary {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-full);
  background-color: transparent;
  color: var(--md-sys-color-primary);
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--md-sys-color-outline-variant);
  cursor: pointer;
  margin-top: 8px;
}

/* 7. Interactive Family Tree Diagram Styling */
.tree-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0 24px;
}
.tree-scroll-wrapper::-webkit-scrollbar {
  height: 6px;
}
.tree-scroll-wrapper::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-outline-variant);
  border-radius: 4px;
}

.tree-board {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  min-width: 100%;
  width: max-content;
  padding: 4px 28px 24px 28px;
  box-sizing: border-box;
}

.tree-level-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  position: relative;
}

/* Ancestors Unhide/Hide Toggle Area */
.tree-ancestors-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  animation: fadeIn 0.25s ease;
}

.tree-ancestor-toggle-area {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 4px 0 14px;
  position: relative;
  z-index: 15;
}

.tree-unhide-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  color: var(--md-sys-color-primary);
  border: 1.5px dashed var(--md-sys-color-primary);
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--elevation-1);
  transition: var(--transition);
}
.tree-unhide-btn:hover {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  transform: translateY(-1px);
}
.tree-unhide-btn:active {
  transform: scale(0.97);
}

.tree-level-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  margin-bottom: 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.tree-couple-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  flex-wrap: nowrap;
}

.tree-couple-unit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  flex-wrap: nowrap;
}

.tree-couple-unit.multi {
  flex-wrap: nowrap;
  gap: 8px;
}

.tree-single-unit {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tree-spouse-bridge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  z-index: 5;
}

.spouse-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px dashed #d97706;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tree-stem-vertical {
  width: 3px;
  height: 24px;
  background-color: var(--md-sys-color-primary);
  border-radius: 2px;
  margin: 0 auto;
}

.tree-branch-container {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  position: relative;
  width: max-content;
  padding-top: 18px;
  gap: 16px;
}

.tree-branch-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 72px;
  right: 72px;
  height: 3px;
  background-color: var(--md-sys-color-primary);
  border-radius: 2px;
}

.tree-child-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.tree-child-node::before {
  content: "";
  position: absolute;
  top: -18px;
  width: 3px;
  height: 18px;
  background-color: var(--md-sys-color-primary);
  border-radius: 2px;
}

/* Tree Member Node Card */
.m3-tree-card {
  width: 144px;
  background: #ffffff;
  border-radius: 16px;
  padding: 10px 8px;
  box-shadow: var(--elevation-2);
  border: 1.5px solid var(--md-sys-color-outline-variant);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  transition: var(--transition);
  box-sizing: border-box;
}
.m3-tree-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--elevation-3);
  border-color: var(--md-sys-color-primary);
}
.m3-tree-card.male {
  border-top: 4px solid #2563eb;
}
.m3-tree-card.female {
  border-top: 4px solid #ec4899;
}
.m3-tree-card.in-law {
  border-top: 4px solid #9333ea !important;
  background: #faf5ff;
}
.m3-tree-card.deceased {
  border-color: #94a3b8 !important;
  background: #f8fafc;
  opacity: 0.94;
}
.m3-tree-card.deceased .node-portrait-img {
  filter: grayscale(85%);
}

/* Corner Number & Status Badges */
.child-order-corner-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 12px;
  background: #006c4c;
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  z-index: 10;
  border: 1.5px solid #ffffff;
  box-sizing: border-box;
}

.deceased-corner-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 9px;
  font-weight: 700;
  background: #334155;
  color: #ffffff;
  padding: 2px 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.node-avatar-badge {
  width: 48px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin-bottom: 5px;
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--elevation-1);
  overflow: hidden;
  position: relative;
}
.node-avatar-badge.male { background: #dbeafe; }
.node-avatar-badge.female { background: #fce7f3; }
.node-avatar-badge.in-law { background: #ede9fe; }

.node-portrait-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  border-radius: 13px;
}

.tree-node-name {
  font-size: 12.5px;
  font-weight: 700;
  color: #0f172a;
  max-width: 135px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.tree-node-role-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin: 3px 0;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.tree-node-role-pill.bio {
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}
.tree-node-role-pill.inlaw {
  background: #f3e8ff;
  color: #7e22ce;
  border: 1px solid #d8b4fe;
}

.tree-node-meta {
  font-size: 10px;
  color: #64748b;
  margin-bottom: 6px;
}

/* Portrait Photo Upload & Cropper UI */
.portrait-avatar-wrapper {
  position: relative;
  width: 90px;
  height: 110px;
  margin: 0 auto 12px;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--elevation-2);
  border: 3px solid #ffffff;
  background: #e2e8f0;
  cursor: pointer;
}
.portrait-avatar-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}
.portrait-avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
}
.portrait-avatar-overlay-btn {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* Interactive Crop Sheet Modal */
.cropper-modal-body {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.cropper-viewport-container {
  width: 270px;
  height: 360px;
  position: relative;
  background: #0f172a;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  touch-action: none;
  cursor: grab;
  margin-bottom: 14px;
  border: 2px solid var(--md-sys-color-primary);
}
.cropper-viewport-container:active {
  cursor: grabbing;
}
.cropper-image-target {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: none;
  user-select: none;
}
.cropper-grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border: 1px solid rgba(255, 255, 255, 0.4);
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.cropper-grid-overlay::before, .cropper-grid-overlay::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.25);
}
.cropper-grid-overlay::before {
  top: 33.33%;
  bottom: 33.33%;
  left: 0;
  right: 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.4);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.4);
}
.cropper-grid-overlay::after {
  left: 33.33%;
  right: 33.33%;
  top: 0;
  bottom: 0;
  border-left: 1px dashed rgba(255, 255, 255, 0.4);
  border-right: 1px dashed rgba(255, 255, 255, 0.4);
}

.cropper-controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 290px;
  margin-bottom: 16px;
}
.cropper-zoom-slider {
  flex: 1;
  accent-color: var(--md-sys-color-primary);
}
.cropper-tool-btn {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Crop Modal Overlay */
.crop-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.crop-modal-card {
  background: var(--md-sys-color-surface);
  border-radius: 28px;
  padding: 18px 20px 22px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--elevation-4);
  display: flex;
  flex-direction: column;
}

.crop-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.tree-node-actions {
  display: flex;
  gap: 3px;
  width: 100%;
  justify-content: center;
  border-top: 1px solid #f1f5f9;
  padding-top: 6px;
}

.node-action-btn {
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: var(--transition);
}
.node-action-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.node-action-btn.del:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* Danger / Delete Confirmation Modal */
.danger-confirm-card {
  text-align: center;
  padding: 10px 0;
}
.danger-confirm-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fee2e2;
  color: #dc2626;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 26px;
}
.btn-danger {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius-full);
  background-color: #dc2626;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  box-shadow: var(--elevation-1);
  transition: var(--transition);
}
.btn-danger:hover {
  background-color: #b91c1c;
}
.btn-danger:active {
  transform: scale(0.98);
}

/* 8. AI Chat Interface */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  max-height: 600px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--elevation-1);
}
.chat-bubble.assistant {
  align-self: flex-start;
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-bottom-left-radius: 4px;
}
.chat-bubble.user {
  align-self: flex-end;
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-bottom-right-radius: 4px;
}
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding-top: 10px;
}

/* Toast Message */
.m3-toast {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--elevation-3);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
  white-space: nowrap;
}
.m3-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========================================================
   TREE PDF PRINTING & PREVIEW SYSTEM
   ======================================================== */

.tree-print-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(5px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

.tree-print-modal-card {
  background: #ffffff;
  border-radius: 24px;
  padding: 20px 22px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
}

.tree-print-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 10px;
}

/* Fullscreen Preview Modal */
.tree-preview-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.2s ease;
}

.tree-preview-modal-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.tree-preview-top-toolbar {
  background: #ffffff;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 10;
}

.tree-preview-sheets-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 24px;
  background: #334155;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* On-Screen Sheet Simulation in Preview */
.preview-sheet-wrapper {
  background: #ffffff;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(0,0,0,0.1);
  border-radius: 4px;
  position: relative;
  box-sizing: border-box;
  margin: 0 auto;
}

/* Sizing preview sheet for A4 Landscape simulation */
.preview-sheet-wrapper.landscape {
  width: 1060px;
  min-height: 750px;
  padding: 20px 24px;
}
.preview-sheet-wrapper.portrait {
  width: 794px;
  min-height: 1060px;
  padding: 20px 24px;
}
.preview-sheet-wrapper.a3.landscape {
  width: 1280px;
  min-height: 900px;
  padding: 24px 28px;
}

/* ========================================================
   STANDALONE PRINT DOCUMENT STYLES
   ======================================================== */

.print-doc-container {
  width: 100%;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #0f172a;
}

.print-page-frame {
  border: 2px solid #006c4c;
  border-radius: 8px;
  padding: 16px 20px;
  position: relative;
  background: #ffffff;
  box-sizing: border-box;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.print-page-frame::before {
  content: "❖";
  position: absolute;
  top: 4px;
  left: 6px;
  color: #006c4c;
  font-size: 10px;
}
.print-page-frame::after {
  content: "❖";
  position: absolute;
  top: 4px;
  right: 6px;
  color: #006c4c;
  font-size: 10px;
}

/* Header */
.print-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #006c4c;
  padding-bottom: 10px;
  margin-bottom: 12px;
  position: relative;
}

.print-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.print-brand-emblem {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #006c4c, #047857);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 2px 6px rgba(0, 108, 76, 0.3);
}

.print-brand-titles {
  display: flex;
  flex-direction: column;
}

.print-title-sub {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #006c4c;
}

.print-title-main {
  font-size: 18px;
  font-weight: 900;
  color: #0f172a;
  letter-spacing: 0.2px;
  line-height: 1.2;
}

.print-title-tagline {
  font-size: 10px;
  color: #475569;
}

.print-header-meta {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.print-page-indicator-pill {
  background: #006c4c;
  color: #ffffff;
  font-size: 10px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 12px;
  letter-spacing: 0.5px;
}

.print-meta-text {
  font-size: 9.5px;
  color: #64748b;
}

/* Section Header */
.print-section-badge-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 6px 0 12px;
}

.print-section-badge {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 14px;
  border-radius: 14px;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ========================================================
   TREE CONNECTOR SYSTEM (UNBROKEN & CRISP)
   ======================================================== */

.print-tree-canvas {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  margin: 6px 0;
  box-sizing: border-box;
}

.print-level-row {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  width: 100%;
}

.print-couple-unit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
}

/* Marriage Bridge */
.print-marriage-bridge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0 4px;
}

.print-marriage-bridge-line {
  width: 48px;
  height: 6px;
  border-top: 2px solid #b45309;
  border-bottom: 2px solid #b45309;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.print-marriage-badge {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #d97706;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  white-space: nowrap;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* In-Law Marriage Bridge */
.print-inlaw-bridge {
  width: 32px;
  height: 4px;
  border-top: 2px solid #7e22ce;
  border-bottom: 2px solid #7e22ce;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.print-inlaw-badge {
  background: #f3e8ff;
  color: #6b21a8;
  border: 1px solid #a855f7;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 6px;
  white-space: nowrap;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Vertical Stems */
.print-stem-vertical {
  width: 2.5px;
  height: 22px;
  background-color: #006c4c;
  border-radius: 1px;
  margin: 0 auto;
  position: relative;
}

/* Child Distribution Bus */
.print-children-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  position: relative;
  margin-top: 2px;
}

.print-bus-row {
  display: flex;
  justify-content: center;
  position: relative;
  width: 100%;
}

.print-children-branches {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  position: relative;
  width: max-content;
  padding-top: 16px;
}

.print-children-branches::before {
  content: "";
  position: absolute;
  top: 0;
  left: 70px;
  right: 70px;
  height: 2.5px;
  background-color: #006c4c;
  border-radius: 1px;
}

.print-child-branch-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.print-child-branch-unit::before {
  content: "";
  position: absolute;
  top: -16px;
  width: 2.5px;
  height: 16px;
  background-color: #006c4c;
  border-radius: 1px;
}

/* Node Cards */
.print-tree-card {
  width: 136px;
  background: #ffffff;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 6px;
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  page-break-inside: avoid;
  break-inside: avoid;
}

.print-tree-card.male {
  border-top: 3.5px solid #1d4ed8;
}
.print-tree-card.female {
  border-top: 3.5px solid #db2777;
}
.print-tree-card.inlaw {
  border-top: 3.5px solid #7e22ce !important;
  background: #faf5ff;
}
.print-tree-card.deceased {
  border-color: #64748b !important;
  background: #f8fafc;
}

/* Corner Badges */
.print-node-code-tag {
  position: absolute;
  top: 4px;
  left: 4px;
  background: #006c4c;
  color: #ffffff;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  z-index: 2;
}

.print-deceased-tag {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #334155;
  color: #ffffff;
  font-size: 8px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 5px;
  z-index: 2;
}

/* Card Avatar */
.print-card-avatar {
  width: 40px;
  height: 48px;
  border-radius: 8px;
  margin: 3px 0 4px;
  background: #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}
.print-card-avatar.male { background: #dbeafe; }
.print-card-avatar.female { background: #fce7f3; }
.print-card-avatar.inlaw { background: #f3e8ff; }

.print-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.print-card-name {
  font-size: 11px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.25;
  margin-bottom: 2px;
  max-width: 124px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.print-card-role-pill {
  font-size: 8.5px;
  font-weight: 700;
  padding: 1.5px 6px;
  border-radius: 8px;
  margin: 2px 0;
  background: #e2e8f0;
  color: #334155;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.print-card-role-pill.bio {
  background: #dcfce7;
  color: #166534;
}
.print-card-role-pill.inlaw {
  background: #f3e8ff;
  color: #6b21a8;
}

.print-card-meta {
  font-size: 8.5px;
  color: #64748b;
  margin-top: 1px;
  line-height: 1.2;
}

/* ========================================================
   CROSS-PAGE CONTINUITY BANNERS (JALUR JELAS TIDAK TERPUTUS)
   ======================================================== */

.print-continuity-card {
  width: 100%;
  max-width: 760px;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 12px auto;
  box-sizing: border-box;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.print-continuity-card.to-next {
  background: #f0fdf4;
  border: 1.5px dashed #16a34a;
}

.print-continuity-card.from-prev {
  background: #eff6ff;
  border: 1.5px dashed #2563eb;
}

.continuity-badge {
  font-size: 10.5px;
  font-weight: 800;
  padding: 3px 12px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.4px;
}
.print-continuity-card.to-next .continuity-badge {
  background: #16a34a;
  color: #ffffff;
}
.print-continuity-card.from-prev .continuity-badge {
  background: #2563eb;
  color: #ffffff;
}

.continuity-title {
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
}

.continuity-desc {
  font-size: 10.5px;
  color: #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.continuity-pill {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 10px;
}

.continuity-note {
  font-size: 9.5px;
  color: #64748b;
  font-style: italic;
}

/* ========================================================
   KETERANGAN HUBUNGAN ANTAR NODE (CROSS-NODE DIRECTORY)
   ======================================================== */

.print-relation-section {
  width: 100%;
  margin-top: 14px;
  border-top: 1.5px solid #cbd5e1;
  padding-top: 10px;
  page-break-inside: avoid;
  break-inside: avoid;
}

.relation-section-title {
  font-size: 11px;
  font-weight: 800;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.relation-legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 8px;
  font-size: 9px;
  color: #334155;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.legend-line {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 2px;
}
.legend-line.marriage {
  border-top: 2px solid #b45309;
  border-bottom: 2px solid #b45309;
  height: 4px;
}
.legend-line.descent {
  background: #006c4c;
}

.print-relation-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5px;
  border: 1px solid #cbd5e1;
}

.print-relation-table th {
  background: #064e3b;
  color: #ffffff;
  padding: 5px 8px;
  text-align: left;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.3px;
  border: 1px solid #064e3b;
}

.print-relation-table td {
  padding: 4.5px 8px;
  border: 1px solid #e2e8f0;
  color: #1e293b;
  vertical-align: middle;
}

.print-relation-table tr:nth-child(even) td {
  background: #f8fafc;
}

.table-node-pill {
  background: #006c4c;
  color: #ffffff;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  display: inline-block;
  text-align: center;
}

/* Document Footer & Authentication Box */
.print-doc-footer {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 8.5px;
  color: #64748b;
}

.print-auth-signature-box {
  display: flex;
  gap: 20px;
  align-items: flex-end;
}

.auth-seal-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 4px 10px;
  background: #fafafa;
}
.auth-seal-stamp {
  font-size: 9px;
  font-weight: 800;
  color: #006c4c;
  letter-spacing: 0.5px;
}

.auth-signature-line {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 140px;
}
.auth-signature-space {
  height: 28px;
}
.auth-signature-title {
  border-top: 1px solid #475569;
  width: 100%;
  text-align: center;
  font-weight: 700;
  color: #1e293b;
  padding-top: 2px;
}

/* ========================================================
   MEDIA PRINT RULES (FOR DIRECT BROWSER PDF & PRINTING)
   ======================================================== */

@media print {
  @page {
    margin: 8mm 10mm;
    size: auto;
  }
  
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .desktop-preview-bar,
  .android-status-bar,
  .m3-top-app-bar,
  .m3-navigation-bar,
  .m3-toast,
  .auth-screen-overlay,
  .crop-modal-overlay,
  .tree-print-modal-overlay,
  .tree-preview-modal-overlay,
  .tree-quick-action-bar,
  .tree-ancestor-toggle-area,
  .tree-node-actions,
  .node-action-btn,
  .preview-sheets-viewport,
  #tree-print-iframe {
    display: none !important;
  }

  .print-page-frame {
    border: 1.5px solid #006c4c !important;
    page-break-after: always !important;
    break-after: page !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 0 !important;
    min-height: 98vh !important;
    box-sizing: border-box !important;
  }

  .print-page-frame:last-child {
    page-break-after: auto !important;
    break-after: auto !important;
  }
}
