/* XMail — Custom styles */

body {
    background-color: #f5f6fa;
}

/* Match button height to Bootstrap floating label inputs */
.btn-floating-height {
    height: calc(3.5rem + 2px);
}

.email-frame {
    width: 100%;
    min-height: 500px;
    border: none;
    background: #fff;
}

.email-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 0.95rem;
    background: #fff;
}

.list-group-item-action.fw-bold {
    background-color: #f0f4ff;
}

.email-from {
    min-width: 180px;
    display: inline-block;
}

.navbar-brand {
    font-weight: 600;
}

/* User avatar badges */
.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 600;
    flex-shrink: 0;
    line-height: 1;
    vertical-align: middle;
}

.user-avatar-sm {
    width: 24px;
    height: 24px;
    font-size: 0.65rem;
}

.user-avatar-md {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
}

.user-avatar-lg {
    width: 40px;
    height: 40px;
    font-size: 0.9rem;
}

/* Category tree (legacy + sidebar) */
.category-tree .category-node {
    margin-bottom: 0.15rem;
}

.category-tree .category-header,
.sidebar-cat-header {
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 0.375rem;
    transition: background-color 0.15s;
}

.category-tree .category-header:hover,
.sidebar-cat-header:hover {
    background-color: #f0f4ff;
}

.category-tree .category-chevron,
.sidebar-cat-header .category-chevron {
    transition: transform 0.2s;
    font-size: 0.75rem;
}

.category-tree .collapsed .category-chevron,
.sidebar-cat-header.collapsed .category-chevron {
    transform: rotate(-90deg);
}

.sidebar-add-mailbox {
    opacity: 0;
    transition: opacity 0.15s;
}

.sidebar-cat-header:hover .sidebar-add-mailbox {
    opacity: 1;
}

.sidebar-drag-handle {
    opacity: 0;
    transition: opacity 0.15s;
}

.sidebar-mailbox:hover .sidebar-drag-handle {
    opacity: 0.5;
}

.sidebar-mailbox:hover .sidebar-drag-handle:hover {
    opacity: 1;
}

/* Admin category tree — sortable */
.sortable-list {
    padding-left: 1.5rem;
}

.sortable-list:first-child {
    padding-left: 0;
}

.sortable-item {
    transition: background-color 0.15s, box-shadow 0.15s;
    cursor: grab;
}

.sortable-item:hover {
    background-color: #f8f9fa !important;
}

.sortable-ghost {
    opacity: 0.4;
}

.sortable-ghost > .sortable-item {
    border-style: dashed !important;
    border-color: #0d6efd !important;
    background-color: #e8f0fe !important;
}

.sortable-chosen > .sortable-item {
    box-shadow: 0 0.25rem 0.75rem rgba(0,0,0,0.15);
}

.sortable-drag {
    opacity: 0.9;
}

/* Category color picker */
.cat-color-trigger {
    cursor: pointer;
    position: relative;
}

.cat-color-trigger:hover {
    opacity: 0.7;
}

