:root {
    --bg: #FAF6EE;
    --surface: #FFFFFF;
    --surface-warm: #F4ECDD;
    --ink: #221B17;
    --ink-muted: #5E5248;
    --crimson: #8C1D18;
    --crimson-dark: #68120E;
    --gold: #B6862C;
    --gold-soft: #EFE3C4;
    --border: #E5D9C3;
    --radius: 12px;
    --shadow: 0 6px 24px rgba(45, 28, 12, 0.07);
    --font-sans: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
    --font-serif: 'Noto Serif', Georgia, serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.6;
    font-size: 15px;
}
a { color: var(--crimson); text-decoration: none; }
a:hover { text-decoration: underline; }

.pv-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 18px;
}

/* Header */
.pv-header {
    background: var(--surface);
    border-bottom: 2px solid var(--gold-soft);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 10px rgba(45, 28, 12, 0.04);
}
.pv-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    gap: 16px;
}
.pv-brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    text-decoration: none !important;
    color: var(--ink);
}
.pv-seal {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--crimson);
    color: #FDF5E6;
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 700;
    display: grid;
    place-items: center;
    border: 2px solid var(--gold);
    box-shadow: 0 2px 6px rgba(140, 29, 24, 0.25);
    flex-shrink: 0;
}
.pv-brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.pv-brand-text strong {
    font-family: var(--font-serif);
    font-size: 19px;
    color: var(--crimson);
    letter-spacing: 0.2px;
}
.pv-brand-text small { font-size: 11.5px; color: var(--ink-muted); }

