/* Ba Zi Calculator — Mobile UI */

/* ── Hide desktop nav on mobile ─────────────────────────────── */
@media (max-width: 768px) {
    .topbar-nav         { display: none !important; }
    .topbar-hamburger   { display: block !important; }
    .lang-switcher      { display: none !important; }
    .topbar-root        { height: 52px !important; }
    .topbar-logo span   { display: none; }
    .user-name, .user-role { display: none !important; }
    /* Keep user pill compact */
    .user-pill { padding: 3px 5px 3px 5px !important; gap: 4px !important; }
}

/* ── Mobile nav panel ────────────────────────────────────────── */
.topbar-nav-links {
    display: none;
    position: fixed;
    top: 52px;
    left: 0;
    right: 0;
    background: #12100d;
    z-index: 9998;
    padding: 6px 0 20px;
    border-bottom: 1px solid rgba(184,134,11,.2);
    max-height: calc(100vh - 52px);
    max-height: calc(100dvh - 52px);
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
    -webkit-overflow-scrolling: touch;
}
.topbar-nav-links.open { display: block; }
.topbar-nav-links a {
    display: flex !important;
    align-items: center;
    padding: 9px 18px !important;
    color: rgba(255,215,0,.85) !important;
    font-size: 13.5px !important;
    line-height: 1.3 !important;
    font-family: 'Poppins', sans-serif !important;
    font-weight: 500 !important;
    border-bottom: 1px solid rgba(255,255,255,.05);
    text-decoration: none;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
}
.topbar-nav-links a:active { background: rgba(255,255,255,.07); }
.topbar-nav-links .topbar-user-pill {
    margin: 10px 14px 0;
    background: rgba(255,255,255,.08);
    border-radius: 8px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: rgba(255,255,255,.7);
    font-size: 13px;
    font-family: 'Poppins', sans-serif;
}

/* ── Main grid ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    .main-grid      { grid-template-columns: 1fr !important; }
    .stats-grid     { grid-template-columns: repeat(2,1fr) !important; gap: 8px !important; }
    .grid-2, .grid-3{ grid-template-columns: 1fr !important; }
    .layout         { grid-template-columns: 1fr !important; }
}

/* ── Pillars: 2-col on phone ─────────────────────────────────── */
@media (max-width: 480px) {
    .pillars-grid { grid-template-columns: repeat(2,1fr) !important; gap: 8px !important; }
    .container    { padding: 10px !important; }
    .fg2          { grid-template-columns: 1fr !important; }
}

/* ── Tab rows: horizontal scroll ─────────────────────────────── */
@media (max-width: 600px) {
    .tab-row-1, .tab-row-2 {
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 2px;
    }
    .tab-row-1::-webkit-scrollbar, .tab-row-2::-webkit-scrollbar { display: none; }
    .tab-btn { flex-shrink: 0 !important; white-space: nowrap !important; }
}

/* ── Auth modal: bottom sheet on phone ───────────────────────── */
@media (max-width: 480px) {
    .auth-overlay { align-items: flex-end !important; }
    .auth-modal   { max-width: 100% !important; border-radius: 20px 20px 0 0 !important; position: fixed !important; bottom: 0; left: 0; right: 0; }
    .auth-mhead   { border-radius: 20px 20px 0 0 !important; }
    .auth-fg input{ font-size: 16px !important; }
    .auth-btn     { font-size: 16px !important; padding: 14px !important; }
}

/* ── Prevent iOS zoom on inputs ─────────────────────────────── */
@media (max-width: 480px) {
    input[type=text], input[type=email], input[type=password],
    input[type=number], select, textarea { font-size: 16px !important; }
}

/* ── Table scroll ────────────────────────────────────────────── */
@media (max-width: 600px) {
    .recent-section, .dt-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    #historyTable, table.dt, table.data-table { min-width: 480px; }
}

/* ── Bottom navigation bar ───────────────────────────────────── */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: white;
    border-top: 1px solid #e8dcc8;
    z-index: 900;
    box-shadow: 0 -2px 10px rgba(0,0,0,.1);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-bottom-nav-inner { display: flex; align-items: stretch; }
.mbn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 4px 8px;
    text-decoration: none;
    color: #8b7355;
    font-size: 9.5px;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    letter-spacing: .3px;
    text-transform: uppercase;
    border: none;
    background: none;
    cursor: pointer;
    gap: 3px;
    min-height: 54px;
    -webkit-tap-highlight-color: transparent;
    transition: color .1s;
}
.mbn-item.active { color: #c0392b; }
.mbn-item:active  { color: #c0392b; background: rgba(192,57,43,.05); }
.mbn-icon { font-size: 20px; line-height: 1; }

@media (max-width: 768px) {
    .mobile-bottom-nav { display: block; }
    body { padding-bottom: calc(54px + env(safe-area-inset-bottom, 0px)) !important; }
}

/* ── PWA standalone ─────────────────────────────────────────── */
@media (display-mode: standalone) {
    .topbar-root { padding-top: env(safe-area-inset-top, 0) !important; height: calc(52px + env(safe-area-inset-top, 0)) !important; }
    .topbar-nav-links {
        top: calc(52px + env(safe-area-inset-top, 0));
        max-height: calc(100vh - 52px - env(safe-area-inset-top, 0));
        max-height: calc(100dvh - 52px - env(safe-area-inset-top, 0));
    }
    .mobile-bottom-nav { padding-bottom: env(safe-area-inset-bottom, 0); }
}
