/* Components CSS: Sidebar, Post-its, Audio Player, Export Dropdown, Pomodoro, Outline, Lore, Modals, Tour */

/* 1. Sidebar Panel */
#sidebar-panel {
    width: 260px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s ease;
    z-index: 5;
}

#sidebar-panel.collapsed {
    margin-left: -260px;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.sidebar-search {
    padding: 12px 16px;
}

.sidebar-search input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 6px 12px;
    color: var(--text-main);
    font-size: 0.85rem;
    outline: none;
}

.sidebar-search input:focus {
    border-color: var(--primary-accent);
}

.doc-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.88rem;
    transition: background 0.2s ease, color 0.2s ease;
}

.doc-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
}

.doc-item.active {
    background: rgba(var(--primary-accent-rgb), 0.2);
    color: var(--primary-accent);
    font-weight: 600;
}

.doc-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.doc-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.doc-item:hover .doc-actions {
    opacity: 1;
}


/* 2. Floating Post-it Sticky Notes (Muted Lo-Fi Pastel Palette) */
.postit-container {
    position: absolute;
    width: 230px;
    min-height: 180px;
    background: #d8c8b0;
    color: #1c1917;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    z-index: 20;
    border: 1px solid rgba(0, 0, 0, 0.12);
    transition: box-shadow 0.2s ease, height 0.2s ease;
}

.postit-container.minimized {
    min-height: 32px !important;
    height: 32px !important;
    overflow: hidden;
}

.postit-container.minimized .postit-body {
    display: none;
}

.postit-container:focus-within {
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    z-index: 25;
}

.postit-header {
    height: 30px;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: move;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.postit-colors {
    display: flex;
    gap: 5px;
}

.postit-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.postit-color-dot:hover {
    transform: scale(1.2);
}

.postit-btn-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.postit-btn-group button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    color: #44403c;
    padding: 2px 4px;
    border-radius: 4px;
}

.postit-btn-group button:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #0c0a09;
}

.postit-body {
    flex: 1;
    padding: 8px;
    display: flex;
}

.postit-textarea {
    width: 100%;
    height: 100%;
    min-height: 130px;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Caveat', cursive, sans-serif;
    font-size: 1.15rem;
    color: inherit;
    line-height: 1.3;
}

/* Muted Lo-Fi Colors */
.postit-yellow { background: #d8c8b0; color: #1c1917; }
.postit-pink { background: #cfa5ad; color: #2b181c; }
.postit-green { background: #a9bfa8; color: #162417; }
.postit-blue { background: #a4b8c9; color: #14222e; }
.postit-purple { background: #bfa4c9; color: #24162b; }


/* 3. Audio Ambient Mixer Panel */
#audio-panel {
    position: absolute;
    top: 60px;
    right: 160px;
    width: 280px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 30;
    display: none;
}

#audio-panel.open {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

.audio-item {
    margin-bottom: 12px;
}

.audio-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.audio-item input[type="range"] {
    width: 100%;
    accent-color: var(--primary-accent);
}


/* 4. Custom Pomodoro Timer Panel */
#pomodoro-panel {
    position: absolute;
    top: 60px;
    right: 120px;
    width: 260px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 30;
    display: none;
}

#pomodoro-panel.open {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

.pomo-custom-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.pomo-custom-input input[type="number"] {
    width: 60px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 4px 6px;
    color: var(--text-main);
    font-size: 0.9rem;
    text-align: center;
    outline: none;
}

.pomo-timer-display {
    font-size: 2.5rem;
    font-weight: 700;
    text-align: center;
    color: var(--text-main);
    letter-spacing: 2px;
    margin: 4px 0 14px 0;
    font-family: 'Space Mono', monospace;
}

.pomo-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.pomo-controls button {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    border: 1px solid var(--panel-border);
}


/* 5. Document Outline Panel */
#outline-panel {
    position: absolute;
    top: 60px;
    right: 170px;
    width: 280px;
    max-height: 380px;
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    z-index: 30;
    display: none;
    flex-direction: column;
}

#outline-panel.open {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.outline-list {
    overflow-y: auto;
    max-height: 320px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.outline-item {
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.outline-item:hover {
    background: rgba(var(--primary-accent-rgb), 0.2);
    color: var(--primary-accent);
}

.outline-h1 { font-weight: 700; color: var(--text-main); }
.outline-h2 { margin-left: 12px; font-size: 0.82rem; }
.outline-h3 { margin-left: 24px; font-size: 0.78rem; opacity: 0.8; }


/* 6. Lore & Character Bible Modal & Form */
#lore-modal .modal-container {
    width: 750px;
}

.lore-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
}

.lore-cats {
    display: flex;
    gap: 6px;
}

.lore-cat-btn {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

.lore-cat-btn.active {
    background: var(--primary-accent);
    color: white;
}

.lore-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-height: 440px;
    overflow-y: auto;
}

.lore-card {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.lore-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.lore-card-icon { font-size: 1.2rem; }
.lore-card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-main); flex: 1; }
.lore-card-badge { font-size: 0.68rem; text-transform: uppercase; background: rgba(var(--primary-accent-rgb), 0.25); color: var(--primary-accent); padding: 2px 6px; border-radius: 4px; }