.pv-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pv-nav a {
    padding: 8px 13px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    color: var(--ink);
    text-decoration: none;
    transition: background .15s, color .15s;
}
.pv-nav a:hover, .pv-nav a.active {
    background: var(--surface-warm);
    color: var(--crimson);
}
.pv-nav a.pv-nav-btn {
    background: var(--crimson);
    color: #FFF;
    margin-left: 6px;
}
.pv-nav a.pv-nav-btn:hover { background: var(--crimson-dark); color: #FFF; }
.pv-menu-toggle {
    display: none;
    background: var(--surface-warm);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 18px;
    cursor: pointer;
    color: var(--crimson);
}

/* Hero & 4-Tab Search */
.pv-hero {
    background:
        radial-gradient(circle at 12% 20%, rgba(182, 134, 44, 0.14), transparent 45%),
        radial-gradient(circle at 88% 15%, rgba(140, 29, 24, 0.12), transparent 45%),
        linear-gradient(180deg, #F5ECD9 0%, #FAF6EE 100%);
    border-bottom: 1px solid var(--border);
    padding: 40px 0 44px;
}
.pv-hero-head { text-align: center; max-width: 780px; margin: 0 auto 24px; }
.pv-kicker {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--gold);
    color: var(--crimson);
    font-size: 12.5px;
    font-weight: 600;
    margin-bottom: 12px;
}
.pv-hero h1 {
    font-family: var(--font-serif);
    font-size: clamp(26px, 4vw, 38px);
    line-height: 1.25;
    margin: 0 0 10px;
    color: var(--crimson-dark);
}
.pv-hero-sub {
    margin: 0;
    color: var(--ink-muted);
    font-size: 15.5px;
}

.pv-search-box {
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: hidden;
    max-width: 980px;
    margin: 0 auto;
}
.pv-search-tabs {
    display: flex;
    background: var(--surface-warm);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.pv-search-tab {
    flex: 1 0 auto;
    padding: 13px 16px;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all .15s;
    white-space: nowrap;
}
.pv-search-tab:hover { color: var(--crimson); background: rgba(255,255,255,0.5); }
.pv-search-tab.active {
    background: var(--surface);
    color: var(--crimson);
    border-bottom-color: var(--crimson);
}
.pv-search-panel { padding: 20px; }
.pv-search-panel[hidden] { display: none; }

.pv-search-row {
    display: grid;
    grid-template-columns: 1fr 180px 180px auto;
    gap: 10px;
    align-items: stretch;
}
.pv-search-row-3 { grid-template-columns: 1fr 220px auto; }
.pv-search-row-4 { grid-template-columns: 180px 140px 140px 1fr auto; }

.pv-input, .pv-select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-family: var(--font-sans);
    font-size: 14.5px;
    background: #FFF;
    color: var(--ink);
    outline: none;
    transition: border-color .15s;
}
.pv-input:focus, .pv-select:focus { border-color: var(--crimson); }

.pv-search-hints {
    margin-top: 12px;
    font-size: 13px;
    color: var(--ink-muted);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.pv-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 11px;
    border-radius: 999px;
    background: var(--surface-warm);
    border: 1px solid var(--border);
    color: var(--ink);
    font-size: 12.5px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}
.pv-chip:hover {
    border-color: var(--crimson);
    color: var(--crimson);
    text-decoration: none;
}

/* Buttons */
.pv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 10px;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    border: 1.5px solid transparent;
    cursor: pointer;
    text-decoration: none !important;
    transition: all .15s;
    white-space: nowrap;
}
.pv-btn-primary { background: var(--crimson); color: #FFF; }
.pv-btn-primary:hover { background: var(--crimson-dark); color: #FFF; }
.pv-btn-gold { background: var(--gold); color: #FFF; }
.pv-btn-gold:hover { background: #9B7020; color: #FFF; }
.pv-btn-outline { background: #FFF; color: var(--crimson); border-color: var(--crimson); }
.pv-btn-outline:hover { background: var(--surface-warm); }
.pv-btn-ghost { background: var(--surface-warm); color: var(--ink); border-color: var(--border); }
.pv-btn-ghost:hover { border-color: var(--crimson); color: var(--crimson); }
.pv-btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

/* Stats Bar */
.pv-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-top: 24px;
}
.pv-stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}
.pv-stat-num {
    font-family: var(--font-serif);
    font-size: 26px;
    font-weight: 700;
    color: var(--crimson);
    line-height: 1.15;
}
.pv-stat-label { font-size: 13px; color: var(--ink-muted); margin-top: 4px; }

/* Sections */
.pv-section { padding: 40px 0; }
.pv-section-alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.pv-section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.pv-section-head h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    margin: 0;
    color: var(--crimson-dark);
}
.pv-section-head p { margin: 4px 0 0; color: var(--ink-muted); font-size: 14.5px; }

/* Lineage Cards */
.pv-card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}
.pv-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.pv-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--gold);
}
.pv-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pv-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--surface-warm);
    color: var(--crimson);
    border: 1px solid var(--border);
}
.pv-badge-gold { background: #FDF4DC; color: #8A5E0A; border-color: #E5C982; }
.pv-badge-warn { background: #FDECEC; color: #991B1B; border-color: #F5C2C2; }
.pv-badge-verified { background: #E6F6EC; color: #166534; border-color: #86EFAC; }
.pv-related-box {
    margin-top: 20px;
    background: var(--surface);
    border: 1.5px solid var(--gold-soft);
    border-radius: var(--radius);
    padding: 20px;
}
.pv-related-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 13px 0;
    border-bottom: 1px dashed var(--border);
    flex-wrap: wrap;
}
.pv-related-item:last-child { border-bottom: none; padding-bottom: 0; }

.pv-card-title {
    font-family: var(--font-serif);
    font-size: 16.5px;
    font-weight: 700;
    line-height: 1.35;
    margin: 0;
}
.pv-card-title a { color: var(--ink); }
.pv-card-title a:hover { color: var(--crimson); text-decoration: none; }
.pv-card-meta {
    font-size: 13px;
    color: var(--ink-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.pv-card-desc {
    font-size: 13.5px;
    color: var(--ink-muted);
    margin: 0;
    flex: 1;
}
.pv-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}

/* Province pills */
.pv-province-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.pv-province-pill {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none !important;
}
.pv-province-pill span {
    background: var(--surface-warm);
    color: var(--crimson);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
}
.pv-province-pill:hover { border-color: var(--crimson); background: #FFFDF8; }

/* Services Grid */
.pv-service-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}
.pv-service-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.pv-service-icon { font-size: 28px; line-height: 1; }
.pv-service-card h3 {
    font-family: var(--font-serif);
    font-size: 16.5px;
    margin: 0;
    color: var(--crimson-dark);
}
.pv-service-card p { font-size: 13.5px; color: var(--ink-muted); margin: 0; flex: 1; }

/* Lineage Detail Page */
.pv-breadcrumb {
    font-size: 13px;
    color: var(--ink-muted);
    margin: 0 0 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.pv-lineage-hero {
    background: linear-gradient(180deg, #F4EBDA 0%, #FAF6EE 100%);
    border-bottom: 1px solid var(--border);
    padding: 26px 0 22px;
}
.pv-lineage-hero h1 {
    font-family: var(--font-serif);
    font-size: clamp(22px, 3vw, 30px);
    color: var(--crimson-dark);
    margin: 0 0 10px;
}
.pv-lineage-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    font-size: 14px;
    color: var(--ink-muted);
    margin-bottom: 16px;
}
.pv-tabs-bar {
    display: flex;
    gap: 6px;
    border-bottom: 2px solid var(--border);
    margin: 22px 0 20px;
    overflow-x: auto;
}
.pv-tab-btn {
    padding: 11px 18px;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: 14.5px;
    font-weight: 600;
    color: var(--ink-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
}
.pv-tab-btn.active {
    color: var(--crimson);
    border-bottom-color: var(--crimson);
    background: var(--surface);
    border-radius: 8px 8px 0 0;
}
.pv-tab-pane[hidden] { display: none; }

/* Tree Viewer */
.pv-tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    padding: 12px 14px;
}
.pv-tree-stage-wrap {
    position: relative;
    background: #FFFDF9;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 12px 12px;
    height: 620px;
    overflow: hidden;
}
.pv-tree-canvas {
    width: 100%;
    height: 100%;
    cursor: grab;
    user-select: none;
}
.pv-tree-canvas:active { cursor: grabbing; }
.pv-node-drawer {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 340px;
    max-width: calc(100% - 24px);
    max-height: calc(100% - 24px);
    overflow-y: auto;
    background: var(--surface);
    border: 1.5px solid var(--gold);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(34, 27, 23, 0.18);
    padding: 16px;
    z-index: 20;
}
.pv-node-drawer[hidden] { display: none; }

/* Narrative / Phả ký */
.pv-gen-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}
.pv-gen-head {
    background: var(--surface-warm);
    padding: 10px 16px;
    font-family: var(--font-serif);
    font-weight: 700;
    color: var(--crimson-dark);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}
.pv-person-item {
    padding: 14px 16px;
    border-bottom: 1px solid #F1E8D8;
}
.pv-person-item:last-child { border-bottom: none; }
.pv-person-item:target { background: #FFF8E1; }
.pv-person-name {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
}
.pv-person-bio {
    margin-top: 6px;
    font-size: 14px;
    color: #3A312A;
    white-space: pre-line;
}

/* Search Result Item */
.pv-result-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 12px;
}
.pv-path-crumb {
    font-size: 12.5px;
    color: var(--ink-muted);
    background: var(--bg);
    padding: 6px 10px;
    border-radius: 8px;
    margin: 8px 0;
}

/* Bai Vi & Cau Doi Preview */
.pv-culture-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.pv-baivi-preview {
    background: linear-gradient(180deg, #5A110E 0%, #3E0A08 100%);
    color: #F6D57A;
    border: 4px double #D8AE48;
    border-radius: 16px 16px 6px 6px;
    padding: 26px 22px;
    text-align: center;
    max-width: 300px;
    margin: 0 auto;
    box-shadow: 0 10px 26px rgba(62, 10, 8, 0.25);
    font-family: var(--font-serif);
}
.pv-baivi-top { font-size: 13px; letter-spacing: 2px; opacity: .88; margin-bottom: 10px; }
.pv-baivi-main { font-size: 22px; font-weight: 700; line-height: 1.45; margin: 12px 0; color: #FFE394; }
.pv-baivi-sub { font-size: 13.5px; line-height: 1.6; color: #F5E6C4; }

.pv-caudoi-box {
    background: #4E0D0A;
    color: #F8D97C;
    border: 3px double #D8AE48;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    font-family: var(--font-serif);
}
.pv-hoanhphi {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 3px;
    border-bottom: 1px solid rgba(216,174,72,0.4);
    padding-bottom: 10px;
    margin-bottom: 14px;
}
.pv-caudoi-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    font-size: 15px;
    line-height: 1.6;
}

/* Pagination */
.pv-pagination {
    display: flex;
    gap: 6px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 24px;
}
.pv-page-link {
    padding: 8px 13px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--ink);
    font-weight: 600;
    font-size: 13.5px;
}
.pv-page-link.active {
    background: var(--crimson);
    color: #FFF;
    border-color: var(--crimson);
}

/* Footer */
.pv-footer {
    background: #231915;
    color: #DFD4C3;
    padding-top: 42px;
    margin-top: 30px;
}
.pv-footer-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr 1fr 1fr;
    gap: 28px;
    padding-bottom: 32px;
}
.pv-brand-footer strong { color: #F5D57A; }
.pv-brand-footer small { color: #C7B9A5; }
.pv-footer-desc { font-size: 13.5px; color: #BFB29E; margin-top: 12px; }
.pv-footer h4 { color: #F5D57A; font-family: var(--font-serif); margin: 0 0 12px; font-size: 15.5px; }
.pv-footer ul { list-style: none; padding: 0; margin: 0; }
.pv-footer li { margin-bottom: 8px; font-size: 13.5px; }
.pv-footer a { color: #DFD4C3; }
.pv-footer a:hover { color: #F5D57A; }
.pv-footer-bottom {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 16px 0;
    font-size: 13px;
    color: #AFA18D;
}

/* Modal & Forms */
.pv-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(25, 16, 10, 0.58);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 100;
}
.pv-modal-backdrop[hidden] { display: none; }
.pv-modal {
    background: var(--surface);
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    padding: 24px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.28);
    max-height: 92vh;
    overflow-y: auto;
}
.pv-modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    border: none;
    background: var(--surface-warm);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
}
.pv-modal h3 { font-family: var(--font-serif); margin: 0 0 6px; color: var(--crimson-dark); }
.pv-modal-sub { margin: 0 0 16px; font-size: 13.5px; color: var(--ink-muted); }
.pv-form-row { margin-bottom: 12px; }
.pv-form-row label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 5px; }
.pv-form-row input, .pv-form-row textarea, .pv-form-row select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 9px;
    font-family: var(--font-sans);
    font-size: 14px;
}
.pv-form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pv-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.pv-form-msg { padding: 10px 12px; border-radius: 8px; font-size: 13.5px; margin-top: 8px; }
.pv-form-msg.ok { background: #E9F7EF; color: #145A32; border: 1px solid #A9DFBF; }
.pv-form-msg.err { background: #FDEDEC; color: #922B21; border: 1px solid #F5B7B1; }

/* Responsive */
@media (max-width: 960px) {
    .pv-card-grid { grid-template-columns: repeat(2, 1fr); }
    .pv-service-grid { grid-template-columns: repeat(2, 1fr); }
    .pv-footer-grid { grid-template-columns: 1fr 1fr; }
    .pv-search-row, .pv-search-row-3, .pv-search-row-4 { grid-template-columns: 1fr; }
    .pv-culture-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
    .pv-menu-toggle { display: inline-flex; }
    .pv-nav {
        display: none;
        position: absolute;
        top: 68px;
        left: 0;
        right: 0;
        background: var(--surface);
        border-bottom: 2px solid var(--gold-soft);
        padding: 12px 18px;
        flex-direction: column;
        align-items: stretch;
    }
    .pv-nav.open { display: flex; }
    .pv-nav a.pv-nav-btn { margin-left: 0; text-align: center; }
    .pv-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .pv-card-grid { grid-template-columns: 1fr; }
    .pv-service-grid { grid-template-columns: 1fr; }
    .pv-footer-grid { grid-template-columns: 1fr; }
    .pv-form-grid-2 { grid-template-columns: 1fr; }
    .pv-tree-stage-wrap { height: 480px; }
}
