body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    overflow-x: hidden;
}

.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.login-page .card-body {
    padding: clamp(1.5rem, 5vw, 3rem);
}

/* --- App shell: fixed sidebar + main on desktop, off-canvas on mobile --- */
.app-shell {
    min-height: 100vh;
    width: 100%;
}

.sidebar {
    width: 260px;
    min-height: 100vh;
    background: #1a365d;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
}

.sidebar .brand {
    color: #fff;
    font-weight: 700;
    padding: 1.25rem;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.8);
    padding: 0.75rem 1.25rem;
    border-radius: 0.375rem;
    margin: 0.125rem 0.5rem;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.sidebar .nav {
    overflow-y: auto;
    flex: 1;
}

.sidebar-close {
    color: rgba(255, 255, 255, 0.85);
    background: transparent;
    border: 0;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.25rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1035;
}

.main-content {
    margin-left: 260px;
    min-height: 100vh;
    background: #f8f9fa;
    min-width: 0;
    flex: 1;
}

.top-navbar {
    background: #fff;
    border-bottom: 1px solid #dee2e6;
    padding: 0.75rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.top-navbar-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.top-navbar-title h5 {
    margin: 0;
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-navbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem 0.75rem;
}

.page-content {
    padding: clamp(1rem, 3vw, 1.5rem);
}

.stat-card {
    border: none;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.stat-card .stat-value {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
}

.impersonation-banner {
    background: #ffc107;
    color: #000;
    padding: 0.5rem 1rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.impersonation-banner .btn {
    margin-top: 0.35rem;
}

.table-card {
    background: #fff;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.certificate-preview {
    border: 2px solid #dee2e6;
    background: #fff;
    min-height: 500px;
    position: relative;
}

/* Tables: scroll on small screens; action buttons wrap instead of overflowing */
.table-responsive {
    -webkit-overflow-scrolling: touch;
}

.table td .btn,
.table td form {
    margin-bottom: 0.25rem;
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.table-actions .btn-group {
    flex-wrap: wrap;
}

/* Filter/toolbars */
.page-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: stretch;
    justify-content: space-between;
}

.page-toolbar .form-control,
.page-toolbar .form-select,
.page-toolbar .btn {
    min-width: 0;
}

/* Nav tabs scroll on narrow screens (template edit Details / Visual Design) */
.nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.nav-tabs .nav-link {
    white-space: nowrap;
}

/* Modals use nearly full width on phones */
@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-dialog.modal-xl {
        max-width: calc(100% - 1rem);
    }
}

/* Stack Bootstrap columns that only specify md/lg breakpoints */
@media (max-width: 767.98px) {
    .row > [class*='col-md-'],
    .row > [class*='col-lg-'],
    .row > [class*='col-xl-'] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .impersonation-banner .btn {
        display: block;
        width: 100%;
        max-width: 16rem;
        margin: 0.5rem auto 0;
    }

    .top-navbar-actions .text-muted {
        display: none;
    }

    .stat-card .stat-value {
        font-size: 1.75rem;
    }
}

/* Mobile sidebar: off-canvas drawer */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .page-content {
        padding: 1rem;
    }
}
