/* ========== Shell layout: sidebar + iframe ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --sidebar-w: 260px;
    --bg: #fff;
    --bg-wash: #f7f8fa;
    --bg-hover: #f0f1f4;
    --panel: #f9fafb;
    --text: #1b2733;
    --text-secondary: #5c6a79;
    --text-muted: #8f99a8;
    --border: #e8ebed;
    --border-light: #f0f1f3;
    --primary: #2b6cb0;
    --primary-hover: #2c5282;
    --primary-light: #ebf4ff;
    --danger: #d94848;
    --radius: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode */
[data-theme="dark"] {
    --bg: #191b1f;
    --bg-wash: #1e2024;
    --bg-hover: #2a2d32;
    --panel: #1e2024;
    --text: #e0e4e8;
    --text-secondary: #a0a8b4;
    --text-muted: #6b7280;
    --border: #2e3138;
    --border-light: #262930;
    --primary: #5b9bd5;
    --primary-hover: #4a8ac4;
    --primary-light: rgba(91,155,213,0.12);
    --danger: #e06060;
    color-scheme: dark;
}

html, body { margin: 0; height: 100%; }

body.shell {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    display: flex;
    overflow: hidden;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; border: none; background: none; cursor: pointer; color: inherit; }

/* ========== Sidebar ========== */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width var(--transition), min-width var(--transition);
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar.collapsed { width: 0 !important; min-width: 0 !important; border-right: none; }
.sidebar.collapsed .sidebar-inner { opacity: 0; pointer-events: none; }
.sidebar.collapsed ~ .sidebar-resize-handle { display: none; }

/* Sidebar resize handle */
.sidebar-resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: background 0.15s;
}
.sidebar-resize-handle:hover,
.sidebar-resizing .sidebar-resize-handle { background: var(--primary); }
.sidebar-resizing { cursor: col-resize; user-select: none; }
.sidebar-resizing .content-pane { pointer-events: none; }
.sidebar-resizing .sidebar { transition: none; }

/* Expand button — visible only when sidebar is collapsed */
.sidebar-expand-btn {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 100;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: background var(--transition);
    cursor: pointer;
}
.sidebar-expand-btn:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-expand-btn svg { display: block; }
.sidebar.collapsed ~ .sidebar-expand-btn { display: block; }

.sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: var(--sidebar-w);
    opacity: 1;
    transition: opacity 0.18s ease;
}

/* Sidebar header */
.sidebar-header { padding: 12px 12px 8px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.sidebar-brand:hover { text-decoration: none; }
.brand-icon { width: 28px; height: 28px; border-radius: 6px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; }
.brand-text { font-size: 16px; font-weight: 700; color: var(--text); }
.sidebar-toggle-btn { padding: 6px; border-radius: 6px; color: var(--text-muted); transition: background var(--transition); }
.sidebar-toggle-btn:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-toggle-btn svg { display: block; }

/* Sidebar search */
.sidebar-search { padding: 4px 12px 8px; }
.sidebar-search form { position: relative; display: flex; align-items: center; }
.sidebar-search svg { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.sidebar-search input {
    width: 100%; padding: 7px 12px 7px 34px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 14px; background: var(--bg); outline: none;
}
.sidebar-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(43,108,176,0.12); }

/* Sidebar nav */
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 8px; }
.sidebar-nav { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 10px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; min-height: 40px; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 6px;
    font-size: 14px; color: var(--text-secondary); cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-decoration: none; white-space: nowrap;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-item svg { flex-shrink: 0; opacity: 0.65; }
.nav-item.active svg { opacity: 1; }
.nav-item-subtle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.nav-section-divider { border-top: 1px solid var(--border-light); margin: 8px 12px; }
.nav-starred { font-size: 13px; gap: 8px; }
.nav-starred svg { flex-shrink: 0; }
.nav-starred-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-section-label {
    display: flex; align-items: center; justify-content: space-between;
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-muted); padding: 16px 10px 4px;
}
.nav-section-action { color: var(--text-muted); padding: 2px; border-radius: 4px; display: flex; }
.nav-section-action:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

/* Collections */
.collection-group { margin-bottom: 1px; }
.collection-group.dragging { opacity: 0.3; }
.collection-drop-indicator { height: 2px; background: var(--primary); border-radius: 1px; margin: 0 8px; pointer-events: none; }
.collection-header { padding: 5px 6px 5px 4px; }

.tree-toggle { padding: 2px; border-radius: 4px; color: var(--text-muted); transition: transform 0.15s; display: flex; flex-shrink: 0; }
.tree-toggle:hover { background: var(--bg-hover); }
.tree-toggle.expanded svg { transform: rotate(90deg); }

.collection-icon { display: flex; flex-shrink: 0; align-items: center; }
.collection-icon svg { display: block; }
.collection-icon span { line-height: 1; }
.collection-name {
    flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 14px; font-weight: 500; color: var(--text); text-decoration: none;
}
.collection-name:hover { color: var(--primary); text-decoration: none; }
.collection-count { font-size: 12px; color: var(--text-muted); background: var(--bg-hover); padding: 0 6px; border-radius: 10px; line-height: 20px; }
.collection-actions { display: none; align-items: center; gap: 2px; margin-left: auto; }
.collection-header:hover .collection-actions { display: flex; }
.collection-header:hover .collection-count { display: none; }
.collection-action-btn { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 4px; color: var(--text-muted); }
.collection-action-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Collection context menu */
.collection-menu { position: fixed; z-index: 200; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,0.12); min-width: 180px; padding: 4px; }
.collection-menu-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; font-size: 13px; color: var(--text-secondary); border-radius: 6px; text-decoration: none; cursor: pointer; }
.collection-menu-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.collection-menu-item svg { flex-shrink: 0; opacity: 0.6; }

