/* ===== BASE ===== */
body {
    padding-top: 56px;
    overflow: hidden;
}

/* ===== MAIN LAYOUT (Split Pane) ===== */
.main-layout {
    display: flex;
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px);
}

/* === Left Panel: Notes List === */
.notes-list-panel {
    width: 100%;
    height: 100%;
    overflow-y: auto;
}

/* === Right Panel: Note Detail === */
.note-detail-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Desktop: split pane side by side */
@media (min-width: 992px) {
    .notes-list-panel {
        width: 400px;
        min-width: 400px;
        max-width: 400px;
        border-right: 1px solid var(--bs-border-color);
    }

    .note-detail-panel {
        display: flex;
        flex: 1;
    }
}

/* Mobile: detail open = list hidden, detail fullscreen */
.main-layout.detail-open .note-detail-panel {
    display: flex;
}

@media (max-width: 991.98px) {
    .main-layout.detail-open .notes-list-panel {
        display: none;
    }

    .main-layout.detail-open .note-detail-panel {
        width: 100%;
    }

    /* Hide FAB when detail is open */
    .main-layout.detail-open ~ .fab-mobile {
        display: none !important;
    }
}

/* ===== CATEGORY HEADER ===== */
.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--bs-primary);
}

.category-header-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--bs-primary);
    margin: 0;
    letter-spacing: 0.02em;
}

.category-header-count {
    background: var(--bs-primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    min-width: 28px;
    text-align: center;
}

/* ===== NOTE LIST ITEMS ===== */
.note-item {
    padding: 14px 16px;
    margin-bottom: 6px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    background: var(--bs-tertiary-bg);
    border: 1px solid transparent;
}

.note-item:hover {
    background: var(--bs-secondary-bg);
    border-color: var(--bs-border-color);
}

.note-item.active {
    background: var(--bs-primary-bg-subtle);
    border-color: var(--bs-primary);
    border-left: 3px solid var(--bs-primary);
    padding-left: 13px;
}

.note-item-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--bs-primary);
}

.note-item-preview {
    font-size: 0.84rem;
    color: var(--bs-secondary-color);
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-bottom: 6px;
    line-height: 1.4;
}

.note-item-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
}

.note-item-meta .badge {
    font-weight: 500;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 8px;
    background: var(--bs-primary-bg-subtle) !important;
    color: var(--bs-primary) !important;
    border: 1px solid color-mix(in srgb, var(--bs-primary) 20%, transparent);
}

.note-item-favorite-btn {
    cursor: pointer;
    font-size: 1rem;
    color: var(--bs-secondary-color);
    opacity: 0.4;
    transition: color 0.15s, opacity 0.15s;
}

.note-item-favorite-btn.is-favorite {
    color: #ffc107;
    opacity: 1;
}

.note-item-favorite-btn:hover {
    color: #ffc107;
    opacity: 1;
}

/* Note actions always visible */
.note-item .note-item-actions {
    opacity: 1;
}

/* Mobile: bigger titles */
@media (max-width: 991.98px) {
    .note-item-title {
        font-size: 1.1rem;
    }
}

/* ===== SWIPE ACTIONS (Mobile) ===== */
.note-item-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    margin-bottom: 6px;
}

.note-item-wrapper .note-item {
    margin-bottom: 0;
    border-radius: 0;
    position: relative;
    z-index: 2;
    transition: transform 0.2s ease;
}

.swipe-bg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    padding: 0 24px;
    color: white;
    z-index: 1;
    transition: background-color 0.15s;
}

.swipe-bg i {
    font-size: 1.5rem;
}

.swipe-bg.swipe-delete {
    justify-content: flex-end;
    background: var(--bs-danger);
}

.swipe-bg.swipe-favorite {
    justify-content: flex-start;
    background: #ffc107;
    color: #333;
}

/* ===== CONTEXT MENU (Long Press) ===== */
.context-menu {
    position: fixed;
    z-index: 1080;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    padding: 6px 0;
    min-width: 200px;
    opacity: 0;
    transform: scale(0.92);
    transition: opacity 0.15s ease, transform 0.15s ease;
    pointer-events: none;
}

.context-menu.show {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 0.92rem;
    color: var(--bs-body-color);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    transition: background-color 0.1s;
}

.context-menu-item:hover,
.context-menu-item:active {
    background: var(--bs-tertiary-bg);
}

.context-menu-item i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.context-menu-item.text-danger i,
.context-menu-item.text-danger {
    color: var(--bs-danger) !important;
}

.context-menu-divider {
    height: 1px;
    background: var(--bs-border-color);
    margin: 4px 0;
}

