/* ============================================
   NoteView - Layout Styles
   ============================================ */

#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
#sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Right Sidebar */
#sidebarRight {
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: relative;
    transition: width 0.3s ease, min-width 0.3s ease;
}
#sidebarRight.collapsed {
    width: 0;
    min-width: 0;
    border-left: none;
    overflow: hidden;
}
.sidebar-right-toggle {
    position: absolute;
    right: 279px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    color: var(--text-muted);
    padding: 0;
    transition: right 0.3s ease;
}
.sidebar-right-toggle:hover {
    color: var(--text-primary);
}
.sidebar-right-toggle svg {
    transition: transform 0.3s ease;
}
#sidebarRight.collapsed ~ .sidebar-right-toggle,
.sidebar-right-toggle.shifted {
    right: -1px;
}
.sidebar-right-toggle.rotated svg {
    transform: rotate(180deg);
}

.app-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-logo-link {
    color: inherit;
    text-decoration: none;
}
.app-logo-link:hover {
    text-decoration: underline;
}

.theme-toggle {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
}
.theme-toggle:hover {
    opacity: 1;
}

/* Sidebar Sections */
.sidebar-section {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.vault-switcher {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.65rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 0;
}

.vault-switcher:hover {
    background: var(--bg-hover, rgba(255,255,255,0.06));
    color: var(--text-primary);
}

.vault-switcher .vault-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: left;
}

.vault-switcher .vault-chevron {
    opacity: 0.5;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.vault-switcher:hover .vault-chevron {
    opacity: 0.8;
}

.sidebar-settings-btn {
    flex-shrink: 0;
    opacity: 0.6;
    transition: opacity 0.15s;
}

.sidebar-settings-btn:hover {
    opacity: 1;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.section-header h3 {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
}

/* View Selector */
.view-selector select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.view-selector select:hover {
    border-color: var(--border-light);
}

.view-selector select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Search */
.search {
    position: relative;
}

.search input {
    width: 100%;
    padding: 0.6rem 0.75rem 0.6rem 2.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.search::before {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    background: currentColor;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat center / contain;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat center / contain;
    opacity: 0.4;
}

.search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

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

/* Edit Sidebar Tags */
.edit-tags-btn {
    background: transparent;
    border: none;
    font-size: 0.8rem;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.edit-tags-btn:hover,
#contextTagGroup.editing-tags .edit-tags-btn {
    opacity: 1;
}

/* Main Content */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-primary);
}

#viewContainer {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

/* No-vault state: hide sidebars and edges */
#app.no-vault #sidebar,
#app.no-vault #sidebarRight,
#app.no-vault #sidebarRightToggle,
#app.no-vault .sidebar-edge { display: none !important; }

/* Mobile Responsive */
#sidebarOverlay { display: none; }
.sidebar-edge { display: none; }

@media (max-width: 768px) {
    body.sidebar-open { overflow: hidden; }
    body { overscroll-behavior-x: none; }

    .sidebar-edge {
        display: block;
        position: fixed;
        top: 0;
        height: 100vh;
        height: 100dvh;
        width: 8px;
        cursor: pointer;
        z-index: 50;
        transition: background 0.2s;
    }
    .sidebar-edge::before {
        content: '';
        position: absolute;
        top: 0;
        height: 100%;
        width: 28px;
    }
    .sidebar-edge-left {
        left: 0;
        background: var(--border);
    }
    .sidebar-edge-left::before { right: -28px; }
    .sidebar-edge-right {
        right: 0;
        background: var(--border);
    }
    .sidebar-edge-right::before { left: -28px; }
    .sidebar-edge-left.hidden { display: none; }
    .sidebar-edge-right.hidden { display: none; }

    #sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        height: 100dvh;
        z-index: 100;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding-left: env(safe-area-inset-left);
    }
    #sidebar.sidebar-open { left: 0; }

    #sidebarRight {
        position: fixed;
        top: 0;
        right: -280px;
        width: 280px;
        height: 100vh;
        height: 100dvh;
        z-index: 100;
        background: var(--bg-secondary);
        border-left: 1px solid var(--border);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transition: right 0.3s ease;
        overflow-y: auto;
        padding-right: env(safe-area-inset-right);
    }
    #sidebarRight.sidebar-open { right: 0; }
    .sidebar-right-toggle { display: none; }

    #sidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
    }
    #sidebarOverlay.active { display: block; }

    #viewContainer { padding: 1rem; padding-top: 3.5rem; }
}

/* PWA install banner */
.install-banner {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--accent);
    padding: 0.75rem 1rem;
    z-index: 200;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top));
}
.install-banner.visible {
    display: flex;
}
.install-banner span {
    flex: 1;
    color: #fff;
}
.install-banner button {
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm, 6px);
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}
.install-banner #installBtn {
    background: #fff;
    color: var(--accent);
    border: none;
    font-weight: 600;
}
.install-banner .dismiss {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0.3rem 0.5rem;
}
