/* ==========================================================================
   Mobile-Specific Theme for CAT SKD CPNS
   Compact, Thumb-friendly, and Optimized for Mobile Screens
   ========================================================================== */

@media (max-width: 768px), (pointer: coarse) and (max-width: 1024px) {
    :root {
        --m-header-h: 50px;
        --m-bottom-h: 58px;
    }

    body {
        font-size: 13px !important;
        line-height: 1.45;
        background-color: #f8fafc;
        -webkit-tap-highlight-color: transparent;
        padding-bottom: calc(var(--m-bottom-h) + env(safe-area-inset-bottom, 12px));
    }

    .container, .container-wide {
        padding: 10px;
        width: 100%;
    }

    /* Topbar Mobile */
    .topbar {
        height: var(--m-header-h);
        padding: 0 10px;
    }
    .brand {
        font-size: 13.5px;
        gap: 6px;
    }
    .brand-badge {
        font-size: 10px;
        padding: 2px 6px;
        border-radius: 4px;
    }
    .topbar-nav {
        gap: 6px;
    }
    .topbar-nav .btn {
        padding: 4px 8px;
        font-size: 11px;
    }
    .user-badge span {
        display: none;
    }
    .avatar {
        width: 28px;
        height: 28px;
        font-size: 11.5px;
    }

    /* Hero Box Mobile */
    .hero-box {
        padding: 14px 14px;
        border-radius: 8px;
        margin-bottom: 14px;
    }
    .hero-title {
        font-size: 16px !important;
        margin-bottom: 4px;
    }
    .hero-sub {
        font-size: 11.5px !important;
        margin-bottom: 10px;
        line-height: 1.4;
    }
    .hero-box::after {
        display: none;
    }
    .hero-box > div:last-child {
        gap: 6px !important;
    }
    .hero-box > div:last-child > div {
        padding: 4px 8px !important;
        font-size: 11px !important;
    }

    /* Mode Cards Mobile */
    .grid-cards {
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 18px;
    }
    .exam-mode-card {
        padding: 14px;
        border-radius: 8px;
    }
    .mode-badge {
        font-size: 10px;
        padding: 2px 6px;
        margin-bottom: 6px;
    }
    .mode-title {
        font-size: 14.5px !important;
        margin-bottom: 4px;
    }
    .mode-meta {
        font-size: 11.5px;
        margin-bottom: 10px;
        gap: 8px;
    }
    .exam-mode-card p {
        font-size: 11.5px !important;
        margin-bottom: 12px !important;
        line-height: 1.4;
    }
    .exam-mode-card .btn {
        padding: 9px 14px;
        font-size: 13px;
    }

    /* Stats Grid Mobile */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 18px;
    }
    .stat-item {
        padding: 10px 12px;
        border-radius: 8px;
    }
    .stat-label {
        font-size: 10px;
        letter-spacing: 0.3px;
        margin-bottom: 2px;
    }
    .stat-val {
        font-size: 18px !important;
    }

    /* Headings */
    h1, h2, h3 {
        letter-spacing: -0.2px;
    }
    h2 {
        font-size: 15px !important;
        margin-bottom: 10px !important;
    }

    /* Table to Card View on Mobile */
    .table-wrap {
        border: none;
        background: transparent;
        box-shadow: none;
    }
    .table thead {
        display: none;
    }
    .table, .table tbody, .table tr, .table td {
        display: block;
        width: 100%;
    }
    .table tr {
        background: #ffffff;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        margin-bottom: 10px;
        padding: 12px 14px;
        box-shadow: var(--shadow-sm);
    }
    .table td {
        padding: 4px 0;
        border: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 12px;
    }
    .table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--gray-500);
        font-size: 10.5px;
        text-transform: uppercase;
        margin-right: 10px;
    }
    .table td:last-child {
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px dashed var(--gray-200);
        display: block;
        text-align: right;
    }
    .table td:last-child .btn {
        width: 100%;
        padding: 6px 10px;
        font-size: 12px;
    }

    /* ======================================================================
       CAT EXAM ROOM MOBILE SPECIFICS (COMPACT FONT SIZES)
       ====================================================================== */

    .cat-header {
        height: var(--m-header-h);
        padding: 0 10px;
    }
    .cat-title {
        font-size: 13px;
        gap: 6px;
    }
    .cat-title span:last-child,
    .cat-title span:nth-child(3) {
        display: none;
    }
    
    .timer-box {
        padding: 4px 10px;
        font-size: 14px;
        gap: 4px;
        letter-spacing: 0.5px;
        border-radius: 4px;
    }
    .timer-box span:first-child {
        display: none;
    }

    #btn-finish {
        padding: 5px 9px;
        font-size: 11.5px;
    }

    .cat-container {
        display: block;
        margin: 0;
        padding: 8px 8px calc(var(--m-bottom-h) + 16px);
    }

    .cat-main {
        min-height: auto;
        padding: 14px 12px 18px;
        border-radius: 8px;
        border: 1px solid var(--gray-200);
    }

    .q-header {
        margin-bottom: 12px;
        padding-bottom: 8px;
    }
    .q-number {
        font-size: 14px !important;
        font-weight: 800;
    }
    #q-total-count {
        font-size: 11px !important;
    }
    .q-meta {
        gap: 6px;
    }
    #q-badge-kat {
        font-size: 10px !important;
        padding: 2px 6px !important;
    }
    #q-subkat {
        font-size: 11px !important;
    }

    /* Question Text - Compact, Readable */
    .q-text {
        font-size: 13px !important;
        line-height: 1.5 !important;
        margin-bottom: 14px !important;
        color: #1e293b;
    }

    /* Options List - Compact & Space-saving */
    .options-list {
        gap: 8px;
        margin-bottom: 16px;
    }
    .opt-card {
        padding: 8px 10px;
        border-radius: 6px;
        border-width: 1.5px;
        min-height: 40px;
        gap: 10px;
        touch-action: manipulation;
    }
    .opt-card:active {
        transform: scale(0.98);
        background: #e0f2fe;
    }
    .opt-radio {
        width: 24px;
        height: 24px;
        font-size: 11px;
        font-weight: 800;
        border-width: 1.5px;
    }
    .opt-content {
        font-size: 12.5px !important;
        line-height: 1.4 !important;
        padding-top: 1px;
    }

    /* Figural SVG Responsive on Mobile */
    .fig-q p {
        font-size: 12px;
    }
    .fig-row {
        gap: 6px;
        justify-content: center;
    }
    svg.fig {
        width: 58px;
        height: 58px;
    }
    .fig-sep {
        font-size: 18px;
    }

    /* Hide Desktop Action Bar and Palette Column on Mobile */
    .cat-actions, .palette-card, .cat-container aside {
        display: none !important;
    }

    /* Bottom Floating Action Bar */
    .mobile-bottom-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--m-bottom-h);
        background: #ffffff;
        border-top: 1px solid var(--gray-200);
        box-shadow: 0 -3px 10px rgba(0,0,0,0.06);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 8px calc(env(safe-area-inset-bottom, 0px) / 2);
        z-index: 900;
        gap: 6px;
    }

    .m-btn {
        flex: 1;
        height: 38px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border-radius: 6px;
        border: 1px solid var(--gray-300);
        background: #ffffff;
        color: var(--gray-700);
        font-size: 9.5px;
        font-weight: 700;
        cursor: pointer;
        padding: 2px 2px;
        touch-action: manipulation;
    }
    .m-btn:active {
        transform: scale(0.95);
    }
    .m-btn-icon {
        font-size: 13px;
        line-height: 1;
        margin-bottom: 1px;
    }

    .m-btn.btn-prev {
        max-width: 58px;
    }
    .m-btn.btn-ragu {
        background: #fef3c7;
        border-color: #f59e0b;
        color: #92400e;
        max-width: 68px;
    }
    .m-btn.btn-ragu.active {
        background: #f59e0b;
        color: #ffffff;
    }
    .m-btn.btn-palette-toggle {
        background: var(--primary-light);
        border-color: #bfdbfe;
        color: var(--primary);
        max-width: 82px;
    }
    .m-btn.btn-next {
        flex: 1.4;
        background: var(--primary);
        color: #ffffff;
        border-color: var(--primary);
        font-size: 11.5px;
        flex-direction: row;
        gap: 4px;
    }

    .swipe-hint {
        text-align: center;
        font-size: 10px;
        color: var(--gray-500);
        margin-top: 10px;
        user-select: none;
    }

    /* Bottom Sheet Drawer (Popup Nomor Soal Mobile) */
    .mobile-drawer-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        background: rgba(15, 23, 42, 0.65);
        backdrop-filter: blur(3px);
        -webkit-backdrop-filter: blur(3px);
        z-index: 1000;
        align-items: flex-end;
        justify-content: center;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .mobile-drawer-overlay.open {
        display: flex !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    .mobile-drawer-sheet {
        background: #ffffff;
        width: 100%;
        max-width: 520px;
        max-height: 82vh;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.3);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .mobile-drawer-overlay.open .mobile-drawer-sheet {
        transform: translateY(0) !important;
    }

    .drawer-handle-bar {
        width: 44px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 999px;
        margin: 10px auto 4px;
        flex-shrink: 0;
    }

    .drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 16px 10px;
        border-bottom: 1px solid var(--gray-200);
        flex-shrink: 0;
    }
    .drawer-title {
        font-size: 14px;
        font-weight: 800;
        color: var(--gray-900);
    }
    #mobile-drawer-count {
        font-size: 11px !important;
        color: var(--gray-500);
        font-weight: 600;
    }
    .drawer-close {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        border: 1px solid var(--gray-200);
        background: var(--gray-100);
        color: var(--gray-700);
        font-size: 20px;
        line-height: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        padding: 0;
    }
    .drawer-close:active {
        background: var(--gray-300);
    }

    .drawer-body {
        padding: 12px 14px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
    }

    .drawer-legend {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        background: var(--gray-50);
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        padding: 8px 10px;
        font-size: 10.5px;
        font-weight: 600;
        color: var(--gray-600);
        margin-bottom: 12px;
    }
    .drawer-legend .legend-item {
        display: flex;
        align-items: center;
        gap: 5px;
    }
    .legend-dot {
        width: 9px;
        height: 9px;
        border-radius: 50%;
        display: inline-block;
    }
    .legend-dot.answered { background: var(--success); }
    .legend-dot.ragu { background: var(--warning); }
    .legend-dot.unanswered { background: #cbd5e1; }
    .legend-dot.current { background: var(--primary); }

    .drawer-grid {
        display: grid !important;
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 8px !important;
        padding-bottom: 24px;
    }
    .drawer-grid .palette-btn {
        height: 42px !important;
        font-size: 13px !important;
        font-weight: 700 !important;
        border-radius: 8px !important;
        border: 1.5px solid var(--gray-300) !important;
        background: #ffffff !important;
        color: var(--gray-800) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        cursor: pointer;
        user-select: none;
        touch-action: manipulation;
        transition: transform 0.1s ease;
    }
    .drawer-grid .palette-btn:active {
        transform: scale(0.92);
    }
    .drawer-grid .palette-btn.answered {
        background: var(--success) !important;
        border-color: #059669 !important;
        color: #ffffff !important;
    }
    .drawer-grid .palette-btn.ragu {
        background: var(--warning) !important;
        border-color: #d97706 !important;
        color: #ffffff !important;
    }
    .drawer-grid .palette-btn.current {
        border-color: var(--primary) !important;
        box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.45) !important;
        font-weight: 900 !important;
    }

    /* ======================================================================
       REVIEW PAGE MOBILE SPECIFICS (COMPACT)
       ====================================================================== */
    .review-banner {
        padding: 14px 12px;
        border-radius: 8px;
        margin-bottom: 12px;
    }
    .review-banner h1 {
        font-size: 15px !important;
        margin-bottom: 4px !important;
    }
    .review-banner p {
        font-size: 11px !important;
        line-height: 1.35 !important;
    }
    .review-banner > div:first-child > div:last-child {
        padding: 8px 12px !important;
    }
    .review-banner > div:first-child > div:last-child > div:first-child {
        font-size: 9.5px !important;
    }
    .review-banner > div:first-child > div:last-child > div:nth-child(2) {
        font-size: 26px !important;
    }
    .review-banner > div:first-child > div:last-child > div:last-child {
        font-size: 10px !important;
    }

    /* Score Cards */
    .score-cards-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        margin-bottom: 14px;
    }
    .score-box {
        padding: 10px 12px;
        border-radius: 8px;
    }
    .score-name {
        font-size: 12px;
    }
    .score-pg {
        font-size: 10.5px;
    }
    .score-number {
        font-size: 20px !important;
        margin-bottom: 4px;
    }
    .score-number span {
        font-size: 11px !important;
    }
    .progress-bar-bg {
        height: 5px;
    }
    .score-box > div:last-child {
        font-size: 10.5px !important;
        margin-top: 5px !important;
    }

    /* Summary Bar */
    .container > div[style*="display: flex; gap: 24px;"] {
        padding: 10px 12px !important;
        gap: 12px !important;
        margin-bottom: 14px !important;
    }
    .container > div[style*="display: flex; gap: 24px;"] span {
        font-size: 9.5px !important;
    }
    .container > div[style*="display: flex; gap: 24px;"] div[style*="font-size: 20px;"] {
        font-size: 14px !important;
    }

    /* Subcategory Breakdown */
    details[style*="padding: 18px 24px;"] {
        padding: 12px 14px !important;
        margin-bottom: 16px !important;
    }
    details[style*="padding: 18px 24px;"] summary {
        font-size: 12.5px !important;
    }
    details[style*="padding: 18px 24px;"] > div > div {
        padding: 8px 10px !important;
    }
    details[style*="padding: 18px 24px;"] > div > div span {
        font-size: 11px !important;
    }

    /* Horizontally scrollable filter pills */
    .filter-bar {
        padding: 8px 10px;
        gap: 4px;
        margin: 0 -10px 12px;
    }
    .filter-bar span {
        font-size: 10.5px !important;
        margin-right: 4px !important;
    }
    .filter-btn {
        padding: 4px 9px;
        font-size: 10.5px;
    }

    /* Review Question Card */
    .review-q-card {
        padding: 12px 10px;
        border-radius: 8px;
        margin-bottom: 10px;
    }
    .review-q-card span[style*="font-size: 18px;"] {
        font-size: 13.5px !important;
    }
    .review-q-card span[style*="color: var(--gray-500);"] {
        font-size: 10.5px !important;
    }
    .review-q-card .badge {
        font-size: 10.5px !important;
        padding: 2px 6px !important;
    }
    .review-q-card .q-text {
        font-size: 12.5px !important;
        line-height: 1.45 !important;
        margin-bottom: 12px !important;
    }

    /* Review Options */
    .review-opt {
        padding: 6px 8px;
        border-radius: 4px;
        margin-bottom: 6px;
        font-size: 11.5px !important;
        line-height: 1.35;
    }
    .review-opt span[style*="min-width: 22px;"] {
        min-width: 16px !important;
        font-size: 11.5px;
    }
    .review-opt > div:first-child {
        gap: 6px !important;
    }
    .tag-user-ans, .tag-user-correct {
        font-size: 9.5px !important;
        padding: 1px 5px !important;
    }
    .opt-score-badge {
        font-size: 9.5px !important;
        padding: 1px 5px !important;
    }

    /* Pembahasan Box */
    .pembahasan-box {
        padding: 8px 10px;
        border-radius: 0 4px 4px 0;
        margin-top: 10px;
        font-size: 11.5px !important;
        line-height: 1.45;
    }
    .pembahasan-box > div:first-child {
        font-size: 11.5px !important;
        margin-bottom: 4px !important;
    }

    /* Modal Mobile */
    .modal-box {
        padding: 18px 16px;
        max-width: 90vw;
        border-radius: 12px;
    }
    .modal-box h3 {
        font-size: 15px !important;
        margin-bottom: 8px;
    }
    .modal-box p {
        font-size: 12px !important;
        margin-bottom: 14px;
    }
    .modal-box div[style*="font-size: 24px;"] {
        font-size: 18px !important;
    }
    .modal-box div[style*="font-size: 11px;"] {
        font-size: 9.5px !important;
    }
    .modal-box .btn {
        padding: 6px 12px;
        font-size: 11.5px;
    }

    /* Auth Card Mobile */
    .auth-card {
        padding: 22px 18px;
        border-radius: 12px;
    }
    .brand-lg {
        font-size: 18px;
    }
    .brand-lg .logo {
        font-size: 13px;
        padding: 2px 7px;
    }
    .auth-desc {
        font-size: 11.5px;
        margin-bottom: 16px;
    }
    .form-group {
        margin-bottom: 12px;
    }
    .form-label {
        font-size: 11px;
        margin-bottom: 4px;
    }
    .form-control {
        padding: 8px 10px;
        font-size: 12.5px;
    }
    .auth-card .btn-lg {
        padding: 9px 16px;
        font-size: 13px;
    }

    /* Font Scale Preferences */
    body.font-sm .q-text { font-size: 11.5px !important; line-height: 1.4 !important; }
    body.font-sm .opt-content { font-size: 11px !important; }
    body.font-sm .pembahasan-box { font-size: 10.5px !important; }

    body.font-lg .q-text { font-size: 14.5px !important; line-height: 1.55 !important; }
    body.font-lg .opt-content { font-size: 13.5px !important; }
    body.font-lg .pembahasan-box { font-size: 13px !important; }

    /* Admin Mobile Adjustments (Header cleaned & compact search/filter) */
    .desktop-only {
        display: none !important;
    }

    /* Dashboard User Card Mobile */
    .dashboard-user-card {
        padding: 12px 14px !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        margin-bottom: 14px !important;
        border-radius: 8px !important;
    }
    .user-profile-info {
        gap: 10px !important;
    }
    .avatar-lg {
        width: 36px !important;
        height: 36px !important;
        font-size: 15px !important;
    }
    .user-welcome-label {
        font-size: 11px !important;
    }
    .user-display-name {
        font-size: 14px !important;
    }
    .user-quick-actions {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)) !important;
        gap: 6px !important;
        width: 100% !important;
        padding-top: 8px !important;
        border-top: 1px solid var(--gray-100) !important;
    }
    .action-btn {
        justify-content: center !important;
        padding: 6px 6px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
    }

    /* Mobile Bottom Navigation Bar for Dashboard & History */
    body .mobile-nav-bar,
    body.is-mobile .mobile-nav-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 52px;
        background: #ffffff;
        border-top: 1px solid var(--gray-200);
        box-shadow: 0 -3px 10px rgba(0,0,0,0.06);
        display: flex !important;
        align-items: center;
        justify-content: space-around;
        padding: 0 4px calc(env(safe-area-inset-bottom, 0px) / 2);
        z-index: 900;
    }
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: var(--gray-600);
        text-decoration: none !important;
        font-size: 10px;
        font-weight: 600;
        padding: 4px 0;
        transition: color 0.15s ease;
    }
    .mobile-nav-item.active {
        color: var(--primary);
        font-weight: 800;
    }
    .mobile-nav-icon {
        font-size: 16px;
        line-height: 1;
        margin-bottom: 2px;
    }

    .admin-actions-bar {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        margin-bottom: 14px !important;
        width: 100% !important;
    }
    .admin-actions-bar .btn {
        padding: 6px 10px !important;
        font-size: 11px !important;
    }

    .admin-search-wrap {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 12px !important;
    }
    .admin-search-wrap h2 {
        font-size: 13.5px !important;
        margin-bottom: 6px !important;
    }
    .admin-search-form {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    .admin-search-input-group {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .admin-search-input {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 11.5px !important;
        padding: 5px 8px !important;
        height: 32px !important;
    }
    .admin-search-select {
        flex: 1 !important;
        min-width: 100px !important;
        box-sizing: border-box !important;
        font-size: 11px !important;
        padding: 4px 6px !important;
        height: 32px !important;
    }
    .admin-search-buttons {
        display: flex !important;
        gap: 4px !important;
    }
    .admin-search-buttons .btn {
        padding: 5px 10px !important;
        font-size: 11px !important;
        height: 32px !important;
    }
}

body.is-mobile .mobile-nav-bar {
    display: flex !important;
}

body.is-mobile .mobile-drawer-overlay.open {
    display: flex !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

body.is-mobile .cat-container aside {
    display: none !important;
}


