/* ============================================
   Mobile Tab Bar — Bottom Navigation
   Only visible at 768px and below
   ============================================ */

/* Tab bar: hidden on desktop */
.mobile-tab-bar {
    display: none;
}

@media (max-width: 768px) {
    /* Prevent horizontal scroll on mobile */
    html, body {
        overflow-x: hidden;
    }

    /* Show tab bar */
    .mobile-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 9999;
        background: var(--color-surface);
        border-top: 1px solid var(--color-border);
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .mobile-tab-bar .tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 8px 4px;
        background: none;
        border: none;
        font-size: 10px;
        color: var(--color-text-secondary);
        cursor: pointer;
        position: relative;
        transition: color var(--transition-fast);
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-tab-bar .tab-item svg {
        width: 22px;
        height: 22px;
    }

    .mobile-tab-bar .tab-item.active {
        color: var(--color-primary);
    }

    .mobile-tab-bar .tab-item:active {
        opacity: 0.7;
    }

    /* Badge */
    .mobile-tab-bar .tab-badge {
        position: absolute;
        top: 4px;
        right: calc(50% - 18px);
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        border-radius: 8px;
        background: var(--color-primary);
        color: #fff;
        font-size: 10px;
        font-weight: 600;
        line-height: 16px;
        text-align: center;
        display: none;
    }

    .mobile-tab-bar .tab-badge.visible {
        display: block;
    }

    /* Cookie consent banner: タブバーの上に表示 */
    #cookieConsent {
        bottom: calc(52px + env(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: 20px !important;
    }

    /* Body padding for tab bar */
    body {
        padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px));
    }

    /* Reorder: canvas first, sidebar second */
    .main-grid {
        display: flex;
        flex-direction: column;
    }

    #canvasPanel {
        order: 1;
    }

    .sidebar {
        order: 2;
    }

    /* Display switching based on active tab */
    body[data-mobile-tab="canvas"] .sidebar { display: none; }

    body[data-mobile-tab="people"] #canvasPanel { display: none; }
    body[data-mobile-tab="people"] #relationsPanel { display: none; }

    body[data-mobile-tab="relations"] #canvasPanel { display: none; }
    body[data-mobile-tab="relations"] #peoplePanel { display: none; }
}
