/* ====================================
   PLUGET TEXT EDITOR — UPDATED CSS
   Light/Dark Themes + Multi-page Tabs
   ==================================== */

/* ==================== DARK THEME (default) ==================== */
:root,
[data-theme="dark"] {
    --background-color: #0a0e27;
    --editor-bg: #1a1f3a;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --toolbar-bg: rgba(26, 31, 58, 0.85);
    --toolbar-border: #2d3458;
    --button-bg: rgba(51, 65, 85, 0.6);
    --button-hover-bg: rgba(71, 85, 105, 0.8);
    --panel-bg: rgba(26, 31, 58, 0.97);
    --panel-border: rgba(76, 110, 245, 0.3);
    --primary-color: #4c6ef5;
    --primary-glow: rgba(76, 110, 245, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --tab-bg: rgba(255,255,255,0.05);
    --tab-active-bg: rgba(76,110,245,0.2);
    --tab-border: rgba(255,255,255,0.1);
    --stats-bg: rgba(0,0,0,0.2);
    --body-bg: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 50%, #0f1729 100%);
    --body-pseudo: radial-gradient(circle at 20% 50%, rgba(76,110,245,0.1) 0%, transparent 50%),
                   radial-gradient(circle at 80% 80%, rgba(139,92,246,0.1) 0%, transparent 50%);
    --card-delete-bg: rgba(239,68,68,0.15);
    --card-delete-color: #f87171;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --shadow-xl: 0 20px 50px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 30px var(--primary-glow);
}

/* ==================== LIGHT THEME ==================== */
[data-theme="light"] {
    --background-color: #f0f4ff;
    --editor-bg: #ffffff;
    --text-color: #1e2235;
    --text-muted: #6b7280;
    --toolbar-bg: rgba(255, 255, 255, 0.92);
    --toolbar-border: #dde3f0;
    --button-bg: rgba(240, 244, 255, 0.9);
    --button-hover-bg: rgba(76, 110, 245, 0.12);
    --panel-bg: rgba(255, 255, 255, 0.98);
    --panel-border: rgba(76, 110, 245, 0.25);
    --primary-color: #4c6ef5;
    --primary-glow: rgba(76, 110, 245, 0.25);
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(76, 110, 245, 0.15);
    --tab-bg: rgba(76,110,245,0.06);
    --tab-active-bg: rgba(76,110,245,0.18);
    --tab-border: rgba(76,110,245,0.2);
    --stats-bg: rgba(76,110,245,0.06);
    --body-bg: linear-gradient(135deg, #e8eeff 0%, #f5f7ff 50%, #eef1ff 100%);
    --body-pseudo: radial-gradient(circle at 20% 50%, rgba(76,110,245,0.06) 0%, transparent 50%),
                   radial-gradient(circle at 80% 80%, rgba(139,92,246,0.05) 0%, transparent 50%);
    --card-delete-bg: rgba(239,68,68,0.08);
    --card-delete-color: #dc2626;
    --shadow-xl: 0 20px 50px rgba(76,110,245,0.12);
    --shadow-glow: 0 0 30px var(--primary-glow);
}

/* ==================== RESET ==================== */
* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    margin: 0;
    background: var(--body-bg);
    background-attachment: fixed;
    color: var(--text-color);
    line-height: 1.6;
    overflow-x: hidden;
    position: relative;
    transition: background 0.3s ease, color 0.3s ease;
}

body::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--body-pseudo);
    pointer-events: none;
    z-index: 0;
}

/* ==================== VIEWS ==================== */
.view { display: none !important; }
.active-view {
    display: block !important;
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* ==================== TOOLBAR ==================== */
.toolbar {
    height: auto;
    min-height: 70px;
    padding: 15px 30px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    gap: 15px;
    transition: background 0.3s ease;
}

.controls, .action-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ==================== BUTTONS ==================== */
button, select, input[type="text"] {
    height: 38px;
    padding: 0 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    background: var(--button-bg);
    backdrop-filter: blur(10px);
    color: var(--text-color);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

button:hover {
    background: var(--button-hover-bg);
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}
button:active { transform: translateY(0); }

/* AI Button */
.ai-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    font-weight: 700;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 20px rgba(118,75,162,0.4); }
    50%       { box-shadow: 0 0 40px rgba(118,75,162,0.8); }
}

