/* ============================================================
   ADMIN PANEL - RESPONSIVE & DISPLAY FIX
   admin-responsive.css  — loaded on all admin pages
   ============================================================ */

/* ─── Reset & Box Sizing ─── */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }

/* ─── Admin Layout ─── */
.admin-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-alt);
}

/* ─── Sidebar ─── */
.admin-sidebar {
    width: 260px;
    background: var(--primary-dark);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 200;
    transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.admin-sidebar::-webkit-scrollbar { width: 4px; }
.admin-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.sidebar-brand {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: var(--primary-dark);
    z-index: 1;
}
.sidebar-brand-name {
    font-size: 1.05rem;
    font-weight: 800;
    font-family: var(--font-head);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav { padding: 0.5rem 0 2rem; flex: 1; }
.nav-section {
    padding: 0.75rem 1rem 0.3rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.4);
    margin: 0;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    color: rgba(255,255,255,0.72);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    margin: 1px 0.5rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar-item a:hover,
.sidebar-item.active a {
    background: rgba(255,255,255,0.12);
    color: #fff;
}
.sidebar-item.active a {
    background: rgba(255,255,255,0.18);
    font-weight: 600;
}

/* ─── Overlay (mobile) ─── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    backdrop-filter: blur(2px);
}
.sidebar-overlay.show { display: block; }

/* ─── Main Content ─── */
.admin-content {
    margin-left: 260px;
    flex: 1;
    min-width: 0; /* critical: prevents overflow */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ─── Top Bar ─── */
.admin-topbar {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0 1.25rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 1rem;
    flex-shrink: 0;
    box-shadow: 0 1px 0 var(--border);
}

.topbar-left  { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }

#sidebarToggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text);
    padding: 0.35rem 0.55rem;
    line-height: 1;
    flex-shrink: 0;
    transition: background 0.15s;
}
#sidebarToggle:hover { background: var(--bg-alt); }

.topbar-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

/* Admin user avatar in topbar */
.admin-topbar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    transition: background 0.15s;
}
.admin-topbar-user:hover { background: var(--bg-alt); }
.admin-topbar-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
    flex-shrink: 0;
}
.admin-topbar-name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.admin-topbar-role {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ─── Main Area ─── */
.admin-main {
    padding: 1.5rem;
    flex: 1;
    min-width: 0;
    overflow-x: hidden;
}

.admin-page-title {
    font-size: 1.35rem;
    font-weight: 800;
    margin-bottom: 1.25rem;
    color: var(--text);
    line-height: 1.3;
}

/* ─── Cards full-width fix ─── */
.card { max-width: 100%; overflow: hidden; }

/* ─── Table responsive ─── */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
.table { min-width: 500px; }
.table th, .table td {
    white-space: nowrap;
    padding: 0.75rem 1rem;
}
.table td.wrap { white-space: normal; }

/* ─── Form layout fixes ─── */
.form-row { display: grid; gap: 1rem; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ─── Stats Grid ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.stat-value  { font-size: 1.6rem; font-weight: 800; line-height: 1; color: var(--text); }
.stat-label  { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ─── Buttons ─── */
.btn { white-space: nowrap; }

/* ─── Permission badge fix ─── */
.sidebar-item a > span[style*="border-radius:20px"] {
    margin-left: auto;
    flex-shrink: 0;
}

/* ─── Role badge ─── */
.role-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ─── Flash messages ─── */
.admin-flash { padding: 0 1.5rem; margin-top: 1rem; }
.admin-flash .alert { border-radius: 8px; }

/* ─── Topbar notification dot ─── */
.notif-dot {
    position: absolute;
    top: -2px; right: -2px;
    width: 8px; height: 8px;
    background: #dc2626;
    border-radius: 50%;
    border: 2px solid var(--bg);
}

/* ════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ════════════════════════════════════════════ */

/* ── Large desktop (1280px+): show sidebar always ── */
@media (min-width: 1280px) {
    .admin-sidebar { transform: none !important; }
    #sidebarToggle { display: none; }
}

/* ── Medium: sidebar hidden by default, toggle shows ── */
@media (max-width: 1279px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
    .admin-content { margin-left: 0; }
    .admin-main { padding: 1.25rem; }
}

/* ── Tablet ── */
@media (max-width: 900px) {
    .admin-main { padding: 1rem; }
    .form-row-2 { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-topbar-name { display: none; }
}

/* ── Mobile ── */
@media (max-width: 640px) {
    .admin-main { padding: 0.75rem; }
    .admin-topbar { padding: 0 0.75rem; height: 56px; }
    .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Hide non-essential topbar items on small screens */
    .topbar-hide-mobile { display: none !important; }

    /* Stack action buttons */
    .admin-page-title { font-size: 1.1rem; }

    /* Table: allow vertical scroll */
    .table-responsive { max-height: 70vh; }
}

@media (max-width: 420px) {
    .stats-grid { grid-template-columns: 1fr; }
    .admin-main { padding: 0.5rem; }
    .card { border-radius: 8px; }
}

/* ────────────────────────────────────────────
   PAGE-SPECIFIC FIXES
   ──────────────────────────────────────────── */

/* Members page */
.member-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* Blog / Media grid */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}
@media (max-width: 640px) {
    .media-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
}

/* Donations / Certificates split layout */
.split-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 1024px) {
    .split-layout { grid-template-columns: 1fr; }
}

/* Quiz question builder */
.quiz-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 900px) {
    .quiz-layout { grid-template-columns: 1fr; }
}

/* Admin users page */
.admin-users-layout {
    display: grid;
    grid-template-columns: 1fr 460px;
    gap: 1.5rem;
    align-items: start;
}
@media (max-width: 1100px) {
    .admin-users-layout { grid-template-columns: 1fr; }
}

/* Settings / appearance double column */
.settings-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
@media (max-width: 860px) {
    .settings-layout { grid-template-columns: 1fr; }
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.show { display: flex; }
.modal-box {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
@media (max-width: 540px) {
    .modal-box { padding: 1.25rem; }
}

/* Pagination */
.pagination-nav { margin-top: 1.25rem; }
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    list-style: none;
    padding: 0; margin: 0;
}
.page-item .page-link {
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text);
    text-decoration: none;
    background: var(--bg);
    transition: all 0.15s;
    display: block;
}
.page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}
.page-item .page-link:hover:not(.active) { background: var(--bg-alt); }
