/* =============================================================
   CWTB Admin Panel — Mobile CSS (rewrite)
   Base width: 380px. Applies to all screens <= 768px.
   ============================================================= */

/* ── Overlay backdrop ── */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}
.mobile-overlay.show {
    display: block;
}

@media (max-width: 768px) {

    /* ── Layout ── */
    html, body { overflow-x: hidden; width: 100%; }

    .admin-body { background: #0d0d16; min-height: 100svh; }

    .admin-layout { display: block; width: 100%; }

    /* ── Sidebar ── */
    .admin-sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 280px;
        height: 100svh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        background: #12121f;
        border-right: 1px solid rgba(59,130,246,0.15);
    }

    .admin-sidebar.open {
        transform: translateX(0);
        box-shadow: 6px 0 32px rgba(0,0,0,0.6);
    }

    .sidebar-header {
        padding: 1.25rem 1rem;
        border-bottom: 1px solid rgba(59,130,246,0.15);
        flex-shrink: 0;
    }

    .sidebar-logo span, .sidebar-logo a {
        font-size: 1rem; font-weight: 700;
        color: #60a5fa; text-decoration: none;
    }

    .sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }

    .sidebar-link {
        display: flex; align-items: center; gap: 0.85rem;
        padding: 0.9rem 1.25rem;
        color: #aaa; text-decoration: none;
        font-size: 0.95rem; font-weight: 500;
        min-height: 52px;
        transition: background 0.15s, color 0.15s;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-link:active, .sidebar-link.active {
        background: rgba(59,130,246,0.1); color: #60a5fa;
    }

    .sidebar-link i { width: 20px; text-align: center; font-size: 1rem; }

    .sidebar-footer {
        padding: 1rem;
        border-top: 1px solid rgba(59,130,246,0.15);
        flex-shrink: 0;
        padding-bottom: max(env(safe-area-inset-bottom,0px), 1rem);
    }

    .admin-user { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; }

    .user-avatar {
        width: 38px; height: 38px; border-radius: 50%;
        background: rgba(59,130,246,0.15);
        display: flex; align-items: center; justify-content: center;
        color: #60a5fa; font-size: 1rem; flex-shrink: 0;
    }

    .user-info { display: flex; flex-direction: column; gap: 2px; }
    .user-name { font-size: 0.9rem; font-weight: 600; color: #fff; display: block; }
    .user-role { font-size: 0.75rem; color: #888; display: block; }
    .settings-icon { color: #888; font-size: 0.8rem; margin-top: 2px; }

    .btn-logout, .sidebar-logout {
        width: 100%; padding: 0.75rem;
        background: rgba(239,68,68,0.15);
        border: 1px solid rgba(239,68,68,0.3);
        border-radius: 8px; color: #ef4444;
        font-size: 0.9rem; font-weight: 600; cursor: pointer;
        display: flex; align-items: center; justify-content: center; gap: 0.5rem;
        min-height: 44px; -webkit-tap-highlight-color: transparent;
    }

    /* ── Sidebar toggle ── */
    .sidebar-toggle {
        display: flex !important;
        position: fixed;
        top: max(env(safe-area-inset-top,0px), 12px);
        left: max(env(safe-area-inset-left,0px), 12px);
        z-index: 1001;
        width: 44px; height: 44px;
        border-radius: 10px;
        align-items: center; justify-content: center;
        font-size: 1.1rem; padding: 0;
        background: #1a1a2e;
        border: 1px solid rgba(59,130,246,0.25);
        color: #60a5fa; cursor: pointer;
        box-shadow: 0 2px 12px rgba(0,0,0,0.5);
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* ── Main content ── */
    .admin-main {
        margin-left: 0 !important;
        width: 100% !important;
        min-height: 100svh;
    }

    /* When top nav is active, let admin-nav.css handle centering */
    .has-admin-nav .admin-main {
        margin-left: auto !important;
        margin-right: auto !important;
        padding: calc(max(env(safe-area-inset-top,0px),0px) + 62px) 20px 32px !important;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    /* ── Page header ── */
    .admin-header { margin-bottom: 1.25rem; }
    .admin-header h1 { font-size: 1.2rem; font-weight: 700; color: #fff; margin: 0 0 4px; }
    .admin-header p { font-size: 0.82rem; color: #888; margin: 0; }

    /* ── Panels / Cards ── */
    .panel, .dashboard-card, .settings-card, .beammp-card, .broadcast-card {
        background: #1a1a2e;
        border: 1px solid rgba(59,130,246,0.15);
        border-radius: 12px;
        margin-bottom: 1rem;
        overflow: hidden;
        width: 100%; box-sizing: border-box;
    }

    .panel-header {
        display: flex; align-items: center; justify-content: space-between;
        padding: 0.9rem 1rem;
        border-bottom: 1px solid rgba(59,130,246,0.12);
        flex-wrap: wrap; gap: 0.5rem;
    }

    .panel-header h3 { font-size: 1rem; font-weight: 600; color: #fff; margin: 0; }
    .panel-body { padding: 1rem; }

    /* ── Buttons ── */
    .btn {
        display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
        padding: 0.7rem 1rem; border-radius: 8px;
        font-size: 0.88rem; font-weight: 600;
        min-height: 44px; border: none; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        text-decoration: none; box-sizing: border-box; white-space: nowrap;
    }

    .btn:active { opacity: 0.8; transform: scale(0.97); }

    .btn-primary  { background: #3b82f6; color: #fff; }
    .btn-secondary { background: rgba(255,255,255,0.1); color: #ccc; border: 1px solid rgba(255,255,255,0.15); }
    .btn-danger   { background: #ef4444; color: #fff; }
    .btn-warning  { background: #f59e0b; color: #000; }
    .btn-success  { background: #22c55e; color: #fff; }
    .btn-sm { padding: 0.5rem 0.75rem; font-size: 0.8rem; min-height: 36px; }

    /* ── Stats grid ── */
    .stats-grid {
        display: grid; grid-template-columns: repeat(2,1fr);
        gap: 0.75rem; margin-bottom: 1rem;
    }

    .stat-card {
        background: #1a1a2e;
        border: 1px solid rgba(59,130,246,0.15);
        border-radius: 12px; padding: 1rem;
        display: flex; flex-direction: column; gap: 0.4rem;
    }

    .stat-value, .stat-number { font-size: 1.6rem; font-weight: 700; color: #60a5fa; line-height: 1; }
    .stat-label { font-size: 0.78rem; color: #888; text-transform: uppercase; letter-spacing: 0.05em; }
    .stat-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1rem; margin-bottom: 0.25rem; }

    /* ── Section headers ── */
    .section-header {
        display: flex; align-items: center; justify-content: space-between;
        flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem;
    }
    .section-header h3 { font-size: 1rem; font-weight: 600; color: #fff; margin: 0; }

    /* ── Forms ── */
    .form-group { margin-bottom: 0.85rem; }

    .form-group label, .form-label {
        display: block; font-size: 0.85rem; font-weight: 600;
        color: #aaa; margin-bottom: 0.4rem;
    }

    .form-group input, .form-group select, .form-group textarea,
    .form-control, input[type="text"], input[type="password"],
    input[type="number"], input[type="email"], select, textarea {
        width: 100%; padding: 0.75rem;
        background: rgba(255,255,255,0.06);
        border: 1px solid rgba(255,255,255,0.12);
        border-radius: 8px; color: #fff;
        font-size: 16px; min-height: 44px;
        box-sizing: border-box;
        -webkit-appearance: none; appearance: none;
    }

    .form-group input:focus, .form-group select:focus,
    .form-group textarea:focus, .form-control:focus {
        outline: none; border-color: rgba(59,130,246,0.5);
    }

    textarea { min-height: 100px; resize: vertical; }

    .form-row { display: flex; flex-direction: column; gap: 0.75rem; }

    .form-actions { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
    .form-actions .btn { width: 100%; }

    /* ── Tables (users page etc.) ── */
    .table-wrapper, .users-table-container {
        width: 100%; overflow-x: auto;
        -webkit-overflow-scrolling: touch; border-radius: 8px;
    }

    .data-table, .users-table, .table-wrapper table {
        width: 100%; min-width: 540px;
        border-collapse: collapse; font-size: 0.82rem;
    }

    .data-table th, .data-table td,
    .table-wrapper table th, .table-wrapper table td {
        padding: 0.6rem 0.65rem; text-align: left;
        white-space: nowrap;
        border-bottom: 1px solid rgba(255,255,255,0.06);
    }

    .data-table th, .table-wrapper table th {
        color: #888; font-size: 0.75rem;
        text-transform: uppercase; letter-spacing: 0.05em;
        font-weight: 600; background: rgba(255,255,255,0.03);
    }

    /* ── Permissions grid ── */
    .permissions-section h4 { font-size: 0.9rem; color: #60a5fa; margin: 0.75rem 0 0.5rem; }
    .permissions-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 0.65rem; }
    .permission-category h5 { font-size: 0.8rem; color: #aaa; margin: 0 0 0.4rem; }
    .permission-item {
        display: flex; align-items: center; gap: 0.4rem;
        font-size: 0.8rem; color: #ccc; cursor: pointer; padding: 0.25rem 0;
    }
    .permission-item input[type="checkbox"] { width: 18px; min-height: unset; flex-shrink: 0; }

    /* ── Settings ── */
    .settings-container { padding: 0; }
    .settings-header {
        display: flex; align-items: flex-start; gap: 0.75rem;
        padding: 1rem; border-bottom: 1px solid rgba(59,130,246,0.12);
    }
    .settings-header i { font-size: 1.4rem; color: #60a5fa; margin-top: 2px; }
    .settings-header h2 { font-size: 1rem; font-weight: 600; color: #fff; margin: 0 0 2px; }
    .settings-header p { font-size: 0.8rem; color: #888; margin: 0; }
    .settings-body { padding: 1rem; }
    .info-item {
        display: flex; justify-content: space-between; align-items: center;
        padding: 0.6rem 0; border-bottom: 1px solid rgba(255,255,255,0.06);
        font-size: 0.88rem;
    }
    .info-item label { color: #888; }
    .info-item span { color: #fff; font-weight: 600; }

    /* ── Quick actions ── */
    .quick-actions { display: flex; flex-direction: column; gap: 0.6rem; }
    .quick-actions .btn { width: 100%; }

    /* ── Activity feed ── */
    .activity-item { display: flex; gap: 0.75rem; padding: 0.65rem 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
    .activity-text { font-size: 0.85rem; color: #ccc; }
    .activity-time { font-size: 0.72rem; color: #666; }

    /* ── Gallery admin ── */
    .gallery-tabs, .gallery-admin-tabs {
        display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none; gap: 0.5rem; padding-bottom: 4px;
        margin-bottom: 1rem; flex-wrap: nowrap;
    }
    .gallery-tabs::-webkit-scrollbar { display: none; }
    .gallery-tab {
        flex: 0 0 auto; padding: 0.6rem 1rem; border-radius: 8px;
        font-size: 0.85rem; font-weight: 600; white-space: nowrap;
        min-height: 40px; -webkit-tap-highlight-color: transparent;
    }
    .gallery-grid, .gallery-admin-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; }

    /* Hide upload tab and tab counters on mobile */
    .gallery-tab[data-tab="upload"] { display: none; }
    .gallery-tab .tab-count { display: none; }
    #galleryUpload { display: none !important; }
    .gallery-item-actions, .gallery-admin-actions { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
    .gallery-item-actions .btn { width: 100%; font-size: 0.82rem; min-height: 38px; }

    /* ── Events admin ── */
    .events-layout, .leaderboard-admin-layout { display: flex; flex-direction: column; gap: 1rem; }
    .leaderboard-form-card { position: static; }

    /* Two separate islands: create form + events list */
    .event-form-card,
    .events-list-card {
        background: #1a1a2e;
        border: 1px solid rgba(59,130,246,0.15);
        border-radius: 12px;
        padding: 1rem;
        overflow: hidden;
    }
    .event-form-card h3 { font-size: 1rem; margin-bottom: 0.75rem; }
    .events-tabs {
        display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: none; gap: 0.5rem; padding-bottom: 4px;
        margin-bottom: 1rem; flex-wrap: nowrap;
    }
    .events-tabs::-webkit-scrollbar { display: none; }
    .events-filters { display: flex; flex-direction: column; gap: 0.6rem; }
    .filter-select { width: 100%; font-size: 16px; min-height: 44px; }
    .event-list-actions { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
    .event-list-actions .btn { width: 100%; min-height: 40px; font-size: 0.82rem; }

    /* Event items inside the list island */
    .events-list { display: flex; flex-direction: column; gap: 0.75rem; }

    /* ── Leaderboard admin ── */
    .leaderboard-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .admin-leaderboard-table { min-width: 460px; font-size: 0.85rem; width: 100%; border-collapse: collapse; }
    .admin-leaderboard-table th, .admin-leaderboard-table td {
        padding: 0.6rem 0.5rem;
        border-bottom: 1px solid rgba(255,255,255,0.06);
        white-space: nowrap;
    }

    /* ── Modals ── */
    .modal {
        position: fixed !important;
        inset: 0 !important;
        z-index: 2000 !important;
        display: none;
        align-items: flex-end !important;
        justify-content: center !important;
        background: rgba(0,0,0,0.75) !important;
        padding: 0 !important;
    }
    .modal.show, .modal.active { display: flex !important; }

    .modal-content {
        width: 100% !important; max-width: 100% !important;
        max-height: 92svh !important; margin: 0 !important;
        border-radius: 20px !important;
        overflow-y: auto !important; -webkit-overflow-scrolling: touch;
        background: #1a1a2e;
        animation: slideUp 0.25s cubic-bezier(0.4,0,0.2,1);
        padding-bottom: max(env(safe-area-inset-bottom,0px), 1rem) !important;
    }

    @keyframes slideUp {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    .modal-content::before {
        display: none;
    }

    .modal-header {
        display: flex; align-items: center; justify-content: space-between;
        padding: 1rem 1.25rem 0.75rem;
        border-bottom: none;
        position: sticky; top: 0; background: #1a1a2e;
        z-index: 2; border-radius: 20px 20px 0 0;  /* top corners match modal */
    }
    .modal-header h3, .modal-header h2 { font-size: 1rem; font-weight: 600; color: #fff; margin: 0; }

    .modal-close {
        width: 36px; height: 36px; border-radius: 50%;
        border: none; background: rgba(255,255,255,0.08);
        color: #aaa; font-size: 1rem; cursor: pointer;
        display: flex; align-items: center; justify-content: center;
        -webkit-tap-highlight-color: transparent; flex-shrink: 0;
    }

    .modal-body { padding: 1rem 1.25rem; }
    .modal-body input, .modal-body select, .modal-body textarea { font-size: 16px; min-height: 44px; }

    .modal-footer { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.75rem 1.25rem 1.25rem; }
    .modal-footer .btn { width: 100%; min-height: 46px; }

    /* ── Login ── */
    .login-container {
        min-height: 100svh; display: flex; align-items: center; justify-content: center;
        padding: max(env(safe-area-inset-top,0px), 1.5rem) 1rem max(env(safe-area-inset-bottom,0px), 1.5rem);
        box-sizing: border-box;
    }
    .login-card {
        width: 100%; max-width: 380px;
        background: #1a1a2e;
        border: 1px solid rgba(59,130,246,0.18);
        border-radius: 16px; padding: 2rem 1.5rem; box-sizing: border-box;
    }
    .login-header { text-align: center; margin-bottom: 1.5rem; }
    .login-header h2 { font-size: 1.5rem; color: #fff; margin: 0 0 4px; }
    .login-header p { font-size: 0.85rem; color: #888; }
    .login-form { display: flex; flex-direction: column; gap: 1rem; }
    .login-form .btn { width: 100%; min-height: 48px; font-size: 1rem; margin-top: 0.25rem; }

    /* ── Toast ── */
    .toast {
        position: fixed;
        left: 1rem; right: 1rem;
        bottom: max(calc(env(safe-area-inset-bottom,0px) + 0.75rem), 1rem);
        top: auto; max-width: none; z-index: 3000;
        border-radius: 10px; font-size: 0.9rem; padding: 0.85rem 1rem;
        transform: translateY(120px); transition: transform 0.25s ease;
    }
    .toast.show { transform: translateY(0); }

    /* ── Role badges ── */
    .role-badge { font-size: 0.7rem; padding: 3px 8px; border-radius: 4px; font-weight: 700; text-transform: uppercase; }

    /* ── Empty states ── */
    .empty-state {
        display: flex; flex-direction: column; align-items: center;
        justify-content: center; padding: 2rem 1rem; gap: 0.75rem; color: #555;
    }
    .empty-state i { font-size: 2.5rem; }
    .empty-state p { font-size: 0.9rem; text-align: center; margin: 0; }

    /* ── Messages ── */
    .message { padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.88rem; display: none; }
    .message.success { display: block; background: rgba(34,197,94,0.15); border: 1px solid rgba(34,197,94,0.3); color: #22c55e; }
    .message.error   { display: block; background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3); color: #ef4444; }

}

/* ── <= 360px ── */
@media (max-width: 360px) {
    .admin-main { padding-left: 14px !important; padding-right: 14px !important; }
    .stats-grid { grid-template-columns: 1fr; }
    .permissions-grid { grid-template-columns: 1fr; }
    .gallery-grid, .gallery-admin-grid { grid-template-columns: 1fr; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .admin-sidebar, .modal-content, .toast { transition: none !important; animation: none !important; }
}
