/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root,
[data-theme="light"] {
    --color-bg: #ffffff;
    --color-bg-secondary: #f7f8fa;
    --color-bg-hover: #f0f1f4;
    --color-border: #e1e4e8;
    --color-text: #24292e;
    --color-text-secondary: #586069;
    --color-primary: #0366d6;
    --color-primary-hover: #0256b9;
    --color-success: #28a745;
    --color-warning: #ffc107;
    --color-danger: #dc3545;
    --color-sidebar: #f6f8fa;
    --color-border-light: #f0f0f0;
    --color-card-hover: var(--shadow);
    --color-active-bg: #e8f0fe;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SFMono-Regular', Consolas, monospace;
}

[data-theme="dark"] {
    --color-bg: #0d1117;
    --color-bg-secondary: #161b22;
    --color-bg-hover: #1c2128;
    --color-border: #30363d;
    --color-text: #e6edf3;
    --color-text-secondary: #8b949e;
    --color-primary: #58a6ff;
    --color-primary-hover: #79b8ff;
    --color-success: #3fb950;
    --color-warning: #d29922;
    --color-danger: #f85149;
    --color-sidebar: #161b22;
    --color-border-light: #21262d;
    --color-active-bg: #1f2937;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

body {
    font-family: var(--font);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Top Navigation */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-logo {
    display: flex;
    align-items: center;
    color: var(--color-text);
}
.nav-logo:hover { text-decoration: none; }
.nav-logo-img { height: 28px; width: auto; }
.nav-logo-dark { display: none; }
[data-theme="dark"] .nav-logo-light { display: none; }
[data-theme="dark"] .nav-logo-dark { display: inline; }

.nav-center { flex: 1; max-width: 500px; margin: 0 20px; }

.search-form { width: 100%; }
.search-input {
    width: 100%;
    padding: 8px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: var(--color-bg-secondary);
    transition: border-color 0.2s, background 0.2s;
}
.search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-bg);
}

.nav-right { display: flex; align-items: center; gap: 10px; }
.nav-user { color: var(--color-text); font-weight: 500; }

.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; background: none;
    cursor: pointer; border-radius: var(--radius); color: var(--color-text-secondary);
}
.theme-toggle:hover { background: var(--color-bg-hover); color: var(--color-text); }
[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

.nav-left { display: flex; align-items: center; gap: 8px; }
.nav-sidebar-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; border: none; background: none;
    cursor: pointer; border-radius: var(--radius); color: var(--color-text-secondary);
}
.nav-sidebar-toggle:hover { background: var(--color-bg-hover); color: var(--color-text); }

/* Layout */
.layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

