/* ==========================================================================
   1. CORE SYSTEM (VARIABLES & FONTS)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@700&display=swap');

:root {
    /* --- COLOR PALETTE --- */
    --primary: #10b981;          /* Emerald 500 */
    --primary-dark: #047857;     
    --primary-light: #ecfdf5;    
    --primary-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
    
    --bg-body: #f1f5f9;          
    --bg-sidebar: rgba(255, 255, 255, 0.95); 
    --bg-paper: #ffffff;
    
    --text-main: #1e293b;        
    --text-muted: #64748b;       
    
    --border: #e2e8f0;
    --radius-md: 12px;
    
    /* --- SHADOWS --- */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-paper: 0 35px 60px -15px rgba(0, 0, 0, 0.15);
    
    --header-height: 72px;
    --sidebar-width: 400px;
}

* { box-sizing: border-box; margin: 0; padding: 0; outline: none; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.6;
    
    /* [QUAN TRỌNG - DESKTOP] */
    height: 100vh; 
    overflow: hidden; /* Khóa cuộn body trên Desktop để dùng cuộn riêng từng vùng */
    -webkit-font-smoothing: antialiased;
}

/* Scrollbar đẹp hơn */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ==========================================================================
   2. HEADER
   ========================================================================== */
.hero {
    height: var(--header-height);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    position: relative; z-index: 100;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.02);
    display: flex; align-items: center;
    width: 100%;
}

.container-narrow {
    width: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.hero h1 {
    font-size: 1.4rem; font-weight: 800;
    color: var(--text-main);
    display: flex; align-items: center; gap: 10px;
    letter-spacing: -0.02em; margin: 0;
    white-space: nowrap;
}
.hero h1 i {
    color: var(--primary); font-size: 1.6rem;
    filter: drop-shadow(0 4px 6px rgba(16, 185, 129, 0.2));
}
.badge {
    background: var(--primary-light); color: var(--primary-dark);
    font-size: 0.65rem; padding: 4px 8px; border-radius: 20px;
    font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    display: inline-block; vertical-align: middle;
}

.actions-header { display: flex; align-items: center; gap: 10px; }

.btn-icon {
    width: 38px; height: 38px;
    border-radius: 50%; border: 1px solid transparent;
    background: transparent; color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; font-size: 1.1rem;
}
.btn-icon:hover { background: white; color: var(--primary); box-shadow: var(--shadow-sm); border-color: var(--border); }

.btn-google {
    background: white; border: 1px solid var(--border);
    padding: 8px 16px; border-radius: 30px;
    font-weight: 600; font-size: 0.85rem; color: var(--text-main);
    display: flex; align-items: center; gap: 8px;
    cursor: pointer; transition: 0.2s; box-shadow: var(--shadow-sm);
}
.btn-google:hover { background: #f8fafc; border-color: #cbd5e1; transform: translateY(-1px); }

#userInfo {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 6px 4px 6px;
    background: white; border: 1px solid var(--border);
    border-radius: 30px; box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}
#userInfo:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
#userAvatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid #f1f5f9; }
#userName { color: var(--text-main); font-weight: 600; font-size: 0.85rem; padding-right: 4px; white-space: nowrap; }
#logoutBtn {
    width: 26px; height: 26px; border-radius: 50%; border: none; background: #f1f5f9;
    color: var(--text-muted); display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: 0.2s; margin-left: 4px;
}
#logoutBtn:hover { background: #fee2e2; color: #ef4444; }

/* ==========================================================================
   3. LAYOUT & SIDEBAR
   ========================================================================== */
.main-layout { 
    display: flex; 
    height: calc(100vh - var(--header-height)); 
    overflow: hidden; /* Desktop: Khóa layout chính để cuộn bên trong */
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid rgba(0,0,0,0.05);
    backdrop-filter: blur(10px);
    display: flex; flex-direction: column;
    padding: 24px;
    
    /* Desktop: Sidebar cuộn độc lập */
    overflow-y: auto; 
    flex-shrink: 0; z-index: 50;
}

