/* Mobile application shell: drawer, bottom navigation, action sheet. */

:root {
    --sdw-tabbar: 60px;
}

.sdw-menu-btn,
.sdw-bottom-nav,
.sdw-sheet,
.sdw-sheet-backdrop,
.sdw-drawer-backdrop {
    display: none;
}

@media (max-width: 860px) {
    html, body { height: 100%; }
    body { overscroll-behavior-y: contain; }

    .sdw-shell {
        display: block;
        min-height: 100%;
    }

    /* Sidebar becomes an off-canvas drawer instead of a full-screen panel. */
    .sdw-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1200;
        width: min(78vw, 300px);
        height: 100dvh;
        padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
        transform: translateX(-104%);
        transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
        overflow-y: auto;
        border-radius: 0 18px 18px 0;
    }

    body.sdw-drawer-open .sdw-sidebar { transform: translateX(0); }

    .sdw-drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1100;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    body.sdw-drawer-open .sdw-drawer-backdrop { opacity: 1; pointer-events: auto; }

    .sdw-main {
        padding: calc(10px + env(safe-area-inset-top)) 12px calc(var(--sdw-tabbar) + 26px + env(safe-area-inset-bottom));
        min-height: 100dvh;
    }

    .sdw-topbar {
        position: sticky;
        top: 0;
        z-index: 900;
        display: flex;
        align-items: center;
        gap: 10px;
        margin: -6px -12px 10px;
        padding: 8px 12px;
        background: rgba(255, 255, 255, 0.94);
        backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--sdw-border, #e5e7eb);
    }

    .sdw-page-title {
        font-size: 17px;
        line-height: 1.2;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sdw-title-wrap { min-width: 0; flex: 1; }

    .sdw-menu-btn {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        gap: 4px;
        width: 38px;
        height: 38px;
        padding: 0 9px;
        border: 1px solid var(--sdw-border, #e5e7eb);
        border-radius: 10px;
        background: #fff;
    }

    .sdw-menu-btn span {
        display: block;
        height: 2px;
        border-radius: 2px;
        background: #0f172a;
    }

    .sdw-topbar-actions { display: flex; gap: 6px; }

    .sdw-card { padding: 14px; border-radius: 14px; margin-bottom: 12px; }
    .sdw-grid-2, .sdw-grid-3, .sdw-grid-4 { grid-template-columns: 1fr !important; gap: 10px; }
    .sdw-table { font-size: 13px; }
    .sdw-table th, .sdw-table td { padding: 8px 10px; }
    .sdw-card-header { gap: 8px; }

    /* Bottom tab bar */
    .sdw-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        gap: 2px;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.97);
        backdrop-filter: blur(12px);
        border-top: 1px solid var(--sdw-border, #e5e7eb);
    }

    .sdw-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 48px;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: #64748b;
        font-size: 10.5px;
        font-weight: 600;
        text-decoration: none;
        letter-spacing: 0.01em;
    }

    .sdw-tab-icon { font-size: 18px; line-height: 1; }
    .sdw-tab.is-active { color: #2563eb; background: #eef4ff; }
    .sdw-tab:active { background: #e2e8f0; }

    /* Action sheet */
    body.sdw-sheet-open { overflow: hidden; }

    .sdw-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1300;
        background: rgba(15, 23, 42, 0.45);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    body.sdw-sheet-open .sdw-sheet-backdrop { opacity: 1; pointer-events: auto; }

    .sdw-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1400;
        display: block;
        max-height: 82dvh;
        overflow-y: auto;
        padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
        background: #fff;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -12px 32px rgba(15, 23, 42, 0.18);
        transform: translateY(102%);
        transition: transform 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    body.sdw-sheet-open .sdw-sheet { transform: translateY(0); }

    .sdw-sheet-grip {
        width: 44px;
        height: 4px;
        margin: 4px auto 12px;
        border-radius: 4px;
        background: #cbd5e1;
    }

    .sdw-sheet-user { display: flex; align-items: center; gap: 10px; padding: 4px 2px 14px; }
    .sdw-sheet-user strong { display: block; font-size: 15px; }
    .sdw-sheet-user small { color: #64748b; font-size: 12px; }

    .sdw-sheet-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        padding-bottom: 12px;
        border-bottom: 1px solid #eef2f7;
    }

    .sdw-sheet-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        padding: 10px 4px;
        border: 0;
        border-radius: 12px;
        background: #f8fafc;
        color: #0f172a;
        font-size: 11px;
        font-weight: 600;
        text-align: center;
        text-decoration: none;
    }

    .sdw-sheet-item span { font-size: 18px; }
    .sdw-sheet-item:active { background: #e2e8f0; }

    .sdw-sheet-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 0; }
    .sdw-sheet-form { display: flex; flex-direction: column; gap: 6px; }
    .sdw-sheet-form label { font-size: 11px; color: #64748b; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
    .sdw-sheet-logout { padding-top: 10px; border-top: 1px solid #eef2f7; }

    /* iOS zooms the page when a control smaller than 16px receives focus. */
    input, select, textarea, .form-control, .form-select { font-size: 16px !important; }
    .btn-sm { font-size: 13px !important; }

    /* Prevent accidental double-tap zoom while keeping scrolling. */
    button, a, .sdw-tab, .sdw-sheet-item { touch-action: manipulation; }
}

@media (min-width: 861px) {
    .sdw-bottom-nav { display: none !important; }
}

/* Standalone (home screen) mode tweaks */
@media (display-mode: standalone) {
    .sdw-main { padding-top: calc(6px + env(safe-area-inset-top)); }
    .sdw-topbar { top: 0; }
}

/* compact workspace: 44px touch targets, minimal whitespace */
@media (max-width: 860px) {
    .sdw-main { padding: calc(6px + env(safe-area-inset-top)) 10px calc(var(--sdw-tabbar) + 18px + env(safe-area-inset-bottom)); }
    .sdw-topbar { margin: -4px -10px 8px; padding: 6px 10px; }
    .sdw-page-title { font-size: 16px; }
    .sdw-card { padding: 12px; margin-bottom: 10px; border-radius: 12px; }
    .sdw-card-header { margin-bottom: 6px; }
    .sdw-card-title { font-size: 15px; margin: 0; }
    .sdw-form section + section { margin-top: 10px; }
    .form-label { margin-bottom: 4px; font-size: 12.5px; }
    .form-control, .form-select { min-height: 44px; padding: 10px 12px; border-radius: 10px; }
    textarea.form-control { min-height: 84px; }
    .btn { min-height: 44px; padding: 10px 14px; border-radius: 10px; }
    .btn-sm { min-height: 40px; padding: 8px 12px; }
    .sdw-grid-2, .sdw-grid-3, .sdw-grid-4 { gap: 8px; }
    .sdw-table th, .sdw-table td { padding: 8px 8px; }
    .sdw-table { font-size: 12.5px; }
    .alert { padding: 10px 12px; margin-bottom: 10px; font-size: 13px; }
    .sdw-empty { padding: 10px 0; }
    .sdw-nav-link { min-height: 44px; display: flex; align-items: center; padding: 10px 12px; }
    .sdw-sidebar { padding-top: calc(10px + env(safe-area-inset-top)); }
    .sdw-brand { margin-bottom: 8px; }
    .sdw-brand-logo { width: 30px; height: 30px; }
    .sdw-brand small { display: none; }
    .sdw-card .row { --bs-gutter-x: 8px; --bs-gutter-y: 8px; }
    .sdw-card h2.mb-3, .sdw-card h2.mb-2 { margin-bottom: 8px !important; }
    .mt-4 { margin-top: 12px !important; }
    .mt-3 { margin-top: 8px !important; }
    .pagination { margin: 10px 0 0; }
    .sdw-sheet-grid { padding-bottom: 8px; }
    .sdw-sheet-item { min-height: 60px; }
    .sdw-sheet-logout { padding-top: 8px; }
    .sdw-sheet-logout .btn { min-height: 46px; }
}
/* iOS: hint to use the home-screen app (full screen, no Safari toolbar) */
@media (max-width: 860px) {
    .ios-install-hint {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: calc(var(--sdw-tabbar) + 10px + env(safe-area-inset-bottom));
        z-index: 1250;
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 12px;
        border-radius: 14px;
        background: #0f172a;
        color: #e2e8f0;
        font-size: 12.5px;
        line-height: 1.35;
        box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
    }
    .ios-hint-text { flex: 1; }
    .ios-hint-close { border: 0; background: transparent; color: #cbd5e1; font-size: 20px; line-height: 1; padding: 0 2px; }
}
/* Floating menu button (bottom right, above the tab bar) */
.sdw-fab {
    position: fixed;
    right: 14px;
    bottom: calc(var(--sdw-tabbar) + 14px + env(safe-area-inset-bottom));
    z-index: 1150;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 54px;
    height: 54px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #2563eb;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.38);
    color: #fff;
    transition: transform .15s ease, opacity .15s ease;
}
.sdw-fab span { display: block; width: 20px; height: 2px; border-radius: 2px; background: #fff; }
.sdw-fab:active { transform: scale(0.94); }
body.sdw-drawer-open .sdw-fab,
body.sdw-sheet-open .sdw-fab { opacity: 0; pointer-events: none; }

@media (max-width: 860px) {
    .sdw-fab { display: flex; }
    .sdw-main { padding-bottom: calc(var(--sdw-tabbar) + 66px + env(safe-area-inset-bottom)); }
}
/* Menu button positions (personal preference) */
@media (max-width: 860px) {
    .sdw-fab { bottom: calc(16px + env(safe-area-inset-bottom)); right: 14px; top: auto; left: auto; transform: none; }
    body.sdw-menu-bottom-left .sdw-fab { left: 14px; right: auto; }
    body.sdw-menu-bottom-center .sdw-fab { left: 50%; right: auto; transform: translateX(-50%); }
    body.sdw-menu-top-left .sdw-fab,
    body.sdw-menu-top-center .sdw-fab,
    body.sdw-menu-top-right .sdw-fab { top: calc(8px + env(safe-area-inset-top)); bottom: auto; }
    body.sdw-menu-top-left .sdw-fab { left: 14px; right: auto; }
    body.sdw-menu-top-center .sdw-fab { left: 50%; right: auto; transform: translateX(-50%); }
    body.sdw-menu-top-right .sdw-fab { right: 14px; left: auto; }
    .sdw-main { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
}
@media (min-width: 861px) {
    .sdw-fab { display: none !important; }
}

/* Drawer action icons + personalisation */
.sdw-sidebar-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 6px 2px 0; }
.sdw-icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, .28);
    background: #1e293b; color: #e2e8f0; font-size: 15px; text-decoration: none; cursor: pointer;
}
.sdw-icon-btn:hover { border-color: #2563eb; color: #fff; }

.prefs-positions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.prefs-position {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 12px 6px; border: 1px solid var(--sdw-border, #e5e7eb); border-radius: 12px;
    font-size: 12px; cursor: pointer; text-align: center;
}
.prefs-position input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.prefs-position:has(input:checked) { border-color: #2563eb; background: #eff6ff; }
.prefs-position-dot { width: 26px; height: 26px; border-radius: 8px; background: #e2e8f0; }
.prefs-position:has(input:checked) .prefs-position-dot { background: #2563eb; }