/* ============================================
   LAYOUT - Header, Sidebar, Main Content
   ============================================ */

/* ---- Loading Screen ---- */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.react-logo-spinner {
    width: 60px;
    height: 60px;
    position: relative;
}

.nucleus {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--accent-react);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 15px var(--accent-react);
}

.orbit {
    position: absolute;
    inset: 0;
    border: 2px solid rgba(97, 218, 251, 0.3);
    border-radius: 50%;
    border-top-color: var(--accent-react);
}

.orbit-1 {
    animation: spin 1s linear infinite;
}

.orbit-2 {
    inset: 8px;
    animation: spin 1.5s linear infinite reverse;
    border-color: rgba(168, 85, 247, 0.3);
    border-top-color: var(--accent-purple);
}

.orbit-3 {
    inset: 16px;
    animation: spin 2s linear infinite;
    border-color: rgba(34, 211, 238, 0.3);
    border-top-color: var(--accent-cyan);
}

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

.loader-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* ---- Header ---- */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    z-index: 1000;
    transition: background var(--transition-normal);
}

[data-theme="light"] #app-header {
    background: rgba(248, 250, 252, 0.85);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

#sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

#sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--accent-react);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none !important;
    cursor: pointer;
}

.logo-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
}

.logo-text .accent {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Search */
.header-center {
    flex: 1;
    max-width: 480px;
    margin: 0 1.5rem;
}

.search-wrapper {
    position: relative;
    width: 100%;
}

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

#search-input {
    width: 100%;
    padding: 0.55rem 3rem 0.55rem 2.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    transition: all var(--transition-normal);
}

#search-input::placeholder {
    color: var(--text-muted);
}

#search-input:focus {
    border-color: var(--accent-react);
    box-shadow: var(--shadow-glow);
    background: var(--bg-secondary);
}

.search-kbd {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    padding: 0.1rem 0.45rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    font-family: var(--font-sans);
    font-size: 0.7rem;
    color: var(--text-muted);
    pointer-events: none;
}

.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 100;
}

.search-results.hidden {
    display: none;
}

.search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--bg-hover);
}

.search-result-item .result-title {
    font-weight: 600;
    color: var(--text-heading);
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
}

.search-result-item .result-category {
    font-size: 0.75rem;
    color: var(--accent-react);
}

.search-no-results {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Theme Toggle */
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

#theme-toggle:hover {
    border-color: var(--accent-react);
    color: var(--accent-react);
    box-shadow: var(--shadow-glow);
}

/* ---- Sidebar ---- */
.app-container {
    display: flex;
    padding-top: var(--header-height);
    min-height: 100vh;
}

#sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 900;
    transition: transform var(--transition-slow);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.25rem 1.25rem 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.sidebar-version {
    font-size: 0.7rem;
    padding: 0.1rem 0.5rem;
    background: rgba(97, 218, 251, 0.1);
    color: var(--accent-react);
    border-radius: var(--radius-full);
    font-weight: 600;
}

#tree-nav {
    padding: 0.5rem 0;
    flex: 1;
    overflow-y: auto;
}

/* Tree Navigation Items */
.tree-section {
    margin-bottom: 0.25rem;
}

.tree-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    transition: color var(--transition-fast);
}

.tree-section-header:hover {
    color: var(--text-secondary);
}

.tree-section-header .chevron {
    display: inline-flex;
    transition: transform var(--transition-normal);
    font-size: 0.6rem;
}

.tree-section-header.collapsed .chevron {
    transform: rotate(-90deg);
}

.tree-section-items {
    overflow: hidden;
    transition: max-height var(--transition-slow);
}

.tree-section-items.collapsed {
    max-height: 0 !important;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 1.25rem 0.45rem 1.75rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 2px solid transparent;
    text-decoration: none !important;
    position: relative;
}

.tree-item::before {
    content: '';
    position: absolute;
    left: 1.25rem;
    top: 50%;
    width: 6px;
    height: 1px;
    background: var(--border-color);
}

.tree-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tree-item.active {
    background: var(--bg-active);
    color: var(--accent-react);
    border-left-color: var(--accent-react);
    font-weight: 500;
}

.tree-item .item-icon {
    font-size: 0.9rem;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.tree-item .item-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-item .item-badge {
    margin-left: auto;
    font-size: 0.65rem;
    padding: 0.05rem 0.4rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    flex-shrink: 0;
}

.badge-new {
    background: rgba(34, 197, 94, 0.15);
    color: var(--accent-green);
}

.badge-important {
    background: rgba(249, 115, 22, 0.15);
    color: var(--accent-orange);
}

.badge-hot {
    background: rgba(239, 68, 68, 0.15);
    color: var(--accent-red);
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 899;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

/* ---- Main Content ---- */
#main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-slow);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 2.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.breadcrumb-separator {
    opacity: 0.4;
}

.page-content {
    flex: 1;
    padding: 2rem 2.5rem 3rem;
    max-width: 920px;
    width: 100%;
}

/* ---- Page Footer ---- */
.page-footer {
    padding: 2rem 2.5rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.page-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 2rem;
}

.page-nav-btn {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    text-decoration: none !important;
    transition: all var(--transition-normal);
    max-width: 45%;
}

.page-nav-btn:hover {
    border-color: var(--accent-react);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.page-nav-btn.hidden {
    visibility: hidden;
}

.page-nav-btn.next {
    margin-left: auto;
    text-align: right;
}

.nav-direction {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.nav-title {
    font-size: 0.9rem;
    color: var(--accent-react);
    font-weight: 600;
}

.footer-info {
    text-align: center;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.footer-info p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ---- Back to Top ---- */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent-react);
    color: var(--text-inverse);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md), var(--shadow-glow);
    transition: all var(--transition-normal);
    z-index: 800;
}

.back-to-top:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.back-to-top.hidden {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}