/* Global sidebar */
.global-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--color-sidebar);
    border-right: 1px solid var(--color-border);
    overflow-y: auto;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    transition: padding 0.2s, opacity 0.2s;
    padding: 8px 0;
}
.global-sidebar.hidden {
    width: 0; min-width: 0; padding: 0; overflow: hidden; opacity: 0; border-right: none;
}
/* Sidebar resize handle */
.sidebar-resizer {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    transition: background 0.15s;
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging {
    background: var(--color-primary);
}
.global-sidebar.hidden + .sidebar-resizer { display: none; }

.gs-content { padding: 0 6px; }

.gs-space { margin-bottom: 2px; }
.gs-space.collapsed .gs-pages { display: none; }
.gs-space.collapsed .gs-chevron { transform: rotate(0deg); }
.gs-space-header {
    display: flex; align-items: center; gap: 4px; padding: 6px 8px;
    cursor: pointer; border-radius: var(--radius); font-size: 0.85rem;
    font-weight: 600; user-select: none;
}
.gs-space-header:hover { background: var(--color-bg-hover); }
.gs-chevron {
    flex-shrink: 0; transition: transform 0.15s; transform: rotate(90deg);
    color: var(--color-text-secondary);
}
.gs-space-icon { flex-shrink: 0; }
.gs-space-name {
    color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.gs-space-name:hover { text-decoration: none; color: var(--color-primary); }

.gs-pages { padding-left: 6px; }

/* Navigation tree */
.nav-subtree { list-style: none; padding-left: 0; }
.nav-subtree .nav-subtree { padding-left: 12px; }
.nav-tree-item { }
.nav-tree-item > .nav-subtree { display: none; }
.nav-tree-item.expanded > .nav-subtree { display: block; }
.nav-tree-row {
    display: flex; align-items: center; gap: 2px; padding: 3px 6px;
    border-radius: var(--radius); font-size: 0.82rem;
}
.nav-tree-row:hover { background: var(--color-bg-hover); }
.nav-tree-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; border: none; background: none; cursor: pointer;
    color: var(--color-text-secondary); border-radius: 3px; flex-shrink: 0; padding: 0;
}
.nav-tree-toggle:hover { background: var(--color-bg-hover); }
.nav-tree-toggle svg { transition: transform 0.15s; }
.nav-tree-item.expanded > .nav-tree-row .nav-tree-toggle svg { transform: rotate(90deg); }
.nav-tree-toggle-placeholder { width: 18px; flex-shrink: 0; }
.nav-page-link {
    color: var(--color-text); overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; flex: 1; min-width: 0;
}
.nav-page-link:hover { text-decoration: none; color: var(--color-primary); }

/* Sidebar drag handles */
.sidebar-drag { cursor: grab; opacity: 0; font-size: 10px; line-height: 1; padding: 0 2px; user-select: none; flex-shrink: 0; color: var(--color-text-secondary); transition: opacity 0.15s; }
.nav-tree-row:hover .sidebar-drag { opacity: 0.5; }
.sidebar-drag:hover { opacity: 1 !important; }
.nav-tree-item.sidebar-dragging { opacity: 0.4; }
.sidebar-drop-before { border-top: 2px solid var(--color-primary) !important; }
.sidebar-drop-after { border-bottom: 2px solid var(--color-primary) !important; }
.sidebar-drop-inside { outline: 2px dashed var(--color-primary); outline-offset: -2px; border-radius: var(--radius); }

/* My spaces & pages highlight */
.gs-mine > .gs-space-header .gs-space-name { color: #1a7f37; }
.nav-page-mine { color: #1a7f37; }
.nav-page-mine:hover { color: #15652c; }
[data-theme="dark"] .gs-mine > .gs-space-header .gs-space-name { color: #3fb950; }
[data-theme="dark"] .nav-page-mine { color: #3fb950; }
[data-theme="dark"] .nav-page-mine:hover { color: #56d364; }

/* Space-specific sidebar (used in space_detail, page_detail) */
.sidebar {
    width: 280px;
    background: var(--color-sidebar);
    border-right: 1px solid var(--color-border);
    padding: 16px;
    overflow-y: auto;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
}

.sidebar-section { margin-bottom: 20px; }
.sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.sidebar-link {
    display: block;
    padding: 6px 10px;
    border-radius: var(--radius);
    color: var(--color-text);
    font-size: 0.9rem;
    transition: background 0.15s;
}
.sidebar-link:hover {
    background: var(--color-bg-hover);
    text-decoration: none;
}
.sidebar-link.active {
    background: var(--color-primary);
    color: white;
}

/* Page tree */
.page-tree { list-style: none; }
.page-tree .page-tree { margin-left: 16px; }
.page-tree-item {
    padding: 4px 8px;
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.page-tree-item:hover { background: var(--color-bg-hover); }
.page-tree-item a { color: var(--color-text); }

.main-content {
    flex: 1;
    padding: 24px 40px;
    min-width: 0;
    margin: 0 auto;
    max-width: 1200px;
    width: 100%;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--color-bg);
    color: var(--color-text);
    transition: all 0.15s;
    text-decoration: none;
}
.btn:hover { background: var(--color-bg-hover); text-decoration: none; }
.btn-primary { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-danger { background: var(--color-danger); color: white; border-color: var(--color-danger); }
.btn-ghost { border: none; background: none; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:hover, .btn[disabled]:hover { background: var(--color-bg); }
.btn-danger:disabled:hover, .btn-danger[disabled]:hover { background: var(--color-danger); }

/* Cards */
.card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow); }
.card-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; }
.card-meta { font-size: 0.8rem; color: var(--color-text-secondary); }

/* Page content styles */
.page-header { margin-bottom: 24px; }
.page-title { font-size: 2rem; font-weight: 700; margin-bottom: 8px; }
.page-meta { font-size: 0.85rem; color: var(--color-text-secondary); display: flex; gap: 16px; flex-wrap: wrap; }

.page-content {
    line-height: 1.8;
    font-size: 1rem;
}
.page-content h1 { font-size: 1.8rem; margin: 1.5em 0 0.5em; }
.page-content h2 { font-size: 1.5rem; margin: 1.3em 0 0.5em; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3em; }
.page-content h3 { font-size: 1.25rem; margin: 1.2em 0 0.5em; }
.page-content p { margin-bottom: 1em; }
.page-content ul, .page-content ol { margin-bottom: 1em; padding-left: 2em; }
.page-content li { margin-bottom: 0.3em; }
.page-content pre {
    background: var(--color-bg-secondary);
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    margin-bottom: 1em;
}
.page-content code {
    background: var(--color-bg-secondary);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.875em;
}
.page-content pre code { background: none; padding: 0; }
.page-content blockquote {
    border-left: 4px solid var(--color-primary);
    padding: 8px 16px;
    margin: 0 0 1em;
    background: var(--color-bg-secondary);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.page-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1em;
}
.page-content th, .page-content td {
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    text-align: left;
}
.page-content th { background: var(--color-bg-secondary); font-weight: 600; }
.page-content img { max-width: 100%; border-radius: var(--radius); }
.page-content hr { border: none; border-top: 1px solid var(--color-border); margin: 1.5em 0; }

/* Breadcrumbs */
.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.breadcrumbs a { color: var(--color-text-secondary); }
.breadcrumbs a:hover { color: var(--color-primary); }
.breadcrumbs .separator { color: var(--color-border); }

/* Tags */
.tag {
    display: inline-block;
    padding: 2px 10px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}
.tag:hover { background: var(--color-bg-hover); text-decoration: none; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }

/* Reactions */
.reactions { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0; }
.reaction-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    background: var(--color-bg);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}
.reaction-btn:hover { background: var(--color-bg-hover); }
.reaction-btn.active { border-color: var(--color-primary); background: var(--color-active-bg); }

/* Comments */
.comment {
    padding: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}
.comment.resolved { opacity: 0.6; }
.comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.comment-author { font-weight: 600; font-size: 0.9rem; }
.comment-date { font-size: 0.8rem; color: var(--color-text-secondary); }
.comment-body { font-size: 0.9rem; line-height: 1.6; }
.comment-actions { margin-top: 8px; display: flex; gap: 8px; }
.comment-replies { margin-left: 24px; margin-top: 12px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9rem;
}
.form-input, .form-textarea, .form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color 0.2s;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
    outline: none;
    border-color: var(--color-primary);
}
.form-textarea { min-height: 120px; resize: vertical; }

.editor-wrapper {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
}
.editor-wrapper .ck-editor__editable {
    min-height: 400px;
}

/* Alerts */
.messages { margin-bottom: 16px; }
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.alert-info { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
[data-theme="dark"] .alert-success { background: #0d2818; color: #3fb950; border-color: #1a4028; }
[data-theme="dark"] .alert-error { background: #2d1013; color: #f85149; border-color: #4a1c1f; }
[data-theme="dark"] .alert-warning { background: #2d2200; color: #d29922; border-color: #4a3800; }
[data-theme="dark"] .alert-info { background: #0d2230; color: #58a6ff; border-color: #1a3a50; }
[data-theme="dark"] .upload-progress-item { background: #1a2332; }
[data-theme="dark"] .macro-status.green { background: #0d2818; color: #3fb950; }
[data-theme="dark"] .macro-status.yellow { background: #2d2200; color: #d29922; }
[data-theme="dark"] .macro-status.red { background: #2d1013; color: #f85149; }
[data-theme="dark"] .macro-status.blue { background: #0d2230; color: #58a6ff; }
.alert-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: inherit; }

/* Space cards */
.space-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.space-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.15s;
}
.space-card:hover { box-shadow: var(--shadow); text-decoration: none; }
.space-icon { font-size: 2rem; margin-bottom: 8px; }
.space-name { font-size: 1.1rem; font-weight: 600; color: var(--color-text); }
.space-desc { font-size: 0.85rem; color: var(--color-text-secondary); margin-top: 6px; }
.space-type {
    display: inline-block;
    padding: 2px 8px;
    background: var(--color-bg-secondary);
    border-radius: 4px;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 500;
    margin-top: 8px;
}

/* Version history */
.version-list { list-style: none; }
.version-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}
.version-info { flex: 1; }
.version-number { font-weight: 600; }
.version-meta { font-size: 0.8rem; color: var(--color-text-secondary); }

/* Search */
.search-results { margin-top: 20px; }
.search-result-item {
    padding: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 8px;
}
.search-result-item:hover { background: var(--color-bg-secondary); }
.search-result-title { font-weight: 600; font-size: 1.05rem; }
.search-result-space { font-size: 0.8rem; color: var(--color-text-secondary); }
.search-result-snippet {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-top: 4px;
}

/* Template picker */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.template-card {
    padding: 16px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--color-bg);
}
.template-card:hover { border-color: var(--color-primary); }
.template-card.active { border-color: var(--color-primary); background: var(--color-active-bg); }
.template-icon { font-size: 2rem; margin-bottom: 8px; }
.template-name { font-weight: 500; }

/* Permissions table */
.permissions-table { width: 100%; border-collapse: collapse; }
.permissions-table th, .permissions-table td { padding: 10px; border: 1px solid var(--color-border); }
.permissions-table th { background: var(--color-bg-secondary); text-align: left; }

/* Members list */
.member-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--color-border);
}
.member-info { display: flex; align-items: center; gap: 10px; }
.member-name { font-weight: 500; }
.member-role { font-size: 0.8rem; color: var(--color-text-secondary); }

/* Utility */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-secondary { color: var(--color-text-secondary); }
.text-sm { font-size: 0.85rem; }
.font-bold { font-weight: 600; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-text-secondary);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state-text { font-size: 1.1rem; margin-bottom: 16px; }

/* Macros */
.macro-toc {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px 24px;
    margin-bottom: 24px;
}
.macro-toc h4 { margin-bottom: 8px; }
.macro-toc ul { list-style: none; padding-left: 0; }
.macro-toc ul ul { padding-left: 16px; }
.macro-toc a { color: var(--color-text-secondary); font-size: 0.9rem; }

.macro-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}
.macro-status.green { background: #d4edda; color: #155724; }
.macro-status.yellow { background: #fff3cd; color: #856404; }
.macro-status.red { background: #f8d7da; color: #721c24; }
.macro-status.blue { background: #d1ecf1; color: #0c5460; }

.macro-page-list {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.macro-page-list-item {
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
}
.macro-page-list-item:last-child { border-bottom: none; }

/* Attachments */
.attachment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 6px;
}
.attachment-item:hover { background: var(--color-bg-secondary); }
.attachment-info { display: flex; align-items: center; gap: 12px; }
.attachment-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--color-text-secondary);
    flex-shrink: 0;
}
.attachment-name { font-weight: 500; }
.attachment-meta { font-size: 0.8rem; color: var(--color-text-secondary); }
.attachment-item.attachment-video,
.attachment-item.attachment-audio { flex-direction: column; align-items: stretch; }
.attachment-player { margin-bottom: 10px; width: 100%; }
.attachment-video-player { width: 100%; max-height: 70vh; border-radius: var(--radius); background: #000; object-fit: contain; }
.attachment-audio-player { width: 100%; }
.attachment-row { display: flex; justify-content: space-between; align-items: center; width: 100%; }

/* Bulk selection */
.attachment-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    margin-bottom: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-secondary);
}
.attachment-toolbar[hidden] { display: none; }
.attachment-toolbar-select {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
}
.attachment-toolbar-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}
.attachment-select,
#attachment-select-all {
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--color-primary);
}

/* Upload progress */
.upload-progress-item {
    padding: 12px 16px;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: #f0f7ff;
}
.upload-file-info { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.upload-filename { font-weight: 500; font-size: 0.9rem; }
.upload-status { font-size: 0.8rem; color: var(--color-text-secondary); }
.upload-bar-container {
    width: 100%;
    height: 6px;
    background: var(--color-border);
    border-radius: 3px;
    overflow: hidden;
}
.upload-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
    transition: width 0.2s;
}
.upload-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-top: 4px;
}

/* Safari compatibility */
.top-nav {
    position: -webkit-sticky;
}
.global-sidebar {
    position: -webkit-sticky;
}
.sidebar {
    position: -webkit-sticky;
}
.form-input, .form-textarea, .form-select {
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--color-bg);
    color: var(--color-text);
}
.form-select {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23586069' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}
.search-input {
    -webkit-appearance: none;
    appearance: none;
    color: var(--color-text);
}
.btn {
    -webkit-appearance: none;
    appearance: none;
}
/* Flex gap fallbacks for older Safari */
@supports not (gap: 8px) {
    .flex.gap-8 > * + * { margin-left: 8px; }
    .flex.gap-16 > * + * { margin-left: 16px; }
    .nav-right > * + * { margin-left: 10px; }
    .nav-left > * + * { margin-left: 8px; }
    .breadcrumbs > * + * { margin-left: 6px; }
    .tags > * + * { margin-left: 6px; }
    .reactions > * + * { margin-left: 6px; }
    .page-meta > * + * { margin-left: 16px; }
    .comment-actions > * + * { margin-left: 8px; }
    .member-info > * + * { margin-left: 10px; }
    .gs-space-header > * + * { margin-left: 4px; }
    .nav-tree-row > * + * { margin-left: 2px; }
    .space-grid { display: flex; flex-wrap: wrap; }
    .space-grid > * { margin: 8px; flex: 1 1 280px; }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .global-sidebar { display: none; }
    .main-content { padding: 16px; }
    .top-nav { padding: 0 12px; }
    .nav-center { display: none; }
    .space-grid { grid-template-columns: 1fr; }
    .nav-sidebar-toggle { display: none; }
}

/* ── Attachment preview modal ─────────────────────────────────────────── */
.attachment-download-link { color: var(--color-text-secondary); text-decoration: none; }
.attachment-download-link:hover { color: var(--color-primary); text-decoration: underline; }

.att-preview-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, 0.6); padding: 24px;
}
.att-preview-modal {
    background: var(--color-bg); border-radius: var(--radius);
    width: min(1000px, 100%); height: min(85vh, 100%);
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}
.att-preview-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--color-border);
    flex: 0 0 auto;
}
.att-preview-title {
    font-weight: 600; font-size: 0.9rem; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.att-preview-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.att-preview-actions #att-preview-close { font-size: 1.2rem; line-height: 1; padding: 2px 8px; }
.att-preview-body {
    flex: 1 1 auto; overflow: auto; background: var(--color-bg-secondary);
    display: flex; align-items: center; justify-content: center;
}
.att-preview-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.att-preview-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.att-preview-nopreview {
    padding: 40px 24px; text-align: center; color: var(--color-text-secondary);
    font-size: 0.9rem;
}

/* ── Attachment folder tree (Phase 4 navigation) ──────────────────────── */
.attachments-tree .attachment-item { margin-left: 0; }
.att-folder { margin: 2px 0; }
.att-folder-header {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px; cursor: pointer; border-radius: var(--radius);
    user-select: none; font-size: 0.9rem;
}
.att-folder-header:hover { background: var(--color-bg-hover); }
.att-folder-header:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.att-folder-toggle { font-size: 0.7rem; width: 12px; transition: transform 0.12s; color: var(--color-text-secondary); }
.att-folder.collapsed > .att-folder-header .att-folder-toggle { transform: rotate(-90deg); }
.att-folder-name { font-weight: 600; }
.att-folder-count {
    font-size: 0.72rem; color: var(--color-text-secondary);
    background: var(--color-bg-secondary); border-radius: 10px; padding: 1px 7px;
}
.att-folder-children { margin-left: 18px; border-left: 1px solid var(--color-border-light); padding-left: 8px; }
.att-folder.collapsed > .att-folder-children { display: none; }
