/* ===== CSS Variables / Theme ===== */
:root[data-theme="dark"] {
    --bg: #0f1117;
    --bg-secondary: #181b25;
    --bg-tertiary: #1f2330;
    --bg-hover: #252936;
    --border: #2a2e3d;
    --border-light: #353a4d;
    --text: #e4e6ef;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --primary: #6366f1;
    --primary-hover: #5457e7;
    --primary-light: rgba(99, 102, 241, 0.15);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: rgba(239, 68, 68, 0.1);
    --success: #22c55e;
    --warning: #fbbf24;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --sidebar-width: 240px;
    --navbar-height: 60px;
}

:root[data-theme="light"] {
    --bg: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f3f9;
    --bg-hover: #eef0f6;
    --border: #e2e5ef;
    --border-light: #d1d5e0;
    --text: #1a1c25;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --primary: #6366f1;
    --primary-hover: #5457e7;
    --primary-light: rgba(99, 102, 241, 0.1);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: rgba(239, 68, 68, 0.08);
    --success: #22c55e;
    --warning: #f59e0b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --sidebar-width: 240px;
    --navbar-height: 60px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s, color 0.2s;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; }
svg { display: block; }

/* ===== Navbar ===== */
.navbar {
    height: var(--navbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 16px;
}
.navbar-left { display: flex; align-items: center; gap: 12px; }
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.15rem;
    white-space: nowrap;
}
.brand-icon { font-size: 1.4rem; }
.navbar-center { flex: 1; max-width: 500px; }
.navbar-right { display: flex; align-items: center; gap: 8px; }

.mobile-menu-btn { display: none; padding: 6px; border-radius: var(--radius-xs); color: var(--text-secondary); }
.mobile-menu-btn:hover { background: var(--bg-hover); color: var(--text); }

.global-search-wrapper {
    position: relative;
    width: 100%;
}
.global-search-wrapper .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
#globalSearch {
    width: 100%;
    padding: 9px 12px 9px 38px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
#globalSearch:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
#globalSearch::placeholder { color: var(--text-muted); }

.search-results-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    display: none;
    z-index: 200;
}
.search-results-dropdown.show { display: block; }
.search-result-group { padding: 8px 0; }
.search-result-group-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 4px 16px;
    font-weight: 600;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.1s;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-icon { font-size: 1.1rem; flex-shrink: 0; }
.search-result-info { flex: 1; min-width: 0; }
.search-result-name { font-weight: 500; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result-meta { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-no-results { padding: 20px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }

.theme-toggle {
    padding: 8px;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="light"] .icon-sun { display: none; }
:root[data-theme="light"] .icon-moon { display: block; }

.logout-btn {
    padding: 8px;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}
.logout-btn:hover { background: var(--danger-light); color: var(--danger); }

/* ===== Layout ===== */
.layout-wrapper {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
}
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    flex-shrink: 0;
    position: sticky;
    top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto;
}
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background 0.15s, color 0.15s;
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary); }
.sidebar-item.muted { color: var(--text-muted); font-size: 0.82rem; }
.sidebar-divider { height: 1px; background: var(--border); margin: 12px 0; }
.sidebar-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); padding: 4px 12px; font-weight: 600; margin-bottom: 4px; }

.main-content {
    flex: 1;
    padding: 28px 32px;
    min-width: 0;
}

/* ===== Login ===== */
.auth-main {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
}
.login-wrapper { width: 100%; max-width: 400px; }
.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 32px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-icon { font-size: 2.5rem; margin-bottom: 12px; }
.login-header h1 { font-size: 1.3rem; font-weight: 700; margin-bottom: 6px; }
.login-header p { color: var(--text-secondary); font-size: 0.9rem; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    text-align: center;
}
.pin-input-wrapper { position: relative; }
.pin-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1.3rem;
    text-align: center;
    letter-spacing: 0.5em;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.pin-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border-light); color: var(--text-secondary); }
.btn-outline:hover { background: var(--bg-hover); color: var(--text); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 6px 12px; font-size: 0.82rem; }
.btn-xs { padding: 4px 10px; font-size: 0.78rem; }
.btn-full { width: 100%; justify-content: center; }