/* ==================== TITLE INPUT ==================== */
#document-title-input {
    background: var(--button-bg);
    border: 1px solid var(--glass-border);
    font-weight: 700;
    font-size: 15px;
    width: clamp(180px, 22vw, 360px);
    outline: none;
    transition: all 0.3s ease;
    color: var(--text-color);
}
#document-title-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px var(--primary-glow);
    width: clamp(220px, 30vw, 440px);
}

/* ==================== COLOR PICKER ==================== */
#text-color-picker {
    width: 46px;
    height: 38px;
    padding: 4px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 2px solid var(--glass-border);
    background: var(--glass-bg);
}
#text-color-picker::-webkit-color-swatch { border-radius: 4px; border: none; }

/* ==================== STATS BAR ==================== */
.doc-stats {
    padding: 10px 30px;
    background: var(--stats-bg);
    border-bottom: 1px solid var(--glass-border);
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
    position: sticky;
    top: 70px;
    z-index: 999;
    backdrop-filter: blur(10px);
    transition: background 0.3s ease;
}
.doc-stats strong { color: var(--primary-color); font-weight: 700; }

/* ==================== PAGE TABS ==================== */
.page-tabs-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    background: var(--tab-bg);
    border-bottom: 1px solid var(--tab-border);
    position: sticky;
    top: 108px;
    z-index: 998;
    backdrop-filter: blur(10px);
    overflow-x: auto;
    scrollbar-width: thin;
    transition: background 0.3s ease;
}

.page-tabs {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.page-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--tab-border);
    background: var(--button-bg);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}
.page-tab:hover {
    background: var(--button-hover-bg);
    color: var(--text-color);
    border-color: var(--primary-color);
}
.page-tab.active {
    background: var(--tab-active-bg);
    color: var(--primary-color);
    border-color: var(--primary-color);
    font-weight: 600;
    box-shadow: 0 0 12px var(--primary-glow);
}
.page-tab-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    margin: 0;
    box-shadow: none;
    transition: all 0.2s;
    min-width: 18px;
    height: 18px;
}
.page-tab-delete:hover {
    background: rgba(239,68,68,0.2);
    color: #f87171;
    transform: none;
    box-shadow: none;
}

.add-page-btn {
    flex-shrink: 0;
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #4c6ef5, #667eea);
    border: none;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 4px 12px var(--primary-glow);
}
.add-page-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px var(--primary-glow);
    background: linear-gradient(135deg, #3b5bdb, #4c6ef5);
}

/* ==================== EDITOR CONTAINER ==================== */
.editor-container {
    position: relative;
    width: 100%;
    overflow: hidden;
}

/* ==================== EDITOR ==================== */
.document-editor {
    width: 95%;
    max-width: 900px;
    min-height: 1100px;
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    margin: 40px auto;
    padding: clamp(40px, 8vw, 90px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl), 0 0 40px rgba(76,110,245,0.08);
    outline: none;
    line-height: 1.9;
    word-break: break-word;
    caret-color: var(--primary-color);
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
    color: var(--text-color);
}
.document-editor:focus {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
}

/* ==================== AI PANEL ==================== */
.ai-overlay {
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 2500;
    opacity: 0; visibility: hidden;
    transition: all 0.3s ease;
}
.ai-overlay.active { opacity: 1; visibility: visible; }

