/**
 * Lineage table – now used inside main UI layout.
 */

:root {
  --lineage-text: #1a1a1a;
  --lineage-text-muted: #666;
  --lineage-link: #0066cc;
  --lineage-link-hover: #004499;
  --lineage-error-bg: #fff3cd;
  --lineage-error-text: #856404;
  --lineage-tree-line: var(--lineage-text-muted);
  --lineage-tree-overlap: 0.4em;
  --lineage-tree-strip-gap: 0.25rem;
  --lineage-tree-overhang: 0.25rem;
}

.lineage-error {
  padding: 8px 12px;
  background: var(--lineage-error-bg);
  color: var(--lineage-error-text);
  font-size: 0.9rem;
}

/* --- Split layout with wiki panel --- */

.lineage-wiki-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.lineage-menu-panel {
  flex: 0 0 auto;
  min-height: 0;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #ffffff;
}

.lineage-wiki-panel {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Independent scroll: center panel content area and flex row */
.lineage-wiki-panel .wiki-content-area {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem;
}

.lineage-wiki-panel .wiki-content-flex {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  max-width: none;
  margin: 0;
}

.lineage-wiki-panel .wiki-content-flex .wiki-article {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  max-width: 85ch;
}

.lineage-wiki-panel .wiki-content-flex .wiki-clergy-aside,
.lineage-wiki-panel #lineage-wiki-aside {
  overflow-y: auto;
  flex-shrink: 0;
}

.lineage-wiki-empty {
  padding: 24px;
  border-radius: 8px;
  background-color: #f3f4f6;
  color: #6b7280;
  font-size: 0.95rem;
}

.lineage-wiki-aside-placeholder {
  font-size: 0.85rem;
  color: #9ca3af;
  padding-top: 8px;
}

/* Search strip: does not shrink; list scrolls in .lineage-table-wrap below */
.lineage-search-wrap {
  flex-shrink: 0;
  padding: 10px 16px 8px;
  border-bottom: 1px solid #e5e7eb;
  background-color: #ffffff;
}

.lineage-search-wrap .lineage-search-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 0.9rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  box-sizing: border-box;
}

.lineage-search-wrap .lineage-search-input:focus {
  outline: none;
  border-color: var(--lineage-link);
  box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.2);
}

.lineage-table-wrap {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
  width: 100%;
  padding: 12px 16px 12px 8px;
  box-sizing: border-box;
}

.lineage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.45;
  color: var(--lineage-text);
}

.lineage-menu-panel .lineage-table {
  width: auto;
  max-width: 100%;
}

.lineage-table th,
.lineage-table td {
  /* padding: 4px 12px; */
  text-align: left;
}

.lineage-table td.name-cell {
  padding-left: 4px;
}

.lineage-table .event-marker {
  margin-right: 0.25em;
}

.lineage-table td.name-cell .name-cell-inner {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.lineage-table td.name-cell .tree-glyph-strip {
  position: relative;
  display: inline-flex;
  align-items: stretch;
  margin-right: var(--lineage-tree-strip-gap);
}

.lineage-table td.name-cell .tree-glyph {
  position: relative;
  display: inline-flex;
  width: 1.25rem;
  height: 100%;
  box-sizing: border-box;
}

/* Ancestor vertical guides */
.lineage-table td.name-cell .tree-glyph-vert::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(-1 * var(--lineage-tree-overlap));
  bottom: calc(-1 * var(--lineage-tree-overlap));
  transform: translateX(-50%);
  border-left: 1px solid var(--lineage-tree-line);
}

/* Root node: small diamond */
.lineage-table td.name-cell .tree-glyph-root::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  transform: translate(-50%, -50%) rotate(45deg);
  background-color: var(--lineage-text);
}

/* Branch connectors (non-last children) */
.lineage-table td.name-cell .tree-glyph-branch::before,
.lineage-table td.name-cell .tree-glyph-branch-last::before {
  /* horizontal from guide to label */
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  right: calc(-1 * var(--lineage-tree-overhang));
  border-top: 1px solid var(--lineage-tree-line);
}

.lineage-table td.name-cell .tree-glyph-branch::after,
.lineage-table td.name-cell .tree-glyph-branch-last::after {
  /* downward vertical from center of node box */
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border-left: 1px solid var(--lineage-tree-line);
}

.lineage-table td.name-cell .tree-glyph-branch::after {
  top: calc(-1 * var(--lineage-tree-overlap));
  bottom: calc(-1 * var(--lineage-tree-overlap));
}