/* ===== PULL TO REFRESH ===== */
.pull-indicator {
    text-align: center;
    padding: 0;
    overflow: hidden;
    height: 0;
    transition: height 0.2s ease;
    color: var(--bs-primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.pull-indicator.visible {
    height: 44px;
}

.pull-indicator .spinner-border {
    width: 18px;
    height: 18px;
    border-width: 2px;
}

/* ===== DETAIL PANEL ===== */
.detail-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--bs-secondary-color);
}

.detail-placeholder i {
    font-size: 3rem;
}

.detail-placeholder p {
    margin-top: 8px;
    font-size: 1.1rem;
}

.detail-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.detail-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--bs-border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.detail-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.detail-actions .form-select {
    width: auto;
    max-width: 180px;
}

.detail-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.detail-title {
    width: 100%;
    border: none;
    outline: none;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding: 4px 0;
    background: transparent;
    color: var(--bs-primary);
}

.detail-title::placeholder {
    color: var(--bs-secondary-color);
    font-weight: 400;
}

.detail-content {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    min-height: 300px;
    flex: 1;
    font-size: 1rem;
    line-height: 1.7;
    background: transparent;
    color: var(--bs-body-color);
}

.detail-content::placeholder {
    color: var(--bs-secondary-color);
}

.detail-footer {
    padding: 6px 16px;
    border-top: 1px solid var(--bs-border-color);
    text-align: right;
    flex-shrink: 0;
    min-height: 32px;
}

/* Save indicator */
#saveIndicator {
    transition: opacity 0.3s;
}

.save-saving {
    color: var(--bs-secondary-color) !important;
}

.save-saved {
    color: var(--bs-success) !important;
}

.save-error {
    color: var(--bs-danger) !important;
}

/* ===== FAB MOBILE ===== */
.fab-mobile {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--bs-primary);
    color: white;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1030;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab-mobile:hover,
.fab-mobile:active {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    background: var(--bs-primary);
    color: white;
}

/* ===== CATEGORIES ===== */
.category-item {
    cursor: pointer;
    padding: 10px 12px;
    margin: 2px 0;
    border-radius: 6px;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    color: inherit;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    transition: background-color 0.15s;
}

.category-item:hover {
    background-color: var(--bs-tertiary-bg);
}

.category-item.active {
    background-color: var(--bs-primary);
    color: white;
}

/* ===== SIDEBAR ===== */
.offcanvas.offcanvas-start {
    max-width: 70vw !important;
}

/* ===== MODALS ===== */
@media (min-width: 768px) {
    .modal-dialog {
        max-width: 600px;
    }
}

@media (min-width: 992px) {
    .modal-dialog {
        max-width: 700px;
    }
}

@media (min-width: 1200px) {
    .modal-dialog {
        max-width: 800px;
    }
}

.custom-modal {
    display: none;
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms cubic-bezier(.6, .6, 0, 1), transform 250ms cubic-bezier(.6, .6, 0, 1);
    transform: translateY(32px) scale(0.98);
    z-index: 1055;
}

.custom-modal.show {
    display: block;
    opacity: 1;
    pointer-events: auto;
    transform: none;
}

.custom-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    opacity: 0;
    z-index: 1050;
    pointer-events: none;
    transition: opacity 250ms cubic-bezier(.6, .6, 0, 1);
}

.custom-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 48px 16px;
}

.empty-state i {
    font-size: 3rem;
    color: var(--bs-secondary-color);
}

.empty-state h5 {
    color: var(--bs-secondary-color);
    margin-top: 12px;
}

.empty-state p {
    color: var(--bs-secondary-color);
    margin-top: 4px;
    font-size: 0.9rem;
}

/* ===== SEARCH HIGHLIGHT ===== */
mark {
    background-color: #fff3cd;
    padding: 0 2px;
    border-radius: 2px;
}

[data-bs-theme="dark"] mark {
    background-color: #664d03;
    color: #fff3cd;
}

/* ===== AI SEARCH ===== */
.ai-search-results {
    margin-top: 12px;
    max-height: 55vh;
    overflow-y: auto;
}

.ai-search-status {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 12px;
    font-size: 0.95rem;
    text-align: center;
}

.ai-search-count {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--bs-secondary-color);
    margin-bottom: 8px;
}

.ai-result-item {
    padding: 12px 14px;
    border: 1px solid var(--bs-border-color);
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.ai-result-item:hover {
    background-color: var(--bs-tertiary-bg);
    border-color: var(--bs-primary);
}

.ai-result-item:active {
    transform: scale(0.99);
}

.ai-result-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
}

.ai-result-title {
    font-weight: 600;
}

.ai-result-item .badge {
    flex-shrink: 0;
    background-color: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    font-weight: 500;
}

.ai-result-preview {
    font-size: 0.85rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
}

.ai-result-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
}

.ai-result-reason {
    font-size: 0.78rem;
    color: var(--bs-primary);
    display: inline-flex;
    align-items: center;
}
