/* Premium Traditional Design System for Family Tree */
:root {
    --bg-main: #fcf9f2;
    --bg-sidebar-mid: #f6efe2;
    --bg-sidebar-left: #271714;
    --color-primary: #3c241f;
    --color-accent: #b8860b; /* Dark Goldenrod */
    --color-accent-gold: #d4af37; /* Metallic Gold */
    --color-navy: #1d2d44;
    --font-heading: 'Golos Text', 'Segoe UI', sans-serif;
    --font-body: 'Golos Text', 'Segoe UI', sans-serif;
    --text-dark: #3c241f;
    --text-light: #fdfaf2;
    --text-muted: #8c736e;
    --border-color: rgba(60, 36, 31, 0.12);
    --border-gold: rgba(212, 175, 55, 0.4);
    --card-shadow: 0 10px 30px rgba(39, 23, 20, 0.08);
    --card-shadow-hover: 0 15px 35px rgba(212, 175, 55, 0.15);
    --transition-smooth: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    width: 100%;
    height: 100%;
    font-family: var(--font-body);
    color: var(--text-dark);
    background-color: var(--bg-main);
    overflow: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(60, 36, 31, 0.15);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(60, 36, 31, 0.3);
}

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
}

/* 1. Far Left: Dark Traditional Sidebar with Wood Texture */
.nav-sidebar {
    width: 80px;
    background: 
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.02) 0px, rgba(255, 255, 255, 0.02) 1px, transparent 1px, transparent 4px),
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.08) 0px, rgba(0, 0, 0, 0.08) 2px, transparent 2px, transparent 12px),
        linear-gradient(to right, #1d0f0d, #271714 30%, #1a0d0b 70%, #150907);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 24px 0;
    border-right: 1px solid rgba(0, 0, 0, 0.4);
    box-shadow: inset -3px 0 12px rgba(0, 0, 0, 0.6), 5px 0 20px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

.logo-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--color-accent-gold), var(--color-accent));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-sidebar-left);
    font-size: 22px;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.nav-item {
    width: 100%;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    gap: 6px;
    transition: var(--transition-smooth);
    border-left: 3px solid transparent;
}

.nav-item i {
    font-size: 20px;
}

.nav-item:hover, .nav-item.active {
    color: var(--color-accent-gold);
    background-color: rgba(255, 255, 255, 0.03);
}

.nav-item.active {
    border-left-color: var(--color-accent-gold);
    background-color: rgba(212, 175, 55, 0.06);
}

/* 2. Middle Left: Unified Sidebar */
.unified-sidebar {
    width: 320px;
    background-color: var(--bg-sidebar-mid);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 90;
    box-shadow: -5px 0 25px rgba(39, 23, 20, 0.03);
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.btn-group-link {
    width: 100%;
    padding: 12px;
    background-color: var(--color-navy);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.8px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(29, 45, 68, 0.2);
    transition: var(--transition-smooth);
}

.btn-group-link:hover {
    background-color: #273b57;
    box-shadow: 0 6px 16px rgba(29, 45, 68, 0.3);
}

.search-box {
    position: relative;
    width: 100%;
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 14px;
}

.search-box input {
    width: 100%;
    padding: 12px 14px 12px 38px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.7);
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--text-dark);
    outline: none;
    transition: var(--transition-smooth);
}

.search-box input:focus {
    border-color: var(--color-accent-gold);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

/* Search results dropdown */
.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background-color: #fff;
    border: 1px solid var(--border-gold);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(39, 23, 20, 0.18);
    z-index: 400;
    max-height: 320px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.search-result-item:hover {
    background-color: rgba(212, 175, 55, 0.1);
}

.search-result-item + .search-result-item {
    border-top: 1px solid var(--border-color);
}

.search-result-item img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-gold);
    flex-shrink: 0;
}

.sr-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sr-years {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-empty {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

/* Drawer close button — mobile only */
.sidebar-close {
    display: none;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    font-size: 16px;
    color: var(--text-dark);
    cursor: pointer;
    z-index: 5;
}

/* Backdrop behind the mobile drawer */
.sidebar-backdrop {
    display: none;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.sidebar-section h3 {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--color-primary);
    position: relative;
    padding-bottom: 6px;
}

.sidebar-section h3::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background-color: var(--color-accent-gold);
}

/* "Удмын гишүүд": breadcrumb chip chain + one next-generation dropdown */
.lineage-cascade {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lineage-chain {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.lineage-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 10px 14px;
    background-color: #fff;
    border: 1px solid var(--border-gold);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.lineage-chip:hover {
    border-color: var(--color-accent-gold);
    box-shadow: 0 3px 10px rgba(212, 175, 55, 0.18);
}

.chip-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.chip-x:hover {
    background-color: #fbeeec;
    color: #b05c50;
}

.lineage-sep {
    font-size: 10px;
    color: var(--text-muted);
}

.lineage-next-wrap {
    position: relative;
    width: 100%;
}

.lineage-next-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.85);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.lineage-next-btn i {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.lineage-next-btn:hover,
.lineage-next-btn.open {
    border-color: var(--color-accent-gold);
    background-color: #fff;
}

.lineage-next-btn.open i {
    transform: rotate(180deg);
}

.lineage-next-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background-color: #fff;
    border: 1px solid var(--border-gold);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(39, 23, 20, 0.18);
    z-index: 400;
    max-height: 320px;
    overflow-y: auto;
}

.lineage-next-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.lineage-next-item:hover {
    background-color: rgba(212, 175, 55, 0.1);
}

.lineage-next-item + .lineage-next-item {
    border-top: 1px solid var(--border-color);
}

.lineage-next-item img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-gold);
    flex-shrink: 0;
}

.ln-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ln-years {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Timeline Center-Aligned */
.timeline-vertical {
    position: relative;
    padding-left: 0;
    margin-left: 0;
    border-left: none;
    display: flex;
    flex-direction: column;
}

.timeline-vertical::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 57px;
    width: 2px;
    border-left: 2px dashed var(--border-gold);
    z-index: 1;
}

.timeline-item {
    position: relative;
    display: flex;
    width: 100%;
    align-items: center;
    z-index: 2;
    margin-top: 26px;
}

.timeline-item:first-child {
    margin-top: 0;
}

/* Follow-up events of the same year sit close under their year marker */
.timeline-item.same-year {
    margin-top: 10px;
}

.timeline-year-side {
    width: 46px;
    flex-shrink: 0;
    text-align: right;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    color: var(--color-accent);
}

.timeline-dot-side {
    width: 24px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.timeline-dot-circle {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--bg-sidebar-mid);
    border: 3px solid var(--color-accent-gold);
    transition: var(--transition-smooth);
}

.timeline-item:hover .timeline-dot-circle,
.timeline-item.active .timeline-dot-circle {
    background-color: var(--color-accent-gold);
    transform: scale(1.3);
    box-shadow: 0 0 8px var(--color-accent-gold);
}

