:root {
    --bg: #ffffff; --sidebar: #f7f7f8; --border: #e5e7eb;
    --accent: #111827; --text: #374151; --hover: #f3f4f6;
    --danger: #ef4444; --highlight: #fef08a;
}

/* 1. Reset & Base Layout */
body { 
    font-family: -apple-system, system-ui, sans-serif; 
    margin: 0; display: flex; height: 100vh; width: 100vw;
    color: var(--text); background: white; overflow: hidden; 
}

mark { background-color: var(--highlight); color: inherit; padding: 0 2px; border-radius: 2px; }

/* 2. Sidebar - Stable Flexbox Approach */
#sidebar { 
    width: 260px; min-width: 260px; 
    background: var(--sidebar); border-right: 1px solid var(--border); 
    display: flex; flex-direction: column; position: relative;
    transition: width 0.3s ease, min-width 0.3s ease;
    z-index: 50;
}

/* State when Sidebar is hidden */
#sidebar.hidden {
    width: 0 !important;
    min-width: 0 !important;
    border-right: none;
    overflow: visible; /* Keeps the button visible */
}

.sidebar-header { padding: 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
#searchBar { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; outline: none; font-size: 13px; box-sizing: border-box; }
.list-container { flex: 1; overflow-y: auto; padding: 10px; }

/* Sidebar List Items */
.folder-header { padding: 12px 8px 4px 8px; font-weight: 700; font-size: 11px; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.05em; }
.note-item { padding: 8px 12px; cursor: pointer; border-radius: 6px; font-size: 13px; margin: 1px 0; border-left: 3px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-item:hover { background: var(--hover); }
.note-item.active { background: white; border-left-color: var(--accent); font-weight: 500; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }

/* 3. The Sidebar Toggle Button */
#sidebarToggle {
    position: absolute;
    left: 260px; /* Aligned to the width of the sidebar */
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 48px;
    background: white;
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    font-size: 16px;
    color: #9ca3af;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
    transition: left 0.3s ease;
}

#sidebar.hidden #sidebarToggle {
    left: 0; /* Snaps to left edge when sidebar is 0 width */
}

/* 4. Main Content Area */
#main { 
    flex: 1; display: flex; flex-direction: column; 
    min-width: 0; position: relative; background: white; 
}

header { padding: 0 24px; height: 56px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: white; z-index: 10; }

.header-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn { 
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; 
    border: none; background: transparent; cursor: pointer; border-radius: 6px; 
    font-size: 18px; transition: background 0.2s; 
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.danger:hover { background: #fee2e2; }

/* 5. Workspace Grid */
.workspace { 
    flex: 1; display: grid; grid-template-columns: 1fr 6px 1fr; 
    overflow: hidden; background: var(--border); 
}

#editor { border: none; padding: 30px; font-family: 'Fira Code', monospace; font-size: 15px; resize: none; outline: none; line-height: 1.6; background: white; }
.resizer { cursor: col-resize; background: var(--sidebar); position: relative; width: 6px; }
.resizer::after { content: ""; position: absolute; left: 2px; top: 50%; height: 40px; width: 2px; background: #d1d5db; transform: translateY(-50%); border-radius: 2px; }
#preview { padding: 30px; overflow-y: auto; background: white; line-height: 1.6; font-size: 16px; }

/* 6. Library View & Tables */
#libraryView { position: absolute; inset: 0; background: white; z-index: 40; display: none; flex-direction: column; padding: 40px; box-sizing: border-box; overflow-y: auto; }
.lib-table { width: 100%; border-collapse: collapse; margin-top: 20px; table-layout: fixed; }
.lib-table th { text-align: left; padding: 12px; border-bottom: 2px solid var(--border); font-size: 13px; color: #6b7280; cursor: pointer; }
.lib-table td { padding: 14px 12px; border-bottom: 1px solid var(--border); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-pill { background: #eff6ff; color: #2563eb; padding: 2px 8px; border-radius: 4px; font-size: 11px; margin-right: 4px; }
select.btn-folder { border: 1px solid var(--border); background: white; padding: 4px 8px; border-radius: 6px; font-size: 12px; cursor: pointer; outline: none; }