/* ==================================================================
   FT LEFT MENU & FAMILY TREE ENHANCED - UNIFIED STYLES
   Theme: GRIPAR Blue (#3b82f6) & Pink (#db2777)
   Version: 2.0 (Cleaned & Optimized)
   ================================================================== */

/* --- ROOT VARIABLES --- */
:root {
  --ftlm-primary: #3b82f6;
  --ftlm-primary-soft: #eff6ff;
  --ftlm-accent: #db2777;
  --ftlm-accent-soft: #fdf2f8;
  --ftlm-text-main: #1e293b;
  --ftlm-text-muted: #64748b;
  --ftlm-bg-card: #ffffff;
  --ftlm-border: #e2e8f0;
  --ftlm-radius: 12px;
  --ftlm-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  --ftlm-font: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ==================================================================
   SECTION A: LEFT MENU (Main Sidebar Card)
   ================================================================== */

.ftlm-wrapper {
  font-family: var(--ftlm-font);
  width: 100%;
  box-sizing: border-box;
}

#ftlm-container {
  width: 100%;
  max-width: 320px;
  background: var(--ftlm-bg-card);
  border-radius: var(--ftlm-radius);
  box-shadow: var(--ftlm-shadow);
  border: 1px solid var(--ftlm-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header */
.ftlm-node-header {
  background: linear-gradient(to bottom, #f8fafc, #ffffff);
  padding: 16px;
  border-bottom: 1px solid var(--ftlm-border);
}

.ftlm-node-box {
  background: #fff;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  text-align: center;
  display: flex;
  flex-direction: column; 
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* Gender Indicators */
.ftlm-node-box[data-gender="Male"] { border-left: 4px solid #3b82f6; }
.ftlm-node-box[data-gender="Female"] { border-left: 4px solid #ec4899; }
.ftlm-node-box[data-gender="home"] { border-left: 4px solid #10b981; }

.ftlm-node-name {
  font-weight: 700;
  font-size: 16px;
  color: var(--ftlm-text-main);
  line-height: 1.4;
}

/* Home display in main menu */
.ftlm-home-display {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.ftlm-home-icon-inline {
  font-size: 18px;
  display: inline-flex;
  align-items: center;
}

.ftlm-node-subtitle-inline {
  font-size: 11px !important;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.ftlm-home-link {
  color: #059669;
  text-decoration: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ftlm-home-link:hover { text-decoration: underline; }

.ftlm-node-id {
  font-size: 11px;
  color: var(--ftlm-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* List & Items */
.ftlm-list {
  list-style: none;
  padding: 12px;
  margin: 0;
  overflow-y: auto;
}

.ftlm-item {
  margin-bottom: 4px;
}

.ftlm-link {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 14px;
  color: var(--ftlm-text-main);
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}

.ftlm-link:hover {
  background: var(--ftlm-primary-soft);
  color: var(--ftlm-primary);
}

/* Icons */
.ftlm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #f1f5f9;
  color: #64748b;
  margin-right: 12px;
  flex-shrink: 0;
}

.ftlm-link:hover .ftlm-icon {
  filter: brightness(0.95);
}
.ftlm-icon svg { width: 18px; height: 18px; stroke-width: 2px; }

/* Badge */
.ftlm-badge {
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  height: 18px;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

/* States */
.ftlm-disabled { opacity: 0.6; filter: grayscale(1); }
.ftlm-disabled .ftlm-link { cursor: not-allowed; background: #f8fafc; }
.ftlm-loading, .ftlm-error, .ftlm-empty { 
  padding: 20px; 
  text-align: center; 
  color: var(--ftlm-text-muted); 
  font-size: 13px; 
}
.ftlm-error { color: #dc2626; }

/* ==================================================================
   SECTION B: TREE CONTEXT MENU (Popup on Tree Nodes)
   ================================================================== */

.ftpro-context-menu {
  position: absolute;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  z-index: 10000;
  min-width: 280px;
  max-width: 320px;
  font-family: var(--ftlm-font);
  overflow: hidden;
  contain: layout style;
  will-change: transform, opacity;
  animation: menuSlideIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes menuSlideIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ftpro-context-menu-header {
  padding: 12px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ftpro-context-menu-title {
  font-weight: 600;
  font-size: 14px;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ftpro-node-role-badge {
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--ftlm-primary-soft);
  color: var(--ftlm-primary);
  font-weight: 700;
}

.ftpro-context-menu-close {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: #64748b;
  display: flex;
  transition: background 0.15s;
}
.ftpro-context-menu-close:hover { background: #e2e8f0; color: #0f172a; }
.ftpro-context-menu-close svg { width: 18px; height: 18px; }

.ftpro-menu-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}

.ftpro-menu-item:hover {
  background: var(--ftlm-primary-soft);
  border-left-color: var(--ftlm-primary);
}

.ftpro-menu-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #f1f5f9;
  color: var(--ftlm-primary);
  margin-right: 12px;
  flex-shrink: 0;
}

.ftpro-menu-item:hover .ftpro-menu-item-icon {
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.ftpro-menu-item-icon svg { width: 18px; height: 18px; }

.ftpro-menu-item-text {
  font-size: 14px;
  color: #334155;
  font-weight: 500;
}

.ftpro-svg .ft-node rect { transition: fill 0.2s, stroke 0.2s; }
.ftpro-svg .ft-node:hover rect { stroke-width: 2px; }

/* ==================================================================
   SECTION C: SUBMENU NAVIGATION
   ================================================================== */

/* Submenu Arrow */
.ftlm-submenu-arrow {
  margin-left: auto;
  font-size: 18px;
  color: #4f46e5;
  font-weight: bold;
  opacity: 0.7;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding-left: 8px;
}

.ftlm-link:hover .ftlm-submenu-arrow {
  opacity: 1;
  transform: translateX(6px);
  color: #4338ca;
}

/* Items with Submenus */
.ftlm-item.has-submenu {
  position: relative;
}

.ftlm-item.has-submenu .ftlm-link {
  padding-right: 50px;
}

.ftlm-item.has-submenu .ftlm-link::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  background: #4f46e5;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ftlm-item.has-submenu .ftlm-link:hover::after {
  opacity: 1;
}

.ftlm-item.has-submenu .ftlm-link:hover {
  background: linear-gradient(to right, var(--ftlm-primary-soft), #ffffff);
  border-left: 3px solid var(--ftlm-primary);
}

/* Submenu Wrapper */
.ftlm-submenu-wrapper .ftlm-container {
  max-width: 100%;
  border: none;
  box-shadow: none;
}

/* Submenu Breadcrumb */
.ftlm-submenu-breadcrumb {
  padding: 12px 16px;
  background: #f8fafc;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 13px;
}

.ftlm-submenu-breadcrumb a {
  color: #4f46e5;
  text-decoration: none;
}

.ftlm-submenu-breadcrumb a:hover {
  text-decoration: underline;
}

/* Loading State */
.ftlm-submenu-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: #64748b;
  font-size: 14px;
}

.ftlm-submenu-loading::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid #e2e8f0;
  border-top-color: #4f46e5;
  border-radius: 50%;
  margin-right: 12px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.ftlm-submenu-empty {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
  font-size: 14px;
}

/* ==================================================================
   SECTION D: SUBMENU MEMBER HEADER (Just Member Name)
   ================================================================== */

.ftlm-submenu-node-header {
  background: linear-gradient(to bottom, #f8fafc, #ffffff);
  padding: 16px;
  border-bottom: 1px solid var(--ftlm-border);
  margin-bottom: 8px;
  animation: slideInDown 0.3s ease-out;
}

.ftlm-submenu-node-box {
  background: #ffffff;
  padding: 16px 24px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #10b981;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.2s ease;
}

.ftlm-submenu-node-box:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: #cbd5e1;
}

.ftlm-submenu-node-box .ftlm-node-name {
  font-weight: 700;
  font-size: 20px;
  color: #0f172a;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

/* Gender-based border colors */
.ftlm-submenu-node-box[data-gender="Male"] {
  border-left-color: #3b82f6;
}

.ftlm-submenu-node-box[data-gender="Female"] {
  border-left-color: #ec4899;
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==================================================================
   SECTION E: BACK TO HOME LINK (Home Design Style)
   ================================================================== */

.ftlm-back-to-home {
  margin-top: 16px;
  padding: 12px 16px;
  border-top: 1px solid #e2e8f0;
}

.ftlm-home-box {
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #10b981;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: all 0.2s ease;
}

.ftlm-home-box:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: #cbd5e1;
}

.ftlm-home-link-new {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 24px;
  text-decoration: none;
  color: inherit;
  gap: 8px;
}

.ftlm-home-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ftlm-home-icon-large {
  font-size: 20px;
  display: flex;
  align-items: center;
}

.ftlm-home-text-large {
  font-weight: 700;
  font-size: 20px;
  color: #0f172a;
  line-height: 1.3;
}

.ftlm-home-subtitle {
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

/* ==================================================================
   RESPONSIVE DESIGN
   ================================================================== */

@media (max-width: 768px) {
  /* Main Menu */
  #ftlm-container { 
    max-width: 100%; 
    border: none; 
    box-shadow: none; 
  }
  .ftlm-link { 
    padding: 14px 16px; 
    font-size: 15px; 
  }
  
  /* Submenu */
  .ftlm-submenu-arrow {
    font-size: 16px;
  }
  .ftlm-item.has-submenu .ftlm-link {
    padding-right: 40px;
  }
  
  /* Member Header */
  .ftlm-submenu-node-header {
    padding: 12px;
  }
  .ftlm-submenu-node-box {
    padding: 14px 18px;
  }
  .ftlm-submenu-node-box .ftlm-node-name {
    font-size: 18px;
  }
  
  /* Back to Home */
  .ftlm-back-to-home {
    padding: 10px 12px;
    margin-top: 12px;
  }
  .ftlm-home-link-new {
    padding: 16px 18px;
  }
  .ftlm-home-icon-large {
    font-size: 18px;
  }
  .ftlm-home-text-large {
    font-size: 18px;
  }
  .ftlm-home-subtitle {
    font-size: 10px;
  }
  
  /* Context Menu (Bottom Sheet) */
  .ftpro-context-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 16px 16px 0 0;
    transform: none;
    border: none;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    animation: slideUpMobile 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  }
  @keyframes slideUpMobile {
    from { transform: translateY(100%); opacity: 0.5; }
    to { transform: translateY(0); opacity: 1; }
  }
  .ftpro-context-menu-backdrop {
    position: fixed; 
    inset: 0; 
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px); 
    z-index: 9999; 
    animation: fadeIn 0.2s ease;
  }
  @keyframes fadeIn { 
    from { opacity: 0; } 
    to { opacity: 1; } 
  }
  .ftpro-menu-item { padding: 14px 20px; }
  .ftpro-context-menu-header { padding: 16px 20px; }
}

/* ==================================================================
   PRINT STYLES
   ================================================================== */

@media print {
  .ftlm-submenu-arrow,
  .ftlm-breadcrumb,
  .ftlm-back-to-home {
    display: none;
  }
  
  .ftlm-submenu-node-header {
    border: 1px solid #e2e8f0;
    page-break-inside: avoid;
  }
}