.timeline-item.active .timeline-event-side {
    color: var(--color-accent);
    font-weight: 700;
}

.timeline-event-side {
    flex: 1;
    text-align: left;
    padding-left: 12px;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--text-dark);
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
}

.timeline-event-side:hover {
    color: var(--color-accent);
}

/* 3. Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

/* Topbar */
.topbar {
    height: 70px;
    background-color: rgba(252, 249, 242, 0.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    z-index: 120; /* the identity menu must cover the canvas toolbar */
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.topbar-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 5px rgba(212, 175, 55, 0.4));
}

.breadcrumbs h2 {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    color: var(--color-primary);
}

.breadcrumbs .sub-title {
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
}

.user-profile {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

/* Identity menu: email, role and the only sign-out in the app */
.user-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 240px;
    background-color: #fff;
    border: 1px solid var(--border-gold);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(39, 23, 20, 0.18);
    z-index: 500;
    padding: 6px 0;
    cursor: default;
}

.um-email {
    padding: 10px 16px 2px;
    font-size: 13px;
    font-weight: 700;
    color: var(--color-primary);
    word-break: break-all;
}

.um-role {
    padding: 0 16px 12px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.um-action {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    text-align: left;
}

.um-action i { color: var(--color-accent); }

.um-action:hover {
    background-color: rgba(212, 175, 55, 0.1);
}

.um-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: #b05c50;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.um-logout:hover {
    background-color: #fbeeec;
}

.user-profile .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--color-accent-gold);
}

/* Canvas Toolbar */
.canvas-toolbar {
    position: absolute;
    top: 24px;
    right: 24px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

/* Same metrics as .btn-profile-action so both button families match */
.canvas-toolbar button {
    padding: 10px 18px;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    box-shadow: var(--card-shadow);
    transition: var(--transition-smooth);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.canvas-toolbar button:hover {
    border-color: var(--color-accent-gold);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.12);
}

/* Icon-only toolbar buttons share one fixed width */
#btn-toggle-sidebar,
#zoom-in,
#zoom-out,
#btn-center {
    width: 44px;
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
}

/* Theater mode: only the tree, a magnifier cursor and an exit button remain */
body.theater .nav-sidebar,
body.theater .topbar,
body.theater .unified-sidebar,
body.theater .sidebar-backdrop,
body.theater .canvas-toolbar,
body.theater .collapse-badge {
    display: none !important;
}

/* Faint clan-emblem watermark behind the full tree; the near-opaque cream
   veil on top keeps it from competing with the content */
body.theater .tree-canvas-container {
    background:
        linear-gradient(rgba(252, 249, 242, 0.93), rgba(252, 249, 242, 0.93)),
        url('logo.png') center / min(58vh, 58vw) no-repeat,
        #fcf9f2;
}

body.theater .tree-canvas-container,
body.theater .tree-canvas-container * {
    cursor: zoom-in !important;
}

body.theater .tree-canvas-container.theater-detail,
body.theater .tree-canvas-container.theater-detail * {
    cursor: zoom-out !important;
}

.theater-exit {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background-color: rgba(60, 36, 31, 0.92);
    color: var(--text-light);
    border: 1px solid var(--color-accent-gold);
    border-radius: 20px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(39, 23, 20, 0.3);
    transition: var(--transition-smooth);
}

.theater-exit:hover {
    background-color: rgba(60, 36, 31, 1);
}

/* Tree Canvas Container */
.tree-canvas-container {
    flex: 1;
    overflow: auto;
    display: flex;
    cursor: grab;
    background: 
        radial-gradient(circle at 50% 50%, rgba(253, 250, 242, 0.3) 0%, rgba(246, 239, 226, 0.5) 100%),
        #fcf9f2;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 100 100'><path d='M0 10 C 30 15, 70 5, 100 12 T 200 10 M -50 60 C 20 50, 60 70, 110 58' fill='none' stroke='rgba(184,134,11,0.025)' stroke-width='0.8'/><path d='M10 0 C 40 40, 20 80, 50 100' fill='none' stroke='rgba(184,134,11,0.015)' stroke-width='0.6'/></svg>");
    position: relative;
    min-height: 0;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.tree-canvas-container:active {
    cursor: grabbing;
}

#tree-svg {
    display: block;
    margin: auto; /* centers the tree when it is smaller than the viewport */
    flex-shrink: 0;
    transform-origin: 0 0;
    transition: transform 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* SVG Rendering Styles */
.link-line {
    fill: none;
    stroke: #8c736e;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.link-line.highlight {
    stroke: var(--color-accent-gold);
    stroke-width: 3.5;
}

/* Spouse Ger cards */
.spouse-yurt-container {
    cursor: pointer;
}


.yurt-bg {
    transition: var(--transition-smooth);
}

/* Path glow sits on the ger image itself, so it traces ger.svg exactly */
image.yurt-bg.highlighted {
    filter: drop-shadow(0 0 3px rgba(212, 175, 55, 0.95))
            drop-shadow(0 0 2px rgba(212, 175, 55, 0.9)) !important;
}

/* Single-person card (rect): a tight rounded-rect glow when on the path */
rect.yurt-bg.highlighted {
    filter: drop-shadow(0 0 4px rgba(212, 175, 55, 0.85)) !important;
}

/* Selection ring — thick gold outline around the active node */
.select-ring {
    fill: rgba(212, 175, 55, 0.12);
    stroke: var(--color-accent-gold);
    stroke-width: 3.5;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

/* Selected node: the rounded-rect ring is its unique marker */
.spouse-yurt-container.selected .select-ring {
    opacity: 1;
}

/* Ancestor chain chips (small rounded rects) glow on the path */
.chain-chip.on-path rect {
    filter: drop-shadow(0 0 4px rgba(212, 175, 55, 0.9));
}

/* Expand/collapse badge */
.collapse-badge {
    cursor: pointer;
}

.collapse-badge circle {
    fill: #ffffff;
    stroke: var(--color-accent-gold);
    stroke-width: 1.5;
    transition: stroke-width 0.15s ease;
}

.collapse-badge text {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 700;
    fill: var(--color-accent);
    user-select: none;
    pointer-events: none;
}

/* Хүрэлцэх дэлгэц (мобайл)-д товчны текст арай том (тойрог нь JS-ээр
   томордог — coarsePointer). CSS-ийн r дарж бичих найдвартай биш тул текст л */
@media (pointer: coarse) {
    .collapse-badge text {
        font-size: 14px;
    }
}

.collapse-badge:hover circle {
    stroke-width: 2.5;
    fill: #fdf6e3;
}

.collapse-badge.badge-expanded {
    transition: opacity 0.2s ease;
}

.spouse-yurt-container:hover .yurt-bg {
    filter: drop-shadow(0 6px 15px rgba(212, 175, 55, 0.4));
}

.yurt-decoration {
    fill: none;
    stroke: #bda083;
    stroke-width: 1;
}

.member-avatar-circle {
    stroke: #d4af37;
    stroke-width: 1.5;
}

.member-name {
    font-family: 'Golos Text', 'Segoe UI', system-ui, -apple-system, sans-serif !important;
    font-size: 11px;
    font-weight: 700;
    fill: var(--color-primary);
}

.member-year {
    font-family: 'Golos Text', 'Segoe UI', system-ui, -apple-system, sans-serif !important;
    font-size: 9px;
    font-weight: 500;
    fill: var(--text-muted);
}

.union-icon-circle {
    fill: #ffffff;
    stroke: #cfb395;
    stroke-width: 1.5;
}

/* Modal styling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(39, 23, 20, 0.45);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.modal-content {
    background-color: #fff;
    width: 90%;
    max-width: 480px;
    border-radius: 16px;
    padding: 36px;
    position: relative;
    box-shadow: 0 20px 50px rgba(39, 23, 20, 0.2);
    border: 1px solid var(--border-color);
}

.close-modal {
    position: absolute;
    right: 24px;
    top: 20px;
    font-size: 26px;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.close-modal:hover {
    color: var(--color-primary);
}

.avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background-color: var(--bg-sidebar-mid);
    color: var(--color-accent);
    font-size: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-accent-gold);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.2);
}

.badge-gen {
    padding: 6px 12px;
    background-color: #f7eed7;
    color: var(--color-primary);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid var(--border-gold);
}

.profile-details {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-row .label {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.detail-row .val {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-primary);
}

.card {
    background-color: #fff;
    border-radius: 16px;
    padding: 30px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    transition: var(--transition-smooth);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 35px rgba(39, 23, 20, 0.12);
}

.view-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

#tree-view {
    /* row-reverse: unified-sidebar (эхний хүүхэд) баруун талд гарна */
    flex-direction: row-reverse !important;
}

.tree-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    position: relative;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ============================
   Person Profile Page
   ============================ */
.profile-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    min-height: 0;
}

