/**
 * Theme Variables Configuration
 * Uses CSS variables for dynamic theme switching.
 * Default is Light Mode.
 */
:root {
    /* Light Mode (Default) */
    --primary-color: #7c3aed;      /* Violet 600 */
    --primary-dark: #6d28d9;       /* Violet 700 */
    --primary-light: #8b5cf6;      /* Violet 500 */
    
    --bg-dark: #f8fafc;            /* Slate 50 - Base background */
    --bg-sidebar: #ffffff;         /* White - Sidebar background */
    --bg-card: #ffffff;            /* White - Card/Modal background */
    --bg-editor: #ffffff;          /* White - Editor area background */
    
    --text-primary: #0f172a;       /* Slate 900 - Primary text */
    --text-secondary: #475569;     /* Slate 600 - Secondary text */
    --text-muted: #64748b;         /* Slate 500 - Muted text */
    
    --border-color: #e2e8f0;       /* Slate 200 - Borders */
    
    --success-color: #10b981;      /* Emerald 500 */
    --warning-color: #f59e0b;      /* Amber 500 */
    --danger-color: #ef4444;       /* Red 500 */
    
    --glass-bg: rgba(255, 255, 255, 0.9); /* Glassmorphism background opacity */
    
    /* Layout Dimensions */
    --sidebar-width: 260px;
    --sidebar-collapsed: 70px;
    --right-panel-width: 320px;
    --header-height: 60px;
}

/**
 * Dark Mode Overrides
 * Activated when 'dark' class is present on <html> tag.
 * These variables override the :root variables when in dark mode.
 */
html.dark {
    /* Dark Mode Colors - Adjusted for better contrast */
    --primary-color: #7c3aed;      /* Violet 600 */
    --primary-dark: #5b21b6;       /* Violet 800 */
    --primary-light: #8b5cf6;      /* Violet 500 */
    
    --bg-dark: #0f172a;            /* Slate 900 - Base background */
    --bg-sidebar: #1e293b;         /* Slate 800 - Sidebar background */
    --bg-card: #334155;            /* Slate 700 - Card/Modal background */
    --bg-editor: #0f172a;          /* Slate 900 - Editor area background */
    
    --text-primary: #f8fafc;       /* Slate 50 - Primary text */
    --text-secondary: #cbd5e1;     /* Slate 300 - Secondary text */
    --text-muted: #94a3b8;         /* Slate 400 - Muted text */
    
    --border-color: #475569;       /* Slate 600 - Borders */
    
    --glass-bg: rgba(15, 23, 42, 0.9); /* Darker glass background */
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

/* Scrollbar styles */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.glass-effect {
    background-color: var(--glass-bg);
    backdrop-filter: blur(10px);
}

.logo-text-gradient {
    background: linear-gradient(135deg, var(--primary-color), #c4b5fd);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Layout & Components */
.main-container {
    display: flex;
    height: calc(100vh - var(--header-height));
    margin-top: var(--header-height);
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    overflow-y: auto;
    flex-shrink: 0;
    position: relative;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed);
}

.sidebar-toggle {
    display: flex;
    justify-content: flex-end;
    padding: 15px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s;
}

.sidebar-toggle i {
    transition: transform 0.3s ease;
}

.sidebar.collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

.sidebar-toggle:hover {
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 0 15px 80px;
}

.sidebar-usage {
    position: absolute;
    left: 15px;
    right: 15px;
    bottom: 18px;
    padding: 10px 12px;
    border-radius: 10px;
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

.sidebar-usage-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.sidebar-usage-title {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.sidebar-usage-percent {
    font-size: 11px;
    color: var(--text-muted);
}

.sidebar-usage-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.sidebar-usage-bar {
    width: 100%;
    height: 4px;
    border-radius: 999px;
    background-color: var(--bg-card);
    overflow: hidden;
}

.sidebar-usage-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--primary-light));
}

.nav-section {
    margin-bottom: 25px;
}

.nav-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
    letter-spacing: 1px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 5px;
    color: var(--text-secondary);
    text-decoration: none;
}

.nav-item:hover, .nav-item.active {
    background-color: rgba(124, 58, 237, 0.15);
    color: var(--primary-light);
}