.ai-panel {
    position: fixed;
    right: -450px;
    top: 0;
    width: 450px;
    height: 100vh;
    background: var(--panel-bg);
    backdrop-filter: blur(30px);
    border-left: 1px solid var(--glass-border);
    box-shadow: -10px 0 50px rgba(0,0,0,0.3);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.ai-panel.active { right: 0; }

.ai-header {
    padding: 22px 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.ai-header h2 { margin: 0; font-size: 20px; font-weight: 700; color: white; }

.ai-close {
    background: rgba(255,255,255,0.2);
    border: none;
    width: 34px; height: 34px;
    border-radius: 50%;
    cursor: pointer;
    color: white;
    font-size: 16px;
    padding: 0;
    min-width: 34px;
}
.ai-close:hover { background: rgba(255,255,255,0.35); transform: rotate(90deg); }

.ai-language-bar {
    padding: 16px 22px;
    background: rgba(0,0,0,0.15);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.ai-language-bar label { color: var(--text-color); font-weight: 600; font-size: 13px; }

#ai-language-selector {
    flex: 1;
    height: 36px;
    padding: 0 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-size: 13px;
    cursor: pointer;
}
#ai-language-selector:focus { outline: none; border-color: var(--primary-color); }

.ai-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-message {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    max-width: 88%;
    animation: messageSlide 0.3s ease;
    box-shadow: 0 3px 12px rgba(0,0,0,0.15);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    font-size: 14px;
}

@keyframes messageSlide {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: linear-gradient(135deg, #4c6ef5 0%, #667eea 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: var(--radius-md);
    border: none;
}

.ai-wiki-result {
    background: rgba(76,110,245,0.05);
    padding: 14px;
    border-left: 3px solid var(--primary-color);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}
.ai-wiki-result h3 { margin: 0 0 8px 0; color: var(--primary-color); font-size: 16px; }
.ai-wiki-result p { margin: 0 0 12px 0; line-height: 1.6; font-size: 13px; }
.wiki-meta { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--glass-border); }
.wiki-meta a { color: var(--primary-color); text-decoration: none; font-weight: 600; font-size: 13px; }
.wiki-meta small { color: var(--text-muted); font-size: 11px; }

.ai-input-container {
    padding: 16px 18px;
    background: rgba(0,0,0,0.15);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 10px;
}
#ai-input {
    flex: 1;
    height: 46px;
    padding: 0 18px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 23px;
    color: var(--text-color);
    outline: none;
    font-size: 14px;
}
#ai-input:focus { border-color: var(--primary-color); box-shadow: 0 0 15px var(--primary-glow); }
.ai-send-btn {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    min-width: 46px;
}
.ai-send-btn:hover { transform: scale(1.1) rotate(15deg); box-shadow: 0 0 25px rgba(118,75,162,0.5); }

/* ==================== MODAL PANELS ==================== */
.modal-panel, .settings-panel {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    background: var(--panel-bg);
    backdrop-filter: blur(30px);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-xl), var(--shadow-glow);
    z-index: 2000;
    overflow-y: auto;
    display: none;
    color: var(--text-color);
}
.modal-panel h2, .settings-panel h2 {
    margin: 0 0 22px 0;
    font-size: 22px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.modal-panel p { color: var(--text-muted); margin: 0 0 14px 0; }
.modal-panel select, .modal-panel input[type="file"] { width: 100%; margin-bottom: 14px; }
.setting-group { margin-bottom: 18px; }
.setting-group label { display: block; margin-bottom: 6px; color: var(--text-muted); font-weight: 600; font-size: 13px; }
.setting-group input { width: 100%; }
.setting-group small { color: var(--text-muted); font-size: 11px; }

/* PDF progress */
.pdf-progress-bar {
    height: 6px;
    background: var(--glass-border);
    border-radius: 3px;
    overflow: hidden;
}
.pdf-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4c6ef5, #764ba2);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ==================== DASHBOARD ==================== */
.dashboard-header {
    padding: 50px 40px 40px;
    text-align: center;
    background: linear-gradient(135deg, rgba(76,110,245,0.08) 0%, transparent 100%);
}
.dashboard-header h1 {
    margin: 0 0 10px 0;
    font-size: clamp(26px, 5vw, 44px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    padding: 40px;
    max-width: 1600px;
    margin: 0 auto;
}

.document-card {
    background: var(--glass-bg);
    backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 26px;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    color: var(--text-color);
}
.document-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}
.document-card:hover::before { transform: scaleX(1); }
.document-card:hover {
    transform: translateY(-6px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-xl), var(--shadow-glow);
}
.document-card h3 { margin: 0 0 10px 0; font-size: 18px; color: var(--primary-color); }
.document-card p { color: var(--text-muted); line-height: 1.6; margin-bottom: 16px; font-size: 13px; }
.document-card .page-count { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.card-actions { display: flex; justify-content: flex-end; gap: 8px; }
.card-actions button { height: 32px; padding: 0 12px; font-size: 12px; }

/* ==================== TABLE STYLES ==================== */
.document-editor table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
    background: var(--glass-bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
.document-editor table th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px;
    font-weight: 700;
}
.document-editor table td {
    padding: 10px 12px;
    border: 1px solid var(--glass-border);
    color: var(--text-color);
}
.document-editor img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 16px 0;
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.15); }
::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* ==================== SEPARATOR ==================== */
.separator { color: var(--text-muted); margin: 0 3px; font-size: 16px; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .toolbar { justify-content: center; padding: 12px; }
    .document-editor { width: 100%; margin: 0; padding: 22px 14px; border-radius: 0; }
    .ai-panel { width: 100%; right: -100%; }
    .document-grid { grid-template-columns: 1fr; padding: 16px; }
    .page-tabs-bar { top: 100px; }
}