/* ==================== RESPONSIVE DESIGN ==================== */

/* Hamburger Menu Button */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #333;
    padding: 10px;
    margin-right: 10px;
}

/* Sidebar */
.sidebar-left {
    transition: all 0.3s ease;
}

/* ========== TABLET (1024px trở xuống) ========== */
@media (max-width: 1024px) {
    .dashboard-layout {
        flex-direction: column;
        gap: 20px;
    }

    .sidebar-left {
        width: 100%;
    }

    .content-right {
        width: 100%;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ========== MOBILE (768px trở xuống) ========== */
@media (max-width: 768px) {
    /* Show hamburger button */
    .hamburger-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Hide nav buttons on mobile */
    .nav-left .nav-btn {
        display: none;
    }

    body[data-page="home"] #btn-open-guide {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        padding: 0;
        font-size: 0;
    }

    body[data-page="home"] #btn-open-guide i { margin: 0; font-size: 17px; }

    /* Các trang không có sidebar vẫn phải giữ đường điều hướng hoạt động. */
    body:not([data-page="home"]) .hamburger-btn {
        display: none;
    }

    body:not([data-page="home"]) .nav-left .nav-btn {
        display: inline-flex;
        align-items: center;
        padding: 8px 10px;
    }

    body:not([data-page="home"]) .nav-left .nav-btn i { margin: 0; }

    /* Sidebar as overlay */
    .sidebar-left {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        height: 100vh;
        background: white;
        z-index: 1000;
        padding: 20px;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    /* Show sidebar when active */
    .sidebar-left.active {
        transform: translateX(0);
    }

    /* Close button in sidebar */
    .sidebar-close-btn {
        position: absolute;
        top: 15px;
        right: 15px;
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        display: none;
    }

    .sidebar-left.active .sidebar-close-btn {
        display: block;
    }

    /* Main content offset when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }

    /* Overlay backdrop */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Grid on mobile */
    .card-grid {
        grid-template-columns: 1fr;
    }

    .study-set-card {
        margin-bottom: 15px;
    }

    /* Flashcard on mobile */
    .flashcard-container {
        height: 300px;
    }

    /* Buttons on mobile */
    .btn {
        padding: 12px 20px;
        font-size: 14px;
    }

    .icon-btn {
        padding: 8px;
    }

    /* Navigation adjustments */
    .top-nav {
        padding: 12px 15px;
    }

    .nav-left .logo {
        font-size: 20px;
        margin-right: 10px;
    }

    /* Input fields */
    .field-input,
    .input-light {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px;
    }

    /* Section header */
    .section-header {
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 20px;
    }

    .section-header h3 {
        font-size: 18px;
    }

    .section-header .btn {
        width: 100%;
    }
}

@media (max-width: 640px) {
    #main-container { padding: 22px 16px; }
    .top-nav { min-height: 60px; }
    .nav-right { gap: 8px; }
    .nav-left { min-width: 0; }
    .study-header, .create-header { align-items: flex-start; gap: 16px; flex-direction: column; }
    .create-actions { width: 100%; flex-wrap: wrap; gap: 9px; }
    .create-actions .btn { flex: 1; text-align: center; }
    .toggle-wrapper { display: flex; align-items: center; min-height: 40px; }
    .field-grid { grid-template-columns: 1fr; gap: 14px; }
    .vocab-input-card { padding: 18px 16px; gap: 12px; }
    .card-number { font-size: 15px; }
    .flashcard-container { height: min(390px, 54vh); margin-bottom: 20px; }
    .card-face { padding: 24px 20px; border-radius: 18px; }
    .fc-term { font-size: clamp(28px, 9vw, 38px); }
    .fc-def { font-size: clamp(24px, 7vw, 32px); }
    .fc-ex { font-size: 16px; }
    .study-controls { gap: 9px; flex-wrap: wrap; }
    .ctrl-btn { width: 52px; height: 52px; }
    .card-counter { width: 100%; order: 3; }
    .btn-group-srs { width: 100%; gap: 8px; }
    .btn-srs { flex: 1; min-width: 0; width: auto; height: 58px; font-size: 14px; }
    .import-options { align-items: flex-start; gap: 14px; flex-direction: column; }
    .modal-overlay { padding: 12px; }
    .modal-content { padding: 20px; border-radius: 16px; }
    #quiz-options-grid { grid-template-columns: 1fr !important; gap: 12px !important; }
    #quiz-question-box, #quiz-result-area { padding: 30px 20px !important; margin-bottom: 24px !important; }
    #quiz-question-text { font-size: 26px !important; }
    .quiz-nav-progress { position: static; width: auto; transform: none; flex: 1; margin: 0 10px; }.quiz-score-mini { gap: 7px; font-size: 12px; }.quiz-score-mini span:last-child { display: none; }.quiz-context { align-items: flex-start; gap: 10px; flex-direction: column; }.quiz-question-box { padding: 36px 20px 62px; border-radius: 20px; }.quiz-options-grid { gap: 10px; }.quiz-option-btn { min-height: 66px; padding: 14px 48px 14px 16px; border-radius: 13px; font-size: 15px; }.quiz-action-buttons, .quiz-result-actions { flex-direction: column-reverse; }.quiz-action-buttons .btn, .quiz-result-actions .btn { width: 100%; }.quiz-result-area { border-radius: 20px; }.quiz-result-stats { gap: 7px; margin: 22px 0; }
    [data-tooltip]::after, [data-tooltip]::before { display: none; }
    .guide-footer { flex-direction: column-reverse; }.guide-footer .btn { width: 100%; text-align: center; }
}

/* ========== SMALL PHONE (480px trở xuống) ========== */
@media (max-width: 480px) {
    .hamburger-btn {
        font-size: 20px;
        padding: 8px;
    }

    .logo {
        font-size: 18px;
    }

    .top-nav {
        padding: 10px;
    }

    .sidebar-left {
        width: 250px;
    }

    .card-grid {
        gap: 10px;
    }

    .btn {
        padding: 10px 15px;
        font-size: 13px;
    }

    .section-header h3 {
        font-size: 16px;
    }

    .flashcard-container {
        height: 250px;
    }

    .input-light {
        font-size: 15px;
    }

    .stat-box {
        padding: 10px;
    }

    .stat-value {
        font-size: 14px;
    }

    .stat-label {
        font-size: 11px;
    }
}

/* ========== TOUCH-FRIENDLY CONTROLS ========== */
@media (max-width: 768px) {
    /* Increase touch target size */
    .btn,
    .icon-btn,
    .user-avatar,
    .study-set-card {
        min-height: 45px;
    }

    /* Better spacing for touch */
    .vocab-input-card {
        margin-bottom: 15px;
    }

    .flashcard-control-btn {
        padding: 15px 20px;
        min-width: 100px;
    }
}

/* ========== LANDSCAPE MODE ========== */
@media (max-width: 768px) and (orientation: landscape) {
    .flashcard-container {
        height: 250px;
    }

    .sidebar-left {
        height: 100%;
        padding-top: 50px;
    }
}

/* ========== DARK MODE RESPONSIVE ========== */
@media (max-width: 768px) {
    body.dark-mode .sidebar-left {
        background: #1f2937;
        color: #e5e7eb;
    }

    body.dark-mode .sidebar-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}
