/* ============================================================
   mobile.css  —  Mobile-only patches
   Linked AFTER all other CSS so these rules win by source order.
   ============================================================ */

/* ── iOS safe viewport height (address bar fix) ──────────── */
@supports (height: 100dvh) {
    .sidebar,
    .tools-panel {
        height: 100dvh;
        max-height: 100dvh;
    }
}

/* ── Sidebar dark overlay (hidden by default) ────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: 199;
    cursor: pointer;
}

.sidebar-overlay.active {
    display: block;
}

/* ================================================================
   768px — tablets and phones
   ================================================================ */
@media (max-width: 768px) {

    /* ── TOOLS PANEL: hide completely ───────────────────────── */
    .tools-panel {
        display: none !important;
        width: 0 !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    /* ── APP GRID: collapse sidebar + tools columns to 0 ───── */
    .app-container,
    .app-container.sidebar-collapsed {
        grid-template-columns: 0 1fr 0 !important;
    }

    /* ── MAIN CONTENT: span full grid width (sidebar is fixed/out-of-flow,
       so auto-placement would put main-content in the 0px first column) ── */
    .main-content {
        grid-column: 1 / -1;
    }

    /* ── SIDEBAR: off-canvas drawer ────────────────────────── */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: min(86vw, var(--sidebar-width));
        max-width: min(86vw, var(--sidebar-width));
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 200;
        box-shadow: 24px 0 60px rgba(15, 23, 42, 0.18);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        background: rgba(15, 23, 42, 0.42);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    .app-container.sidebar-collapsed .sidebar-header {
        justify-content: flex-start;
    }

    .app-container.sidebar-collapsed .logo-text,
    .app-container.sidebar-collapsed .nav-label,
    .app-container.sidebar-collapsed .nav-item span {
        display: inline;
    }

    .app-container.sidebar-collapsed .nav-label {
        display: block;
    }

    .app-container.sidebar-collapsed .nav-item {
        justify-content: flex-start;
        padding: 10px 12px;
    }

    .sidebar-nav {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    /* ── SIDEBAR: hide the desktop collapse-toggle button ───── */
    .sidebar-toggle {
        display: none !important;
    }

    /* ── MOBILE MENU BUTTON: show hamburger ────────────────── */
    .mobile-menu-btn {
        width: 40px;
        height: 40px;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    .mobile-menu-btn i,
    .mobile-menu-btn svg {
        width: 22px;
        height: 22px;
    }

    /* ── HEADER: tighter padding ─────────────────────────────── */
    .top-header {
        padding: 0 16px;
        gap: 12px;
    }

    .header-left {
        flex: 1;
        min-width: 0;
        gap: 10px;
    }

    .header-right {
        flex-shrink: 0;
        gap: 8px;
        min-width: 0;
    }

    .icon-btn {
        width: 40px;
        height: 40px;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    html[data-theme="light"] #themeToggle .light-icon,
    html[data-theme="dark"] #themeToggle .dark-icon {
        display: none !important;
    }

    .breadcrumb {
        flex: 1;
        min-width: 0;
        padding: 6px 10px;
        gap: 8px;
        font-size: 0.875rem;
    }

    .breadcrumb a {
        max-width: 40%;
    }

    .breadcrumb span {
        flex: 1;
    }

    .breadcrumb a,
    .breadcrumb i,
    .breadcrumb svg,
    .user-trigger > i:last-child {
        display: none !important;
    }

    /* ── GLOBAL SEARCH BAR: hide from header ─────────────────── */
    .header-center {
        display: none !important;
    }

    /* ── USER INFO: hide name/role text, keep avatar ────────── */
    .user-info {
        display: none;
    }

    .user-trigger {
        min-height: 44px;
        padding: 6px 8px;
        gap: 8px;
    }

    .user-dropdown {
        position: fixed;
        top: calc(var(--header-height) + 10px);
        right: 12px;
        width: min(280px, calc(100vw - 24px));
        min-width: 0;
        max-width: calc(100vw - 24px);
        z-index: 1000;
        border-radius: 18px;
    }

    .user-dropdown a {
        min-height: 46px;
        font-size: 0.95rem;
    }

    /* ── PAGE CONTENT: scrollable with tighter padding ──────── */
    .page-content {
        padding: 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ── TOOL MODAL: fullscreen on mobile ──────────────────── */
    .tool-modal {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    /* ── LEGAL / STANDALONE PAGES ────────────────────────────── */
    .legal-container {
        margin: 16px;
        padding: 24px;
    }
}

/* ================================================================
   480px — small phones (iPhone SE, older Android)
   ================================================================ */
@media (max-width: 480px) {

    .sidebar {
        width: min(88vw, var(--sidebar-width));
        max-width: min(88vw, var(--sidebar-width));
    }

    .top-header {
        padding: 0 12px;
    }

    .breadcrumb {
        padding: 6px 8px;
        gap: 6px;
        font-size: 0.8125rem;
    }

    .breadcrumb i,
    .breadcrumb svg {
        width: 12px;
        height: 12px;
    }

    .page-content {
        padding: 12px;
    }

    .legal-container {
        margin: 8px;
        padding: 20px 16px;
    }
}
