/*
 * Piattaforma genealogica 0.8.7
 * Interfaccia mobile compatta, menu hamburger e albero a pieno spazio.
 * Le regole desktop restano nel foglio site.css.
 */

.mobile-menu-toggle {
    display: none;
}

.mobile-menu-icon {
    display: grid;
    width: 20px;
    gap: 4px;
}

.mobile-menu-icon > span {
    display: block;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition: transform .18s ease, opacity .18s ease;
}

@media (max-width: 820px) {
    html {
        scroll-padding-top: 68px;
    }

    body {
        overflow-x: hidden;
    }

    .site-header {
        position: sticky;
        top: 0;
        z-index: 9000;
        box-shadow: 0 1px 0 rgba(31, 52, 43, .10);
    }

    .header-inner {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-rows: auto auto;
        align-items: center;
        gap: 6px 8px;
        min-height: 56px;
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .brand {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: clamp(.92rem, 4vw, 1.08rem);
        line-height: 1.15;
    }

    .header-actions {
        display: contents;
    }

    .language-switcher {
        grid-column: 2;
        grid-row: 1;
        margin: 0;
        gap: 2px;
    }

    .language-option {
        display: inline-grid;
        place-items: center;
        width: 36px;
        min-width: 36px;
        height: 36px;
        padding: 0;
        border-radius: 10px;
    }

    .language-option > span:last-child {
        display: none;
    }

    .mobile-menu-toggle {
        grid-column: 3;
        grid-row: 1;
        display: inline-grid;
        place-items: center;
        width: 42px;
        min-width: 42px;
        height: 42px;
        padding: 0;
        border: 1px solid var(--line, #cbd5cf);
        border-radius: 12px;
        background: #fff;
        color: var(--accent, #245b45);
        box-shadow: 0 2px 8px rgba(30, 50, 42, .10);
        cursor: pointer;
    }

    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:focus-visible {
        border-color: var(--accent, #245b45);
        background: #f2f7f4;
    }

    .mobile-menu-open .mobile-menu-icon > span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }

    .mobile-menu-open .mobile-menu-icon > span:nth-child(2) {
        opacity: 0;
    }

    .mobile-menu-open .mobile-menu-icon > span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    .site-primary-navigation {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        margin: 0;
        padding: 7px;
        align-items: stretch;
        flex-direction: column;
        gap: 0;
        border: 1px solid var(--line, #cbd5cf);
        border-radius: 14px;
        background: #fff;
        box-shadow: 0 14px 32px rgba(30, 50, 42, .18);
    }

    .mobile-nav-ready .site-header:not(.mobile-menu-open) .site-primary-navigation {
        display: none;
    }

    .site-primary-navigation > a,
    .site-primary-navigation > .session-status,
    .site-primary-navigation > .inline-form {
        width: 100%;
        box-sizing: border-box;
    }

    .site-primary-navigation > a,
    .site-primary-navigation .link-button {
        display: flex;
        align-items: center;
        min-height: 44px;
        padding: 9px 11px;
        border: 0;
        border-radius: 9px;
        background: transparent;
        color: var(--ink, #24332c);
        text-align: left;
        text-decoration: none;
        font: inherit;
        font-weight: 750;
    }

    .site-primary-navigation > a:hover,
    .site-primary-navigation > a:focus-visible,
    .site-primary-navigation .link-button:hover,
    .site-primary-navigation .link-button:focus-visible {
        background: #eef5f1;
        color: var(--accent, #245b45);
    }

    .site-primary-navigation .inline-form {
        display: block;
        margin: 0;
    }

    .site-primary-navigation .link-button {
        width: 100%;
        cursor: pointer;
    }

    .site-primary-navigation .session-status {
        min-height: 34px;
        padding: 8px 11px;
        color: var(--muted, #68756f);
        font-size: .78rem;
    }

    main.container {
        padding-top: 14px;
    }

    .site-footer {
        margin-top: 28px;
    }

    .footer-inner {
        gap: 5px 12px;
        padding-top: 14px;
        padding-bottom: 14px;
        font-size: .76rem;
    }

    /* Albero: testata corta e area grafica dominante. */
    .tree-toolbar {
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 8px;
    }

    .tree-toolbar h1 {
        margin-top: 1px;
        margin-bottom: 2px;
        font-size: clamp(1.15rem, 5.4vw, 1.48rem);
        line-height: 1.15;
    }

    .tree-toolbar .tree-intro {
        display: none;
    }

    .tree-toolbar > .actions {
        gap: 6px;
    }

    .tree-toolbar > .actions .button {
        min-height: 36px;
        padding: 7px 10px;
        font-size: .78rem;
    }

    .combined-generation-controls {
        display: grid;
        width: 100%;
        gap: 5px;
    }

    .generation-picker {
        width: 100%;
        flex-wrap: nowrap;
        gap: 3px;
        overflow-x: auto;
        padding: 1px 0 3px;
        scrollbar-width: thin;
    }

    .generation-picker > span {
        flex: 0 0 74px;
        margin-right: 1px;
        font-size: .67rem;
        line-height: 1.1;
    }

    .generation-button {
        min-width: 29px;
        width: 29px;
        height: 29px;
        padding: 0;
        border-radius: 8px;
        font-size: .76rem;
    }

    .tree-buttons {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        width: 100%;
        gap: 6px;
    }

    .tree-buttons .tool-button[data-fit-tree],
    .tree-buttons .tool-button[data-center-tree] {
        min-width: 0;
        min-height: 38px;
        height: auto;
        padding: 7px 8px;
        line-height: 1.1;
        font-size: .74rem;
    }

    .combined-tree-viewport {
        height: calc(100dvh - 258px);
        min-height: 420px;
        max-height: none;
        padding: 8px;
        border-radius: 13px;
        overscroll-behavior: contain;
    }

    .tree-help {
        display: none;
    }

    .tree-siblings-popover {
        max-height: calc(100dvh - 76px);
        overflow: auto;
        overscroll-behavior: contain;
    }

    .siblings-card-row {
        scroll-snap-type: x proximity;
    }

    .sibling-tree-card {
        scroll-snap-align: start;
    }
}

@media (max-width: 620px) {
    main.container {
        padding-top: 10px;
        padding-bottom: 24px;
    }

    .page-heading {
        gap: 10px;
        margin-bottom: 14px;
    }

    .page-heading h1 {
        margin-top: 1px;
        margin-bottom: 3px;
        font-size: clamp(1.34rem, 7vw, 1.82rem);
        line-height: 1.12;
    }

    .page-heading p,
    .hero > p,
    .card p {
        font-size: .9rem;
        line-height: 1.45;
    }

    .eyebrow {
        margin-bottom: 2px;
        font-size: .68rem;
    }

    .hero {
        margin-bottom: 14px;
        padding: 20px 15px;
        border-radius: 18px;
    }

    .hero h1 {
        margin: 4px 0 8px;
        font-size: clamp(1.58rem, 9vw, 2.12rem);
        line-height: 1.05;
    }

    .search-form {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
        gap: 7px;
    }

    .search-form input,
    .search-form select {
        min-width: 0;
        width: 100%;
    }

    .search-form button {
        min-width: 74px;
        padding-right: 12px;
        padding-left: 12px;
    }

    .stats-grid,
    .stats-grid-four {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px;
    }

    .stats-grid .card,
    .stats-grid-four .card {
        min-height: 94px;
        padding: 13px 10px;
        text-align: center;
    }

    .stats-grid strong,
    .stats-grid-four strong {
        font-size: clamp(1.28rem, 7vw, 1.72rem);
    }

    .stats-grid span,
    .stats-grid-four span {
        font-size: .74rem;
        line-height: 1.25;
    }

    .card {
        padding: 15px;
        border-radius: 15px;
    }

    .actions {
        gap: 7px;
    }

    .actions .button,
    .actions .button-link {
        min-height: 40px;
        padding: 8px 11px;
        font-size: .8rem;
    }

    .search-page-heading {
        align-items: stretch;
    }

    .search-summary-bar {
        display: grid;
        gap: 10px;
        padding: 12px;
    }

    .search-order-form {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        width: 100%;
        gap: 8px;
    }

    .search-order-form select {
        min-width: 0;
        width: 100%;
    }

    .search-results-table {
        display: grid;
        gap: 10px;
    }

    .search-results-header {
        display: none;
    }

    .search-result-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 9px;
        padding: 12px;
        border: 1px solid var(--line, #cbd5cf);
        border-radius: 14px;
        background: #fff;
        box-shadow: 0 3px 12px rgba(30, 50, 42, .06);
    }

    .search-result-row > [role="cell"] {
        min-width: 0;
    }

    .search-person-cell {
        padding-bottom: 8px;
        border-bottom: 1px solid var(--line, #d8dfdb);
    }

    .relation-chips {
        gap: 5px;
    }

    .relation-chip {
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .pagination {
        gap: 8px;
        font-size: .78rem;
    }

    .profile-header {
        grid-template-columns: 82px minmax(0, 1fr);
        gap: 12px;
        align-items: start;
    }

    .portrait-wrap,
    .portrait {
        width: 82px;
        height: 106px;
    }

    img.portrait {
        object-fit: contain;
        background: #fff;
    }

    .profile-header h1 {
        font-size: clamp(1.4rem, 7.4vw, 1.9rem);
        line-height: 1.08;
    }

    .profile-header .actions {
        grid-column: 1 / -1;
    }

    .facts div,
    .compact-facts div {
        grid-template-columns: minmax(0, 1fr);
        gap: 2px;
        padding-top: 9px;
        padding-bottom: 9px;
    }

    .facts dd,
    .facts dt {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .document-card,
    .relative-group {
        padding: 13px;
    }

    .document-card .actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
    }

    .document-card .button {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    .contact-form-card,
    .auth-card {
        padding: 16px;
    }

    .contact-form-card input,
    .contact-form-card select,
    .contact-form-card textarea,
    .auth-card input {
        width: 100%;
        box-sizing: border-box;
    }

    .contribution-callout {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
        padding: 17px;
    }

    .contribution-callout .button-link {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    .tree-toolbar > .actions {
        width: 100%;
    }

    .tree-toolbar > .actions .button {
        width: 100%;
        box-sizing: border-box;
        text-align: center;
    }

    .combined-tree-viewport {
        height: calc(100dvh - 248px);
        min-height: 390px;
        padding: 6px;
    }

    .tree-boundary-label {
        font-size: .64rem;
    }
}

@media (max-width: 390px) {
    .header-inner {
        grid-template-columns: minmax(0, 1fr) auto auto;
        gap: 5px;
    }

    .language-option {
        width: 32px;
        min-width: 32px;
        height: 34px;
    }

    .mobile-menu-toggle {
        width: 38px;
        min-width: 38px;
        height: 38px;
    }

    .stats-grid,
    .stats-grid-four {
        grid-template-columns: minmax(0, 1fr);
    }

    .generation-picker > span {
        flex-basis: 66px;
        font-size: .62rem;
    }

    .generation-button {
        min-width: 27px;
        width: 27px;
        height: 27px;
    }
}

@media (pointer: coarse) and (max-width: 820px) {
    .branch-toggle,
    .siblings-toggle,
    .tree-explore-link {
        width: 31px;
        height: 31px;
    }

    .branch-toggle {
        right: -15px;
        bottom: -15px;
    }

    .combined-root-ancestors .branch-toggle,
    .tree-canvas-ancestors .branch-toggle {
        top: -15px;
        bottom: auto;
    }

    .siblings-toggle,
    .tree-explore-link {
        left: -15px;
        bottom: -15px;
    }

    .tree-union-spouse-explore {
        width: 29px;
        height: 29px;
        flex-basis: 29px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mobile-menu-icon > span {
        transition: none;
    }
}


/* Versione 0.8.6: testata e controlli dell'albero compatti su mobile. */
.generation-controls-mobile {
    display: none;
}

.tree-back-icon {
    display: none;
}

@media (max-width: 820px) {
    .tree-heading-toolbar {
        display: grid;
        grid-template-columns: 36px minmax(0, 1fr);
        align-items: center;
        gap: 4px 8px;
        margin-bottom: 5px;
    }

    .tree-heading-toolbar > div:first-child {
        grid-column: 2;
        grid-row: 1;
        min-width: 0;
    }

    .tree-heading-toolbar .eyebrow,
    .tree-heading-toolbar .tree-intro {
        display: none;
    }

    .tree-heading-toolbar h1 {
        margin: 0;
        overflow-wrap: anywhere;
        font-size: clamp(1.08rem, 5vw, 1.36rem);
        line-height: 1.12;
    }

    .tree-heading-toolbar > .actions {
        grid-column: 1;
        grid-row: 1;
        width: auto;
        margin: 0;
    }

    .tree-heading-toolbar .tree-back-link {
        display: inline-grid;
        place-items: center;
        width: 36px;
        min-width: 36px;
        height: 36px;
        min-height: 36px;
        padding: 0;
        border: 1px solid var(--line, #cbd5cf);
        border-radius: 10px;
        background: #fff;
        color: var(--accent, #245b45);
        box-shadow: none;
    }

    .tree-heading-toolbar .tree-back-link:hover,
    .tree-heading-toolbar .tree-back-link:focus-visible {
        border-color: var(--accent, #245b45);
        background: #eef5f1;
    }

    .tree-back-icon {
        display: block;
        font-size: 1.55rem;
        font-weight: 500;
        line-height: 1;
        transform: translateY(-1px);
    }

    .tree-back-label {
        display: none;
    }

    .generation-controls-desktop {
        display: none !important;
    }

    .generation-controls-mobile {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        gap: 8px;
    }

    .generation-stepper {
        display: flex;
        align-items: center;
        min-width: 0;
        gap: 3px;
    }

    .generation-step-label {
        min-width: 28px;
        color: var(--muted, #68756f);
        font-size: .68rem;
        font-weight: 850;
        line-height: 1;
        white-space: nowrap;
    }

    .generation-step-button,
    .generation-step-value {
        display: inline-grid;
        place-items: center;
        width: 30px;
        min-width: 30px;
        height: 30px;
        box-sizing: border-box;
        padding: 0;
        border-radius: 8px;
        font-size: .8rem;
        font-weight: 850;
        line-height: 1;
        font-variant-numeric: tabular-nums;
    }

    .generation-step-button {
        border: 1px solid var(--line, #cbd5cf);
        background: #eef3f0;
        color: var(--ink, #24332c);
        text-decoration: none;
    }

    .generation-step-button:not(.is-disabled):hover,
    .generation-step-button:not(.is-disabled):focus-visible {
        border-color: var(--accent, #245b45);
        background: #e3eee8;
        color: var(--accent, #245b45);
    }

    .generation-step-button.is-disabled {
        opacity: .35;
        cursor: default;
    }

    .generation-step-value {
        background: var(--accent, #245b45);
        color: #fff;
    }

    .tree-controls-toolbar {
        display: grid;
        width: 100%;
        gap: 6px;
        box-sizing: border-box;
        margin-bottom: 6px;
        padding: 8px 10px;
        border: 1px solid var(--line, #cbd5cf);
        border-radius: 12px;
        background: #fff;
    }

    .tree-controls-toolbar .tree-buttons {
        gap: 6px;
    }

    .tree-controls-toolbar .tree-buttons .tool-button[data-fit-tree],
    .tree-controls-toolbar .tree-buttons .tool-button[data-center-tree] {
        min-height: 34px;
        padding: 6px 8px;
        font-size: .72rem;
    }

    .tree-private-note,
    .tree-controls-toolbar ~ p:has(.legend-dot.private) {
        display: none;
    }

    .combined-tree-viewport {
        height: calc(100dvh - 178px);
        min-height: 480px;
        margin-top: 0;
        padding: 6px;
    }
}

@media (max-width: 620px) {
    .tree-heading-toolbar > .actions {
        width: auto;
    }

    .tree-heading-toolbar > .actions .tree-back-link {
        width: 36px;
        min-width: 36px;
        height: 36px;
        padding: 0;
    }

    .combined-tree-viewport {
        height: calc(100dvh - 172px);
        min-height: 460px;
    }
}

@media (max-width: 390px) {
    .generation-controls-mobile {
        gap: 5px;
    }

    .generation-stepper {
        gap: 2px;
    }

    .generation-step-label {
        min-width: 25px;
        font-size: .63rem;
    }

    .generation-step-button,
    .generation-step-value {
        width: 28px;
        min-width: 28px;
        height: 28px;
        font-size: .76rem;
    }

    .tree-controls-toolbar {
        padding-right: 7px;
        padding-left: 7px;
    }
}


/* Versione 0.8.7: statistiche della home compatte in griglia 2 × 2 su smartphone. */
@media (max-width: 620px) {
    .stats-grid,
    .stats-grid-four {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
        gap: 7px;
        margin-bottom: 12px;
    }

    .stats-grid .card,
    .stats-grid-four .card {
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-width: 0;
        min-height: 74px;
        box-sizing: border-box;
        padding: 9px 6px;
        border-radius: 13px;
        text-align: center;
    }

    .stats-grid strong,
    .stats-grid-four strong {
        display: block;
        font-size: clamp(1.18rem, 7vw, 1.5rem);
        line-height: 1.05;
        font-variant-numeric: tabular-nums;
    }

    .stats-grid span,
    .stats-grid-four span {
        display: block;
        margin-top: 3px;
        overflow-wrap: anywhere;
        font-size: .66rem;
        line-height: 1.15;
    }
}