.icon-btn {
    padding: 6px;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn-sm { padding: 4px; }
.icon-btn-danger:hover { background: var(--danger-light); color: var(--danger); }

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-title { font-size: 1.6rem; font-weight: 700; }
.page-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { font-size: 1.8rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.82rem; color: var(--text-secondary); }

/* ===== Sections ===== */
.section { margin-bottom: 32px; }
.section-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 14px; }

/* ===== Recent List ===== */
.recent-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}
.recent-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.recent-item:hover { border-color: var(--primary); transform: translateX(2px); }
.recent-icon { font-size: 1.3rem; flex-shrink: 0; }
.recent-info { flex: 1; min-width: 0; }
.recent-name { font-weight: 500; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-meta { font-size: 0.78rem; color: var(--text-muted); }
.recent-arrow { color: var(--text-muted); font-size: 1.1rem; }

/* ===== Workspace Grid ===== */
.workspace-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.workspace-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.workspace-card:hover { border-color: var(--primary); box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.workspace-card-header { display: flex; gap: 12px; align-items: flex-start; }
.workspace-icon { font-size: 1.8rem; flex-shrink: 0; }
.workspace-card-title h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.workspace-card-title p { font-size: 0.83rem; color: var(--text-secondary); }
.workspace-card-meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.meta-badge {
    font-size: 0.78rem;
    padding: 3px 10px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    font-weight: 500;
}
.meta-time { font-size: 0.78rem; color: var(--text-muted); }
.workspace-card-actions { display: flex; align-items: center; gap: 6px; margin-top: auto; }
.workspace-card-actions .btn-outline { flex: 1; justify-content: center; }

/* ===== Workspace Header ===== */
.workspace-header { margin-bottom: 24px; }
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 16px;
    transition: color 0.15s;
}
.back-link:hover { color: var(--primary); }
.workspace-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}
.workspace-title-info { display: flex; gap: 14px; align-items: flex-start; }
.workspace-title-icon { font-size: 2.2rem; }
.workspace-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Resource Toolbar ===== */
.resource-toolbar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.resource-search {
    position: relative;
    flex: 1;
    min-width: 200px;
}
.resource-search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}
.resource-search input {
    width: 100%;
    padding: 9px 12px 9px 38px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.resource-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.resource-search input::placeholder { color: var(--text-muted); }
.resource-controls { display: flex; gap: 8px; }
.select-control {
    padding: 9px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.88rem;
    outline: none;
    cursor: pointer;
}
.select-control:focus { border-color: var(--primary); }

/* ===== Filter Tabs ===== */
.filter-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 4px;
    flex-wrap: wrap;
}
.filter-tab {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    transition: all 0.15s;
    white-space: nowrap;
}
.filter-tab:hover { background: var(--bg-hover); color: var(--text); }
.filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Resource Grid ===== */
.resource-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}
.resource-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.resource-card:hover { border-color: var(--border-light); box-shadow: var(--shadow); }
.resource-card.favorite { border-color: var(--warning); box-shadow: 0 0 0 1px var(--warning); }
.resource-card-top { display: flex; align-items: center; gap: 10px; }
.resource-card-icon { font-size: 1.5rem; flex-shrink: 0; }
.resource-card-name { flex: 1; font-weight: 600; font-size: 0.95rem; }
.resource-card-fav {
    padding: 2px;
    color: var(--text-muted);
    border-radius: var(--radius-xs);
    transition: all 0.15s;
}
.resource-card-fav:hover { color: var(--warning); }
.resource-card-fav.active { color: var(--warning); }
.resource-card-url {
    font-size: 0.82rem;
    color: var(--primary);
    word-break: break-all;
    transition: opacity 0.15s;
}
.resource-card-url:hover { opacity: 0.8; text-decoration: underline; }
.resource-card-desc { font-size: 0.83rem; color: var(--text-secondary); }
.resource-card-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-badge {
    font-size: 0.72rem;
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    color: var(--text-secondary);
    font-weight: 500;
}
.tag-badge-info { background: var(--primary-light); color: var(--primary); }
.resource-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}
.resource-card-menu { display: flex; gap: 2px; }

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 20px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
    animation: fadeIn 0.15s ease;
}
.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.2s ease;
}
.modal-body-grid .form-row {
    display: flex;
    gap: 16px;
}
.modal-body-grid .form-row > .form-group {
    flex: 1;
}
.modal:has(.modal-body-grid) {
    max-width: 700px;
}
@media (max-width: 600px) {
    .modal-body-grid .form-row {
        flex-direction: column;
        gap: 0;
    }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.15rem; font-weight: 600; }
