/* OVERALL */
:root {
    --bg-body: #0d0d0f;        
    --bg-sidebar: #141417;    
    --bg-card: #1c1c1f;        
    --border-color: #27272a;  
    --text-main: #f4f4f5;     
    --text-sub: #a1a1aa;      
    --accent: #94BEFF;        
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --header-height: 80px;    
}

* { margin: 0; padding: 0; box-sizing: border-box; }

* { -webkit-tap-highlight-color: transparent; outline: none; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 10px; transition: background 0.3s; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

html, body {
    scrollbar-width: thin;
    scrollbar-color: #3f3f46 var(--bg-body);
    width: 100%; min-height: 100dvh; overflow-x: hidden; overflow-y: auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body); color: var(--text-main); margin: 0;
}

.app-container { display: flex; width: 100%; min-height: 100dvh; overflow: visible; position: relative; }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width); background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 1100; 
    position: fixed; top: 0; left: 0; height: 100dvh;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-header {
    height: var(--header-height); min-height: var(--header-height);      
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; border-bottom: 1px solid var(--border-color); transition: padding 0.3s;
}
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 0; }

.logo-area {
    display: flex; align-items: center; gap: 12px; font-weight: 700; 
    font-size: 20px; letter-spacing: 0.5px; white-space: nowrap; transition: opacity 0.2s;
}
.sidebar.collapsed .logo-area { display: none; }
.logo-icon {
    width: 32px; height: 32px; background: transparent; border: none; border-radius: 8px; 
    display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.main-logo { width: 100%; height: 100%; object-fit: cover; }

.toggle-btn {
    background: transparent; border: none; color: var(--text-sub);
    cursor: pointer; padding: 6px; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.toggle-btn:hover { color: var(--text-main); background: #27272a; }

/* MENU */
.nav-menu { padding: 20px 12px; flex: 1; overflow-y: auto; overflow-x: hidden; }
.nav-group-title { color: var(--text-sub); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; margin: 20px 0 10px 12px; white-space: nowrap; }
.sidebar.collapsed .nav-group-title { display: none; }
.nav-item { display: flex; align-items: center; padding: 8px 12px; color: var(--text-sub); text-decoration: none; border-radius: 8px; margin-bottom: 2px; transition: all 0.2s; cursor: pointer; white-space: nowrap; position: relative; }
.nav-item:hover, .nav-item.active { background-color: rgba(148, 190, 255, 0.1); color: var(--accent); }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; margin-right: 16px; }
.nav-text { transition: opacity 0.2s; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 0; }
.sidebar.collapsed .nav-item svg { margin-right: 0; }
.sidebar.collapsed .nav-text { display: none; }
.nav-item::after { content: attr(data-tooltip); position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%); background-color: var(--text-main); color: var(--bg-body); padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: 0.2s ease; box-shadow: 0 4px 6px rgba(0,0,0,0.3); z-index: 1000; }
.sidebar.collapsed .nav-item:hover::after { opacity: 1; }

.main-content {
    flex: 1; display: flex; flex-direction: column; width: 100%; min-height: 100dvh;
    background-color: var(--bg-body); overflow: visible; position: relative;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
}

/* TOP HEADER */
.top-header {
    height: var(--header-height); min-height: var(--header-height);      
    display: flex; align-items: center; padding: 0 40px; border-bottom: 1px solid var(--border-color);
    background: rgba(13, 13, 15, 0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    position: fixed; top: 0; right: 0; left: var(--sidebar-width); 
    z-index: 1000; transition: left 0.3s ease, width 0.3s ease;
}
.top-header h2 { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; margin: 0; color: var(--text-main); }

/* CENTERING */
@media (min-width: 769px) {
    body:has(.sidebar.collapsed) .main-content {
        margin-left: var(--sidebar-collapsed) !important;
    }
    body:has(.sidebar.collapsed) .top-header,
    body:has(.sidebar.collapsed) .comic-viewer,
    body:has(.sidebar.collapsed) .modal {
        left: var(--sidebar-collapsed) !important;
        width: calc(100vw - var(--sidebar-collapsed)) !important;
    }
}

.mobile-menu-btn { display: none; background: transparent; border: none; color: var(--text-main); margin-right: 16px; cursor: pointer; padding: 4px; font-size: 20px; }

.content-area { padding: 40px; max-width: 1200px; margin: 0 auto; width: 100%; padding-top: calc(var(--header-height) + 20px); }

/* CM VIEWER */
.comic-viewer {
    position: fixed;
    top: var(--header-height); 
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    background: var(--bg-body);
    z-index: 950;
    display: none;
    flex-direction: column;
    transition: left 0.3s ease;
    overflow: hidden;
}
.comic-viewer.active { display: flex; }

.viewer-header {
    height: 50px;
    border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; 
    background: var(--bg-sidebar);
    flex-shrink: 0;
    transition: margin-top 0.2s ease-out;
}
.viewer-header.hide { margin-top: -50px; }

.header-align-container {
    display: flex; 
    align-items: center; 
    gap: 15px;
    width: 100%;
    max-width: 1200px; 
    margin: 0 auto;
    padding: 0 40px;
}

.header-align-container h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.viewer-navigation {
    height: 50px;
    padding: 0 30px;
    border-top: 1px solid var(--border-color);
    display: flex; justify-content: center; align-items: center; gap: 12px;
    background: rgba(20, 20, 23, 0.95);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    transition: margin-bottom 0.2s ease-out;
}
.viewer-navigation.hide { margin-bottom: -50px; }

.comic-pages {
    flex: 1;
    overflow-y: auto;
    display: flex; flex-direction: column; align-items: center;
    padding: 10px 0;
}
.comic-pages img { width: 100%; max-width: 800px; margin-bottom: 5px; display: block; }

.back-btn-nav {
    width: 32px !important; height: 32px !important; 
    min-width: 32px !important; min-height: 32px !important;
    border-radius: 50%; background: var(--accent); color: #000; 
    border: none; cursor: pointer; display: flex; 
    align-items: center; justify-content: center; padding: 0 !important;
    transition: all 0.2s ease; flex-shrink: 0;
}
.back-btn-nav svg { width: 18px !important; height: 18px !important; display: block; }

.viewer-navigation button {
    padding: 5px 14px; font-size: 13px; height: 32px;
    background: var(--accent); border: none; border-radius: 6px;
    color: #000; font-weight: 700; cursor: pointer;
}

#comic-toc {
    background: #27272a; color: white; padding: 5px 10px;
    height: 32px; font-size: 13px; border-radius: 4px;
    border: 1px solid var(--border-color); outline: none;
}

/* === IMG VIEWER === */
.image-viewer { display: none; position: fixed; z-index: 9999;
    left: 0; top: 0; width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.9); backdrop-filter: blur(5px);
    align-items: center; justify-content: center;
}

