/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w:      260px;
    --topbar-h:       52px;
    --bg:             #ffffff;
    --bg-hover:       #f4f4f5;
    --bg-active:      #ededff;
    --sidebar-bg:     #f9f9fa;
    --sidebar-border: #e8e8ea;
    --text:           #1a1a2e;
    --text-2:         #6b7280;
    --text-3:         #9ca3af;
    --accent:         #6366f1;
    --accent-hover:   #4f46e5;
    --danger:         #ef4444;
    --border:         #e5e7eb;
    --radius:         6px;
    --shadow:         0 4px 20px rgba(0,0,0,.08);
    --shadow-sm:      0 1px 4px rgba(0,0,0,.06);
    --font:           -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --mono:           "SFMono-Regular", Consolas, monospace;
    --transition:     0.15s ease;
}

html, body { height: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); overflow: hidden; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-mode { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #f0f0ff 0%, #fafaff 100%); overflow: auto; }

.login-card { background: #fff; border-radius: 16px; box-shadow: var(--shadow); padding: 48px 40px; max-width: 400px; width: 100%; text-align: center; }

.login-logo svg { width: 64px; height: 64px; margin-bottom: 20px; }
.login-card h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.login-card > p { color: var(--text-2); margin-bottom: 32px; font-size: .95rem; line-height: 1.5; }

.btn-google { display: inline-flex; align-items: center; gap: 12px; padding: 12px 24px; background: #fff; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; font-weight: 500; color: var(--text); text-decoration: none; transition: var(--transition); cursor: pointer; width: 100%; justify-content: center; }
.btn-google:hover { background: #f8f8f8; border-color: #c0c0c8; box-shadow: var(--shadow-sm); }
.btn-google svg { width: 20px; height: 20px; }

.login-note { margin-top: 20px; font-size: .8rem; color: var(--text-3); }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-mode { display: flex; height: 100vh; overflow: hidden; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: width var(--transition), transform var(--transition);
    position: relative;
    z-index: 10;
}
#sidebar.collapsed { width: 0; overflow: hidden; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.app-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .95rem; color: var(--text); }

.btn-open-sidebar {
    position: fixed; top: 14px; left: 12px; z-index: 20;
    background: var(--sidebar-bg); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 6px; cursor: pointer; display: none; align-items: center;
    box-shadow: var(--shadow-sm); transition: var(--transition);
}
.btn-open-sidebar:hover { background: var(--bg-hover); }
.btn-open-sidebar svg { width: 18px; height: 18px; }
.btn-open-sidebar.visible { display: flex; }

.sidebar-user {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}
.user-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.user-avatar-placeholder {
    width: 30px; height: 30px; border-radius: 50%; background: var(--accent);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: .85rem; font-weight: 600; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name  { display: block; font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { display: block; font-size: .7rem; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-logout { color: var(--text-3); text-decoration: none; padding: 4px; border-radius: 4px; display: flex; transition: var(--transition); }
.btn-logout:hover { color: var(--danger); background: #fff0f0; }
.btn-logout svg { width: 16px; height: 16px; }

.sidebar-actions { padding: 10px 8px; flex-shrink: 0; }

.btn-new-page {
    display: flex; align-items: center; gap: 6px;
    width: 100%; padding: 7px 10px; border: none; border-radius: var(--radius);
    background: var(--accent); color: #fff; font-size: .83rem; font-weight: 500;
    cursor: pointer; transition: var(--transition);
}
.btn-new-page:hover { background: var(--accent-hover); }
.btn-new-page svg { width: 16px; height: 16px; }

/* PAGE TREE */
.page-tree { flex: 1; overflow-y: auto; padding: 4px 0; }
.tree-loading { padding: 16px 16px; color: var(--text-3); font-size: .82rem; }

.tree-item { position: relative; }
.tree-row {
    display: flex; align-items: center; gap: 2px;
    padding: 3px 8px; border-radius: 5px; margin: 1px 4px;
    cursor: pointer; user-select: none; min-height: 30px;
    transition: background var(--transition);
}
.tree-row:hover { background: var(--bg-hover); }
.tree-row.active { background: var(--bg-active); color: var(--accent); font-weight: 500; }

.tree-toggle { width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--text-3); font-size: .7rem; border-radius: 3px; transition: transform var(--transition); }
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.empty { opacity: 0; pointer-events: none; }

.tree-icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-3); }
.tree-title { flex: 1; font-size: .83rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tree-btn-add { opacity: 0; padding: 2px 4px; border: none; background: none; border-radius: 3px; cursor: pointer; color: var(--text-3); flex-shrink: 0; display: flex; align-items: center; transition: var(--transition); }
.tree-row:hover .tree-btn-add { opacity: 1; }
.tree-btn-add:hover { background: var(--border); color: var(--accent); }
.tree-btn-add svg { width: 12px; height: 12px; }

.tree-children { margin-left: 14px; display: none; }
.tree-children.open { display: block; }

/* TITLE INLINE EDIT */
.tree-title-input { flex: 1; border: 1px solid var(--accent); border-radius: 3px; padding: 1px 4px; font-size: .83rem; outline: none; background: #fff; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
#main-content {
    flex: 1; overflow: hidden; display: flex; flex-direction: column; min-width: 0;
}

/* EMPTY STATE */
.empty-state {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 16px; padding: 40px; text-align: center;
}
.empty-state h2 { font-size: 1.4rem; font-weight: 600; }
.empty-state p  { color: var(--text-2); font-size: .95rem; }

.btn-primary {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 20px; background: var(--accent); color: #fff;
    border: none; border-radius: var(--radius); font-size: .9rem; font-weight: 500;
    cursor: pointer; transition: var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary svg { width: 16px; height: 16px; }

/* PAGE EDITOR */
.page-editor { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.editor-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; height: var(--topbar-h); border-bottom: 1px solid var(--border);
    flex-shrink: 0; gap: 12px;
}
.breadcrumb { font-size: .82rem; color: var(--text-2); display: flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; }
.breadcrumb span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.breadcrumb .sep { color: var(--text-3); flex-shrink: 0; }

.editor-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.save-status { font-size: .78rem; color: var(--text-3); min-width: 80px; text-align: right; }
.save-status.saving  { color: var(--accent); }
.save-status.saved   { color: #16a34a; }
.save-status.error   { color: var(--danger); }

.btn-icon {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
    background: none; color: var(--text-2); font-size: .8rem; cursor: pointer; transition: var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon svg { width: 14px; height: 14px; }

/* UPDATE BANNER */
.update-banner {
    display: flex; align-items: center; gap: 10px;
    background: #fffbeb; border-bottom: 1px solid #fcd34d;
    padding: 8px 20px; font-size: .83rem; color: #92400e;
    flex-shrink: 0;
}
.update-banner svg { width: 16px; height: 16px; color: #d97706; flex-shrink: 0; }
.update-banner span { flex: 1; }
.update-banner button {
    border: none; border-radius: 4px; padding: 4px 10px; cursor: pointer;
    font-size: .78rem; transition: var(--transition);
}
#btn-reload-page  { background: #d97706; color: #fff; }
#btn-reload-page:hover  { background: #b45309; }
#btn-dismiss-banner { background: transparent; color: #92400e; font-size: .9rem; padding: 4px; }
#btn-dismiss-banner:hover { background: #fde68a; }

/* EDITOR BODY */
.editor-body { flex: 1; overflow-y: auto; padding: 0; }
.editor-container { max-width: 780px; margin: 0 auto; padding: 48px 60px 100px; }

@media (max-width: 768px) { .editor-container { padding: 24px 20px 80px; } }

/* PAGE TITLE */
.page-title {
    font-size: 2.2rem; font-weight: 700; line-height: 1.2; outline: none;
    margin-bottom: 8px; color: var(--text); word-break: break-word;
    min-height: 1.2em;
}
.page-title:empty::before { content: attr(data-placeholder); color: var(--text-3); pointer-events: none; }
.page-title:focus { caret-color: var(--accent); }

/* PAGE META */
.page-meta { font-size: .78rem; color: var(--text-3); margin-bottom: 32px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.page-meta span { display: flex; align-items: center; gap: 4px; }

/* EDITOR.JS OVERRIDES */
.editorjs-container { min-height: 300px; }
.codex-editor__redactor { padding-bottom: 60px !important; }
.ce-block__content { max-width: 100% !important; }
.ce-toolbar__content { max-width: 100% !important; }

/* Force placeholder text */
.ce-paragraph[data-placeholder]:empty::before {
    content: attr(data-placeholder);
    color: #9ca3af;
    pointer-events: none;
}

/* Heading styles */
.ce-header h1 { font-size: 1.875rem; font-weight: 700; }
.ce-header h2 { font-size: 1.5rem; font-weight: 600; }
.ce-header h3 { font-size: 1.25rem; font-weight: 600; }
.ce-header h4 { font-size: 1.125rem; font-weight: 600; }

/* Code block */
.ce-code__textarea { font-family: var(--mono) !important; font-size: .85rem !important; background: #1e1e2e !important; color: #cdd6f4 !important; border-radius: 8px !important; border-color: transparent !important; }

/* Quote */
.cdx-quote__text { font-style: italic; }

/* Checklist */
.cdx-checklist__item-checkbox { border-radius: 4px; }
.cdx-checklist__item--checked .cdx-checklist__item-checkbox { background: var(--accent) !important; border-color: var(--accent) !important; }

/* Table */
.tc-wrap { --color-border: var(--border) !important; border-radius: 8px !important; overflow: hidden !important; }
.tc-table__cell { border-color: var(--border) !important; }
.tc-toolbox .tc-toolbox__toggler { background: var(--bg-hover) !important; }

/* Warning block */
.cdx-warning { border-left: 4px solid #f59e0b; background: #fffbeb; border-radius: 0 8px 8px 0; }

/* Marker (highlight) */
.cdx-marker { background: #fef08a; border-radius: 2px; padding: 0 2px; }

/* Inline code */
code { background: #f3f4f6; border-radius: 3px; padding: 1px 5px; font-family: var(--mono); font-size: .85em; }

/* ============================================================
   SLASH MENU
   ============================================================ */
.slash-menu {
    position: fixed; z-index: 1000; background: #fff;
    border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow); width: 260px; overflow: hidden;
}
.slash-menu-search { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.slash-menu-search input { width: 100%; border: none; outline: none; font-size: .85rem; color: var(--text); background: none; }

.slash-list { list-style: none; max-height: 280px; overflow-y: auto; padding: 4px 0; }
.slash-list li {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 12px; cursor: pointer; transition: background var(--transition);
    font-size: .85rem;
}
.slash-list li:hover, .slash-list li.active { background: var(--bg-hover); }
.slash-list .cmd-icon { width: 28px; height: 28px; border-radius: 6px; background: var(--bg-hover); display: flex; align-items: center; justify-content: center; font-size: .95rem; flex-shrink: 0; }
.slash-list .cmd-info { display: flex; flex-direction: column; }
.slash-list .cmd-name { font-weight: 500; }
.slash-list .cmd-desc { font-size: .73rem; color: var(--text-3); }
.slash-list .no-results { color: var(--text-3); justify-content: center; padding: 16px; }

/* ============================================================
   CONTEXT MENU (árvore)
   ============================================================ */
.ctx-menu {
    position: fixed; z-index: 1000; background: #fff;
    border: 1px solid var(--border); border-radius: 8px;
    box-shadow: var(--shadow); list-style: none; padding: 4px; min-width: 180px;
}
.ctx-menu li {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px; border-radius: 5px; cursor: pointer;
    font-size: .85rem; transition: background var(--transition);
}
.ctx-menu li:hover { background: var(--bg-hover); }
.ctx-menu li.danger { color: var(--danger); }
.ctx-menu li.danger:hover { background: #fff0f0; }
.ctx-menu li svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ============================================================
   MODAL (histórico)
   ============================================================ */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.3); backdrop-filter: blur(2px); }
.modal-panel {
    position: relative; background: #fff; border-radius: 12px;
    box-shadow: var(--shadow); width: 90vw; max-width: 900px;
    max-height: 85vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-body { flex: 1; overflow: hidden; }

.history-layout { display: flex; height: 100%; }
.history-list { width: 260px; border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.history-preview { flex: 1; overflow-y: auto; padding: 20px; }
.history-hint { color: var(--text-3); font-size: .85rem; text-align: center; margin-top: 40px; }

.history-entry {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: background var(--transition);
}
.history-entry:hover { background: var(--bg-hover); }
.history-entry.active { background: var(--bg-active); }
.history-entry .h-title { font-size: .85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-entry .h-meta  { font-size: .75rem; color: var(--text-3); margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.history-entry .h-avatar { width: 18px; height: 18px; border-radius: 50%; }
.history-preview-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 16px; }

.loading { padding: 20px; color: var(--text-3); font-size: .85rem; text-align: center; }
.hidden { display: none !important; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ============================================================
   TOGGLE SIDEBAR BUTTON (inline)
   ============================================================ */
#btn-toggle-sidebar {
    border: none; background: none; padding: 4px; border-radius: 4px;
    cursor: pointer; color: var(--text-3); display: flex; align-items: center; transition: var(--transition);
}
#btn-toggle-sidebar:hover { background: var(--bg-hover); color: var(--text); }
#btn-toggle-sidebar svg { width: 18px; height: 18px; }

/* ============================================================
   ANIMAÇÕES
   ============================================================ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.slash-menu:not(.hidden), .ctx-menu:not(.hidden), .modal:not(.hidden) { animation: fadeIn .1s ease; }