.cat-color-input {
    position: absolute;
    width: 0;
    height: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

/* Mailbox access avatars in admin tree */
.mailbox-avatars {
    flex-wrap: wrap;
}

.mailbox-avatar-badge {
    transition: opacity 0.15s, transform 0.15s;
}

.mailbox-avatar-badge:hover {
    opacity: 0.7;
    transform: scale(1.15);
}

/* Inline editable names */
.cat-name-editable:hover,
.mailbox-name-editable:hover {
    text-decoration: underline;
    text-decoration-style: dashed;
    text-underline-offset: 3px;
}

/* Mixed tree node type indicators */
li[data-type="mailbox"] > .sortable-item {
    border-left: 3px solid #0d6efd;
}

li[data-type="category"] > .sortable-item {
    border-left: 3px solid #ffc107;
}

/* Context menu (right-click on mailbox) */
.mailbox-context-menu {
    position: absolute;
    z-index: 10000;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    box-shadow: 0 0.25rem 1rem rgba(0,0,0,0.15);
    min-width: 220px;
    padding: 0.25rem 0;
    font-size: 0.85rem;
}

.context-menu-item {
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    transition: background-color 0.1s;
}

.context-menu-item:hover {
    background-color: #f0f4ff;
}

.context-menu-item-danger:hover {
    background-color: #fff0f0;
    color: #dc3545;
}

.context-menu-separator {
    height: 1px;
    background-color: #dee2e6;
    margin: 0.25rem 0;
}

.context-menu-label {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    color: #6c757d;
    font-weight: 600;
    text-transform: uppercase;
}

.context-menu-colors {
    display: flex;
    gap: 0.35rem;
    padding: 0.25rem 0.75rem 0.35rem;
    align-items: center;
}

.context-menu-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.context-menu-color:hover {
    transform: scale(1.2);
}

.context-menu-color-active {
    border-color: #212529;
}

.context-menu-color-none {
    background-color: #dee2e6;
    font-size: 0.65rem;
    color: #6c757d;
}

/* Email color indicator */
.email-color-indicator {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: 2px 0 0 2px;
}

/* ========================================
   Split-pane layout (Outlook-like)
   ======================================== */

.split-pane {
    display: flex;
    height: calc(100vh - 56px - 48px);
    overflow: hidden;
    background: #fff;
}

/* Sidebar */
.split-sidebar {
    width: 300px;
    min-width: 300px;
    max-width: 300px;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
}

.split-sidebar-header {
    border-bottom: 1px solid #dee2e6;
    background: #f0f1f3;
    flex-shrink: 0;
}

.split-sidebar-body {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem 0;
}

/* Sidebar mailbox items */
.sidebar-mailbox {
    padding: 0.35rem 0.5rem;
    border-radius: 0.25rem;
    margin: 1px 0.35rem;
    font-size: 0.85rem;
    transition: background-color 0.12s;
}

.sidebar-mailbox:hover {
    background-color: #e2e6ea;
}

.sidebar-mailbox-active {
    background-color: #0d6efd !important;
    color: #fff !important;
}

.sidebar-mailbox-active .text-truncate,
.sidebar-mailbox-active .sidebar-mailbox-addr,
.sidebar-mailbox-active i {
    color: #fff !important;
}

.sidebar-mailbox-active .sidebar-badge {
    color: #fff !important;
}

.sidebar-cat-name {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6c757d;
}

.sidebar-badge {
    font-size: 0.7rem;
}

/* Email list panel */
.split-list {
    width: 380px;
    min-width: 300px;
    max-width: 450px;
    border-right: 1px solid #dee2e6;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.split-list-header {
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    flex-shrink: 0;
}

.split-list-body {
    overflow-y: auto;
    flex: 1;
}

/* Email rows */
.email-row {
    position: relative;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.1s;
}

.email-row:hover {
    background-color: #f5f7ff;
}

.email-row-active {
    background-color: #e8f0fe !important;
    border-left: 3px solid #0d6efd;
}

.email-row-unread {
    font-weight: 600;
}

.email-row-unread .email-row-subject {
    color: #212529;
}

.email-row-main {
    display: flex;
    align-items: center;
    margin-bottom: 2px;
}

.email-row-from {
    font-size: 0.85rem;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-row-subject {
    font-size: 0.8rem;
    color: #666;
}

.email-row-date {
    font-size: 0.72rem;
    color: #999;
    margin-top: 1px;
}

/* Preview panel */
.split-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}

.split-preview-body {
    overflow-y: auto;
    flex: 1;
}

.split-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #adb5bd;
}

/* Email list tabs (Reçus / Envoyés) */
.email-tabs {
    display: flex;
    gap: 0;
}

.email-tab {
    background: none;
    border: none;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: #6c757d;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.email-tab:hover {
    color: #333;
}

.email-tab-active {
    color: #0d6efd;
    border-bottom-color: #0d6efd;
    font-weight: 600;
}

/* Preview actions (Reply / Forward) */
.preview-actions {
    background: #f8f9fa;
}

/* Quill editor in compose modal */
#composeEditor {
    min-height: 200px;
    background: #fff;
}

#composeEditor .ql-editor {
    min-height: 180px;
    font-size: 0.9rem;
}

/* Compose attachment list */
.compose-attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.compose-attachment-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    background: #e9ecef;
    border-radius: 0.25rem;
    font-size: 0.78rem;
    color: #495057;
}

[data-bs-theme="dark"] .compose-attachment-badge {
    background: #343a40;
    color: #dee2e6;
}

/* Preview content */
.preview-header {
    border-bottom: 1px solid #dee2e6;
    background: #fafbfc;
}

.preview-attachments {
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    font-size: 0.85rem;
}

.preview-body {
    flex: 1;
}

.preview-iframe {
    width: 100%;
    min-height: 300px;
    border: none;
    background: #fff;
}

.preview-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
    margin: 0;
}

/* ========================================
   Dark mode overrides
   ======================================== */

[data-bs-theme="dark"] body {
    background-color: #1a1d21;
}