.lore-card-details { font-size: 0.82rem; color: var(--text-muted); line-height: 1.4; white-space: pre-wrap; flex: 1; }

.lore-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 8px;
}

.lore-form-container {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
    display: none;
    flex-direction: column;
    gap: 12px;
}

.lore-form-container.open {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.lore-form-row {
    display: flex;
    gap: 10px;
}

.lore-form-row input,
.lore-form-row select,
.lore-form-container textarea {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--panel-border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text-main);
    font-size: 0.85rem;
    outline: none;
}

.lore-form-container textarea {
    width: 100%;
    min-height: 80px;
    resize: vertical;
}


/* 7. Export Dropdown Menu */
.export-dropdown-menu {
    position: absolute;
    bottom: 34px;
    right: 0;
    background: #1e293b;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    min-width: 190px;
    z-index: 40;
}

.export-dropdown-menu.open {
    display: flex;
    animation: fadeIn 0.15s ease-out;
}

.dropdown-item {
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 6px;
    text-align: left;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
}

.dropdown-item:hover {
    background: rgba(var(--primary-accent-rgb), 0.2);
    color: var(--primary-accent);
}

.dropdown-divider {
    height: 1px;
    background: var(--panel-border);
    margin: 4px 0;
}


/* 8. Settings Modal Dialog */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-container {
    width: 580px;
    max-width: 90vw;
    background: #1e293b;
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--panel-border);
    background: rgba(15, 23, 42, 0.4);
}

.tab-btn {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.88rem;
    cursor: pointer;
    transition: color 0.2s ease, background 0.2s ease;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary-accent);
    border-bottom-color: var(--primary-accent);
    background: rgba(var(--primary-accent-rgb), 0.1);
}

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-main);
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.preset-card {
    height: 70px;
    border-radius: 8px;
    background-size: cover;
    background-position: center;
    border: 2px solid transparent;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    padding: 6px;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.preset-card:hover {
    transform: scale(1.03);
}

.preset-card.active {
    border-color: var(--primary-accent);
}

.preset-title {
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.65);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
}


/* 9. Interactive Onboarding Tour */
.tour-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
    display: none;
    pointer-events: auto;
}

.tour-backdrop.open {
    display: block;
}

.tour-popover {
    position: fixed;
    width: 330px;
    background: #1e293b;
    border: 2px solid var(--primary-accent);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: none;
    flex-direction: column;
    gap: 8px;
    transition: top 0.25s ease, left 0.25s ease;
}

.tour-popover.open {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.tour-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tour-step-badge {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(var(--primary-accent-rgb), 0.25);
    color: var(--primary-accent);
    padding: 2px 8px;
    border-radius: 6px;
}

.tour-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px;
}

.tour-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 4px;
}

.tour-desc {
    font-size: 0.86rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.tour-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--panel-border);
}

.tour-btn {
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    border: none;
    font-weight: 600;
}

.tour-btn-sec {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
}

.tour-btn-main {
    background: var(--primary-accent);
    color: white;
}

.tour-target-highlight {
    position: relative;
    z-index: 95 !important;
    outline: 3px solid var(--primary-accent) !important;
    outline-offset: 2px;
    box-shadow: 0 0 15px var(--primary-accent) !important;
    border-radius: 6px;
    transition: outline 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Responsive Components & Modals for Mobile / Tablet */
@media (max-width: 768px) {
    /* Overlay Sidebar on Mobile */
    #sidebar-panel {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 85vw;
        max-width: 280px;
        z-index: 50;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.6);
    }

    #sidebar-panel.collapsed {
        margin-left: -85vw;
    }

    /* Centered Popovers on Mobile */
    #audio-panel,
    #pomodoro-panel,
    #outline-panel {
        position: fixed !important;
        top: 70px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        right: auto !important;
        width: 92vw !important;
        max-width: 340px !important;
        z-index: 60 !important;
    }

    /* Responsive Modals */
    .modal-container,
    #lore-modal .modal-container {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
        border-radius: 12px !important;
    }

    .lore-grid {
        grid-template-columns: 1fr !important;
    }

    .lore-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .lore-cats {
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .preset-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Mobile Post-its */
    .postit-container {
        max-width: 88vw !important;
    }

    /* Tour Popover on Mobile */
    .tour-popover {
        width: 92vw !important;
        left: 4vw !important;
        transform: none !important;
    }
}
