/* ═══════════════════════════════════════════════════════════
   📚 Personal Encyclopedia — Stylesheet
   ═══════════════════════════════════════════════════════════ */

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

:root {
    --bg: #0f0f23; --bg2: #1a1a3e; --bg3: #252550;
    --text: #e2e8f0; --text2: #94a3b8;
    --accent: #818cf8; --accent2: #6366f1;
    --border: #2d3250; --danger: #ef4444; --success: #10b981;
    --radius: 12px; --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

/* ═══ Header ═══ */
.header {
    background: linear-gradient(135deg, var(--bg2), var(--bg3));
    border-bottom: 1px solid var(--border);
    padding: 32px 24px 24px; text-align: center;
}
.header h1 {
    font-size: 28px; font-weight: 700; margin-bottom: 4px;
    background: linear-gradient(135deg, var(--accent), #c084fc);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.header p { color: var(--text2); font-size: 14px; margin-bottom: 20px; }
.auth-bar {
    display: flex; justify-content: center; align-items: center; gap: 10px;
    margin-top: 12px; font-size: 13px;
}
.auth-bar .logged-in { color: var(--success); }
.auth-bar button {
    padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px;
    background: none; color: var(--text2); font-size: 12px; cursor: pointer;
}
.auth-bar button:hover { border-color: var(--accent); color: var(--accent); }

/* ═══ Search Box ═══ */
.search-box { max-width: 680px; margin: 0 auto; position: relative; }
.search-box input {
    width: 100%; padding: 14px 50px 14px 20px;
    border: 2px solid var(--border); border-radius: 50px;
    background: var(--bg); color: var(--text); font-size: 16px; outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.2); }
.search-box input::placeholder { color: var(--text2); }
.search-box .search-icon {
    position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
    font-size: 20px; color: var(--text2); pointer-events: none;
}

/* ═══ Layout ═══ */
.container {
    max-width: 1200px; margin: 0 auto; padding: 24px;
    display: grid; grid-template-columns: 300px 1fr; gap: 24px;
}
@media (max-width: 860px) {
    .container { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .sidebar.show { display: block; position: fixed; inset: 0; z-index: 100; background: var(--bg2); padding: 24px; overflow-y: auto; }
}

/* ═══ Filter Panel (Sidebar) ═══ */
.sidebar { position: sticky; top: 24px; height: fit-content; }
.filter-panel {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
}
.filter-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; cursor: pointer; user-select: none;
    transition: background 0.15s;
}
.filter-header:hover { background: var(--bg3); }
.filter-header h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--text2); }
.filter-header .toggle-icon { font-size: 10px; color: var(--text2); transition: transform 0.25s; }
.filter-header .toggle-icon.open { transform: rotate(180deg); }
.filter-body { max-height: 0; overflow: hidden; transition: max-height 0.3s ease, padding 0.3s ease; }
.filter-body.open { max-height: 600px; padding: 0 0 12px; }

/* Filter search */
.filter-search { padding: 0 12px; margin-bottom: 8px; position: relative; }
.filter-search::before {
    content: '🔍'; position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
    font-size: 11px; pointer-events: none;
}
.filter-search input {
    width: 100%; padding: 8px 12px 8px 32px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-size: 13px; outline: none;
}
.filter-search input:focus { border-color: var(--accent); }
.filter-search input::placeholder { color: var(--text2); }

/* Active filter badge */
.active-filter { padding: 10px 12px; display: flex; align-items: center; gap: 8px; }
.active-filter-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600; color: white;
    cursor: pointer; transition: filter 0.15s;
}
.active-filter-badge:hover { filter: brightness(1.2); }

/* Tree */
.filter-tree { list-style: none; max-height: 320px; overflow-y: auto; padding: 0 8px; }
.filter-tree ul { list-style: none; }
.filter-tree .tree-row {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; border-radius: 6px;
    cursor: pointer; font-size: 13px; user-select: none; transition: background 0.1s;
}
.filter-tree .tree-row:hover { background: var(--bg3); }
.filter-tree .tree-row.active { background: var(--accent2); color: white; font-weight: 600; }
.filter-tree .tree-row .arrow {
    width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
    font-size: 8px; color: var(--text2); transition: transform 0.2s; flex-shrink: 0;
}
.filter-tree .tree-row .arrow.open { transform: rotate(90deg); }
.filter-tree .tree-row .arrow.hidden { visibility: hidden; }
.filter-tree .tree-row .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.filter-tree .tree-row .name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.filter-tree .tree-row .count { font-size: 10px; color: var(--text2); min-width: 18px; text-align: right; }
.filter-tree .tree-row.active .count { color: rgba(255,255,255,0.7); }
.filter-tree .tree-row.hidden { display: none; }
.filter-tree .children { padding-left: 18px; overflow: hidden; transition: max-height 0.2s ease; }
.filter-tree .children.collapsed { max-height: 0 !important; }