[data-bs-theme="dark"] .email-frame,
[data-bs-theme="dark"] .email-text,
[data-bs-theme="dark"] .preview-text,
[data-bs-theme="dark"] .preview-iframe {
    background: #212529;
}

[data-bs-theme="dark"] .list-group-item-action.fw-bold {
    background-color: #2b3035;
}

[data-bs-theme="dark"] .split-pane,
[data-bs-theme="dark"] .split-list,
[data-bs-theme="dark"] .split-preview {
    background: #212529;
}

[data-bs-theme="dark"] .split-sidebar {
    background: #1a1d21;
}

[data-bs-theme="dark"] .split-sidebar-header,
[data-bs-theme="dark"] .split-list-header {
    background: #2b3035;
}

[data-bs-theme="dark"] .preview-header {
    background: #2b3035;
}

[data-bs-theme="dark"] .preview-attachments {
    background: #2b3035;
}

[data-bs-theme="dark"] .mailbox-context-menu {
    background: #2b3035;
    border-color: #495057;
}

[data-bs-theme="dark"] .context-menu-item:hover {
    background-color: #343a40;
}

[data-bs-theme="dark"] .context-menu-item-danger:hover {
    background-color: #3b2025;
}

[data-bs-theme="dark"] .context-menu-separator {
    background-color: #495057;
}

[data-bs-theme="dark"] .context-menu-color-active {
    border-color: #e9ecef;
}

[data-bs-theme="dark"] .context-menu-color-none {
    background-color: #495057;
    color: #adb5bd;
}

[data-bs-theme="dark"] .sortable-item:hover {
    background-color: #2b3035 !important;
}

[data-bs-theme="dark"] .sortable-ghost > .sortable-item {
    background-color: #1a2942 !important;
}

[data-bs-theme="dark"] .category-tree .category-header:hover,
[data-bs-theme="dark"] .sidebar-cat-header:hover {
    background-color: #2b3035;
}

[data-bs-theme="dark"] .sidebar-mailbox:hover {
    background-color: #343a40;
}

[data-bs-theme="dark"] .email-row {
    border-bottom-color: #2b3035;
}

[data-bs-theme="dark"] .email-row:hover {
    background-color: #2b3035;
}

[data-bs-theme="dark"] .email-row-active {
    background-color: #1a2942 !important;
}

[data-bs-theme="dark"] .email-row-unread .email-row-subject {
    color: #e9ecef;
}

[data-bs-theme="dark"] .email-row-from {
    color: #dee2e6;
}

[data-bs-theme="dark"] .email-row-subject {
    color: #adb5bd;
}

[data-bs-theme="dark"] .email-row-date {
    color: #6c757d;
}

[data-bs-theme="dark"] .email-tab {
    color: #adb5bd;
}

[data-bs-theme="dark"] .email-tab:hover {
    color: #dee2e6;
}

[data-bs-theme="dark"] .email-tab-active {
    color: #6ea8fe;
    border-bottom-color: #6ea8fe;
}

[data-bs-theme="dark"] .preview-actions {
    background: #2b3035;
}

/* Quill editor dark mode */
[data-bs-theme="dark"] #composeEditor {
    background: #212529;
    color: #dee2e6;
}

[data-bs-theme="dark"] #composeEditor .ql-editor {
    color: #dee2e6;
}

[data-bs-theme="dark"] #composeEditor .ql-editor.ql-blank::before {
    color: #6c757d;
}

[data-bs-theme="dark"] .ql-toolbar.ql-snow {
    background: #2b3035;
    border-color: #495057;
}

[data-bs-theme="dark"] .ql-container.ql-snow {
    border-color: #495057;
}

[data-bs-theme="dark"] .ql-snow .ql-stroke {
    stroke: #adb5bd;
}

[data-bs-theme="dark"] .ql-snow .ql-fill {
    fill: #adb5bd;
}

[data-bs-theme="dark"] .ql-snow .ql-picker-label {
    color: #adb5bd;
}

[data-bs-theme="dark"] .ql-snow .ql-picker-options {
    background: #2b3035;
    border-color: #495057;
}

[data-bs-theme="dark"] .ql-snow .ql-picker-item:hover {
    color: #fff;
}

/* ========================================
   Responsive: stack panels on mobile
   ======================================== */

@media (max-width: 991.98px) {
    .split-pane {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 56px - 48px);
    }

    .split-sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }

    .split-list {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid #dee2e6;
    }

    .split-preview {
        min-height: 400px;
    }
}

@media (max-width: 575.98px) {
    .split-sidebar {
        max-height: 150px;
    }

    .split-list {
        max-height: 250px;
    }
}