/* Quick-create inline input */
.quick-create-input { display: block; width: calc(100% - 8px); margin: 2px 4px 4px; padding: 5px 8px; border: 1px solid var(--primary); border-radius: 4px; font-size: 13px; font-family: var(--font); outline: none; background: var(--bg); box-shadow: 0 0 0 2px rgba(43,108,176,0.12); }

/* Document tree */
.doc-tree { display: none; padding-left: 16px; margin-left: 18px; border-left: 1px solid var(--border-light); }
.doc-tree.open { display: block; }
.doc-tree a {
    display: block; padding: 4px 10px; font-size: 13px; color: var(--text-secondary);
    border-radius: 4px; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-tree a:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.doc-tree .subtree { padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--border-light); }
.tree-empty { padding: 4px 12px; font-size: 12px; color: var(--text-muted); }

/* Sidebar footer */
.sidebar-footer { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.sidebar-avatar {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: flex;
    align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: #fff; background: var(--primary);
}
img.sidebar-avatar { object-fit: cover; }
.sidebar-user-info { min-width: 0; line-height: 1.35; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-email { font-size: 11px; color: var(--text-muted); text-decoration: none; }
.sidebar-user-email:hover { color: var(--primary); text-decoration: none; }
.sidebar-footer .sidebar-toggle-btn { margin-left: auto; flex-shrink: 0; }

/* ========== Content pane ========== */
.content-pane {
    flex: 1;
    height: 100%;
    min-width: 0;
    overflow-y: auto;
}

/* ========== Login page (not in shell) ========== */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: var(--bg-wash); font-family: var(--font);
}
.login-card {
    background: var(--bg); padding: 48px; border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); text-align: center; max-width: 400px; width: 100%;
}
.login-card h1 { font-size: 28px; margin-bottom: 8px; color: var(--text); }
.login-card > p { color: var(--text-secondary); margin-bottom: 32px; }
.btn-google {
    display: inline-flex; align-items: center; gap: 10px; background: #fff;
    border: 1px solid #dadce0; padding: 10px 24px; font-size: 15px; border-radius: 8px;
    color: var(--text); text-decoration: none;
}
.btn-google:hover { background: #f7f8f8; text-decoration: none; }
[data-theme="dark"] .btn-google { background: var(--bg-hover); border-color: var(--border); }
[data-theme="dark"] .btn-google:hover { background: var(--bg-wash); }
[data-theme="dark"] .login-card { box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
.login-note { margin-top: 16px; font-size: 12px; color: var(--text-muted); }

/* ========== Keyboard shortcuts panel (right sidebar) ========== */
.shortcuts-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 1000;
    width: 320px; background: var(--bg); border-left: 1px solid var(--border);
    box-shadow: -4px 0 24px rgba(0,0,0,0.1);
    display: flex; flex-direction: column;
    transform: translateX(100%); transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.shortcuts-panel.visible { transform: translateX(0); }
.shortcuts-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.shortcuts-header h2 { font-size: 1rem; font-weight: 600; }
.shortcuts-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); padding: 0 4px; line-height: 1; }
.shortcuts-close:hover { color: var(--text); }
.shortcuts-body { overflow-y: auto; padding: 12px 20px 20px; flex: 1; }
.shortcuts-section { margin-bottom: 16px; }
.shortcuts-section h3 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.shortcut-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; font-size: 0.875rem; color: var(--text); }
.shortcut-row span { flex: 1; }
.shortcut-row kbd { display: inline-block; background: var(--bg-wash); border: 1px solid var(--border); border-radius: 4px; padding: 2px 7px; font-size: 0.75rem; font-family: inherit; color: var(--text-muted); margin-left: 4px; min-width: 22px; text-align: center; }
[data-theme="dark"] .shortcuts-panel { background: var(--bg); }
[data-theme="dark"] .shortcut-row kbd { background: var(--bg-hover); }

/* ========== Command palette ========== */
.cmd-palette-overlay { display: none; position: fixed; inset: 0; z-index: 1001; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); }
.cmd-palette-overlay.visible { display: flex; justify-content: center; align-items: flex-start; padding-top: 80px; }
.cmd-palette { background: var(--bg); border-radius: 12px; width: 560px; max-height: 70vh; display: flex; flex-direction: column; box-shadow: 0 16px 48px rgba(0,0,0,0.25); border: 1px solid var(--border); overflow: hidden; }
.cmd-palette-input-wrap { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cmd-palette-input-wrap svg { color: var(--text-muted); flex-shrink: 0; }
.cmd-palette-input-wrap input { flex: 1; border: none; background: none; font-size: 1rem; color: var(--text); outline: none; }
.cmd-palette-input-wrap input::placeholder { color: var(--text-muted); }
.cmd-palette-input-wrap kbd { font-size: 0.7rem; background: var(--bg-wash); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; color: var(--text-muted); flex-shrink: 0; }
.cmd-palette-results { overflow-y: auto; max-height: 50vh; }
.cmd-palette-results:empty::after { content: "Type to search documents and actions..."; display: block; padding: 24px 16px; color: var(--text-muted); font-size: 0.875rem; text-align: center; }
.cmd-result { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; font-size: 0.875rem; color: var(--text); border-bottom: 1px solid var(--border); }
.cmd-result:last-child { border-bottom: none; }
.cmd-result:hover, .cmd-result.active { background: var(--bg-hover); }
.cmd-result-icon { color: var(--text-muted); flex-shrink: 0; }
.cmd-result-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-result-meta { font-size: 0.75rem; color: var(--text-muted); flex-shrink: 0; }
.cmd-result-section { padding: 8px 16px 4px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
[data-theme="dark"] .cmd-palette { background: var(--bg); }