.lineage-table td.name-cell .tree-glyph-branch-last::after {
  /* short stub to visually terminate the branch */
  top: calc(-1 * var(--lineage-tree-overlap));
  bottom: 50%;
}

.lineage-table a {
  color: var(--lineage-link);
  text-decoration: none;
}

.lineage-table a:hover {
  color: var(--lineage-link-hover);
  text-decoration: underline;
}

.lineage-menu-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.lineage-menu-link:hover {
  text-decoration: underline;
}

.lineage-root-heading-main .lineage-menu-link {
  color: var(--lineage-link);
}
.lineage-root-heading-main .lineage-menu-link:hover {
  color: var(--lineage-link-hover);
  text-decoration: underline;
}

.lineage-root-summary-row .lineage-root-summary-cell {
  padding-left: calc(8px + (var(--depth) + 1) * 1.25rem + var(--lineage-tree-strip-gap));
  padding-top: 0.1em;
  padding-bottom: 0;
  vertical-align: bottom;
}

.lineage-root-summary {
  font-size: 0.875em;
  color: var(--lineage-text-muted);
}

.lineage-root-summary-row .lineage-root-summary {
  margin-left: 0;
}

.lineage-row-active > .name-cell {
  background-color: #eff6ff;
}

#lineage-wiki-body.loading {
  opacity: 0.65;
  transition: opacity 0.15s ease-in-out;
}

.lineage-wiki-loading {
  padding: 16px 20px;
  font-size: 0.9rem;
  color: var(--lineage-text-muted);
}

.lineage-table-empty {
  color: var(--lineage-text-muted);
}

/* --- Option A: Full-screen swap (mobile) --- */
.lineage-back-to-menu-btn {
  display: none;
}

@media (max-width: 768px) {
  .lineage-wiki-layout {
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }

  /* Menu first: full-screen overlay when in menu view */
  .lineage-wiki-layout:not(.mobile-view-content) .lineage-menu-panel {
    position: fixed;
    inset: 0;
    z-index: 100;
    max-height: none;
    max-width: none;
    border-right: none;
    border-bottom: none;
  }

  /* Content hidden until user selects */
  .lineage-wiki-layout:not(.mobile-view-content) .lineage-wiki-panel {
    visibility: hidden;
    pointer-events: none;
    position: fixed;
    inset: 0;
  }

  /* Content view: hide menu, show content */
  .lineage-wiki-layout.mobile-view-content .lineage-menu-panel {
    display: none;
  }

  .lineage-wiki-layout.mobile-view-content .lineage-wiki-panel {
    visibility: visible;
    pointer-events: all;
    position: static;
    flex: 1;
    overflow: auto;
  }

  /* Stack aside above article on mobile */
  .lineage-wiki-panel .wiki-content-flex {
    flex-direction: column;
    overflow: visible;
  }

  .lineage-wiki-panel .wiki-content-flex .wiki-article {
    order: 1;
    max-width: none;
  }

  .lineage-wiki-panel .wiki-content-flex .wiki-clergy-aside,
  .lineage-wiki-panel .wiki-content-flex #lineage-wiki-aside {
    order: 0;
    width: 100%;
    border-left: none;
    padding-left: 0;
    padding-top: 0;
    position: static;
  }

  .lineage-wiki-panel .wiki-clergy-aside .wiki-profile-image {
    max-width: 200px;
    margin-left: auto;
    margin-right: auto;
    display: block;
  }

  /* FAB: visible only in content view on mobile */
  .lineage-wiki-layout.mobile-view-content .lineage-back-to-menu-btn {
    display: flex;
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 1100;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    padding: 0;
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    color: var(--lineage-text);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }

  .lineage-wiki-layout.mobile-view-content .lineage-back-to-menu-btn:hover {
    background-color: #f9fafb;
    color: var(--lineage-link);
  }

  .lineage-wiki-panel .wiki-content-area {
    overflow-y: auto;
  }
}

@media (max-width: 640px) {
  .lineage-table-wrap {
    padding: 8px 8px;
  }

  .lineage-table {
    font-size: 0.875rem;
  }

  .lineage-table th,
  .lineage-table td {
    padding: 3px 8px;
  }

  .lineage-table td.name-cell .tree-glyph {
    width: 1.1rem;
  }

  .lineage-table td.name-cell .tree-glyph-strip {
    --lineage-tree-strip-gap: 0.2rem;
    --lineage-tree-overhang: 0.2rem;
  }
}