.profile-page {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.profile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn-profile-action {
    white-space: nowrap;
}

.btn-profile-action {
    padding: 10px 18px;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    box-shadow: var(--card-shadow);
    transition: var(--transition-smooth);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-profile-action:hover {
    border-color: var(--color-accent-gold);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.12);
}

.profile-header-card {
    display: flex;
    align-items: center;
    gap: 30px;
    border-top: 4px solid var(--color-accent-gold);
}

.profile-portrait {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--color-accent-gold);
    box-shadow: 0 6px 18px rgba(212, 175, 55, 0.25);
    flex-shrink: 0;
}

.profile-head-info {
    flex: 1;
    min-width: 0;
}

.profile-head-info h1 {
    font-family: var(--font-heading);
    font-size: 30px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 10px;
}

.profile-badges {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
}

.profile-years {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.profile-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 30px;
}

.fact-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.fact-item i {
    color: var(--color-accent);
    font-size: 16px;
    width: 20px;
    text-align: center;
}

.fact-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.fact-val {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
}

.profile-grid {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 24px;
    align-items: start;
}

.profile-main, .profile-side {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0;
}

.profile-section h3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-gold);
    display: flex;
    align-items: center;
    gap: 10px;
}

.profile-section h3 i {
    color: var(--color-accent);
    font-size: 15px;
}

.profile-bio {
    font-size: 15px;
    line-height: 1.8;
    color: var(--text-dark);
    font-weight: 400;
}

.profile-empty {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

/* Life events vertical timeline */
.profile-events {
    display: flex;
    flex-direction: column;
    position: relative;
}

.profile-events::before {
    content: '';
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 76px;
    width: 2px;
    border-left: 2px dashed var(--border-gold);
}

.pe-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 0;
    position: relative;
}

.pe-year {
    width: 46px;
    flex-shrink: 0;
    text-align: right;
    font-size: 14px;
    font-weight: 700;
    color: var(--color-accent);
    padding-top: 6px;
}

.pe-icon {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: #fff;
    border: 2px solid var(--color-accent-gold);
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    z-index: 1;
}

.pe-body {
    padding-top: 4px;
    min-width: 0;
}

.pe-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-primary);
}

.pe-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 2px;
}

/* Relatives list */
.relatives-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.relative-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition-smooth);
    background-color: #fff;
}

.relative-item:hover {
    border-color: var(--color-accent-gold);
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.15);
    transform: translateX(3px);
}

.relative-item img {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-gold);
    flex-shrink: 0;
}

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

.relative-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.relative-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.relative-years {
    font-size: 11px;
    color: var(--text-muted);
}

.relative-item > i {
    color: var(--text-muted);
    font-size: 12px;
}

/* Profile photo gallery */
.profile-photos {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.profile-photo {
    margin: 0;
}

.profile-photo img {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border-gold);
    display: block;
}

.profile-photo figcaption {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 6px;
}

.photo-year {
    font-weight: 700;
    color: var(--color-accent);
}

@media (max-width: 980px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }
    .profile-header-card {
        flex-direction: column;
        text-align: center;
    }
    .profile-facts {
        justify-content: center;
    }
}

/* ============================
   Full Timeline & Gallery pages
   ============================ */
.page-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    min-height: 0;
}

.page-heading {
    margin-bottom: 28px;
}

.page-heading h2 {
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.page-heading h2 i {
    color: var(--color-accent);
    font-size: 20px;
}

.page-heading p {
    font-size: 14px;
    color: var(--text-muted);
}

.timeline-page {
    max-width: 780px;
    margin: 0 auto;
}

/* Family history card at the top of the timeline page */
.tl-history-card {
    margin-bottom: 28px;
    padding: 24px 28px;
    background: linear-gradient(120deg, rgba(212, 175, 55, 0.1), rgba(212, 175, 55, 0.03));
    border: 1px solid var(--border-gold);
    border-left: 4px solid var(--color-accent-gold);
    border-radius: 14px;
}

.tl-history-card h3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.tl-history-card h3 i {
    color: var(--color-accent);
}

.tl-history-card p {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-dark);
}

/* Картын толгой дахь "үзэх" холбоос */
.tl-card-link {
    margin-left: auto;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-accent);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.tl-card-link:hover {
    text-decoration: underline;
}

/* Санаачлагчийн гарын үсэг */
.tl-by {
    margin-top: 12px;
    text-align: right;
    font-style: italic;
    font-size: 13.5px;
    color: var(--color-navy);
}

/* Бүтээлүүд — ном/зохиолын карт */
.work-card {
    margin-bottom: 24px;
}

.work-head {
    display: flex;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
    padding: 20px 24px;
    background: linear-gradient(120deg, rgba(212, 175, 55, 0.1), rgba(212, 175, 55, 0.03));
    border: 1px solid var(--border-gold);
    border-left: 4px solid var(--color-accent-gold);
    border-radius: 14px;
}