.tabs { display: flex; background: #e2e8f0; padding: 4px; border-radius: 14px; margin-bottom: 24px; }
.tab-btn {
    flex: 1; padding: 8px; border: none; background: transparent;
    border-radius: 10px; font-size: 0.85rem; font-weight: 600;
    color: var(--text-muted); cursor: pointer; transition: all 0.25s ease;
}
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { background: white; color: var(--primary-dark); box-shadow: 0 2px 6px rgba(0,0,0,0.05); }

.tab-content { display: none; animation: fadeInSlide 0.4s ease forwards; }
.tab-content.active { display: block; }
@keyframes fadeInSlide { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.step-card { margin-bottom: 24px; }
.step-card h3 {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
    font-weight: 700; color: var(--text-muted); margin-bottom: 12px;
    display: flex; align-items: center; gap: 8px;
}
.step-card h3::before {
    content: ''; width: 6px; height: 6px; background: var(--primary);
    border-radius: 50%; display: inline-block;
}

.inp, .ta, select.inp {
    width: 100%; padding: 12px 14px;
    border: 1px solid #e2e8f0; border-radius: 10px;
    font-size: 0.95rem; font-family: inherit;
    background: white; color: var(--text-main);
    transition: all 0.2s; box-shadow: 0 2px 0 rgba(0,0,0,0.02);
}
.inp:focus, .ta:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }
.ta { resize: vertical; min-height: 100px; line-height: 1.6; }

.btn {
    width: 100%; padding: 12px 16px; border: none; border-radius: 10px;
    cursor: pointer; font-weight: 600; font-size: 0.95rem;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: all 0.3s;
}
.btn.primary { background: var(--primary-gradient); color: white; box-shadow: 0 4px 15px rgba(16, 185, 129, 0.25); }
.btn.primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(16, 185, 129, 0.35); }
.btn.secondary { background: white; border: 2px dashed #cbd5e1; color: var(--text-muted); }
.btn.secondary:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.export-bar { display: flex; gap: 8px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.btn.outline { background: white; border: 1px solid var(--border); color: var(--text-main); flex: 1; min-width: 120px; }
.btn.outline:hover { background: #f8fafc; border-color: var(--text-muted); }
.btn-save { background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important; color: white !important; }

.history-card {
    background: white; border: 1px solid var(--border);
    border-radius: 10px; padding: 14px; margin-bottom: 10px;
    cursor: pointer; transition: all 0.2s;
}
.history-card:hover { border-color: var(--primary); transform: translateX(4px); box-shadow: var(--shadow-sm); }
.history-card h4 { font-weight: 600; color: var(--text-main); margin-bottom: 2px; font-size: 0.9rem; }
.history-card .meta { font-size: 0.75rem; color: var(--text-muted); }

/* ==========================================================================
   4. WORKSPACE & PAPER
   ========================================================================== */
.preview-area {
    flex: 1; 
    background-color: #f8fafc;
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 24px 24px;
    display: flex; flex-direction: column; position: relative;
    overflow: hidden; /* Desktop: Ẩn scroll ngoài để scroll bên trong */
}

.editor-toolbar {
    position: absolute; top: 15px; left: 50%; transform: translateX(-50%);
    background: rgba(255,255,255,0.95); backdrop-filter: blur(8px);
    padding: 6px 12px; border-radius: 100px;
    display: flex; gap: 6px;
    box-shadow: 0 8px 20px -5px rgba(0,0,0,0.1); border: 1px solid rgba(0,0,0,0.05);
    z-index: 40;
    flex-wrap: wrap; justify-content: center; max-width: 90%;
}
.editor-toolbar button {
    width: 32px; height: 32px; border: none; background: transparent;
    border-radius: 50%; color: var(--text-muted); cursor: pointer; transition: 0.2s;
}
.editor-toolbar button:hover { background: #f1f5f9; color: var(--text-main); }
.divider { width: 1px; height: 16px; background: #e2e8f0; align-self: center; margin: 0 4px; }

.scroll-container {
    flex: 1; 
    /* Desktop: Cuộn độc lập bên trong vùng này */
    overflow-y: auto; 
    padding: 70px 20px 40px;
    display: flex; flex-direction: column; align-items: center;
}

.paper {
    width: 210mm; min-height: 297mm;
    background: var(--bg-paper);
    padding: 20mm 20mm;
    margin-bottom: 40px;
    box-shadow: var(--shadow-paper); border-radius: 2px;
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt; line-height: 1.6; color: #111;
    position: relative;
    max-width: 100%; box-sizing: border-box;
}

.paper-header {
    width: calc(100% + 40mm); margin-left: -20mm; margin-top: -20mm; margin-bottom: 24pt;
    padding: 12pt 0;
    background: #f0fdf4; border-bottom: 3px solid var(--primary);
    color: var(--primary-dark);
    text-align: center; font-weight: 700; text-transform: uppercase;
    font-family: 'Inter', sans-serif; font-size: 11pt; letter-spacing: 1px;
}

.doc-title {
    font-family: 'Playfair Display', serif;
    text-align: center; font-size: 22pt; font-weight: 700;
    margin-bottom: 24pt; color: #1e293b;
    border: none; outline: none; line-height: 1.3;
}

.doc-body { text-align: justify; min-height: 400px; }
.doc-body h1, .doc-body h2, .doc-body h3 {
    font-family: 'Playfair Display', serif;
    margin-top: 16pt; margin-bottom: 8pt; color: #0f172a;
}
.doc-body p { margin-bottom: 12pt; }
.doc-body ul, .doc-body ol { margin-left: 20pt; margin-bottom: 12pt; }
.paper table { width: 100%; border-collapse: collapse; margin: 14pt 0; font-size: 11pt; }
.paper th, .paper td { border: 1px solid #333; padding: 6pt; vertical-align: top; }
.paper th { background-color: #f8fafc; font-weight: bold; text-align: center; font-family: 'Inter', sans-serif; }

#assessmentResultContainer { border: 2px solid var(--primary); background: #f0fdf4; overflow: hidden; border-radius: 4px; margin-top: 20px; }
.paper-header.bg-green { background: var(--primary); color: white; width: 100%; margin: 0; padding: 8px; font-size: 10pt; border: none; }
#assessmentResult { padding: 16px; font-family: 'Inter', sans-serif; font-size: 10pt; }

.status-text {
    text-align: center; margin-top: 12px; font-size: 0.85rem;
    color: var(--primary); font-weight: 500; min-height: 20px; font-style: italic;
}
.hidden-section, .hidden { display: none !important; }

.upload-box {
    border: 2px dashed #cbd5e1; border-radius: 10px; padding: 30px 16px;
    text-align: center; background: #f8fafc; color: var(--text-muted);
    cursor: pointer; transition: 0.2s; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.upload-box:hover { border-color: var(--primary); background: var(--primary-light); }
.img-preview { width: 100%; border-radius: 10px; margin-top: 12px; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }

.context-menu {
    position: absolute; background: white; width: 160px;
    border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.12);
    padding: 4px; z-index: 9999; display: none; border: 1px solid rgba(0,0,0,0.05);
}
.menu-item {
    padding: 8px 10px; font-size: 0.85rem; color: var(--text-main);
    cursor: pointer; border-radius: 4px; display: flex; align-items: center; gap: 8px;
}
.menu-item:hover { background: #f1f5f9; color: var(--primary); }
.menu-item.text-red:hover { background: #fef2f2; color: #ef4444; }
.context-menu hr { border-top: 1px solid #f1f5f9; margin: 4px 0; }

/* ==========================================================================
   6. RESPONSIVE SYSTEM (FIX LỖI KHÔNG CUỘN ĐƯỢC)
   ========================================================================== */

/* --- TABLET & MOBILE (Dưới 1024px) --- */
@media (max-width: 1024px) {
    /* MỞ KHÓA CUỘN CHO BODY */
    body {
        height: auto;
        overflow-y: auto;
        overflow-x: hidden; /* Tránh thanh cuộn ngang */
    }

    /* Layout chuyển sang cột dọc, chiều cao tự động */
    .main-layout { 
        flex-direction: column; 
        height: auto; 
        overflow: visible;
    }
    
    /* Header linh hoạt */
    .hero { height: auto; padding: 12px 0; }
    .container-narrow { flex-wrap: wrap; gap: 10px; }
    .hero h1 { flex: 1; min-width: 150px; font-size: 1.2rem; }
    .actions-header { margin-left: auto; }

    /* Sidebar nằm trên, cuộn theo trang */
    .sidebar { 
        width: 100%; 
        border-right: none; 
        border-bottom: 1px solid var(--border);
        padding: 20px;
        overflow: visible;
        height: auto;
    }

    /* Khu vực xem văn bản */
    .preview-area {
        height: auto;
        min-height: auto;
        overflow: visible;
    }
    
    .scroll-container {
        padding: 60px 16px 30px; /* Padding nhỏ hơn cho mobile */
        height: auto;
        overflow: visible;
    }

    /* Paper chuyển sang chế độ tràn viền cho dễ đọc */
    .paper {
        width: 100%; 
        min-height: 500px;
        padding: 20px; /* Giảm lề giấy */
        margin-bottom: 20px;
        box-shadow: none; 
        border: 1px solid #eee;
    }
    
    /* Fix Header giấy */
    .paper-header {
        width: calc(100% + 40px); 
        margin-left: -20px; margin-top: -20px;
    }

    .doc-title { font-size: 1.5rem; }
    .editor-toolbar { width: 90%; top: 10px; padding: 4px 10px; }
}

/* --- SMALL MOBILE (Dưới 480px) --- */
@media (max-width: 480px) {
    .badge { display: none; }
    .btn-google span { display: none; } 
    .btn-google { padding: 8px; border-radius: 50%; width: 38px; height: 38px; justify-content: center; }
    #userName { display: none; }
    
    .export-bar { flex-direction: column; }
    .btn.outline { width: 100%; }
}