.image-viewer.show { display: flex; }

.viewer-content { max-width: 95%; max-height: 90vh;
    object-fit: contain; border-radius: 0px; animation: zoomIn 0.3s ease;
}
.close-viewer { position: absolute; top: 20px; right: 30px; color: #fff;
    font-size: 40px; font-weight: bold; cursor: pointer; transition: 0.2s;
}
.close-viewer:hover { color: var(--accent); }
.gallery-img { cursor: pointer; transition: opacity 0.2s; }
.gallery-img:hover { opacity: 0.92; }
@keyframes zoomIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.nav-arrow { position: absolute; top: 50%; transform: translateY(-50%);
    font-size: 40px; color: white; font-weight: bold; cursor: pointer;
    padding: 15px; user-select: none; transition: 0.2s; z-index: 10000;
}

.nav-arrow:hover { color: var(--accent); }
.prev-arrow { left: 20px; }
.next-arrow { right: 20px; }

/* CARD + GRID */
.grid-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 15px; }
.grid-layout > div h2 { font-size: 16px !important; font-weight: 700;}
.card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 8px; padding: 15px; transition: transform 0.2s, border-color 0.2s; cursor: pointer; display: flex; flex-direction: column; }
.card:hover { transform: translateY(-4px); border-color: var(--accent); }
.card-img { width: 100%; height: 320px; object-fit: cover; border-radius: 8px; margin-bottom: 16px; display: block; }
.card-tag { display: inline-block; align-self: flex-start; padding: 4px 10px; background: rgba(255, 255, 255, 0.05); color: var(--text-sub); border-radius: 4px; font-size: 12px; font-weight: 600; margin-bottom: 16px; }
.card-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; line-height: 1.4; }
.card-desc { font-size: 16px; color: var(--text-sub); line-height: 1.6; white-space: pre-line; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 20; -webkit-box-orient: vertical; overflow: hidden; }

.overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); z-index: 1200; opacity: 0; pointer-events: none; transition: opacity 0.3s; }

