:root {
    --primary: #ef4444;
    --primary-dark: #dc2626;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg); color: var(--text); min-height: 100vh; line-height: 1.5;
}

.container { max-width: 1400px; margin: 0 auto; padding: 8px; }

header { text-align: center; padding: 8px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
header h1 {
    font-size: 1.4rem; margin-bottom: 2px;
    background: linear-gradient(135deg, var(--primary), #f97316);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
header p { color: var(--text-muted); font-size: 0.85rem; }

.back-link {
    display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted);
    text-decoration: none; margin-bottom: 8px; font-size: 0.85rem; transition: color 0.2s;
}
.back-link:hover { color: var(--primary); }

.tabs { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; justify-content: center; }
.tab-btn {
    padding: 6px 14px; background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text); border-radius: 6px; cursor: pointer; font-size: 0.85rem; transition: all 0.2s;
}
.tab-btn:hover { border-color: var(--primary); }
.tab-btn.active { background: var(--primary); border-color: var(--primary); }

.tool-section { display: none; }
.tool-section.active { display: block; }

.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; padding: 10px;
}

.drop-zone {
    border: 2px dashed var(--border); border-radius: 8px;
    padding: 16px 12px; text-align: center; cursor: pointer; transition: all 0.2s; margin-bottom: 8px;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background: rgba(239,68,68,0.05); }
.drop-zone-icon { font-size: 1.4rem; margin-bottom: 4px; }
.drop-zone input { display: none; }
.drop-zone p { font-size: 0.85rem; color: var(--text-muted); }

.btn {
    padding: 8px 16px; border: none; border-radius: 6px; font-size: 0.9rem;
    cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; gap: 6px;
}
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #475569; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover { background: #d97706; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.file-info {
    background: var(--bg); padding: 10px 12px; border-radius: 6px;
    margin: 8px 0; font-size: 0.8rem; color: var(--text-muted);
}
.file-info span { color: var(--text); font-weight: 500; }

.muted-center { text-align: center; color: var(--text-muted); padding: 20px; font-size: 0.85rem; }

.input-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.text-input {
    flex: 1; min-width: 200px; padding: 10px 14px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 6px; color: var(--text); font-size: 0.9rem;
}
.text-input:focus { outline: none; border-color: var(--primary); }
.page-input {
    width: 50px; padding: 4px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text); text-align: center; font-size: 0.85rem;
}

/* PDF Viewer */
.pdf-viewer-container { display: flex; gap: 8px; height: calc(100vh - 180px); min-height: 500px; }
.pdf-sidebar {
    width: 100px; background: var(--bg); border-radius: 6px; padding: 4px;
    overflow-y: auto; flex-shrink: 0;
}
.pdf-thumbnail {
    cursor: pointer; margin-bottom: 6px; border: 2px solid transparent;
    border-radius: 3px; transition: border-color 0.2s; position: relative;
}
.pdf-thumbnail:hover, .pdf-thumbnail.active { border-color: var(--primary); }
.pdf-thumbnail canvas { width: 100%; display: block; }
.pdf-thumbnail-label { text-align: center; font-size: 0.7rem; color: var(--text-muted); padding: 2px; }
.pdf-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.pdf-controls {
    display: flex; gap: 6px; align-items: center; padding: 6px 10px;
    background: var(--bg); border-radius: 6px; margin-bottom: 6px; flex-wrap: wrap; font-size: 0.85rem;
}
.pdf-controls select { padding: 4px 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 4px; color: var(--text); font-size: 0.8rem; }
.search-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.search-bar input {
    flex: 1; padding: 6px 12px; background: var(--bg); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 0.85rem;
}
.search-bar input:focus { outline: none; border-color: var(--primary); }
.pdf-canvas-container {
    flex: 1; overflow: auto; background: var(--bg); border-radius: 6px;
    display: flex; flex-direction: column; align-items: center; padding: 12px; gap: 8px;
}
.pdf-canvas-container canvas { box-shadow: 0 2px 12px rgba(0,0,0,0.3); max-width: 100%; }
.view-warning {
    background: rgba(245,158,11,0.1); color: var(--warning); padding: 8px; border-radius: 6px;
    border: 1px solid var(--warning); text-align: center; width: 100%; font-size: 0.8rem;
}
.results-panel {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
    padding: 12px; margin: 8px 0; max-height: 250px; overflow-y: auto;
}
.results-panel h4 { margin: 0 0 8px; font-size: 0.9rem; }
.search-result-item, .bookmark-item {
    padding: 8px 10px; margin: 4px 0; background: var(--bg); border: 1px solid var(--border);
    border-radius: 4px; cursor: pointer; transition: all 0.15s; font-size: 0.8rem;
}
.search-result-item:hover, .bookmark-item:hover { background: var(--primary); color: white; }