.filter-footer { padding: 10px 12px 0; border-top: 1px solid var(--border); margin-top: 4px; }
.filter-footer .stat { display: flex; justify-content: space-between; font-size: 11px; color: var(--text2); padding: 2px 0; }

/* Sidebar buttons */
.btn-row { display: flex; gap: 6px; margin-top: 12px; }
.btn-sm {
    flex: 1; padding: 8px; border: 1px dashed var(--border); border-radius: 8px;
    background: none; color: var(--text2); font-size: 12px; cursor: pointer; text-align: center;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }

/* ═══ Main Content ═══ */
.main-content { min-height: 400px; }
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.toolbar .result-info { color: var(--text2); font-size: 14px; }

/* ═══ Buttons ═══ */
.btn-primary {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; background: var(--accent2); color: white;
    border: none; border-radius: 8px; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: var(--accent); transform: translateY(-1px); }

/* ═══ Note Cards ═══ */
.notes-grid { display: grid; gap: 16px; }
.note-card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
    cursor: pointer; transition: all 0.2s; position: relative;
}
.note-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.note-card .note-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.note-card .note-title { font-size: 17px; font-weight: 600; flex: 1; line-height: 1.3; }
.note-card .note-excerpt {
    color: var(--text2); font-size: 14px; line-height: 1.6;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden; margin-bottom: 12px;
}
.note-card .note-meta { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text2); flex-wrap: wrap; }
.note-card .note-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.note-card .note-tags span { background: var(--bg); padding: 2px 8px; border-radius: 4px; font-size: 11px; color: var(--accent); }
.note-card .note-category {
    display: inline-flex; padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: white; flex-shrink: 0;
}
.note-card .note-actions {
    position: absolute; top: 12px; right: 12px;
    display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s;
}
.note-card:hover .note-actions { opacity: 1; }
.note-card .note-actions button {
    width: 32px; height: 32px; border: none; border-radius: 6px;
    background: var(--bg3); color: var(--text2); cursor: pointer;
    font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.note-card .note-actions button:hover { background: var(--accent2); color: white; }
.note-card .note-actions button.btn-del:hover { background: var(--danger); }

/* ═══ Modals ═══ */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    z-index: 200; justify-content: center; align-items: center; padding: 24px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); width: 100%; max-width: 640px;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-header .btn-close {
    width: 36px; height: 36px; border: none; border-radius: 8px;
    background: var(--bg3); color: var(--text2); font-size: 18px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.modal-header .btn-close:hover { background: var(--danger); color: white; }
.modal-body { padding: 24px; }
.modal-footer {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 16px 24px; border-top: 1px solid var(--border);
}
.btn-secondary {
    padding: 10px 20px; background: var(--bg3); color: var(--text);
    border: none; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.btn-secondary:hover { background: var(--border); }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit; outline: none;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group textarea { min-height: 200px; resize: vertical; line-height: 1.7; }
.form-group .hint { font-size: 11px; color: var(--text2); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 13px; margin-bottom: 8px; display: none; }

/* Category tree select (inside modal) */
.cat-tree-select { max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.cat-tree-select label {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--text);
}
.cat-tree-select label:hover { background: var(--bg3); }
.cat-tree-select label.selected { background: rgba(99,102,241,0.2); color: var(--accent); }
.cat-tree-select input[type="radio"] { display: none; }

/* Detail modal */
.detail-content { line-height: 1.8; white-space: pre-wrap; font-size: 15px; }
.detail-meta {
    display: flex; gap: 20px; margin-bottom: 20px;
    padding-bottom: 16px; border-bottom: 1px solid var(--border);
    font-size: 13px; color: var(--text2); flex-wrap: wrap;
}

/* ═══ Utilities ═══ */
mark { background: rgba(129,140,248,0.3); color: var(--text); border-radius: 2px; padding: 0 2px; }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text2); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }

.mobile-fab {
    display: none; position: fixed; bottom: 24px; left: 24px;
    width: 48px; height: 48px; border-radius: 50%; border: none;
    background: var(--accent2); color: white; font-size: 20px;
    cursor: pointer; z-index: 99; box-shadow: var(--shadow);
}
@media (max-width: 860px) { .mobile-fab { display: flex; align-items: center; justify-content: center; } }

.kbd {
    display: inline-block; padding: 2px 6px; font-size: 11px; font-family: monospace;
    background: var(--bg3); border: 1px solid var(--border); border-radius: 4px; color: var(--text2);
}
