/* ---------------------------------------------------------------------------
   CSS Custom Properties
   --------------------------------------------------------------------------- */

:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    --bg: #F9FAFB;
    --surface: #FFFFFF;
    --text: #111827;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;
    --border: #E5E7EB;
    --border-light: #F3F4F6;
    --success: #10B981;
    --success-light: #D1FAE5;
    --accent: #6366F1;
    --accent-light: #E0E7FF;
    --error: #EF4444;
    --error-light: #FEE2E2;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

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

.hidden { display: none !important; }

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font);
}

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

.btn-secondary {
    background: var(--border-light);
    color: var(--text);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
    background: var(--error-light);
    color: var(--error);
}
.btn-danger:hover { background: var(--error); color: #fff; }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* ---------------------------------------------------------------------------
   Login Page
   --------------------------------------------------------------------------- */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #EEF2FF 0%, #F9FAFB 50%, #EDE9FE 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    border-radius: 16px;
    color: var(--primary);
    margin-bottom: 20px;
}

.login-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 28px;
}

.login-error {
    background: var(--error-light);
    color: var(--error);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

.login-form { text-align: left; }

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color 0.15s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.login-form .btn { margin-top: 8px; }

/* ---------------------------------------------------------------------------
   Top Navigation
   --------------------------------------------------------------------------- */

.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
}

.top-nav-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.nav-back:hover {
    background: var(--border-light);
    color: var(--text);
}

.nav-logo { color: var(--primary); }

.nav-title {
    font-size: 15px;
    font-weight: 600;
}

.top-nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-user {
    font-size: 13px;
    color: var(--text-secondary);
}

.nav-logout {
    font-size: 13px;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.15s;
}
.nav-logout:hover {
    background: var(--border-light);
    color: var(--text);
}

.nav-backup-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.nav-backup-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}
.nav-backup-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}
.nav-backup-status {
    font-size: 12px;
    color: var(--text-muted);
}
.nav-backup-status.backup-success {
    color: #10B981;
    font-weight: 500;
}

/* ---------------------------------------------------------------------------
   Home / Hub Page
   --------------------------------------------------------------------------- */

.hub-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 100px 24px 60px;
}

.hub-header {
    margin-bottom: 40px;
}

.hub-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 6px;
}

.hub-header p {
    color: var(--text-secondary);
    font-size: 15px;
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.app-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: all 0.2s ease;
    position: relative;
    text-decoration: none;
    color: var(--text);
}

.app-card-active {
    cursor: pointer;
}

.app-card-active:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.app-card-future {
    opacity: 0.5;
    cursor: default;
}

.app-card-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-card-active .app-card-icon {
    background: var(--primary-light);
    color: var(--primary);
}

.app-card-future .app-card-icon {
    background: var(--border-light);
    color: var(--text-muted);
}

.app-card-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.app-card-content p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.app-card-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-active {
    background: var(--success-light);
    color: var(--success);
}

.badge-coming {
    background: var(--border-light);
    color: var(--text-muted);
}

/* ---------------------------------------------------------------------------
   Library Layout
   --------------------------------------------------------------------------- */

.library-layout {
    display: flex;
    margin-top: 56px;
    min-height: calc(100vh - 56px);
}

/* Sidebar */
.library-sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    overflow-y: auto;
    flex-shrink: 0;
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
}

.upload-btn {
    margin-bottom: 24px;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-heading {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.tag-list {
    list-style: none;
}

.tag-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}

.tag-list li:hover {
    background: var(--border-light);
}

.tag-list li.active-tag {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.tag-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tag-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--border-light);
    padding: 1px 7px;
    border-radius: 10px;
}

.tag-delete-btn {
    display: none;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    text-align: center;
    align-items: center;
    justify-content: center;
}

.tag-edit-btn {
    display: none;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    line-height: 1;
    text-align: center;
    align-items: center;
    justify-content: center;
}
.tag-list li:hover .tag-delete-btn,
.tag-list li:hover .tag-edit-btn { display: flex; }
.tag-list li:hover .tag-count { display: none; }
.tag-edit-btn:hover { background: var(--accent-light); color: var(--accent); }
.tag-delete-btn:hover { background: var(--error-light); color: var(--error); }

.sidebar-empty {
    font-size: 13px;
    color: var(--text-muted);
    padding: 8px;
}

/* Main Content */
.library-main {
    flex: 1;
    margin-left: 260px;
    padding: 20px 28px;
    position: relative;
}

/* Search Bar */
.search-bar {
    position: relative;
    margin-bottom: 16px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    background: var(--surface);
    transition: border-color 0.15s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* Filter Bar */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.filter-tabs {
    display: flex;
    gap: 4px;
}

.filter-tab {
    padding: 6px 14px;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font);
}

.filter-tab:hover { background: var(--border-light); }
.filter-tab.active {
    background: var(--primary-light);
    color: var(--primary);
}

