/* ============================================================ */
/* FILE: css/style.css - CORE STYLES                            */
/* Reset, Variables, Layout, Header, Tabs, Panels, Footer, Responsive */
/* ĐÃ SỬA: Xóa stats-bar, thêm search-bar                       */
/* ⭐ V5 (GỘP LISTEN + DICTATION):                              */
/*   - THÊM CSS cho .listen-sub-tabs + .listen-sub-tab-btn      */
/*   - THÊM CSS cho .listen-sub-panel (ẩn/hiện)                 */
/*   - Giữ nguyên toàn bộ CSS cũ 100%                           */
/* ⭐ OPTION A FIX ZOOM MOBILE:                                  */
/*   - body: touch-action + text-size-adjust + tap-highlight    */
/*   - media query cuối file: input/textarea/select font 16px   */
/*     (chặn iOS Safari auto-zoom khi focus input)              */
/* ============================================================ */

/* ===== RESET & ROOT ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --border: #334155;
    --gradient-1: #60a5fa;
    --gradient-2: #a78bfa;
    --folder-indent: 24px;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', 'Inter', 'Roboto', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 1.5rem;
    /* ⭐ OPTION A FIX ZOOM MOBILE: chặn double-tap zoom + iOS text auto-resize + bỏ highlight xanh */
    touch-action: manipulation;                /* Chặn double-tap zoom, vẫn cho scroll/pinch */
    -webkit-text-size-adjust: 100%;            /* Chặn iOS tự resize text khi xoay màn hình */
    -webkit-tap-highlight-color: transparent;  /* Bỏ highlight xanh khi tap trên mobile */
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* ===== HEADER ===== */
.header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 0.5rem;
}

.header h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--gradient-1), var(--gradient-2));
    -webkit-background-clip: text;
    -moz-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.5px;
}

/* ============================================================ */
/* ===== SEARCH BAR - THAY THẾ STATS ===== */
/* ============================================================ */

.search-bar {
    background: var(--bg-secondary);
    border-radius: 28px;
    padding: 0.8rem 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.search-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-container {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
}

.search-icon {
    font-size: 1.2rem;
    color: var(--text-secondary);
    flex-shrink: 0;
}

#searchInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    padding: 0.6rem 0;
    outline: none;
    min-width: 0;
    width: 100%;
}

#searchInput::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.search-clear-btn {
    background: var(--bg-primary);
    border: none;
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.search-clear-btn:hover {
    background: var(--danger);
    color: white;
}

/* ===== SEARCH RESULTS ===== */
.search-results {
    display: none;
    margin-top: 0.6rem;
    border-top: 1px solid var(--border);
    padding-top: 0.6rem;
    max-height: 400px;
    overflow-y: auto;
}

.search-results.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

.search-result-count {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding: 0.2rem 0.4rem;
}

.search-result-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ===== SEARCH RESULT ITEM ===== */
.search-result-item {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 0.8rem 1rem;
    border: 1px solid transparent;
    transition: all 0.15s;
    cursor: pointer;
}

.search-result-item:hover {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

.search-result-item .term-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.search-result-item .term {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--accent);
}

.search-result-item .definition {
    color: var(--text-primary);
    font-size: 0.95rem;
}

.search-result-item .word-type {
    font-size: 0.7rem;
    color: var(--text-secondary);
    background: var(--bg-card);
    padding: 0.1rem 0.6rem;
    border-radius: 20px;
}

.search-result-item .speak-btn-small {
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.1rem 0.6rem;
    border-radius: 20px;
    background: var(--bg-card);
    transition: all 0.2s;
    border: none;
}

.search-result-item .speak-btn-small:hover {
    background: var(--accent);
    color: white;
}

.search-result-item .detail-row {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.3rem;
    padding-left: 0.2rem;
}

.search-result-item .detail-row .label {
    opacity: 0.6;
    margin-right: 0.2rem;
}

.search-result-item .example-text {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.2rem;
    padding-left: 0.2rem;
}

/* ===== TABS ===== */
.tabs {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.tab-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.75rem 1.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 100px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: var(--bg-card);
    color: white;
    transform: translateY(-1px);
}

.tab-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* ===== SUB-TABS ===== */
.sub-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 0.5rem;
}