/* PDF Editor */
.editor-toolbar {
    display: flex; gap: 8px; align-items: center; padding: 8px 10px;
    background: var(--bg); border-radius: 6px; margin-bottom: 8px; flex-wrap: wrap;
}
.editor-tool-group { display: flex; gap: 4px; align-items: center; font-size: 0.8rem; }
.editor-tool-group label { color: var(--text-muted); font-size: 0.75rem; }
.tool-active { background: var(--primary) !important; color: white !important; }
.color-pick { width: 28px; height: 28px; border: none; cursor: pointer; border-radius: 4px; }
.size-slider { width: 80px; accent-color: var(--primary); }
.editor-canvas-wrap {
    position: relative; background: var(--bg); border-radius: 6px;
    overflow: auto; max-height: 75vh; display: flex; justify-content: center;
}
#editorPdfCanvas { display: block; }
#editorOverlayCanvas {
    position: absolute; top: 0; left: 0; cursor: crosshair;
}
.editor-inline-text {
    position: absolute; background: transparent; border: 1px dashed var(--primary);
    outline: none; color: #000; padding: 2px 4px; min-width: 80px; min-height: 1.5em;
    font-size: 16px; z-index: 10; resize: none; overflow: hidden;
    line-height: 1.3; white-space: pre-wrap; word-wrap: break-word;
}
.editor-inline-text::placeholder { color: rgba(0,0,0,0.3); }

/* PDF Merge */
.pdf-list { min-height: 100px; background: var(--bg); border-radius: 6px; padding: 10px; margin: 12px 0; }
.pdf-item {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 6px; cursor: grab; font-size: 0.85rem;
}
.pdf-item:active { cursor: grabbing; }
.pdf-item.dragging { opacity: 0.5; }
.pdf-item-icon { font-size: 1.3rem; }
.pdf-item-info { flex: 1; }
.pdf-item-name { font-weight: 500; font-size: 0.85rem; }
.pdf-item-meta { font-size: 0.75rem; color: var(--text-muted); }
.pdf-item-remove { background: none; border: none; color: var(--primary); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }
.pdf-item-handle { color: var(--text-muted); font-size: 1rem; }

/* Password */
.password-status {
    padding: 10px 14px; border-radius: 6px; margin: 10px 0;
    display: flex; align-items: center; gap: 10px; font-size: 0.85rem;
}
.password-status.encrypted { background: rgba(245,158,11,0.15); border: 1px solid var(--warning); }
.password-status.unlocked { background: rgba(34,197,94,0.15); border: 1px solid var(--success); }
.password-status.no-password { background: rgba(59,130,246,0.15); border: 1px solid #3b82f6; }

/* EPUB Reader */
.epub-controls {
    display: flex; gap: 8px; align-items: center; margin-bottom: 6px;
    padding: 6px 10px; background: var(--bg); border-radius: 6px; flex-wrap: wrap;
}
.epub-controls select { padding: 4px 8px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 4px; color: var(--text); font-size: 0.8rem; }
.epub-container { display: flex; gap: 8px; height: calc(100vh - 220px); min-height: 400px; }
.epub-toc {
    width: 220px; background: var(--bg); border-radius: 6px; padding: 10px;
    overflow-y: auto; flex-shrink: 0;
}
.epub-toc h3 { margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.toc-item {
    padding: 6px 10px; cursor: pointer; border-radius: 4px;
    margin-bottom: 3px; transition: background 0.2s; font-size: 0.8rem;
}
.toc-item:hover { background: var(--bg-card); }
.toc-item.active { background: var(--primary); }
.toc-item.nested { padding-left: 20px; font-size: 0.75rem; }
.epub-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.epub-content {
    flex: 1; background: #fff; color: #1a1a1a; border-radius: 6px;
    overflow: hidden; position: relative;
}
.epub-content.dark { background: #1e1e1e; color: #e0e0e0; }
.epub-content.sepia { background: #f4ecd8; color: #5c4b37; }
#epub-reader { width: 100%; height: 100%; }
.chapter-progress {
    display: flex; align-items: center; gap: 8px; padding: 6px 10px;
    background: var(--bg); border-radius: 6px; margin-top: 8px;
}
.chapter-progress input[type="range"] { flex: 1; accent-color: var(--primary); }
.chapter-progress span { font-size: 0.75rem; color: var(--text-muted); min-width: 30px; }

/* Loading */
.loading-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8); flex-direction: column; align-items: center;
    justify-content: center; z-index: 1000; display: none;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 40px; height: 40px; border: 3px solid var(--border);
    border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 14px; font-size: 0.95rem; }

/* Responsive */
@media (max-width: 768px) {
    .pdf-viewer-container, .epub-container { flex-direction: column; height: auto; }
    .pdf-sidebar, .epub-toc { width: 100%; max-height: 150px; }
    .pdf-canvas-container, .epub-content { min-height: 50vh; }
    .editor-toolbar { flex-direction: column; }
}

/* Fullscreen mode */
.fullscreen-mode {
    position: fixed !important;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    background: var(--bg);
    padding: 8px;
    border-radius: 0 !important;
    margin: 0 !important;
    max-width: none !important;
}
.fullscreen-mode .pdf-viewer-container,
.fullscreen-mode .epub-container { height: calc(100vh - 80px) !important; }
.fullscreen-mode .epub-content { flex: 1; }
.fullscreen-mode .drop-zone { display: none; }
.fullscreen-exit-btn {
    position: fixed; top: 10px; right: 10px; z-index: 10000;
    padding: 6px 12px; background: var(--primary); color: white;
    border: none; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.fullscreen-exit-btn:hover { background: var(--primary-dark); }