.view-toggles {
    display: flex;
    gap: 2px;
    background: var(--border-light);
    border-radius: 6px;
    padding: 2px;
}

.view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.view-btn.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    margin-bottom: 24px;
    transition: border-color 0.2s;
}

.upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon { color: var(--text-muted); margin-bottom: 12px; }
.upload-title { font-size: 16px; font-weight: 500; margin-bottom: 4px; }
.upload-divider { font-size: 13px; color: var(--text-muted); margin: 8px 0; }
.upload-formats { font-size: 12px; color: var(--text-muted); margin-top: 12px; }

/* Auto-split toggle */
.upload-option { margin-top: 16px; }
.auto-split-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 13px;
}
.auto-split-toggle input[type="checkbox"] {
    margin-right: 6px;
    accent-color: var(--accent);
}
.auto-split-label {
    font-weight: 500;
    color: var(--text-primary);
}
.auto-split-hint {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    max-width: 400px;
}

/* Split badge on cards */
.split-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.match-score-badge {
    display: inline-block;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: middle;
    letter-spacing: 0.3px;
}

/* Recording date in detail panel */
.recording-date-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.recording-date-label {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}
.recording-date-input {
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    outline: none;
}
.recording-date-input:focus { border-color: var(--accent); }

.paste-section { margin-top: 24px; }

.paste-divider-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.paste-divider-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

.paste-divider-text {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.paste-textarea {
    width: 100%;
    min-height: 100px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    resize: vertical;
    margin-bottom: 10px;
}

.paste-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* Processing Banner */
.processing-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    color: var(--primary);
    font-weight: 500;
}

.btn-cancel-processing {
    margin-left: auto;
    padding: 4px 14px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--error);
    border-radius: 6px;
    background: transparent;
    color: var(--error);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-cancel-processing:hover {
    background: var(--error);
    color: #fff;
}

.processing-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--primary-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Document Grid */
.doc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.doc-grid.list-view {
    grid-template-columns: 1fr;
}

.doc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}

/* Reserve space in the top-right corner of grid cards for the score badge */
.doc-card.has-score-badge {
    padding-top: 34px;
}

.doc-card > .match-score-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    margin-left: 0;
    z-index: 1;
}

.doc-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.doc-card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 10px;
}

.doc-type-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    flex-shrink: 0;
}