.work-cover {
    flex-shrink: 0;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary);
    color: var(--color-accent-gold);
    border-radius: 12px;
    font-size: 24px;
}

.work-info h3 {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 3px;
}

.work-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.work-by {
    font-size: 13px;
    color: var(--color-navy);
    font-style: italic;
}

.work-by i {
    color: var(--color-accent);
    margin-right: 5px;
}

/* Оршил / Цацал үг — эвхэгддэг урт бичвэр */
.tl-doc {
    margin-bottom: 16px;
    background-color: #fff;
    border: 1px solid var(--border-gold);
    border-radius: 12px;
    overflow: hidden;
}

.tl-doc > summary {
    list-style: none;
    cursor: pointer;
    padding: 16px 22px;
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.tl-doc > summary::-webkit-details-marker {
    display: none;
}

.tl-doc > summary i {
    color: var(--color-accent);
}

/* Нээх/хаах сум */
.tl-doc > summary::after {
    content: '\f078'; /* fa chevron-down */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: auto;
    font-size: 12px;
    color: var(--color-accent);
    transition: transform 0.2s ease;
}

.tl-doc[open] > summary::after {
    transform: rotate(180deg);
}

.tl-doc[open] > summary {
    border-bottom: 1px solid var(--border-color);
}

.tl-doc-body {
    padding: 18px 22px 22px;
    max-height: 460px;
    overflow-y: auto;
}

.tl-doc-body p {
    font-size: 14px;
    line-height: 1.85;
    color: var(--text-dark);
    margin-bottom: 14px;
    text-align: justify;
}

.tl-doc-body p:last-child {
    margin-bottom: 0;
}

.tl-list {
    position: relative;
}

.tl-list::before {
    content: '';
    position: absolute;
    top: 10px;
    bottom: 10px;
    left: 82px;
    width: 2px;
    border-left: 2px dashed var(--border-gold);
}

.tl-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 12px 0;
    position: relative;
}

.tl-year {
    width: 50px;
    flex-shrink: 0;
    text-align: right;
    font-size: 15px;
    font-weight: 700;
    color: var(--color-accent);
    padding-top: 7px;
}

.tl-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: #fff;
    border: 2px solid var(--color-accent-gold);
    color: var(--color-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    z-index: 1;
}

.tl-body {
    padding-top: 2px;
    min-width: 0;
}

.tl-person {
    font-size: 12px;
    font-weight: 700;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.tl-person:hover {
    color: var(--color-primary);
    text-decoration: underline;
}

.tl-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--color-primary);
}

.tl-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 2px;
}

.tl-historic {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 20px 0 20px 60px;
    padding: 14px 20px;
    background: linear-gradient(120deg, rgba(212, 175, 55, 0.14), rgba(212, 175, 55, 0.05));
    border: 1px solid var(--border-gold);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
    position: relative;
    z-index: 1;
}

.tl-historic i {
    color: var(--color-accent);
    font-size: 18px;
}

.tl-year-h {
    font-weight: 800;
    color: var(--color-accent);
}

/* ============ Түүхэн товчоон — шинэ загвар (макетаас) ============ */
.mt-wrap { max-width: 860px; margin: 0 auto; }

/* Hero — page-scroll-ын padding-ийг нөхөж бүтэн өргөнөөр */
.mt-hero {
    text-align: center;
    padding: 44px 20px 34px;
    margin: -32px -40px 30px;
    background:
        linear-gradient(rgba(252, 249, 242, 0.86), rgba(252, 249, 242, 0.94)),
        url('logo.png') center 40px / 150px no-repeat;
}
.mt-hero-logo {
    width: 92px; height: 92px; object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(212, 175, 55, 0.5)); margin-bottom: 14px;
}
.mt-hero h1 {
    font-family: var(--font-heading); font-size: 30px; font-weight: 700;
    color: var(--color-primary); margin: 0 0 8px; line-height: 1.25;
}
.mt-hero-sub {
    font-size: 14px; color: var(--color-accent); font-weight: 600; letter-spacing: 1px;
    text-transform: uppercase; margin: 0 0 14px;
}
.mt-hero-lead {
    font-size: 15px; color: var(--text-dark); line-height: 1.7; max-width: 560px; margin: 0 auto;
}

/* Статистик */
.mt-stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin: 8px 0 34px; }
.mt-stat {
    background: #fff; border: 1px solid var(--border-gold);
    border-radius: 14px; padding: 16px 6px; text-align: center; box-shadow: var(--card-shadow);
}
.mt-stat b {
    display: block; font-family: var(--font-heading); font-size: 23px; font-weight: 700;
    color: var(--color-accent-gold); line-height: 1;
}
.mt-stat span { display: block; margin-top: 6px; font-size: 11.5px; color: var(--text-muted); }

/* Хэсгийн гарчиг */
.mt-h {
    font-family: var(--font-heading); font-size: 18px; font-weight: 700;
    color: var(--color-primary); margin: 34px 0 14px; display: flex; align-items: center; gap: 10px;
}
.mt-h i { color: var(--color-accent); }
.mt-h-link { cursor: pointer; justify-content: space-between; }
.mt-h-link > span:first-child { display: flex; align-items: center; gap: 10px; }
.mt-see-all { font-size: 13px; font-weight: 600; color: var(--color-accent); display: inline-flex; align-items: center; gap: 6px; }
.mt-h-link:hover .mt-see-all { text-decoration: underline; }

/* Түүх / санаачлагч карт */
.mt-history {
    padding: 26px 30px; border-radius: 16px;
    background: linear-gradient(120deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.03));
    border: 1px solid var(--border-gold); border-left: 4px solid var(--color-accent-gold);
}
.mt-history p { font-size: 14.5px; line-height: 1.85; color: var(--text-dark); margin: 0; }
.mt-by { margin-top: 12px; text-align: right; font-style: italic; font-size: 13.5px; color: var(--color-navy); }

