/* ForestFlow mobile layer. Loaded on every page from includes/theme_loader.php.
   Desktop is untouched: everything new is hidden above 768px. */

:root { --ff-bar-h: 62px; --ff-safe-t: env(safe-area-inset-top, 0px); --ff-safe-b: env(safe-area-inset-bottom, 0px); }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
img, video, canvas, svg { max-width: 100%; }

/* ---- pieces used on all sizes ---- */
.ff-bottomnav, .ff-bell { display: none; }
.ff-badge {
    display: inline-flex; align-items: center; justify-content: center; min-width: 19px; height: 19px; padding: 0 5px;
    border-radius: 999px; background: #ef4444; color: #fff; font-size: .68rem; font-weight: 700; line-height: 1; margin-left: auto;
}
.ff-badge[hidden] { display: none !important; }

.ff-toast-wrap { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 9998; width: min(94vw, 440px); display: flex; flex-direction: column; gap: .5rem; pointer-events: none; }
.ff-toast {
    pointer-events: auto; display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem; border-radius: 14px; cursor: pointer; text-decoration: none;
    background: var(--bg-panel, #14231a); color: var(--text-main, #fff); border: 1px solid var(--accent-green, #4CAF50);
    box-shadow: 0 12px 36px rgba(0, 0, 0, .45); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    animation: ffToastIn .35s cubic-bezier(.22, 1, .36, 1) both;
}
.ff-toast b { display: block; font-size: .92rem; margin-bottom: 2px; }
.ff-toast span { font-size: .84rem; color: var(--text-muted, #a9b8ac); word-break: break-word; }
@keyframes ffToastIn { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }

.ff-install {
    position: fixed; left: .8rem; right: .8rem; z-index: 96; display: none; align-items: center; gap: .8rem; padding: .8rem 1rem; border-radius: 16px;
    bottom: calc(var(--ff-bar-h) + var(--ff-safe-b) + .7rem);
    background: var(--bg-panel, #14231a); color: var(--text-main, #fff); border: 1px solid var(--accent-green, #4CAF50);
    box-shadow: 0 14px 40px rgba(0, 0, 0, .5); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.ff-install.show { display: flex; }
.ff-install .t { flex: 1; font-size: .88rem; line-height: 1.3; }
.ff-install .t small { display: block; color: var(--text-muted, #a9b8ac); font-size: .76rem; }
.ff-install a.go { padding: .55rem .9rem; border-radius: 10px; background: var(--accent-green, #4CAF50); color: #fff; font-weight: 700; text-decoration: none; font-size: .85rem; white-space: nowrap; }
.ff-install button.x { background: none; border: 0; color: var(--text-muted, #a9b8ac); font-size: 1.3rem; padding: .2rem .4rem; cursor: pointer; }

/* ---- inside the Android app ---- */
html.ff-app { overscroll-behavior-y: contain; }
html.ff-app .ff-install, html.ff-app [data-web-only] { display: none !important; }
html:not(.ff-app) [data-app-only] { display: none !important; }
html.ff-app .ff-bottomnav, html.ff-app .sidebar, html.ff-app .ff-bell { -webkit-user-select: none; user-select: none; }

/* ============================ PHONES & SMALL TABLETS ============================ */
@media (max-width: 768px) {
    html { overflow-x: hidden; }                       /* a wide element must never stretch the whole page / bottom bar */
    body { padding-bottom: calc(var(--ff-bar-h) + var(--ff-safe-b)); max-width: 100vw; }
    body .main-content { padding: calc(4.6rem + var(--ff-safe-t)) 1rem 1.4rem !important; }

    .ff-menu-btn { top: calc(.8rem + var(--ff-safe-t)) !important; }
    .sidebar { padding-top: calc(1.5rem + var(--ff-safe-t)) !important; padding-bottom: calc(1.5rem + var(--ff-safe-b)) !important; }

    .ff-bell {
        display: flex; align-items: center; justify-content: center; position: fixed; z-index: 90;
        top: calc(.8rem + var(--ff-safe-t)); right: .8rem; width: 46px; height: 46px; border-radius: 14px; text-decoration: none;
        border: 1px solid var(--border-color, rgba(255, 255, 255, .12)); background: var(--sidebar-bg, rgba(11, 20, 13, .88)); color: var(--text-main, #fff);
        -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
    }
    .ff-bell svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
    .ff-bell .ff-badge { position: absolute; top: -5px; right: -5px; margin: 0; }
    .ff-bell:active { transform: scale(.92); }

    .ff-bottomnav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 85;
        height: calc(var(--ff-bar-h) + var(--ff-safe-b)); padding-bottom: var(--ff-safe-b);
        background: var(--sidebar-bg, rgba(11, 20, 13, .95)); border-top: 1px solid var(--border-color, rgba(255, 255, 255, .1));
        -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    }
    .ff-bottomnav a, .ff-bottomnav button {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
        background: none; border: 0; cursor: pointer; text-decoration: none; font: inherit; font-size: .68rem; font-weight: 500;
        color: var(--text-muted, #a9b8ac); position: relative; transition: color .2s;
    }
    .ff-bottomnav svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform .25s cubic-bezier(.34, 1.8, .64, 1); }
    .ff-bottomnav .on { color: var(--accent-green, #4CAF50); font-weight: 700; }
    .ff-bottomnav .on svg { transform: translateY(-2px) scale(1.1); filter: drop-shadow(0 0 6px var(--accent-green, #4CAF50)); }
    .ff-bottomnav a:active svg, .ff-bottomnav button:active svg { transform: scale(.88); }
    .ff-bottomnav .ff-badge { position: absolute; top: 6px; left: calc(50% + 6px); margin: 0; }

    .ff-toast-wrap { bottom: calc(var(--ff-bar-h) + var(--ff-safe-b) + 12px); }
    #ffUpsell { bottom: calc(var(--ff-bar-h) + var(--ff-safe-b) + 14px) !important; }

    /* ---- comfortable touch targets, no iOS zoom-on-focus ---- */
    input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select, textarea { font-size: 16px !important; min-height: 44px; }
    button, .btn, [role=button], .g-btn { min-height: 40px; }
    .main-content h2 { font-size: 1.45rem; }

    /* ---- pages whose layout was desktop-only ---- */
    .main-content .card[style*="max-width"], .main-content [style*="max-width:600px"], .main-content [style*="max-width: 400px"], .main-content [style*="max-width:400px"] { max-width: 100% !important; }
    .main-content [style*="1fr 1fr 1fr"] { grid-template-columns: 1fr !important; gap: 0 !important; }   /* tasks: create form */
    .main-content [style*="3fr 1fr"] { grid-template-columns: 1fr !important; }                     /* calendar: grid + add-event card */
    .calendar-grid { gap: .2rem !important; font-size: .78rem; }
    .calendar-header { flex-wrap: wrap; gap: .6rem; }
    .calendar-nav { display: flex; gap: .4rem; flex-wrap: wrap; }
    .task-item { flex-wrap: wrap; gap: .5rem; }
    .task-left { min-width: 0; flex: 1 1 200px; }
    .dashboard-header, .notes-toolbar { flex-wrap: wrap; gap: .6rem; }
    .search-bar { max-width: 100% !important; }
    .shortcut-grid { grid-template-columns: repeat(2, 1fr) !important; }

    /* study groups: let every column shrink to the screen (a plain "1fr" column refuses to shrink below its widest child) */
    .main-content { min-width: 0; max-width: 100%; }
    .g-layout { grid-template-columns: minmax(0, 1fr) !important; }
    .g-layout > *, .g-grid2 > *, .g-friends > *, .lib-grid > * { min-width: 0; }
    .g-grid2, .g-friends, .lib-grid, .aud-people { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)) !important; }
    .g-tabs { flex-wrap: wrap !important; gap: .4rem; }
    .g-tabs button, .g-chip { padding: .5rem .85rem; }
    .g-row[style*="nowrap"] { flex-wrap: wrap !important; }
    .g-in, .g-sel, .g-chatform textarea, .lib-search { min-width: 0 !important; }
    .lib-bar > * { flex: 1 1 100%; }
    .g-head { flex-wrap: wrap; }
    .g-chat { height: min(380px, 55vh); }
    .g-card-title { flex-wrap: wrap; }

    /* tables and code never push the page sideways */
    .main-content pre, .main-content code { white-space: pre-wrap; word-break: break-word; }
}

@media (max-width: 380px) {
    .shortcut-grid { grid-template-columns: 1fr !important; }
    .ff-bottomnav { font-size: .62rem; }
}

@media (prefers-reduced-motion: reduce) {
    .ff-toast { animation: none; }
    .ff-bottomnav svg { transition: none; }
}
