/* ============================================
   PHẢ ĐỒ - NGUYỄN TỘC PHƯƠNG LƯU
   Family Tree - Mobile-First Design
   ============================================ */

:root {
    /* Colors */
    --color-primary: #991b1b;
    --color-primary-light: #dc2626;
    --color-male: #991b1b;
    --color-female: #2563eb;
    --color-external: #6366f1;
    --color-gold: #fbbf24;
    --color-bg: #fefce8;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-border: #e5e7eb;
    --color-shadow: rgba(0, 0, 0, 0.1);

    /* Typography */
    --font-display: 'Playfair Display', serif;
    --font-body: 'Open Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing */
    --node-width: 120px;
    --node-height: 50px;
    --gap-h: 16px;
    --gap-v: 50px;

    /* Effects */
    --transition: 0.2s ease;
    --radius: 8px;
}

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

html {
    font-size: 14px;
}

body {
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================
   LAYOUT
   ============================================ */

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============================================
   HEADER
   ============================================ */

.header {
    text-align: center;
    padding: 1rem 0.5rem;
    background: linear-gradient(135deg, #991b1b, #b91c1c);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 50;
}

.lotus-icon {
    font-size: 2rem;
    margin-bottom: 0.25rem;
}

.main-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.2rem;
}

.sub-title {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* ============================================
   CONTROLS
   ============================================ */

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 0;
    z-index: 40;
}

.search-box input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 0.9rem;
    width: 150px;
    transition: var(--transition);
}

.search-box input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.zoom-controls {
    display: flex;
    gap: 0.25rem;
}

.zoom-controls button {
    width: 32px;
    height: 32px;
    border: 1px solid var(--color-border);
    background: #fff;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
}

.zoom-controls button:active {
    background: var(--color-primary);
    color: #fff;
}