.doc-type-audio { background: #FEF3C7; color: #D97706; }
.doc-type-video { background: #DBEAFE; color: #2563EB; }
.doc-type-pdf { background: #FEE2E2; color: #DC2626; }
.doc-type-docx { background: #DBEAFE; color: #2563EB; }
.doc-type-pptx { background: #FDE68A; color: #B45309; }
.doc-type-csv { background: #D1FAE5; color: #059669; }
.doc-type-text { background: var(--border-light); color: var(--text-secondary); }

.doc-card-info { flex: 1; min-width: 0; }

.doc-card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-card-filename {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.doc-card-summary {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.doc-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-pill {
    padding: 2px 10px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.doc-card-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 10px;
}

/* Doc card in list view */
.list-view .doc-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
}

.list-view .doc-card-header { margin-bottom: 0; flex-shrink: 0; }
.list-view .doc-card-summary { display: none; }
.list-view .doc-card-tags { flex-shrink: 0; }
.list-view .doc-card-date { margin-top: 0; margin-left: auto; flex-shrink: 0; }

/* In list view, return the badge to inline flow on the right side */
.list-view .doc-card.has-score-badge { padding-top: 14px; }
.list-view .doc-card > .match-score-badge {
    position: static;
    order: 99;
    margin-left: 8px;
    flex-shrink: 0;
}

/* Status indicator on cards */
.doc-status-processing .doc-card-title::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--warning);
    border-radius: 50%;
    margin-left: 8px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 80px 24px;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p { font-size: 14px; max-width: 400px; margin: 0 auto; }

/* ---------------------------------------------------------------------------
   Detail Panel
   --------------------------------------------------------------------------- */

.detail-panel {
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    width: 560px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.08);
    z-index: 500;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.detail-header {
    padding: 20px 24px 0;
    position: relative;
}

.detail-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
}
.detail-close:hover { background: var(--border-light); color: var(--text); }

.detail-title {
    font-size: 20px;
    font-weight: 600;
    padding-right: 40px;
    outline: none;
    border-bottom: 2px solid transparent;
    transition: border-color 0.15s;
}
.detail-title:focus {
    border-bottom-color: var(--primary);
}

.detail-meta {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.gdrive-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.15s;
}

.gdrive-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

/* Detail Tabs */
.detail-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    margin-top: 16px;
}

.detail-tab {
    padding: 10px 16px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    font-family: var(--font);
}

.detail-tab:hover { color: var(--text); }
.detail-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.detail-text {
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    color: var(--text);
}

.detail-summary {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
}

/* Topics in detail */
.topic-card {
    background: var(--border-light);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
}

.topic-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.topic-name {
    font-size: 14px;
    font-weight: 600;
}

.topic-relevance {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
}

.topic-excerpt {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    padding: 8px 0 4px 12px;
    border-left: 2px solid var(--primary);
    margin-top: 6px;
}

/* Related docs in detail */
.related-doc {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.related-doc:hover { background: var(--border-light); }

.related-doc-title {
    font-size: 14px;
    font-weight: 500;
}

.related-doc-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* Detail Actions */
.detail-actions {
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* ---------------------------------------------------------------------------
   Folders in Sidebar
   --------------------------------------------------------------------------- */

.sidebar-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.sidebar-add-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}
.sidebar-add-btn:hover {
    background: var(--border-light);
    color: var(--primary);
}

.folder-list {
    list-style: none;
    margin-bottom: 8px;
}

.folder-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.folder-item:hover { background: var(--border-light); }
.folder-item.active-folder {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.folder-actions {
    display: none;
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    gap: 2px;
    align-items: center;
}
.folder-item:hover .folder-actions { display: flex; }

.folder-edit-btn,
.folder-delete-btn {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}
.folder-edit-btn { font-size: 13px; }
.folder-delete-btn { font-size: 16px; }
.folder-add-sub-btn { font-size: 16px; }
.folder-edit-btn:hover { background: var(--accent-light); color: var(--accent); }
.folder-delete-btn:hover { background: var(--error-light); color: var(--error); }
.folder-add-sub-btn {
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.folder-add-sub-btn:hover { background: var(--accent-light); color: var(--accent); }

/* Folder tree caret + nesting */
.folder-caret {
    display: inline-block;
    width: 16px;
    height: 16px;
    line-height: 16px;
    text-align: center;
    margin-right: 2px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: transform 0.12s ease;
    user-select: none;
    flex-shrink: 0;
    border-radius: 3px;
}
.folder-caret:hover { background: var(--border-light); color: var(--text); }
.folder-caret.expanded { transform: rotate(90deg); }
.folder-caret-spacer {
    display: inline-block;
    width: 14px;
    margin-right: 2px;
    flex-shrink: 0;
}
.folder-item { display: flex; align-items: center; gap: 6px; }
.folder-item .folder-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.folder-item svg { flex-shrink: 0; }

.folder-count {
    flex-shrink: 0;
    font-size: 0.7rem;
    color: var(--text-tertiary, #6b7280);
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
    min-width: 18px;
    text-align: center;
}
.folder-item.active-folder .folder-count {
    color: var(--accent, #818cf8);
    background: rgba(129, 140, 248, 0.12);
}

.new-folder-input {
    display: flex;
    gap: 4px;
    padding: 4px 10px;
}

.new-folder-input input {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    font-family: var(--font);
}

.new-folder-input input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ---------------------------------------------------------------------------
   Semantic Search
   --------------------------------------------------------------------------- */

.semantic-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
}

.semantic-toggle input {
    accent-color: var(--primary);
    cursor: pointer;
}

.semantic-label { font-weight: 500; }

.semantic-toggle input:checked ~ .semantic-label {
    color: var(--primary);
}

.search-bar { position: relative; }

.semantic-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #EDE9FE;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 13px;
    color: #6D28D9;
}

.semantic-banner svg { flex-shrink: 0; color: #6D28D9; }

/* ---------------------------------------------------------------------------
   Sort & Filter Right
   --------------------------------------------------------------------------- */

.filter-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sort-select {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.sort-select:focus { outline: none; border-color: var(--primary); }

/* ---------------------------------------------------------------------------
   Add Tag Input
   --------------------------------------------------------------------------- */

.add-tag-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.add-tag-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
}

.add-tag-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ---------------------------------------------------------------------------
   Topic Card Enhancements
   --------------------------------------------------------------------------- */

.topic-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topic-remove-btn {
    display: none;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    text-align: center;
}

.topic-card:hover .topic-remove-btn { display: flex; align-items: center; justify-content: center; }
.topic-remove-btn:hover { background: var(--error-light); color: var(--error); }

/* ---------------------------------------------------------------------------
   Folder Select in Detail
   --------------------------------------------------------------------------- */

.folder-select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: var(--font);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    min-width: 120px;
}

.folder-select:focus { outline: none; border-color: var(--primary); }

/* No results */
.no-results {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 768px) {
    .library-sidebar {
        display: none;
    }
    .library-main {
        margin-left: 0;
    }
    .detail-panel {
        width: 100%;
    }
    .app-grid {
        grid-template-columns: 1fr;
    }
    .hub-container {
        padding: 80px 16px 40px;
    }
    .doc-grid {
        grid-template-columns: 1fr;
    }
}