.modal-close {
    padding: 4px;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    transition: all 0.15s;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ===== Forms ===== */
.form-group { margin-bottom: 18px; }
.form-label {
    display: block;
    font-size: 0.83rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-secondary);
}
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.form-checkbox input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.form-checkbox span { font-size: 0.9rem; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    box-shadow: var(--shadow-lg);
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideInRight 0.2s ease;
    min-width: 250px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }
.toast-icon { font-size: 1.1rem; }

/* ===== Animations ===== */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOutRight { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* ===== Responsive / Mobile ===== */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: var(--navbar-height);
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .mobile-menu-btn { display: inline-flex; }
    .main-content { padding: 20px 16px; }
    .navbar-center { max-width: 100%; }
    .navbar-brand .brand-text { display: none; }
}

@media (max-width: 600px) {
    .page-header { flex-direction: column; }
    .workspace-title-row { flex-direction: column; }
    .workspace-actions { width: 100%; }
    .workspace-actions .btn { flex: 1; justify-content: center; }
    .form-row { grid-template-columns: 1fr; }
    .resource-toolbar { flex-direction: column; }
    .resource-controls { width: 100%; }
    .select-control { width: 100%; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .resource-grid { grid-template-columns: 1fr; }
    .workspace-grid { grid-template-columns: 1fr; }
    .recent-list { grid-template-columns: 1fr; }
    .toast-container { left: 16px; right: 16px; bottom: 16px; }
    .toast { min-width: 0; }
    .modal { max-width: 100%; }
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.15s ease;
}
.loading-overlay.hidden { display: none; }
.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.loading-text {
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 500;
    margin-top: 16px;
}

/* ===== Button Loading State ===== */
.btn.is-loading {
    pointer-events: none;
    opacity: 0.7;
    position: relative;
}
.btn.is-loading .btn-content { visibility: hidden; }
.btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ===== Role Badge ===== */
.role-badge {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 4px 10px;
    border-radius: 20px;
    text-transform: uppercase;
}
.role-admin {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
}
.role-viewer {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

/* ===== Favorites Page ===== */
.favorite-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
.favorite-item:hover { border-color: var(--warning); transform: translateX(2px); }
.favorite-item .recent-arrow { display: none; }
.recent-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ===== Skeleton Loading for cards ===== */
.skeleton-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    height: 160px;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
@keyframes skeleton-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Sub-Workspaces ===== */
.sub-workspace-section {
    margin-bottom: 24px;
}
.sub-workspace-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 12px;
}
.sub-workspace-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.2s, transform 0.2s;
}
.sub-workspace-card:hover {
    border-color: var(--border-light);
    transform: translateY(-2px);
}
.sub-workspace-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}
.sub-workspace-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}
.sub-workspace-card-title h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 4px 0;
}
.sub-workspace-card-title p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.4;
}
.sub-workspace-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== Resource Credentials ===== */
.resource-card-credentials {
    margin-top: 8px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.credential-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.credential-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 90px;
}
.credential-value {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}
.credential-text {
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.78rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 3px 8px;
    border-radius: 4px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.icon-btn-xs {
    padding: 3px;
    border-radius: 4px;
    flex-shrink: 0;
}

/* ===== Resource Notes ===== */
.resource-card-notes {
    margin-top: 8px;
}
.notes-toggle-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s;
}
.notes-toggle-btn:hover {
    border-color: var(--border-light);
    color: var(--text-primary);
}
.notes-viewer {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    font-size: 0.875rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-primary);
    max-height: 400px;
    overflow-y: auto;
}