.sub-tab-btn {
    background: transparent;
    border: none;
    padding: 0.6rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 100px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.sub-tab-btn:hover {
    background: var(--bg-card);
    color: white;
    transform: translateY(-1px);
}

.sub-tab-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* ============================================================ */
/* ⭐ V5: SUB-TABS CHO TAB LISTEN (Vocabulary | Dictation)       */
/* ============================================================ */

#listeningPanel .listen-sub-tabs {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border);
    flex-wrap: wrap;
}

#listeningPanel .listen-sub-tab-btn {
    background: transparent;
    border: none;
    padding: 0.7rem 1.75rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 100px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

#listeningPanel .listen-sub-tab-btn:hover {
    background: var(--bg-card);
    color: white;
    transform: translateY(-1px);
}

#listeningPanel .listen-sub-tab-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Sub-panel ẩn/hiện */
#listeningPanel .listen-sub-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

#listeningPanel .listen-sub-panel.active {
    display: block;
}

/* ============================================================ */
/* ===== LOCALSTORAGE TAB - SUB-PANELS ===== */
/* ============================================================ */

#managePanel .sub-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

#managePanel .sub-panel.active-sub-panel {
    display: block;
}

/* ===== BACKUP SECTION ===== */
.backup-section {
    background: var(--bg-secondary);
    border-radius: 28px;
    padding: 1.5rem 1.8rem;
    margin-bottom: 1.5rem;
    border: 2px dashed var(--accent);
    transition: all 0.3s ease;
}

.backup-section:hover {
    border-style: solid;
    border-color: var(--accent-hover);
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.1);
}

.backup-section h3 {
    margin-top: 0;
    margin-bottom: 0.8rem;
    color: var(--text-primary);
}

.backup-section .backup-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 0.2rem 0.8rem;
    border-radius: 60px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 0.5rem;
}

.backup-section .backup-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-top: 0.5rem;
}

/* ===== SUB-PANELS ===== */
.fb-sub-panel,
.sb-sub-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

.fb-sub-panel.active-sub-panel,
.sb-sub-panel.active-sub-panel {
    display: block;
}

/* ===== MODE PANELS ===== */
.mode-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

.mode-panel.active-panel {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== TAB FILL BLANK & SENTENCE ===== */
.tab-btn[data-tab="fillblank"],
.tab-btn[data-tab="sentence"] {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-color: var(--border);
    box-shadow: none;
}

.tab-btn[data-tab="fillblank"]:hover,
.tab-btn[data-tab="sentence"]:hover {
    background: var(--bg-card);
    color: white;
    border-color: var(--accent);
    transform: translateY(-1px);
}

.tab-btn[data-tab="fillblank"].active,
.tab-btn[data-tab="sentence"].active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.5);
    transform: translateY(0);
}

/* ===== PANELS ===== */
.set-manager,
.batch-import-container,
.single-add,
.quiz-container,
.listening-container,
.match-container {
    background: var(--bg-secondary);
    border-radius: 28px;
    padding: 1.8rem;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    margin-bottom: 1.8rem;
    border: 1px solid var(--border);
}

h3 {
    font-size: 1.3rem;
    margin-bottom: 1.2rem;
    color: var(--text-primary);
    font-weight: 600;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 10px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
    border-radius: 10px;
}

/* ===== FORMAT EXAMPLE ===== */
.format-example {
    background: var(--bg-primary);
    padding: 0.8rem 1rem;
    border-radius: 20px;
    margin-bottom: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-left: 3px solid var(--accent);
}

.format-example code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.75rem;
}

/* ===== NAVIGATION ===== */
.nav-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 0.5rem;
}

