:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-shade: #f3f4f6;
    --bg-surface: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --danger-color: #ef4444;
    --navbar-height: 60px;
    --sidebar-width: 280px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-shade);
    margin: 0;
    padding: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Base resets */
* {
    box-sizing: border-box;
}

h1, h2, h3, p {
    margin: 0;
}

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

/* App Layout */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 1.2rem;
    justify-content: space-between;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-shade);
    height: 100%;
}

.topbar {
    height: var(--navbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
}

.workspace {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Category Tree Styles */
.category-tree ul {
    list-style: none;
    padding-left: 20px;
    margin: 0;
}

.category-tree > ul {
    padding-left: 0; /* Root ul */
}

.category-item {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    cursor: pointer;
    color: var(--text-main);
    transition: background 0.1s;
    user-select: none;
}

.category-item:hover {
    background: var(--bg-shade);
}

.category-item.active {
    background: #e0e7ff;
    color: var(--primary-hover);
    font-weight: 500;
}

.category-toggle {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.doc-list {
    margin-top: 5px;
}

.doc-item {
    padding: 6px 20px 6px 48px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.95rem;
    display: block;
}

.doc-item.active-doc {
    color: var(--primary-hover);
    font-weight: 500;
    background: #f0fdf4;
}

.doc-item:hover {
    background: var(--bg-shade);
    color: var(--text-main);
}

/* Editor styles */
.editor-container {
    background: var(--bg-surface);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.editor-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.doc-title-input {
    width: 100%;
    font-size: 24px;
    font-weight: 600;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-main);
}

.tag-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tag {
    background: #e2e8f0;
    color: #475569;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
}

.tag-remove {
    margin-left: 6px;
    cursor: pointer;
    font-weight: bold;
}

.tag-input {
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: 4px;
    outline: none;
    font-size: 0.85rem;
}

.editor-body {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

/* CKEditor 5 override inside container */
.ck-editor {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

.ck-editor__main {
    flex: 1 !important;
    overflow-y: auto !important;
}

.ck-content {
    height: 100% !important;
    border: none !important;
    border-radius: 0 !important;
}

.ck.ck-editor__main>.ck-editor__editable:not(.ck-focused) {
    border-color: transparent !important;
}

/* Buttons and Inputs */
.btn {
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #fff;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-shade);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-shade);
    border-radius: 20px;
    padding: 6px 16px;
    width: 300px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
}

.search-bar input {
    border: none;
    background: transparent;
    outline: none;
    width: 100%;
    padding: 4px 8px;
    font-size: 0.9rem;
}

.autosave-indicator {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.modal {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.modal.active {
    display: flex;
}

.modal-header {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    outline: none;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Dashboard Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.empty-state h2 {
    margin-bottom: 8px;
    color: var(--text-main);
}
