/* ============================================
   Top navigation
   ============================================ */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.top-nav {
    background: #212529;
    color: #fff;
    padding: 0.65rem 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    z-index: 100;
}

.nav-brand {
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.1rem;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    color: #dee2e6;
    text-decoration: none;
    padding: 0.5rem 0.85rem;
    border-radius: 0.25rem;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.nav-user {
    margin-left: auto;
    color: #dee2e6;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

/* ============================================
   Toggle checkbox — hidden everywhere
   ============================================ */
.nav-toggle-input {
    display: none;
}

/* ============================================
   Hamburger label — hidden on desktop
   ============================================ */
.hamburger {
    display: none;
    background: transparent;
    border: 1px solid #6c757d;
    border-radius: 0.25rem;
    padding: 0.5rem 0.7rem;
    cursor: pointer;
    margin-left: auto;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    margin: 5px 0;
    background: #fff;
    border-radius: 1px;
}

/* ============================================
   Backdrop — COMPLETELY inert on desktop.
   display:none + pointer-events:none means it
   cannot intercept clicks or be seen on any
   desktop or Android browser.
   ============================================ */
.nav-backdrop {
    display: none;
    pointer-events: none;
}

/* ============================================
   Mobile — everything drawer-related lives here
   ============================================ */
@media (max-width: 768px) {

    /* Show the hamburger */
    .hamburger {
        display: flex;
        align-items: center;
    }

    /* Drawer: off-screen by default */
    .nav-links {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: 280px;
        background: #212529;
        flex-direction: column;
        align-items: stretch;
        padding: 3.5rem 1rem 1.5rem;
        gap: 0;
        transform: translateX(100%);
        transition: transform 0.22s ease-out;
        z-index: 1050;
        box-shadow: -2px 0 12px rgba(0, 0, 0, 0.4);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Nav links inside the drawer */
    .nav-link {
        display: block;
        padding: 0.9rem 1rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 0;
        font-size: 1rem;
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.08);
    }

    .nav-link:last-of-type { border-bottom: 0; }

    .nav-user {
        margin-left: 0;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    .nav-user .me-3 { margin-right: 0 !important; }

    /* Backdrop: covers only the LEFT side so the drawer links
       are always directly tappable with no element above them */
    .nav-backdrop {
        pointer-events: auto;
        position: fixed;
        top: 0;
        left: 0;
        width: calc(100% - 280px);
        height: 100vh;
        background: rgba(0, 0, 0, 0.45);
        z-index: 1040;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        /* Still hidden until checkbox is checked */
        display: none;
    }

    /* CSS toggle: open the drawer */
    .nav-toggle-input:checked ~ .app-shell .nav-links {
        transform: translateX(0);
    }

    /* CSS toggle: show the backdrop */
    .nav-toggle-input:checked ~ .app-shell .nav-backdrop {
        display: block;
    }
}

/* ============================================
   Sortable table headers
   ============================================ */
.col-sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.col-sortable:hover {
    background-color: #f0f0f0;
}

/* ============================================
   Clickable dashboard cards
   ============================================ */
.stat-card-link {
    display: block;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
    color: inherit;
}

.stat-card-link:hover {
    transform: translateY(-2px);
    text-decoration: none;
    color: inherit;
}

.stat-card-link:hover .card { box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important; }

/* ============================================
   Custom modal (Edit User dialog)
   ============================================ */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1060;
}

.modal-custom {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.25);
    z-index: 1070;
    width: 520px;
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}

.modal-custom .modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-custom .modal-header h5 { margin: 0; }

.btn-close-custom {
    background: none;
    border: 0;
    font-size: 1.5rem;
    line-height: 1;
    color: #6c757d;
    cursor: pointer;
    padding: 0 0.5rem;
}

.modal-custom .modal-body {
    padding: 1.25rem;
    overflow-y: auto;
}

.modal-custom .modal-footer {
    padding: 0.75rem 1.25rem;
    border-top: 1px solid #e9ecef;
}

.row-clickable { cursor: pointer; }
.row-clickable:hover { background-color: #f8f9fa; }

/* ============================================
   Footer
   ============================================ */
.app-footer {
    background: #212529;
    color: #6c757d;
    font-size: 0.8rem;
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid #2d3238;
}

.app-footer a {
    color: #6c757d;
    text-decoration: none;
}

.app-footer a:hover { color: #adb5bd; }

.footer-sep { color: #3d4349; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Foldable card header caret (Apps / Subscriptions create forms) */
.fold-caret {
    width: 8px; height: 8px;
    border-right: 2px solid #6c757d;
    border-bottom: 2px solid #6c757d;
    transform: rotate(-45deg);
    transition: transform .18s;
    flex: none;
    margin-left: 2px;
}
.fold-caret.open { transform: rotate(45deg); }

/* Wider custom modal for the subscription edit form */
.modal-custom-wide { max-width: 720px; width: calc(100% - 32px); }