/* Билэгдлийн тухай */
.mt-emblem {
    display: flex; gap: 24px; align-items: center; padding: 24px 28px; border-radius: 16px;
    background: linear-gradient(120deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.03));
    border: 1px solid var(--border-gold); border-left: 4px solid var(--color-accent-gold);
}
.mt-emblem-img {
    width: 132px; height: 132px; flex-shrink: 0; object-fit: contain;
    border-radius: 14px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.mt-emblem-body p { font-size: 14.5px; line-height: 1.8; color: var(--text-dark); margin: 0 0 10px; }
.mt-emblem-list { margin: 0 0 10px; padding-left: 20px; }
.mt-emblem-list li { font-size: 13.5px; line-height: 1.7; color: var(--text-dark); margin-bottom: 5px; }
.mt-emblem-list b, .mt-emblem-body > p b { color: var(--color-navy); }

/* Дурсамжийн зураг */
.mt-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.mt-photo {
    position: relative; border-radius: 12px; overflow: hidden; aspect-ratio: 1;
    border: 1px solid var(--border-gold); cursor: zoom-in;
}
.mt-photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.3s ease; }
.mt-photo:hover img { transform: scale(1.06); }
.mt-photo figcaption {
    position: absolute; left: 0; right: 0; bottom: 0;
    background: linear-gradient(transparent, rgba(20, 12, 10, 0.82)); color: #fff;
    font-size: 10.5px; padding: 16px 8px 7px; line-height: 1.3;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Он цагийн товчоон */
.mt-decade { background: #fff; border: 1px solid var(--border-color); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.mt-decade > summary { list-style: none; cursor: pointer; padding: 14px 18px; display: flex; align-items: center; gap: 14px; }
.mt-decade > summary::-webkit-details-marker { display: none; }
.mt-decade-year { font-family: var(--font-heading); font-size: 16px; font-weight: 700; color: var(--color-accent); min-width: 108px; white-space: nowrap; }
.mt-decade-sum { flex: 1; font-size: 13px; color: var(--text-muted); }
.mt-decade-sum b { color: var(--text-dark); font-weight: 700; }
.mt-decade-sum .hl { color: var(--color-accent-gold); }
.mt-decade > summary::after { content: '\f078'; font-family: 'Font Awesome 6 Free'; font-weight: 900; font-size: 11px; color: var(--text-muted); }
.mt-decade[open] > summary::after { content: '\f077'; }
.mt-events { padding: 8px 18px 16px; border-top: 1px dashed var(--border-gold); }
.mt-year { display: grid; grid-template-columns: 56px 1fr; gap: 10px; padding: 8px 0; }
.mt-year + .mt-year { border-top: 1px solid var(--border-color); }
.mt-year-label { font-family: var(--font-heading); font-size: 15px; font-weight: 700; color: var(--color-accent); padding-top: 6px; }
.mt-year-body { display: flex; flex-direction: column; gap: 2px; }
.mt-hist { display: flex; align-items: center; gap: 9px; padding: 7px 9px; margin-bottom: 3px; background: rgba(29, 45, 68, 0.06); border-left: 3px solid var(--color-navy); border-radius: 6px; font-size: 12.5px; color: var(--color-navy); font-weight: 600; }
.mt-hist i { color: var(--color-navy); font-size: 12px; }
.mt-hist.world { background: rgba(76, 154, 143, 0.1); border-left-color: #4c9a8f; color: #2f6b62; }
.mt-hist.world i { color: #4c9a8f; }
.mt-ev { display: flex; align-items: center; gap: 10px; padding: 5px 8px; font-size: 13px; border-radius: 6px; }
.mt-ev > i { width: 15px; text-align: center; font-size: 11px; color: var(--border-gold); }
.mt-ev-name { color: var(--color-primary); font-weight: 600; white-space: nowrap; cursor: pointer; }
.mt-ev-name:hover { color: var(--color-accent); text-decoration: underline; }
.mt-ev-what { color: var(--text-muted); font-size: 12px; }
.mt-ev.death > i { color: #a05a4e; }
.mt-ev.death .mt-ev-what { color: #a05a4e; }
.mt-ev.note { background: rgba(212, 175, 55, 0.09); }
.mt-ev.note > i { color: var(--color-accent-gold); }
.mt-ev.note .mt-ev-what { color: var(--text-dark); font-size: 12.5px; white-space: normal; }
.mt-ev.marriage > i { color: #c26b8a; }
.mt-ev.education > i { color: #4c9a8f; }
.mt-ev.work > i { color: #6d84b0; }

@media (max-width: 768px) {
    .mt-hero { margin: -16px -16px 24px; padding: 32px 16px 26px; }
    .mt-hero h1 { font-size: 24px; }
}
@media (max-width: 560px) {
    .mt-stats { gap: 6px; }
    .mt-stat { padding: 11px 3px; }
    .mt-stat b { font-size: 17px; }
    .mt-stat span { margin-top: 4px; font-size: 9.5px; }
    .mt-emblem { flex-direction: column; text-align: center; padding: 20px 18px; }
    .mt-emblem-list { text-align: left; }
}

/* ============ Бүтээлүүд хуудас ============ */
.works-page { max-width: 1000px; margin: 0 auto; }
.works-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.works-intro { font-size: 14px; color: var(--text-muted); }
.works-add {
    flex-shrink: 0; display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 16px; border: none; border-radius: 10px; cursor: pointer;
    background: var(--color-accent-gold); color: #3c241f; font-weight: 700; font-size: 14px;
    box-shadow: var(--card-shadow);
}
.works-add:hover { background: var(--color-accent); color: #fff; }

.works-group { margin-bottom: 34px; }
.works-group-h {
    display: flex; align-items: center; gap: 10px;
    font-family: var(--font-heading); font-size: 17px; font-weight: 700; color: var(--color-primary);
    margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border-gold);
}
.works-group-h i { color: var(--color-accent); font-size: 15px; }
.works-group-n {
    margin-left: auto; font-size: 12px; font-weight: 600; color: var(--text-muted);
    background: rgba(212, 175, 55, 0.12); padding: 2px 10px; border-radius: 20px;
}
.works-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.work-card2 {
    position: relative; background: #fff; border: 1px solid var(--border-color);
    border-radius: 14px; overflow: hidden; box-shadow: var(--card-shadow);
    cursor: pointer; transition: transform 0.18s ease, box-shadow 0.18s ease;
    display: flex; flex-direction: column;
}
.work-card2:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12); }
.work-cover-img { height: 160px; background-size: contain; background-repeat: no-repeat; background-position: center; background-color: rgba(212, 175, 55, 0.06); }
.work-cover-icon {
    height: 150px; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.16), rgba(212, 175, 55, 0.04));
    color: var(--color-accent-gold); font-size: 46px;
}
.work-card2-body { padding: 14px 16px 18px; }
.work-type {
    display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
    color: var(--color-accent); text-transform: uppercase; letter-spacing: 0.4px;
}
.work-card2-body h3 { font-family: var(--font-heading); font-size: 16px; font-weight: 700; color: var(--color-primary); margin: 6px 0 2px; }
.work-author { font-size: 12.5px; color: var(--color-navy); margin-bottom: 4px; }
.work-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.work-admin { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.work-admin button {
    width: 30px; height: 30px; border: none; border-radius: 8px; cursor: pointer;
    background: rgba(255, 255, 255, 0.92); color: var(--color-primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18); font-size: 12px;
}
.work-admin .work-del:hover { background: #a05a4e; color: #fff; }
.work-admin .work-edit:hover { background: var(--color-accent); color: #fff; }

.works-empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.works-empty i { font-size: 40px; color: var(--border-gold); margin-bottom: 14px; display: block; }
.works-empty code { background: rgba(0, 0, 0, 0.06); padding: 2px 6px; border-radius: 5px; font-size: 12px; }

/* Бүтээлийн модал (дэлгэрэнгүй ба засварлагч) */
.works-modal {
    position: fixed; inset: 0; z-index: 600; background: rgba(20, 12, 10, 0.6);
    display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.works-modal-box {
    position: relative; background: var(--bg-main, #fcf9f2); border-radius: 16px;
    max-width: 640px; width: 100%; padding: 30px 32px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}
.works-modal-x {
    position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border: none;
    border-radius: 50%; cursor: pointer; background: rgba(0, 0, 0, 0.06); color: var(--color-primary); font-size: 15px;
}
.works-modal-x:hover { background: rgba(0, 0, 0, 0.12); }

.work-detail h2 { font-family: var(--font-heading); font-size: 22px; color: var(--color-primary); margin: 8px 0 4px; }
.work-detail-author { font-size: 13px; color: var(--color-navy); font-style: italic; margin-bottom: 14px; }
.work-detail-cover { display: block; max-width: 100%; max-height: 420px; object-fit: contain; border-radius: 12px; margin: 0 auto 16px; }
.work-detail-desc { font-size: 14px; line-height: 1.7; color: var(--text-dark); margin-bottom: 16px; }
.work-detail-text p { font-size: 14px; line-height: 1.85; color: var(--text-dark); margin-bottom: 12px; text-align: justify; }
.work-detail-link {
    display: inline-flex; align-items: center; gap: 8px; margin-top: 12px;
    padding: 9px 16px; border-radius: 10px; background: var(--color-accent-gold); color: #3c241f;
    font-weight: 700; font-size: 13px; text-decoration: none;
}

/* Бүтээлийн форм */
.work-form h2 { font-family: var(--font-heading); font-size: 20px; color: var(--color-primary); margin: 0 0 16px; }
.work-form label { display: block; font-size: 13px; font-weight: 600; color: var(--color-primary); margin-bottom: 12px; }
.work-form input, .work-form select, .work-form textarea {
    display: block; width: 100%; margin-top: 5px; padding: 9px 11px; font-size: 14px; font-family: inherit;
    border: 1px solid var(--border-color); border-radius: 9px; background: #fff; color: var(--text-dark);
}
.work-form textarea { resize: vertical; line-height: 1.6; }
.wf-row { display: flex; gap: 14px; }
.wf-row label { flex: 1; }
.wf-cover-preview { margin-bottom: 12px; }
.wf-cover-preview img { max-height: 120px; border-radius: 10px; display: block; margin-bottom: 6px; }
.wf-cover-clear { border: none; background: none; color: #a05a4e; cursor: pointer; font-size: 12.5px; text-decoration: underline; padding: 0; }
.wf-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.wf-cancel { padding: 9px 18px; border: 1px solid var(--border-color); border-radius: 9px; background: #fff; cursor: pointer; font-weight: 600; }
.wf-save { padding: 9px 22px; border: none; border-radius: 9px; background: var(--color-accent-gold); color: #3c241f; font-weight: 700; cursor: pointer; }
.wf-save:hover { background: var(--color-accent); color: #fff; }
.wf-save:disabled { opacity: 0.6; cursor: default; }
.wf-msg { margin-top: 10px; font-size: 13px; color: var(--color-accent); text-align: right; }

/* Бүтээлийн бүлгүүдийн засвар */
.wf-chapters-wrap { margin-bottom: 12px; }
.wf-chapters-label { font-size: 13px; font-weight: 600; color: var(--color-primary); margin-bottom: 8px; }
.wf-chapters-label span { font-weight: 400; font-size: 11.5px; color: var(--text-muted); }
.wf-chapter { border: 1px solid var(--border-color); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: rgba(212, 175, 55, 0.04); }
.wf-chapter-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.wf-ch-title { flex: 1; margin-top: 0 !important; }
.wf-chapter-btns { display: flex; gap: 4px; flex-shrink: 0; }
.wf-chapter-btns button { width: 30px; height: 30px; border: 1px solid var(--border-color); border-radius: 7px; background: #fff; cursor: pointer; color: var(--color-primary); font-size: 11px; }
.wf-chapter-btns button:disabled { opacity: 0.35; cursor: default; }
.wf-chapter-btns button:hover:not(:disabled) { border-color: var(--color-accent); color: var(--color-accent); }
.wf-chapter-btns .wf-ch-del:hover:not(:disabled) { background: #a05a4e; color: #fff; border-color: #a05a4e; }
.wf-ch-body { margin-top: 0 !important; }
.wf-add-chapter { display: inline-flex; align-items: center; gap: 7px; padding: 7px 14px; border: 1px dashed var(--border-gold); border-radius: 9px; background: none; color: var(--color-accent); font-weight: 600; font-size: 13px; cursor: pointer; }
.wf-add-chapter:hover { background: rgba(212, 175, 55, 0.08); }

.gallery-page {
    max-width: 1100px;
    margin: 0 auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 22px;
}

.gallery-card {
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    transition: var(--transition-smooth);
}

.gallery-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
}

.gallery-card > img {
    width: 100%;
    display: block;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

.g-caption {
    padding: 12px 14px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    border-top: 1px solid var(--border-color);
}

.g-person {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    transition: var(--transition-smooth);
}

.g-person:hover {
    color: var(--color-accent);
    background-color: rgba(212, 175, 55, 0.06);
}

.g-person img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-gold);
}

.g-person span {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.g-person i {
    font-size: 11px;
    color: var(--text-muted);
}

/* Зургийг бүтэн хэмжээгээр томруулж үзэх (lightbox) */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(20, 12, 10, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: zoom-out;
}

.lightbox-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin: 0;
    max-width: 94vw;
}

.lightbox-img {
    max-width: 94vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

.lightbox-caption {
    color: #f2e9dc;
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
    max-width: 720px;
}

.lightbox-caption strong {
    color: var(--color-accent-gold);
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.24);
}

/* Toolbar states */
.canvas-toolbar button.active {
    background-color: #835c36;
    color: #fff;
    border-color: var(--color-accent-gold);
}

#btn-toggle-sidebar {
    display: none;
}

.load-error {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 16px 24px 0;
    padding: 14px 18px;
    background-color: #fbeeec;
    border: 1px solid rgba(176, 92, 80, 0.5);
    border-radius: 10px;
    font-size: 13px;
    color: #7c3f36;
    line-height: 1.6;
}

.load-error i {
    color: #b05c50;
    font-size: 18px;
    margin-top: 2px;
}

.load-error code {
    background-color: rgba(176, 92, 80, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
}

/* ============================
   Login screen
   ============================ */
.login-screen {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 50% 30%, rgba(212, 175, 55, 0.08), transparent 60%),
        var(--bg-main);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background-color: #fff;
    border: 1px solid var(--border-gold);
    border-top: 4px solid var(--color-accent-gold);
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(39, 23, 20, 0.15);
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin: 0 auto;
    filter: drop-shadow(0 3px 8px rgba(212, 175, 55, 0.45));
}

.login-card h2 {
    font-family: var(--font-heading);
    color: var(--color-primary);
    font-size: 24px;
}

.login-card p {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.6;
}

.login-card input {
    padding: 13px 16px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-family: var(--font-body);
    font-size: 14px;
    outline: none;
    text-align: center;
}

.login-card input:focus {
    border-color: var(--color-accent-gold);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

.login-card button {
    padding: 13px;
    background: linear-gradient(135deg, var(--color-accent-gold), var(--color-accent));
    color: #fff;
    border: none;
    border-radius: 10px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.login-card button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(212, 175, 55, 0.35);
}

.login-card button:disabled {
    opacity: 0.6;
    cursor: wait;
}

.login-fb {
    background: #1877f2 !important;
    margin-bottom: 4px;
}

.login-fb:hover {
    box-shadow: 0 8px 20px rgba(24, 119, 242, 0.35) !important;
}

.login-or {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    margin: 14px 0 10px;
}

.login-or::before,
.login-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.login-or span {
    padding: 0 12px;
}

#login-msg {
    font-size: 14px;
    color: #4a7c59;
    min-height: 18px;
    font-weight: 600;
    line-height: 1.5;
}

#login-msg.error {
    color: #b05c50;
}

/* ============================
   Member editor
   ============================ */
.editor-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(39, 23, 20, 0.5);
    backdrop-filter: blur(5px);
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.editor-card {
    background-color: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 760px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 60px rgba(39, 23, 20, 0.3);
    overflow: hidden;
}

.editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 26px;
    border-bottom: 1px solid var(--border-color);
}

.editor-head h2 {
    font-family: var(--font-heading);
    font-size: 19px;
    color: var(--color-primary);
}

.ed-close {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-muted);
    cursor: pointer;
}

.editor-note {
    margin: 14px 26px 0;
    padding: 10px 14px;
    background-color: rgba(212, 175, 55, 0.1);
    border: 1px solid var(--border-gold);
    border-radius: 8px;
    font-size: 12px;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.editor-note i {
    color: var(--color-accent);
}

.editor-body {
    padding: 10px 26px 20px;
    overflow-y: auto;
    flex: 1;
}

.editor-body h4 {
    font-family: var(--font-heading);
    font-size: 14px;
    color: var(--color-primary);
    margin: 20px 0 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--border-gold);
}

.ed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px 16px;
}

.ed-grid label,
.editor-body > label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.ed-grid input,
.ed-grid select,
.editor-body textarea,
.ed-event-row input,
.ed-event-row select,
.ed-photo-row input {
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    color: var(--text-dark);
    outline: none;
    background-color: #fff;
}

.ed-grid input:focus,
.ed-grid select:focus,
.editor-body textarea:focus,
.ed-event-row input:focus,
.ed-photo-row input:focus {
    border-color: var(--color-accent-gold);
}

.editor-body textarea {
    width: 100%;
    resize: vertical;
    line-height: 1.6;
}

.ed-check {
    flex-direction: row !important;
    align-items: center;
    gap: 8px !important;
    padding-top: 18px;
}

.ed-event-row {
    display: grid;
    grid-template-columns: 70px 110px 1fr 1.4fr 36px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.ed-photo-row {
    display: grid;
    grid-template-columns: 56px 1fr 80px 36px;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.ed-photo-row img {
    width: 56px;
    height: 42px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border-gold);
}

.ed-remove {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    height: 34px;
    color: #b05c50;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.ed-remove:hover {
    background-color: #fbeeec;
    border-color: #b05c50;
}

.ed-add {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    background-color: #fff;
    border: 1px dashed var(--color-accent-gold);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-accent);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.ed-add:hover {
    background-color: rgba(212, 175, 55, 0.08);
}

.editor-msg {
    margin-top: 14px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-accent);
    min-height: 18px;
}

.editor-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 26px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-main);
}

.ed-btn {
    padding: 11px 20px;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background-color: #fff;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dark);
    cursor: pointer;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.ed-btn:hover {
    border-color: var(--color-accent-gold);
}

.ed-btn-primary {
    background: linear-gradient(135deg, var(--color-accent-gold), var(--color-accent));
    color: #fff;
    border: none;
}

.ed-btn-primary:hover {
    box-shadow: 0 6px 16px rgba(212, 175, 55, 0.35);
}

.ed-btn-danger {
    color: #b05c50;
    border-color: rgba(176, 92, 80, 0.4);
}

.ed-btn-danger:hover {
    background-color: #fbeeec;
    border-color: #b05c50;
}

.btn-action-edit {
    border-color: var(--border-gold);
    color: var(--color-accent);
}

/* ============================
   Members page
   ============================ */
.members-page {
    max-width: 900px;
    margin: 0 auto;
}

.members-toolbar {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 20px;
}

.members-toolbar .search-box {
    flex: 1;
}

.members-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.member-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.member-row:hover {
    border-color: var(--color-accent-gold);
    box-shadow: 0 4px 14px rgba(212, 175, 55, 0.14);
    transform: translateX(3px);
}

.member-row > img {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-gold);
    flex-shrink: 0;
}

.mr-main {
    flex: 1;
    min-width: 0;
}

.mr-name {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--color-primary);
}

/* Only the name may truncate — the badge sits outside the ellipsis zone */
.mr-name-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mr-tag {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    color: var(--color-accent);
    background-color: rgba(212, 175, 55, 0.12);
    border: 1px solid var(--border-gold);
    border-radius: 10px;
    padding: 1px 8px;
}

.mr-sub {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mr-gen {
    font-size: 12px;
    font-weight: 700;
    color: var(--color-accent);
    width: 60px;
    text-align: right;
    flex-shrink: 0;
}

.mr-years {
    font-size: 12px;
    color: var(--text-muted);
    width: 90px;
    text-align: right;
    flex-shrink: 0;
}

.mr-edit {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition-smooth);
    flex-shrink: 0;
}

.mr-edit:hover {
    color: var(--color-accent);
    border-color: var(--color-accent-gold);
}

/* ============================
   Map page
   ============================ */
.map-page {
    max-width: 1000px;
    margin: 0 auto;
}

.map-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.btn-map-mode {
    padding: 10px 18px;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.btn-map-mode.active {
    background-color: #835c36;
    color: #fff;
    border-color: var(--color-accent-gold);
}

#leaflet-map {
    height: 520px;
    border-radius: 14px;
    border: 1px solid var(--border-gold);
    box-shadow: var(--card-shadow);
    z-index: 1;
}

.map-popup {
    font-family: var(--font-body);
    min-width: 180px;
}

.map-popup-place {
    font-weight: 700;
    color: var(--color-primary);
    font-size: 14px;
}

.map-popup-count {
    font-size: 11px;
    color: var(--color-accent);
    font-weight: 700;
    margin-bottom: 8px;
}

.map-member-link {
    padding: 4px 0;
    font-size: 13px;
    color: var(--text-dark);
    cursor: pointer;
    border-bottom: 1px dashed var(--border-color);
}

.map-member-link:hover {
    color: var(--color-accent);
}

/* Themed map markers */
.map-pin {
    background: none;
    border: none;
    text-align: center;
}

.map-pin i {
    font-size: 34px;
    color: var(--color-accent);
    text-shadow: 0 2px 4px rgba(39, 23, 20, 0.35);
}

.map-pin span {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    font-family: var(--font-body);
}

/* ============================
   Settings & submissions
   ============================ */
.settings-page {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.submission-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 10px;
    background-color: #fff;
}

.submission-row.sub-done {
    opacity: 0.6;
}

.sub-main {
    flex: 1;
    min-width: 0;
}

.sub-head {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 6px;
}

.sub-sender {
    font-size: 12px;
    font-weight: 700;
    color: var(--color-primary);
}

.sub-member {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-accent);
    cursor: pointer;
}

.sub-member:hover {
    text-decoration: underline;
}

.sub-date {
    font-size: 11px;
    color: var(--text-muted);
}

.sub-message {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-dark);
}

.sub-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.sub-actions .ed-btn {
    padding: 8px 12px;
}

.sub-badge {
    font-size: 11px;
    font-weight: 700;
    color: #4a7c59;
    background-color: rgba(74, 124, 89, 0.1);
    border: 1px solid rgba(74, 124, 89, 0.3);
    border-radius: 10px;
    padding: 4px 10px;
    align-self: center;
}

/* ============================
   Mobile layout (≤ 900px)
   ============================ */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column-reverse;
        height: 100vh;
        height: 100dvh;
    }

    /* Left nav becomes a bottom bar */
    .nav-sidebar {
        width: 100%;
        height: 62px;
        flex-direction: row;
        justify-content: center;
        padding: 0 4px;
        border-right: none;
        border-top: 1px solid rgba(0, 0, 0, 0.4);
        box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.5), 0 -5px 20px rgba(0, 0, 0, 0.3);
        flex-shrink: 0;
    }

    .nav-sidebar .logo-area {
        display: none !important;
    }

    .nav-menu {
        flex-direction: row;
        gap: 0;
        width: auto;
        flex: 1;
        justify-content: space-around;
    }

    .nav-item {
        height: 62px;
        flex: 1;
        font-size: 10px;
        gap: 4px;
        border-left: none;
        border-top: 3px solid transparent;
    }

    /* Finger-sized touch targets for the lineage chips */
    .lineage-chain {
        gap: 9px;
    }

    .lineage-chip {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 14px;
    }

    /* Finger-sized rows in the next-generation list */
    .lineage-next-btn {
        padding: 14px 16px;
        font-size: 14px;
    }

    .lineage-next-item {
        padding: 15px 16px;
    }

    .ln-name {
        font-size: 14px;
    }

    .chip-x {
        width: 28px;
        height: 28px;
        margin: -6px -8px -6px -2px; /* big hit area without inflating the chip */
        font-size: 13px;
    }

    .nav-item i {
        font-size: 18px;
    }

    .nav-item.active {
        border-left: none;
        border-top-color: var(--color-accent-gold);
    }

    /* Topbar compact */
    .topbar {
        height: 54px;
        padding: 0 14px;
    }

    .topbar-logo {
        width: 30px;
        height: 30px;
    }

    .topbar-left {
        gap: 10px;
    }

    .breadcrumbs h2 {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 60vw;
    }

    .breadcrumbs .sub-title {
        display: none;
    }

    .user-profile .avatar {
        width: 30px;
        height: 30px;
    }

    /* Tree sidebar becomes a slide-in drawer; the 52px strip stays
       visible as an orientation cue and a tap-to-close target */
    .unified-sidebar {
        position: fixed;
        top: 0;
        bottom: 62px;
        right: 0;
        left: auto;
        width: calc(100% - 52px);
        transform: translateX(105%);
        transition: transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
        z-index: 300;
        box-shadow: none;
    }

    .unified-sidebar.open {
        transform: translateX(0);
        box-shadow: -25px 0 60px rgba(39, 23, 20, 0.35);
    }

    .unified-sidebar .sidebar-header {
        padding-right: 62px;
    }

    .sidebar-close {
        display: flex;
    }

    .sidebar-backdrop.show {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 62px;
        background-color: rgba(39, 23, 20, 0.4);
        z-index: 290;
    }

    #btn-toggle-sidebar {
        display: flex;
        order: 1; /* toolbar-ийн баруун зах — drawer баруунаас гарахтай нийцүүлэв */
    }

    .canvas-toolbar {
        top: 12px;
        right: 12px;
        left: 12px;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
    }

    /* Page paddings */
    .profile-scroll,
    .page-scroll {
        padding: 16px;
    }

    .profile-head-info h1 {
        font-size: 22px;
    }

    .profile-badges {
        justify-content: center;
        flex-wrap: wrap;
    }

    .tl-list::before {
        left: 60px;
    }

    .tl-year {
        width: 34px;
        font-size: 12px;
    }

    .tl-historic {
        margin-left: 0;
    }

    .ed-event-row {
        grid-template-columns: 60px 1fr 36px;
        grid-auto-flow: row dense;
    }

    .ed-event-row .ed-ev-title,
    .ed-event-row .ed-ev-desc {
        grid-column: 1 / -1;
    }

    /* Зургийн мөр — жижиг дэлгэцэнд багтаана (1fr caption агшина) */
    .ed-photo-row {
        grid-template-columns: 50px 1fr 64px 34px;
        gap: 6px;
    }

    .ed-photo-row input {
        min-width: 0;
    }

    .ed-photo-row img {
        width: 50px;
    }

    .mr-years,
    .mr-gen {
        display: none;
    }

    .members-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    #leaflet-map {
        height: 380px;
    }

    .submission-row {
        flex-direction: column;
    }

    /* Засварлагчийн footer — жижиг дэлгэцэнд товчнууд багтаана */
    .editor-foot {
        padding: 12px 14px;
        gap: 8px;
    }

    .ed-btn {
        padding: 10px 12px;
        font-size: 12.5px;
        gap: 6px;
        white-space: nowrap;
    }
}

/* Small touch screens zoom with a pinch — the +/- pair would only
   crowd the single toolbar row. A narrow desktop window (fine pointer)
   keeps the buttons, since a mouse has no pinch. */
@media (max-width: 900px) and (pointer: coarse) {
    #zoom-in,
    #zoom-out {
        display: none;
    }
}