.modal { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: var(--sidebar-width); 
    width: calc(100vw - var(--sidebar-width)); 
    height: 100vh; 
    background: rgba(0,0,0,0.8); 
    backdrop-filter: blur(4px); 
    z-index: 2000; 
    align-items: center; 
    justify-content: center; 
    padding-bottom: 60px;
    opacity: 0; 
    transition: left 0.3s ease, width 0.3s ease, opacity 0.3s ease; 
}

.modal.show { display: flex; opacity: 1; }

.modal-content { 
    background: var(--bg-card); 
    border: 1px solid var(--border-color); 
    border-radius: 12px; 
    padding: 30px; 
    width: 90%; 
    max-width: 750px; 
    position: relative; 
    max-height: 80vh; 
    margin-top: auto;
    margin-bottom: 40px;
    overflow-y: auto; 
    transform: translateY(30px); 
    transition: transform 0.3s ease; 
    scrollbar-width: thin;
    scrollbar-color: #3f3f46 transparent;
}

.modal-content::-webkit-scrollbar { width: 6px; background: transparent; }
.modal-content::-webkit-scrollbar-track {
    background: transparent !important;
    margin-top: 30px;
    margin-bottom: 30px;
}

.modal-content::-webkit-scrollbar-thumb { background-color: #3f3f46; border-radius: 10px; }

.modal-content::-webkit-scrollbar-thumb:hover { background-color: var(--accent); }

.close-btn { position: absolute; top: 15px; right: 20px; font-size: 28px; color: var(--text-sub); cursor: pointer; }
.close-btn { display: none !important; } /* xấu, thôi ẩn đi */

#modal-img { width: 100%; height: 350px; object-fit: cover; border-radius: 8px; margin-bottom: 20px; }
#modal-name { font-size: 24px; color: var(--accent); margin-bottom: 15px; }
.modal-info-grid { display: grid; grid-template-columns: 120px 1fr; gap: 10px; margin-bottom: 20px; font-size: 14px; }
.info-label { color: var(--text-sub); font-weight: 600; }
.info-value { color: var(--text-main); white-space: pre-line; word-break: break-word; line-height: 1.6; }
.modal-desc { font-size: 14px; line-height: 1.6; color: var(--text-main); padding-top: 15px; border-top: 1px solid var(--border-color); }

/* MOBILE (chỉnh lắm thế cứ tí lại chỉnh chó) */
@media (max-width: 768px) {
    :root { --header-height: 50px; }
    .sidebar-header, .top-header { height: var(--header-height); min-height: var(--header-height); padding: 0 15px; }
    .logo-area { display: flex !important; font-size: 16px; gap: 8px; }
    .logo-icon { width: 24px; height: 24px; }
    .top-header h2 { font-size: 16px; }
    .viewer-header { height: 40px !important; }
    .viewer-header.hide { margin-top: -40px; }
    .header-align-container { padding: 0 20px; gap: 8px; }
    .header-align-container h2 { font-size: 13px !important; }
    .main-content { margin-left: 0; }

    .top-header, .comic-viewer, .modal { left: 0 !important; width: 100vw !important; }

    .modal { height: 100dvh !important; padding-bottom: calc(env(safe-area-inset-bottom) + 15vh) !important; align-items: center; justify-content: center; }
    .modal-content { max-height: 70dvh !important; margin-bottom: 0 !important; width: 90%; scrollbar-width: none !important; }
    .modal-content::-webkit-scrollbar { display: none !important; }
    
    .sidebar .toggle-btn { display: none; }
    .mobile-menu-btn { display: flex; align-items: center; }
    .content-area { padding: 20px; padding-top: calc(var(--header-height) + 10px); }

    .grid-layout { grid-template-columns: 1fr; gap: 16px; }
    .grid-layout.characters-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    .grid-layout.characters-grid .card-img { height: 180px; margin-bottom: 8px; }
    .grid-layout.characters-grid .card-title { font-size: 14px; }
    .grid-layout > div h2 { font-size: 15px !important; }
    
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; z-index: 2100; }
    .sidebar.mobile-open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
    .overlay.mobile-open { opacity: 1; pointer-events: auto; }
}

.grid-layout.characters-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.modal-gallery-container { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.gallery-img { width: 100%; border-radius: 0px; border: none; object-fit: cover; }
.card-desc, .modal-desc { white-space: pre-line; word-break: break-word; }