#cardCounter {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== MODE SELECTOR ===== */
.mode-selector {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

/* ===== MODE BADGE ===== */
.mode-badge {
    background: var(--warning);
    color: white;
    padding: 0.3rem 1rem;
    border-radius: 60px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
    margin-top: 0.5rem;
}

/* ===== FOOTER ===== */
footer {
    text-align: center;
    margin-top: 2.5rem;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    opacity: 0.6;
    border-top: 1px solid var(--border);
}

/* ============================================================ */
/* ===== RESPONSIVE ===== */
/* ============================================================ */

@media (max-width: 768px) {
    body { padding: 1rem; }
    .tab-btn { padding: 0.5rem 1rem; font-size: 0.7rem; }
    .sub-tab-btn { padding: 0.4rem 1rem; font-size: 0.75rem; }
    .btn { padding: 0.5rem 1rem; font-size: 0.75rem; }
    .btn-mode { padding: 0.4rem 1rem; font-size: 0.7rem; }
    .match-column { min-width: 200px; }
    :root { --folder-indent: 16px; }
    .folder-header { padding: 8px 10px; }
    .set-item-in-folder { padding: 6px 10px 6px 8px; }
    .sub-tabs { gap: 0.3rem; }

    /* ⭐ V5: LISTEN sub-tabs responsive */
    #listeningPanel .listen-sub-tabs {
        gap: 0.3rem;
        margin-bottom: 1.2rem;
    }

    #listeningPanel .listen-sub-tab-btn {
        padding: 0.55rem 1.1rem;
        font-size: 0.8rem;
        flex: 1;
        min-width: 0;
    }

    /* Search bar responsive */
    .search-bar {
        padding: 0.6rem 1rem;
        border-radius: 20px;
    }

    #searchInput {
        font-size: 0.9rem;
        padding: 0.4rem 0;
    }

    .search-clear-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    .search-result-item {
        padding: 0.6rem 0.8rem;
    }

    .search-result-item .term {
        font-size: 0.95rem;
    }

    .search-result-item .definition {
        font-size: 0.85rem;
    }

    .search-results {
        max-height: 300px;
    }

    /* Sentence responsive */
    .sb-question {
        font-size: 1.2rem;
        padding: 0.8rem;
    }
    
    #sbInput {
        font-size: 0.9rem;
        min-height: 60px;
    }
    
    #sbQuestionListContainer .card-item {
        flex-direction: column;
        align-items: stretch;
    }
    
    #sbQuestionListContainer .card-item > div:last-child {
        display: flex;
        gap: 0.5rem;
        margin-top: 0.5rem;
    }
    
    #sbHistoryContainer .history-item {
        flex-direction: column;
        align-items: flex-start;
    }

    #listeningPanel {
        padding: 0.5rem;
    }

    /* Backup section responsive */
    .backup-section {
        padding: 1rem;
    }

    .backup-section .backup-badge {
        font-size: 0.5rem;
        padding: 0.1rem 0.5rem;
    }

    #managePanel .sub-tab-btn {
        padding: 0.4rem 1rem;
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .search-bar {
        padding: 0.5rem 0.8rem;
        border-radius: 16px;
    }

    .search-result-item .term-row {
        flex-wrap: wrap;
    }

    .search-result-item .detail-row {
        font-size: 0.75rem;
    }

    .search-result-item .example-text {
        font-size: 0.75rem;
    }

    /* ⭐ V5: LISTEN sub-tabs responsive nhỏ hơn */
    #listeningPanel .listen-sub-tabs {
        gap: 0.25rem;
        margin-bottom: 1rem;
        padding-bottom: 0.3rem;
    }

    #listeningPanel .listen-sub-tab-btn {
        padding: 0.5rem 0.7rem;
        font-size: 0.72rem;
    }

    .sb-question {
        font-size: 1rem;
        padding: 0.6rem;
    }
    
    #sbInput {
        font-size: 0.8rem;
        min-height: 50px;
        padding: 0.6rem 0.8rem;
    }
    
    .edit-sb-question-btn,
    .delete-sb-question-btn {
        font-size: 0.65rem;
        padding: 0.2rem 0.6rem;
    }

    .backup-section {
        padding: 0.8rem;
    }

    .backup-section h3 {
        font-size: 1rem;
    }

    #managePanel .sub-tab-btn {
        padding: 0.3rem 0.8rem;
        font-size: 0.65rem;
    }
}

/* ============================================================ */
/* ⭐ OPTION A FIX ZOOM MOBILE: CHỐNG ZOOM INPUT TRÊN MOBILE      */
/* Safari iOS tự zoom khi focus input/textarea/select có         */
/* font-size < 16px. Force về 16px trên mobile để chặn.          */
/* !important để override các rule khác từ components.css,       */
/* conversationScript.css, modes.css.                            */
/* Chỉ áp dụng cho max-width: 768px → desktop không bị ảnh hưởng. */
/* ============================================================ */

@media (max-width: 768px) {
    input,
    textarea,
    select {
        font-size: 16px !important;
    }
}