.nav-item i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.nav-item span {
    font-size: 14px;
    font-weight: 500;
}

.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-section h3 {
    display: none;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-outline {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--primary-light);
}

/* Editor Area */
.editor-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-editor);
    overflow: hidden;
}

.editor-toolbar {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.toolbar-btn.active {
    background-color: rgba(124, 58, 237, 0.2);
    color: var(--primary-light);
    border-color: var(--primary-light);
}

.document-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.document-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Noto Serif SC', serif;
}

.document-stats {
    display: flex;
    gap: 15px;
    font-size: 13px;
    color: var(--text-muted);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.editor-area {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.chapter-list {
    width: 220px;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 15px;
    background-color: var(--bg-sidebar);
    flex-shrink: 0;
}

.chapter-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.chapter-list-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.chapter-item {
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.chapter-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.chapter-item.active {
    background-color: rgba(124, 58, 237, 0.15);
    border-left-color: var(--primary-color);
}

.chapter-title {
    font-weight: 500;
    margin-bottom: 5px;
}

.chapter-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

.add-chapter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    border-radius: 8px;
    background-color: rgba(124, 58, 237, 0.1);
    color: var(--primary-light);
    cursor: pointer;
    margin-top: 10px;
    border: 1px dashed var(--primary-light);
    justify-content: center;
    transition: background 0.2s;
}

.add-chapter:hover {
    background-color: rgba(124, 58, 237, 0.2);
}

.text-editor {
    flex: 1;
    padding: 25px 30px;
    overflow-y: auto;
    font-family: 'Noto Serif SC', serif;
    line-height: 1.8;
    background: transparent;
    border: none;
    color: var(--text-primary);
    resize: none;
}

.text-editor:focus {
    outline: none;
}

/* Right Panel */
.right-panel {
    width: var(--right-panel-width);
    background-color: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease;
    flex-shrink: 0;
}

.right-panel.collapsed {
    width: 0;
    border-left: none;
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
}

.panel-tab {
    flex: 1;
    padding: 15px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
    position: relative;
}

.panel-tab:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.03);
}

.panel-tab.active {
    color: var(--primary-light);
}

.panel-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--primary-color);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.panel-section {
    margin-bottom: 25px;
}

.panel-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Components */
.outline-item {
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.outline-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.outline-item.active {
    background-color: rgba(124, 58, 237, 0.15);
    border-left-color: var(--primary-color);
}

.character-card {
    background-color: var(--bg-card);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    border: 1px solid var(--border-color);
}

.character-name {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--primary-light);
}

.character-desc {
    font-size: 14px;
    color: var(--text-secondary);
}

.version-item {
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 10px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
}

.version-item:hover {
    border-color: var(--primary-light);
}

.version-time {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.version-preview {
    font-size: 14px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* AI Chat Styles */
.ai-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ai-chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 90;
}

.ai-chat-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.ai-chat-drawer {
    position: fixed;
    top: var(--header-height);
    right: 0;
    width: 380px;
    height: calc(100vh - var(--header-height));
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-color);
    transform: translateX(100%);
    transition: transform 0.2s;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.ai-chat-drawer.open {
    transform: translateX(0);
}

@media (max-width: 1024px) {
    .ai-chat-drawer {
        width: 100%;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    padding: 12px 15px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
    max-width: 90%;
}

.ai-message {
    background-color: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.2);
    align-self: flex-start;
    color: var(--text-secondary);
}

.user-message {
    background-color: rgba(30, 41, 59, 0.7);
    border: 1px solid var(--border-color);
    align-self: flex-end;
    color: var(--text-primary);
}

.chat-input-area {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-input-area textarea {
    width: 100%;
    padding: 12px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    resize: none;
    height: 80px;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--primary-light);
}

.chat-input-area button {
    align-self: flex-end;
    padding: 8px 20px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.chat-input-area button:hover {
    background-color: var(--primary-dark);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease-out forwards;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .chapter-list {
        position: fixed;
        left: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 90;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.3);
    }
    
    .right-panel {
        position: fixed;
        right: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 90;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
        width: 100%;
        max-width: 320px;
    }
}


