* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Be Vietnam Pro', "Segoe UI", system-ui, -apple-system, sans-serif;
    background: linear-gradient(180deg, #f0f7fc 0%, #e8f2f9 100%);
    min-height: 100vh;
    color: #1a1a1a;
}
.app-header {
    padding: 0.45rem 1rem 0.5rem;
    background: rgba(255,255,255,0.85);
    border-bottom: 1px solid #c5dce8;
    box-shadow: 0 1px 3px rgba(0,80,120,0.08);
}
.app-header h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    color: #0d47a1;
}
.app-header-minimal {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 0.75rem;
    width: 100%;
}
.app-header-minimal h2 {
    flex: 0 1 auto;
    min-width: 0;
}
.app-header-minimal .logout {
    color: #c62828;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.9rem;
    flex-shrink: 0;
    white-space: nowrap;
}
.app-header-minimal .logout:hover {
    text-decoration: underline;
}
.app-header-end {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.65rem;
    flex-shrink: 0;
}
.app-header-end #add-root-btn {
    margin: 0;
    padding: 0.32rem 0.72rem;
    font-size: 0.85rem;
    border-width: 1px;
}
@media (max-width: 520px) {
    .app-header-minimal {
        flex-wrap: wrap;
    }
    .app-header-end {
        width: 100%;
        justify-content: flex-end;
    }
}
.toolbar {
    margin-top: 0.35rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.admin-bar {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #c5dce8;
    font-size: 0.82rem;
    color: #37474f;
}
.admin-bar label { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; min-width: 180px; }
.admin-bar input[type="text"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid #90caf9;
    border-radius: 6px;
    font-size: 0.8rem;
}
.admin-bar button.secondary {
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    border: 1px solid #1976d2;
    background: #fff;
    color: #1976d2;
    font-weight: 600;
    cursor: pointer;
}
.admin-bar button.secondary:hover { background: #e3f2fd; }
.admin-bar a.logout {
    color: #c62828;
    font-weight: 600;
    margin-left: auto;
}
.hint {
    font-size: 0.85rem;
    color: #546e7a;
}
body.giapha-read-only .admin-only { display: none !important; }
body.giapha-read-only #confirm-backdrop,
body.giapha-read-only #modal-backdrop { display: none !important; visibility: hidden !important; pointer-events: none !important; }
#add-root-btn {
    display: none;
    padding: 0.45rem 1rem;
    font-size: 0.95rem;
    border-radius: 8px;
    border: 2px solid #1976d2;
    background: #fff;
    color: #1976d2;
    cursor: pointer;
    font-weight: 600;
}
#add-root-btn:hover { background: #e3f2fd; }
.tree-viewport {
    width: 100%;
    height: calc(100vh - 76px);
    min-height: 480px;
    overflow: auto;
    padding: 0.175rem 1rem 1.25rem;
    cursor: grab;
}
body.giapha-read-only .tree-viewport { height: calc(100vh - 100px); }
.tree-viewport:active { cursor: grabbing; }
#tree-simple {
    margin: 0 auto;
    min-width: min-content;
    min-height: 400px;
}
.treant > .node { padding: 0; }
.treant .collapse-switch { display: none; }
.node-card {
    position: relative;
    min-width: 188px;
    max-width: 220px;
    padding: 0.65rem 0.75rem 0.55rem;
    border-radius: 10px;
    background: linear-gradient(165deg, #e3f2fd 0%, #bbdefb 45%, #90caf9 100%);
    border: 1px solid #64b5f6;
    box-shadow: 0 3px 8px rgba(25, 118, 210, 0.18);
    text-align: center;
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.15s;
}
.node-card:hover {
    box-shadow: 0 5px 14px rgba(25, 118, 210, 0.28);
}
.node-card--selected {
    background: linear-gradient(165deg, #fff9c4 0%, #fff59d 50%, #ffee58 100%);
    border-color: #fbc02d;
    box-shadow: 0 4px 16px rgba(251, 192, 45, 0.35);
}
.node-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}
.node-card:hover .node-actions,
.node-card--selected .node-actions {
    opacity: 1;
}
.node-actions button {
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}
.action-add-child {
    background: #1976d2;
    color: #fff;
}
.action-add-child:hover { background: #1565c0; }
.action-add-spouse {
    background: #c62828;
    color: #fff;
    font-size: 0.85rem;
}
.action-add-spouse:hover { background: #b71c1c; }
.action-edit-person {
    background: #6a1b9a;
    color: #fff;
    font-size: 0.8rem;
}
.action-edit-person:hover { background: #4a148c; }
.action-delete-person {
    background: #455a64;
    color: #fff;
    font-size: 0.85rem;
}
.action-delete-person:hover { background: #37474f; }
.node-spouse-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-top: 0.2rem;
    padding-top: 0.25rem;
    border-top: 1px dashed rgba(38, 50, 56, 0.25);
}
.node-spouse-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}
.node-card:hover .node-spouse-actions,
.node-card--selected .node-spouse-actions {
    opacity: 1;
    pointer-events: auto;
}
.node-spouse-edit-link.action-edit-person {
    width: auto !important;
    height: auto !important;
    min-height: 0;
    padding: 0 2px !important;
    font-size: 0.68rem !important;
    font-weight: 600;
    background: transparent !important;
    color: #6a1b9a !important;
    text-decoration: underline;
    border-radius: 0;
}
.node-spouse-edit-link.action-edit-person:hover {
    background: transparent !important;
    color: #4a148c !important;
}
.node-spouse-delete-link.action-delete-person {
    width: auto !important;
    height: auto !important;
    min-height: 0;
    padding: 0 2px !important;
    font-size: 0.68rem !important;
    font-weight: 600;
    background: transparent !important;
    color: #c62828 !important;
    text-decoration: underline;
    border-radius: 0;
}
.node-spouse-delete-link.action-delete-person:hover {
    background: transparent !important;
    color: #b71c1c !important;
}
.node-name-primary {
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1.25;
    margin: 0.15rem 0 0.1rem;
    hyphens: none;
    word-break: normal;
    overflow-wrap: anywhere;
}
.node-name-primary.male { color: #c62828; }
.node-name-primary.female { color: #2e7d32; }
.node-spouse {
    font-size: 0.78rem;
    color: #263238;
    line-height: 1.2;
}
.node-spouse-list {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    margin-top: 0.15rem;
}
.node-meta {
    font-size: 0.72rem;
    color: #37474f;
    margin-top: 0.15rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-backdrop.visible { display: flex; }
.modal-panel {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.modal-panel h3 {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    color: #0d47a1;
}
.modal-panel label {
    display: block;
    margin-bottom: 0.65rem;
    font-size: 0.9rem;
}
.modal-panel .life-date-block {
    border: 1px solid #e3f2fd;
    border-radius: 8px;
    padding: 0.5rem 0.65rem 0.65rem;
    margin: 0 0 0.65rem;
}
.modal-panel .life-date-block legend {
    padding: 0 0.35rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: #0d47a1;
}
.modal-panel .date-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.65rem;
    align-items: flex-end;
    margin: 0;
}
.modal-panel .date-row label {
    flex: 1 1 5rem;
    min-width: 4rem;
    margin-bottom: 0;
    font-size: 0.8rem;
}
.modal-panel .date-row input {
    max-width: none;
    width: 100%;
}
.modal-panel .date-hint {
    font-size: 0.78rem;
    color: #546e7a;
    margin: 0 0 0.65rem;
    line-height: 1.35;
}
.modal-panel input,
.modal-panel select {
    margin-top: 0.25rem;
    width: 100%;
    max-width: 280px;
    padding: 0.4rem 0.5rem;
    border: 1px solid #90caf9;
    border-radius: 6px;
}
.modal-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}
.modal-actions button {
    padding: 0.45rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    border: none;
}
.modal-actions button[type="submit"] {
    background: #1976d2;
    color: #fff;
}
.modal-actions .btn-cancel {
    background: #eceff1;
    color: #37474f;
}
.empty-tree {
    text-align: center;
    padding: 2rem;
    color: #78909c;
    font-size: 1rem;
}
.empty-tree-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: min(420px, calc(100vh - 200px));
    max-width: 420px;
    margin: 0 auto;
    padding: 2rem 1rem;
    text-align: center;
}
.empty-tree-wrap .empty-tree-title {
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
    color: #37474f;
    font-weight: 600;
}
.empty-tree-wrap .empty-tree-desc {
    margin: 0 0 1.25rem;
    font-size: 0.95rem;
    color: #546e7a;
    line-height: 1.45;
    word-break: break-word;
    max-width: 100%;
}
.empty-tree-add-first {
    padding: 0.75rem 1.35rem;
    font-size: 1.05rem;
    border-radius: 10px;
    border: none;
    background: #1976d2;
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(25, 118, 210, 0.35);
}
.empty-tree-add-first:hover { background: #1565c0; }
.empty-tree-note {
    margin: 1rem 0 0;
    font-size: 0.82rem;
    color: #c62828;
    line-height: 1.4;
}
.empty-tree-note--warn { color: #e65100; }
.confirm-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(13, 71, 161, 0.35);
    backdrop-filter: blur(2px);
    z-index: 1100;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.confirm-backdrop.visible { display: flex; }
.confirm-panel {
    background: #fff;
    border-radius: 16px;
    padding: 1.35rem 1.5rem 1.25rem;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(0, 40, 80, 0.28), 0 0 0 1px rgba(100, 181, 246, 0.35);
    border: 1px solid #bbdefb;
}
.confirm-panel h3 {
    margin: 0 0 0.65rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #0d47a1;
    line-height: 1.3;
}
.confirm-body {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.5;
    color: #37474f;
}
.confirm-actions {
    margin-top: 1.25rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.confirm-actions button {
    padding: 0.5rem 1.15rem;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
}
.confirm-btn-cancel {
    background: #eceff1;
    color: #37474f;
}
.confirm-btn-cancel:hover { background: #dfe4e7; }
.confirm-btn-ok {
    background: linear-gradient(180deg, #e53935 0%, #c62828 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(198, 40, 40, 0.35);
}
.confirm-btn-ok:hover {
    background: linear-gradient(180deg, #d32f2f 0%, #b71c1c 100%);
}