.action-btn {
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

.add-btn {
    background: #16a34a;
    color: #fff;
}

.export-btn {
    background: #d97706;
    color: #fff;
}

.stats {
    font-size: 0.75rem;
    color: var(--color-primary);
    font-weight: 600;
    white-space: nowrap;
}

.legend {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    font-size: 0.7rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    color: var(--color-text-light);
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid var(--color-border);
}

.dot.ancestor {
    background: #fef3c7;
    border-color: #d97706;
}

.dot.internal {
    background: #fecaca;
    border-color: #dc2626;
}

.dot.external {
    background: #dbeafe;
    border-color: #2563eb;
}

/* ============================================
   TREE WRAPPER & CONTAINER
   ============================================ */

.tree-wrapper {
    flex: 1;
    overflow: auto;
    background: linear-gradient(180deg, #fffbeb, #fef3c7);
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.tree-container {
    padding: 1rem;
    min-width: max-content;
    transform-origin: 0 0;
    position: relative;
}

/* ============================================
   MINI-MAP
   ============================================ */

.mini-map {
    position: fixed;
    bottom: 80px;
    right: 10px;
    width: 150px;
    height: 100px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px var(--color-shadow);
    overflow: hidden;
    z-index: 50;
    display: none;
}

.mini-map.visible {
    display: block;
}

.mini-map canvas {
    width: 100%;
    height: 100%;
}

.mini-map-viewport {
    position: absolute;
    border: 2px solid var(--color-primary);
    background: rgba(153, 27, 27, 0.1);
    pointer-events: none;
}

/* ============================================
   GENERATIONS
   ============================================ */

.generation {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: var(--gap-h);
    align-items: center;
    padding: 0.75rem 0;
    margin-bottom: var(--gap-v);
    transition: all 0.3s ease;
}

.generation.collapsed {
    margin-bottom: 0.5rem;
}

.generation.collapsed .node {
    display: none;
}

.generation-label {
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    padding: 0.4rem 0.8rem;
    background: linear-gradient(135deg, var(--color-primary), #b91c1c);
    border-radius: 15px;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition);
}

.generation-label:hover {
    transform: scale(1.05);
}

.generation-label .collapse-icon {
    font-size: 0.6rem;
    transition: transform 0.3s ease;
}

.generation.collapsed .generation-label .collapse-icon {
    transform: rotate(-90deg);
}

.generation.collapsed .generation-label {
    opacity: 0.7;
}

/* ============================================
   NODES - Unified Design
   ============================================ */

.node {
    min-width: var(--node-width);
    min-height: var(--node-height);
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--color-male);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: #fff;
    box-shadow: 0 2px 6px var(--color-shadow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.node:active {
    transform: scale(0.98);
}

.node.highlight {
    border-color: var(--color-gold);
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.5);
}

.node.dimmed {
    opacity: 0.3;
}

.node.lineage-highlight {
    border-color: var(--color-gold);
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

/* Node Colors */
.node.ancestor {
    background: linear-gradient(135deg, #fef3c7, #fcd34d);
    border-color: #d97706;
}

/* Female = Blue border */
.node.female {
    border-color: var(--color-female);
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
}

/* External Branch = Dashed border */
.node.external-branch {
    border-style: dashed;
    border-color: var(--color-external);
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
}

.node-name {
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1.2;
    color: var(--color-text);
}

.node-spouse {
    font-size: 0.65rem;
    color: var(--color-primary);
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   CONNECTORS SVG
   ============================================ */

.connectors-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 0;
}

.connector-line {
    fill: none;
    stroke: #9ca3af;
    stroke-width: 1.5;
}

/* ============================================
   INFO PANEL
   ============================================ */

.info-panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    max-height: 70vh;
    background: #fff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 100;
    overflow-y: auto;
}

.info-panel.active {
    transform: translateY(0);
}

.close-btn {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 28px;
    height: 28px;
    border: none;
    background: #f3f4f6;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
}

.info-panel h3 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--color-primary);
    margin-bottom: 0.75rem;
    padding-right: 2rem;
}

.info-details p {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.info-details strong {
    color: var(--color-primary);
}

.info-section {
    margin: 0.75rem 0;
    padding: 0.5rem;
    background: #f9fafb;
    border-radius: var(--radius);
}

.info-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

.info-btn {
    padding: 0.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.75rem;
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

.info-btn.edit-btn {
    background: #3b82f6;
    color: #fff;
}

.info-btn.spouse-btn {
    background: #ec4899;
    color: #fff;
}

.info-btn.child-btn {
    background: #22c55e;
    color: #fff;
}

.info-btn.delete-btn {
    background: #ef4444;
    color: #fff;
}

/* ============================================
   LISTS
   ============================================ */

.spouse-list,
.children-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0;
}

.spouse-item,
.child-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem;
    background: #fff;
    border-radius: 6px;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.spouse-item button,
.child-item button {
    padding: 0.2rem 0.4rem;
    border: none;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
}

.btn-delete-spouse,
.btn-delete-child {
    background: #ef4444;
    color: #fff;
}

.btn-move-up,
.btn-move-down {
    background: #3b82f6;
    color: #fff;
    margin-right: 2px;
}

/* ============================================
   MODALS
   ============================================ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 16px 16px 0 0;
    padding: 1.5rem;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.modal-content h3 {
    font-family: var(--font-display);
    color: var(--color-primary);
    margin-bottom: 1rem;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
}

/* Form Styles */
.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 600;
    color: var(--color-primary);
    font-size: 0.85rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.form-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 1rem;
}

.btn-cancel,
.btn-submit {
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
    font-weight: 500;
}

.btn-cancel {
    background: #e5e7eb;
    color: var(--color-text);
}

.btn-submit {
    background: var(--color-primary);
    color: #fff;
}

/* ============================================
   FOOTER
   ============================================ */

.footer {
    text-align: center;
    padding: 0.75rem;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.75rem;
}

/* ============================================
   DESKTOP ENHANCEMENTS
   ============================================ */

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }

    .header {
        padding: 1.5rem 1rem;
    }

    .main-title {
        font-size: 2.5rem;
        letter-spacing: 0.3rem;
    }

    .sub-title {
        font-size: 1rem;
    }

    .controls {
        padding: 1rem;
        gap: 1rem;
    }

    .search-box input {
        width: 200px;
    }

    :root {
        --node-width: 140px;
        --node-height: 55px;
        --gap-h: 25px;
        --gap-v: 60px;
    }

    .tree-container {
        padding: 2rem;
    }

    .info-panel {
        position: fixed;
        right: -350px;
        top: 50%;
        bottom: auto;
        left: auto;
        transform: translateY(-50%);
        width: 320px;
        max-height: 80vh;
        border-radius: 16px 0 0 16px;
        transition: right 0.3s ease;
    }

    .info-panel.active {
        right: 0;
        transform: translateY(-50%);
    }

    .info-actions {
        grid-template-columns: 1fr;
    }

    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: 16px;
        max-width: 450px;
    }

    .node:hover {
        transform: translateY(-3px);
        box-shadow: 0 6px 16px var(--color-shadow);
    }
}

/* ============================================
   PRINT
   ============================================ */

@media print {

    .controls,
    .info-panel,
    .footer,
    .modal {
        display: none !important;
    }

    .tree-wrapper {
        overflow: visible;
    }
}