/* library-view component styles */

library-view {
    display: flex;
    flex: 1;
    overflow: hidden;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: #ececec;
}

library-view .library-sidebar {
    width: 240px;
    min-width: 240px;
    background: #16222c;
    border-right: 1px solid #2d4050;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
}

library-view .library-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0.75rem;
    font-weight: 700;
    font-size: 0.95rem;
}

library-view .library-add-btn {
    background: #3A7CA5;
    color: #fff;
    border: none;
    border-radius: 4px;
    width: 28px;
    height: 28px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

library-view .library-add-btn:hover { background: #81C3D7; }

library-view .library-section-title {
    padding: 0.5rem 1rem 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #8e8e8e;
    font-weight: 600;
    letter-spacing: 0.05em;
}

library-view .library-cat-item {
    padding: 0.4rem 1rem 0.4rem 1.5rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: #b4b4b4;
    border-left: 3px solid transparent;
}

library-view .library-cat-item:hover { background: #2d4050; }
library-view .library-cat-item.active {
    background: #243442;
    color: #ececec;
    border-left-color: #3A7CA5;
}

library-view .library-tags {
    padding: 0.5rem 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

library-view .library-tag {
    background: #243442;
    border: 1px solid #2d4050;
    color: #b4b4b4;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    cursor: pointer;
}

library-view .library-tag:hover { background: #2d4050; color: #ececec; }
library-view .library-tag.active { background: #3A7CA5; color: #fff; border-color: #3A7CA5; }

library-view .library-main {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    padding-bottom: 0.5rem;
}

library-view .library-main::-webkit-scrollbar { width: 6px; }
library-view .library-main::-webkit-scrollbar-track { background: transparent; }
library-view .library-main::-webkit-scrollbar-thumb { background: #2d4050; border-radius: 3px; }
library-view .library-main::-webkit-scrollbar-thumb:hover { background: #8e8e8e; }

library-view .library-page-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

library-view .library-card {
    background: #16222c;
    border: 1px solid #2d4050;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

library-view .library-card:hover { border-color: #3A7CA5; }

library-view .library-card-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
}

library-view .library-card-summary {
    font-size: 0.8rem;
    color: #b4b4b4;
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

library-view .library-card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

library-view .library-card-category {
    font-size: 0.7rem;
    background: #243442;
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
    color: #8e8e8e;
}

library-view .library-card-tag {
    font-size: 0.65rem;
    color: #81C3D7;
}

library-view .library-card-version {
    font-size: 0.7rem;
    background: #243442;
    padding: 0.1rem 0.5rem;
    border-radius: 4px;
    color: #81C3D7;
}

library-view .library-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1rem;
    color: #8e8e8e;
}

library-view .library-empty-text {
    font-size: 0.95rem;
}

library-view .library-empty-btn {
    background: #3A7CA5;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

library-view .library-empty-btn:hover { background: #81C3D7; }

/* Viewer */
library-view .library-viewer {
    max-width: 800px;
}

library-view .library-viewer-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

library-view .library-back-btn,
library-view .library-edit-btn,
library-view .library-delete-btn,
library-view .library-history-btn {
    background: #243442;
    border: 1px solid #2d4050;
    color: #b4b4b4;
    padding: 0.35rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
}

library-view .library-back-btn:hover,
library-view .library-edit-btn:hover,
library-view .library-history-btn:hover { background: #2d4050; color: #ececec; }
library-view .library-delete-btn:hover { background: #ef4444; color: #fff; border-color: #ef4444; }

library-view .library-viewer-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

library-view .library-viewer-meta {
    font-size: 0.8rem;
    color: #8e8e8e;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

library-view .library-viewer-content {
    line-height: 1.7;
    font-size: 0.9rem;
}

library-view .library-viewer-content h1,
library-view .library-viewer-content h2,
library-view .library-viewer-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

library-view .library-viewer-content p { margin-bottom: 0.75rem; }
library-view .library-viewer-content ul,
library-view .library-viewer-content ol { margin-bottom: 0.75rem; padding-left: 1.5rem; }
library-view .library-viewer-content li { margin-bottom: 0.25rem; }
library-view .library-viewer-content code {
    background: #243442;
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-size: 0.85em;
}
library-view .library-viewer-content pre {
    background: #243442;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0 0 0.75rem;
}
library-view .library-viewer-content pre code { background: none; padding: 0; }

/* Editor */
library-view .library-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
}

library-view .library-editor-tabs {
    display: flex;
    align-items: center;
    gap: 0;
    border-bottom: 1px solid #2d4050;
    margin-bottom: 1rem;
}

library-view .library-editor-tab {
    padding: 0.5rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #b4b4b4;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    margin-bottom: -1px;
    font-family: inherit;
}

library-view .library-editor-tab:hover { color: #ececec; }
library-view .library-editor-tab.active {
    color: #3A7CA5;
    border-bottom-color: #3A7CA5;
}

library-view .library-editor-panel {
    display: none;
    flex: 1;
    min-height: 0;
}

library-view .library-editor-panel.active {
    display: flex;
    flex-direction: column;
}

library-view .library-editor-panel-general {
    display: none;
}

library-view .library-editor-panel-general.active {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem 1.25rem;
    max-width: 800px;
    align-content: start;
}

library-view .library-editor-panel-general .form-group-full {
    grid-column: 1 / -1;
}

@media (max-width: 600px) {
    library-view .library-editor-panel-general.active {
        grid-template-columns: 1fr;
    }
}

library-view .library-editor .form-group {
    margin-bottom: 0.85rem;
}

library-view .library-editor label {
    display: block;
    font-size: 0.75rem;
    color: #b4b4b4;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

library-view .library-editor label .char-count {
    float: right;
    font-weight: 400;
    color: #b4b4b4;
    opacity: 0.7;
}
library-view .library-editor label .char-count.at-limit {
    color: #ef4444;
    opacity: 1;
}

library-view .library-editor .form-group > input,
library-view .library-editor .form-group > select,
library-view .library-editor .form-group > textarea {
    width: 100%;
    background: #243442;
    border: 1px solid #2d4050;
    color: #ececec;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.85rem;
    box-sizing: border-box;
}

library-view .library-editor .form-group > input:focus,
library-view .library-editor .form-group > select:focus,
library-view .library-editor .form-group > textarea:focus {
    outline: none;
    border-color: #b4b4b4;
}

library-view .library-editor-panel-general textarea {
    min-height: 60px;
    resize: vertical;
    font-size: 0.85rem;
    line-height: 1.4;
}

library-view .library-editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

library-view .library-save-btn {
    background: #3A7CA5;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.45rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

library-view .library-save-btn:hover { background: #81C3D7; }
library-view .library-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

library-view .library-cancel-btn {
    background: none;
    color: #b4b4b4;
    border: 1px solid #2d4050;
    border-radius: 6px;
    padding: 0.45rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

library-view .library-cancel-btn:hover { background: #2d4050; color: #ececec; }

/* Editor Delete button in tab row */
library-view .lib-ed-delete-btn { padding: 0.2rem 0.6rem; font-family: inherit; }

/* Tag editor */
library-view .tag-editor {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    align-items: center;
    background: #243442;
    border: 1px solid #2d4050;
    border-radius: 4px;
    padding: 0.3rem 0.5rem;
    cursor: text;
    min-height: 34px;
}

library-view .tag-editor:focus-within { border-color: #b4b4b4; }

library-view .tag-editor-input {
    background: none;
    border: none;
    outline: none;
    color: #ececec;
    font-size: 0.85rem;
    font-family: inherit;
    flex: 1;
    min-width: 80px;
}

library-view .tag-editor-input::placeholder { color: #8e8e8e; }

library-view .tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: #2F6690;
    color: #ececec;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
}

library-view .tag-pill-remove {
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.7;
}

library-view .tag-pill-remove:hover { opacity: 1; }

/* Content editor */
library-view .content-editor-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

library-view .content-editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    background: #16222c;
    border: 1px solid #2d4050;
    border-radius: 6px 6px 0 0;
    flex-wrap: wrap;
}

library-view .content-editor-toolbar button {
    background: none;
    border: 1px solid transparent;
    color: #b4b4b4;
    padding: 0.2rem 0.45rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
}

library-view .content-editor-toolbar button:hover { background: #2d4050; color: #ececec; }
library-view .content-editor-toolbar button.active { background: #2F6690; color: #ececec; }

library-view .content-editor-toolbar select {
    background: #243442;
    border: 1px solid #2d4050;
    color: #b4b4b4;
    padding: 0.2rem 0.3rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

library-view .ce-sep {
    width: 1px;
    height: 18px;
    background: #2d4050;
    margin: 0 0.15rem;
}

/* "Source" HTML-view toggle button */
library-view .ce-viewtabs {
    display: inline-flex;
    border: 1px solid #2d4050;
    border-radius: 4px;
    overflow: hidden;
}
library-view .ce-viewtabs button {
    background: none;
    border: none;
    border-left: 1px solid #2d4050;
    color: #b4b4b4;
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
}
library-view .ce-viewtabs button:first-child { border-left: none; }
library-view .ce-viewtabs button:hover { background: #2d4050; color: #ececec; }
library-view .ce-viewtabs button.active { background: #2F6690; color: #ececec; }

library-view .content-editor-body {
    display: flex;
    flex: 1;
    min-height: 0;
    border: 1px solid #2d4050;
    border-top: none;
    border-radius: 0 0 6px 6px;
}

library-view .content-editor-body textarea {
    flex: 1;
    background: #243442;
    color: #ececec;
    border: none;
    padding: 0.75rem;
    font-family: 'SFMono-Regular', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    border-radius: 0 0 6px 6px;
    min-height: 300px;
}

/* Rich (WYSIWYG) editing surface */
library-view .content-editor-rich {
    flex: 1;
    background: #243442;
    color: #ececec;
    padding: 0.75rem;
    overflow-y: auto;
    line-height: 1.7;
    font-size: 0.9rem;
    outline: none;
    border-radius: 0 0 6px 6px;
    min-height: 300px;
}
library-view .content-editor-rich:empty::before {
    content: 'Start typing\2026';
    color: #8e8e8e;
}
library-view .content-editor-rich h1,
library-view .content-editor-rich h2,
library-view .content-editor-rich h3 { margin: 0.6em 0 0.3em; line-height: 1.25; }
library-view .content-editor-rich p { margin: 0 0 0.6em; }
library-view .content-editor-rich ul,
library-view .content-editor-rich ol { margin: 0 0 0.6em 1.4em; }
library-view .content-editor-rich blockquote {
    margin: 0 0 0.6em;
    padding: 0.1em 0.9em;
    border-left: 3px solid #2F6690;
    color: #b4b4b4;
}
library-view .content-editor-rich code {
    background: #16222c;
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-family: 'SFMono-Regular', 'Consolas', monospace;
    font-size: 0.85em;
}
library-view .content-editor-rich pre {
    background: #16222c;
    padding: 0.75rem;
    border-radius: 4px;
    overflow-x: auto;
}
library-view .content-editor-rich pre code { background: none; padding: 0; }
library-view .content-editor-rich mark { background: #f6e05e; color: #1a202c; padding: 0 0.15em; }
library-view .content-editor-rich img { max-width: 100%; }
library-view .content-editor-rich table { border-collapse: collapse; margin: 0 0 0.6em; }
library-view .content-editor-rich th,
library-view .content-editor-rich td { border: 1px solid #2d4050; padding: 0.3em 0.6em; }
library-view .content-editor-rich hr { border: none; border-top: 1px solid #2d4050; margin: 0.8em 0; }

library-view .ce-hidden { display: none !important; }

/* Version history */
library-view .version-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.75rem; }
library-view .version-row {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 0.5rem 0.75rem; background: #243442;
    border: 1px solid #2d4050; border-radius: 6px;
}
library-view .version-meta { display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; font-size: 0.85rem; }
library-view .version-seq { font-weight: 600; color: #81C3D7; }
library-view .version-when { color: #b4b4b4; }
library-view .version-author { color: #b4b4b4; }
library-view .version-msg { color: #8e8e8e; font-style: italic; }
library-view .version-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
library-view .version-actions button {
    background: #16222c; border: 1px solid #2d4050;
    color: #b4b4b4; border-radius: 4px;
    padding: 0.25rem 0.6rem; font-size: 0.8rem; font-family: inherit; cursor: pointer;
}
library-view .version-actions button:hover { background: #2d4050; color: #ececec; }

/* Toast */
library-view .library-toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #243442;
    color: #ececec;
    border: 1px solid #2d4050;
    padding: 0.5rem 1.25rem;
    border-radius: 8px;
    font-size: 0.85rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1000;
}

library-view .library-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
    library-view {
        flex-direction: column;
    }
    library-view .library-sidebar {
        width: 100%;
        min-width: 0;
        max-height: 150px;
        border-right: none;
        border-bottom: 1px solid #2d4050;
    }
    library-view .library-page-list {
        grid-template-columns: 1fr;
    }
    library-view .library-editor-panel-general.active {
        grid-template-columns: 1fr;
    }
}
