@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
:root {
    --bg: #ffffff;
    --bg2: #f7f7f5;
    --surface: #f0f0ee;
    --text: #37352f;
    --text2: #787774;
    --accent: #2383e2;
    --accent2: #9065e3;
    --green: #448361;
    --green-bg: #dbeddb;
    --blue: #527da5;
    --blue-bg: #d3e5ef;
    --red: #c4554d;
    --red-bg: #ffe2dd;
    --gray: #91918e;
    --gray-bg: #e3e2e0;
    --yellow: #c29243;
    --yellow-bg: #fdecc8;
    --border: #e9e9e7;
    --sidebar-w: 260px;
    --content-w: 800px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --serif: 'Georgia', 'Palatino Linotype', 'Times New Roman', serif;
    --mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    height: 100vh; height: 100dvh;
    position: fixed; left: 0; top: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 100;
    transition: transform 0.2s;
    font-size: 14px;
}
.sidebar-hdr {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600; font-size: 14px; color: var(--text2);
    display: flex; align-items: center; gap: 6px;
}
.sidebar-hdr a { color: var(--text); text-decoration: none; }
.sidebar-search { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.sidebar-search input {
    width: 100%; padding: 5px 10px;
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 5px; color: var(--text); font-size: 13px; outline: none;
}
.sidebar-search input:focus { border-color: var(--accent); }
.tree { padding: 4px 0; }
.tree-item {
    display: flex; align-items: center;
    padding: 3px 8px 3px calc(8px + var(--depth, 0) * 18px);
    cursor: pointer; font-size: 13px; color: var(--text2);
    text-decoration: none; border-radius: 4px; margin: 0 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-item:hover { background: var(--surface); color: var(--text); }
.tree-item.active { background: var(--surface); color: var(--accent); font-weight: 500; }
.tree-item .icon { margin-right: 5px; font-size: 13px; flex-shrink: 0; opacity: 0.7; display: inline-flex; }
.tree-item .lucide-icon, .lucide-icon { width: 16px; height: 16px; flex-shrink: 0; margin-right: 5px; opacity: 0.7; }
.card-title .lucide-icon { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }
.card-title .icon { margin-right: 4px; }
.tree-dir > .tree-children { display: none; }
.tree-dir.open > .tree-children { display: block; }
.tree-dir > .tree-item .chv {
    margin-right: 3px; transition: transform 0.15s; font-size: 9px; opacity: 0.5;
}
.tree-dir.open > .tree-item .chv { transform: rotate(90deg); }
.sidebar.hidden { transform: translateX(-100%); }

/* === Main === */
.main-wrapper {
    margin-left: var(--sidebar-w);
    flex: 1; min-height: 100vh;
    display: flex; justify-content: center;
    background: var(--bg);
}
.main {
    width: 100%;
    max-width: var(--content-w);
    padding: 0 32px 40px;
    overflow-wrap: break-word; word-wrap: break-word; min-width: 0;
}
.breadcrumb {
    font-size: 12px; color: var(--text2); margin-bottom: 4px;
    padding: 6px 0;
}
.breadcrumb a { color: var(--text2); text-decoration: none; }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb span.sep { margin: 0 4px; color: var(--border); }

/* === Cover + Icon (notion4ever style) === */
.cover {
    width: 100vw;
    position: relative;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 0;
}
.cover img { width: 100%; height: 200px; object-fit: cover; display: block; }
.page-icon {
    font-size: 78px; line-height: 78px;
    margin-top: -42px; margin-bottom: 4px;
    position: relative; z-index: 1;
}
.page-icon .lucide-icon { width: 72px; height: 72px; }
.page-icon img { width: 78px; height: 78px; object-fit: cover; border-radius: 8px; }
.no-cover .page-icon { margin-top: 0; }

/* === Badges === */
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.badge {
    padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 500;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-gray { background: var(--gray-bg); color: var(--gray); }
.badge-default { background: var(--surface); color: var(--text2); }
.tag {
    background: var(--surface); color: var(--text2);
    padding: 1px 6px; border-radius: 3px; font-size: 12px; white-space: nowrap;
}

/* === Properties === */
.props {
    background: var(--bg2); border-radius: 6px; padding: 6px 12px;
    margin-bottom: 18px; font-size: 13px;
}
.props table { width: 100%; border-collapse: collapse; }
.props tr { border-bottom: 1px solid var(--border); }
.props tr:last-child { border-bottom: none; }
.props td { padding: 5px 6px; vertical-align: top; }
.pk { color: var(--text2); font-weight: 500; white-space: nowrap; width: 1%; padding-right: 12px; }
.pv { color: var(--text); word-break: break-word; }

/* === Markdown content === */
.md { overflow-wrap: break-word; word-break: break-word; font-family: var(--serif); font-size: 16px; line-height: 1.7; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-family: var(--font); font-weight: 700; }
.md h1 { font-size: 1.875em; margin: 2em 0 0.5em; }
.md h2 { font-size: 1.5em; margin: 1.4em 0 0.4em; }
.md h3 { font-size: 1.25em; margin: 1.2em 0 0.3em; }
.md h4 { font-size: 1em; margin: 1em 0 0.3em; }
.md p { margin: 0.5em 0; }
.md a { color: var(--accent); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md a.wikilink { color: var(--accent2); text-decoration: underline; text-decoration-style: dotted; }
.md code {
    background: var(--surface); padding: 2px 5px; border-radius: 3px;
    font-family: var(--mono); font-size: 0.85em;
}
.md pre {
    background: var(--bg2); border: 1px solid var(--border); border-radius: 6px;
    padding: 12px; overflow-x: auto; margin: 1em 0; max-width: 100%;
    position: relative;
}
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 1em 0; max-width: 100%; }
.md table { border-collapse: collapse; font-family: var(--font); font-size: 14px; min-width: 100%; width: max-content; }
.md th, .md td { white-space: nowrap; }
.md td { white-space: normal; min-width: 80px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--bg2); font-weight: 600; font-size: 13px; color: var(--text2); }
.md blockquote {
    border-left: 3px solid var(--border); padding-left: 14px; margin: 1em 0;
    color: var(--text2); font-style: italic;
}
.md ul, .md ol { padding-left: 1.5em; margin: 0.5em 0; }
.md li { margin: 3px 0; }
.md img { max-width: 100%; height: auto; border-radius: 4px; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md mark { background: var(--yellow-bg); color: var(--text); padding: 0 3px; border-radius: 2px; }
.md input[type="checkbox"] { margin-right: 6px; cursor: pointer; width: 16px; height: 16px; vertical-align: middle; accent-color: var(--accent); }
.md li.task-item { list-style: none !important; margin-left: -1.5em; }

/* === Callouts === */
.callout { border-radius: 6px; padding: 12px 16px; margin: 1em 0; border-left: 4px solid; }
.callout-title { font-family: var(--font); font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.callout-body { font-size: 14px; }
.callout-body p { margin: 3px 0; }
.callout-note { border-color: var(--accent); background: #e8f0fe; }
.callout-tip, .callout-hint { border-color: #0d9488; background: #e6f6f4; }
.callout-warning, .callout-caution { border-color: var(--yellow); background: var(--yellow-bg); }
.callout-danger, .callout-error { border-color: var(--red); background: var(--red-bg); }
.callout-success, .callout-check, .callout-done { border-color: var(--green); background: var(--green-bg); }
.callout-quote, .callout-cite { border-color: var(--gray); background: var(--bg2); }
.callout-question { border-color: var(--yellow); background: var(--yellow-bg); }

/* === Toolbar === */
.toolbar { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.btn {
    padding: 5px 14px; border-radius: 4px;
    border: 1px solid var(--border); background: var(--bg);
    color: var(--text); cursor: pointer; font-size: 13px;
    text-decoration: none; display: inline-flex; align-items: center; gap: 4px;
    font-family: var(--font);
}
.btn:hover { background: var(--surface); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.9; }
.btn.active { background: var(--surface); font-weight: 600; }

/* === Edit === */
.edit-area {
    width: 100%; min-height: 70vh;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 14px; font-family: var(--mono); font-size: 14px;
    line-height: 1.6; resize: vertical; outline: none;
}
.edit-area:focus { border-color: var(--accent); }

/* === Toast === */
.toast {
    position: fixed; bottom: 20px; right: 20px;
    background: var(--green); color: white;
    padding: 8px 18px; border-radius: 6px;
    font-size: 13px; font-weight: 500; z-index: 1000;
    animation: toast 2s ease-in-out;
}
@keyframes toast {
    0% { opacity: 0; transform: translateY(10px); }
    15% { opacity: 1; transform: translateY(0); }
    85% { opacity: 1; }
    100% { opacity: 0; }
}

/* === Gallery (cards view) === */
.db-toolbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.view-tabs { display: flex; gap: 2px; }
.view-tab {
    padding: 4px 12px; font-size: 13px; color: var(--text2);
    cursor: pointer; border-radius: 4px; text-decoration: none;
    border: none; background: none; font-family: var(--font);
}
.view-tab:hover { background: var(--surface); color: var(--text); }
.view-tab.active { background: var(--surface); color: var(--text); font-weight: 500; }
.filter-info { font-size: 12px; color: var(--text2); }

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.card {
    border: 1px solid var(--border); border-radius: 6px;
    overflow: hidden; transition: box-shadow 0.15s;
    background: var(--bg);
}
.card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.card a { text-decoration: none; color: var(--text); display: block; }
.card-cover { height: 120px; overflow: hidden; background: var(--bg2); }
.card-cover img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 10px 12px; }
.card-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.card-meta { font-size: 12px; color: var(--text2); display: flex; flex-wrap: wrap; gap: 4px; }

/* List view */
.db-list { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.db-row {
    display: flex; align-items: center; padding: 8px 14px;
    border-bottom: 1px solid var(--border); gap: 12px;
    text-decoration: none; color: var(--text); font-size: 14px;
}
.db-row:last-child { border-bottom: none; }
.db-row:hover { background: var(--bg2); }
.db-row-title { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-row-status { flex-shrink: 0; }
.db-row-tags { flex-shrink: 0; display: flex; gap: 4px; }
.db-row-date { flex-shrink: 0; font-size: 12px; color: var(--text2); }

/* Table view */
.db-table { width: 100%; border-collapse: collapse; font-size: 13px; font-family: var(--font); }
.db-table th {
    text-align: left; padding: 6px 10px; font-weight: 500; font-size: 12px;
    color: var(--text2); border-bottom: 1px solid var(--border); background: var(--bg2);
    white-space: nowrap;
}
.db-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.db-table tr:hover { background: var(--bg2); }
.db-table a { color: var(--text); text-decoration: none; font-weight: 500; }
.db-table a:hover { color: var(--accent); }
.db-table .cell-tags { display: flex; gap: 3px; flex-wrap: wrap; }

/* === Search results (sidebar) === */
.search-results { padding: 0 8px; }
.sr-item {
    padding: 5px 8px; font-size: 12px; color: var(--text);
    cursor: pointer; border-radius: 4px; text-decoration: none; display: block;
}
.sr-item:hover { background: var(--surface); }
.sr-path { color: var(--text2); font-size: 11px; }
.sr-match { color: var(--yellow); font-size: 11px; }

/* === Home === */
.home-recent { margin-top: 16px; }
.home-recent h3 { font-size: 14px; font-weight: 600; color: var(--text2); margin-bottom: 8px; }

/* === Canvas === */
.canvas-container {
    width: 100%; overflow: auto; -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border); border-radius: 8px; background: var(--bg2);
    min-height: 300px; max-height: 80vh;
}
.canvas-container svg { width: 100%; height: auto; min-height: 300px; }
.canvas-node {
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    padding: 8px 10px; font-size: 13px; line-height: 1.4;
    overflow: hidden; height: 100%; font-family: var(--font);
    color: var(--text);
}
.canvas-node p { margin: 2px 0; }
.canvas-node a { color: var(--accent); }

/* === Top bar === */
.topbar {
    display: flex; align-items: center; gap: 6px;
    padding: 0; margin: 0;
    position: sticky; top: 0; z-index: 10;
    background: var(--bg);
    min-height: 28px;
}
.topbar-toggle {
    background: none; border: none; color: var(--text2); cursor: pointer;
    padding: 4px 6px; border-radius: 4px; font-size: 18px; flex-shrink: 0;
    display: flex; align-items: center;
}
.topbar-toggle:hover { background: var(--surface); color: var(--text); }
.topbar-bc {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 12px; color: var(--text2);
}
.topbar-bc a { color: var(--text2); text-decoration: none; }
.topbar-bc a:hover { color: var(--text); }
.topbar-bc .sep { margin: 0 3px; color: var(--border); }
.topbar-actions { display: flex; gap: 4px; flex-shrink: 0; }
.topbar-btn {
    background: none; border: none; color: var(--text2); cursor: pointer;
    padding: 4px 8px; border-radius: 4px; font-size: 13px;
    text-decoration: none; display: inline-flex; align-items: center;
}
.topbar-btn:hover { background: var(--surface); color: var(--text); }
.overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.3); z-index: 50;
}

/* === Mobile === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 85vw; max-width: 300px; }
    .sidebar.open { transform: translateX(0); box-shadow: 2px 0 12px rgba(0,0,0,0.15); }
    .overlay.open { display: block; }
    .main-wrapper { margin-left: 0; }
    .main { padding: 10px 14px 30px; max-width: 100vw; width: 100%; }
    .cover { width: 100vw; left: 50%; transform: translateX(-50%); }
    .cover img { height: 140px; }
    .page-icon { font-size: 56px; line-height: 56px; margin-top: -30px; }
    .page-icon .lucide-icon { width: 52px; height: 52px; }
    .md h1 { font-size: 1.5em; }
    .md h2 { font-size: 1.25em; }
    .md pre { padding: 8px; font-size: 12px; }
    .gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
    .card-cover { height: 80px; }
    .card-body { padding: 8px 10px; }
    .card-title { font-size: 13px; }
    .db-table { font-size: 12px; }
    .db-row { padding: 6px 10px; font-size: 13px; }
    .breadcrumb { font-size: 11px; }
}

/* === Icon Picker === */
#icon-picker-overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.4); z-index:999; }
#icon-picker-overlay.open { display:block; }
#icon-picker {
    position:fixed; top:50%; left:50%; transform:translate(-50%,-50%);
    width:420px; max-width:95vw; max-height:80vh;
    background:var(--bg); border:1px solid var(--border); border-radius:12px;
    box-shadow:0 8px 32px rgba(0,0,0,0.2); z-index:1000;
    flex-direction:column; overflow:hidden; display:none;
}
#icon-picker.open { display:flex; }
.icon-picker-header { display:flex; justify-content:space-between; align-items:center; padding:12px 16px; border-bottom:1px solid var(--border); }
.icon-picker-title { font-weight:600; font-size:14px; }
.icon-picker-close { background:none; border:none; font-size:20px; cursor:pointer; color:var(--text2); padding:0 4px; }
.icon-picker-close:hover { color:var(--text); }
.icon-picker-tabs { display:flex; padding:8px 16px 0; gap:4px; }
.icon-picker-tab {
    padding:6px 16px; border:none; background:none; font-size:13px;
    cursor:pointer; color:var(--text2); border-bottom:2px solid transparent; border-radius:4px 4px 0 0;
}
.icon-picker-tab:hover { color:var(--text); background:var(--surface); }
.icon-picker-tab.active { color:var(--accent); border-bottom-color:var(--accent); }
.icon-picker-search-wrap { padding:8px 16px; }
.icon-picker-search-wrap input {
    width:100%; padding:6px 10px; border:1px solid var(--border); border-radius:6px;
    background:var(--surface); color:var(--text); font-size:13px; outline:none; box-sizing:border-box;
}
.icon-picker-search-wrap input:focus { border-color:var(--accent); }
.icon-picker-custom { display:flex; gap:4px; padding:0 16px 8px; }
.icon-picker-custom input {
    flex:1; padding:4px 8px; border:1px solid var(--border); border-radius:4px;
    background:var(--surface); color:var(--text); font-size:16px; min-width:0;
}
.icon-picker-custom button {
    padding:4px 10px; border:1px solid var(--border); border-radius:4px;
    background:var(--surface); cursor:pointer; font-size:12px; color:var(--text2); white-space:nowrap;
}
.icon-picker-custom button:hover { background:var(--accent); color:white; border-color:var(--accent); }
#icon-picker-grid {
    display:flex; flex-wrap:wrap; gap:2px; padding:8px 16px;
    overflow-y:auto; flex:1; max-height:300px; align-content:flex-start;
}
.icon-pick {
    width:36px; height:36px; display:flex; align-items:center; justify-content:center;
    border:none; background:none; border-radius:6px; cursor:pointer; font-size:20px;
    color:var(--text); transition:background 0.1s;
}
.icon-pick:hover { background:var(--surface); }
.icon-pick i { width:20px; height:20px; }
.icon-picker-footer {
    display:flex; justify-content:space-between; align-items:center;
    padding:8px 16px 12px; border-top:1px solid var(--border);
}
.icon-picker-color { display:flex; align-items:center; gap:6px; font-size:12px; color:var(--text2); }
.icon-picker-color input[type=color] { width:28px; height:28px; border:1px solid var(--border); border-radius:4px; cursor:pointer; padding:0; }
#icon-picker-color-reset {
    background:none; border:1px solid var(--border); border-radius:4px;
    padding:2px 8px; font-size:11px; cursor:pointer; color:var(--text2);
}
#icon-picker-color-reset:hover { background:var(--surface); }

/* Page icon edit affordance */
.page-icon[data-icon-path] { cursor:pointer; transition:opacity 0.15s; }
.page-icon[data-icon-path]:hover { opacity:0.7; }
.page-icon-add { margin-bottom:4px; }
.icon-add-btn {
    display:inline-flex; align-items:center; justify-content:center;
    width:36px; height:36px; border:2px dashed var(--border); border-radius:8px;
    color:var(--text2); font-size:22px; line-height:1; opacity:0; transition:opacity 0.2s;
}
.page-icon-add:hover .icon-add-btn { opacity:0.6; }
