/* Fullscreen overlay controls (light/default theme). */
#email-fullscreen-overlay .fullscreen-btn-bar {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    padding: 10px 16px;
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: center;
    align-self: flex-end;
}
#email-fullscreen-overlay .fullscreen-btn-bar button {
    min-width: 40px;
    min-height: 40px;
    border-radius: 8px;
    font-size: 1.0em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    background: #f3f4f6;
    color: #111827;
    transition: background 0.12s, transform 0.08s;
}
#email-fullscreen-overlay .fullscreen-btn-bar button:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}
#email-fullscreen-overlay .fullscreen-btn-bar #email-fullscreen-delete {
    background: #fee2e2;
    color: #7f1d1d;
}
#email-fullscreen-overlay .fullscreen-btn-bar #email-fullscreen-delete:hover {
    background: #fecaca;
}
#email-fullscreen-overlay .fullscreen-btn-bar #email-fullscreen-reply {
    background: #eef2ff;
    color: #312e81;
}
#email-fullscreen-overlay .fullscreen-btn-bar #email-fullscreen-reply:hover {
    background: #e0e7ff;
}
#email-fullscreen-overlay .fullscreen-btn-bar #email-fullscreen-close {
    background: #f3f4f6;
}
#email-fullscreen-overlay .fullscreen-btn-bar #email-fullscreen-close:hover {
    background: #e5e7eb;
}

/* Mailbox dark-theme enforcement layer. */

/* Shell. */
.mailbox-container[data-theme="dark"],
#email-list-view[data-theme="dark"] {
    background: var(--mb-shell, #1A1A1E) !important;
}

/* Folder sidebar. */

.mailbox-container[data-theme="dark"] .folder-sidebar {
    background: var(--mb-panel, #2A2A2F) !important;
    border: 1px solid var(--mb-border-strong, #3C3C44) !important;
    border-radius: 12px !important;
}

.mailbox-container[data-theme="dark"] .folder-header {
    background: var(--mb-panel-2, #1f1f24) !important;
    border-bottom: 1px solid var(--mb-border, #3C3C44) !important;
}

.mailbox-container[data-theme="dark"] .folder-list {
    background: var(--mb-panel, #2A2A2F) !important;
}

/* Match the folder and email list scrollbars. */
.mailbox-container[data-theme="dark"] .folder-list::-webkit-scrollbar {
    width: 8px;
}
.mailbox-container[data-theme="dark"] .folder-list::-webkit-scrollbar-track {
    background: var(--mb-shell, #1f1f24) !important;
    border-radius: 4px;
}
.mailbox-container[data-theme="dark"] .folder-list::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--mb-accent-strong, #4F46E5) 28%, var(--mb-panel-3, #3C3C44)) !important;
    border-radius: 4px;
}
.mailbox-container[data-theme="dark"] .folder-list::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--mb-accent-strong, #4F46E5) 42%, var(--mb-panel-3, #4a4a55)) !important;
}

.mailbox-container[data-theme="dark"] .folder-item {
    background: transparent !important;
    color: #d1d5db !important;
    border-bottom: 1px solid #3C3C44 !important;
    border-left: 3px solid transparent !important;
}

.mailbox-container[data-theme="dark"] .folder-item:hover {
    background: var(--mb-hover, #3A3A42) !important;
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .folder-item.selected {
    background: var(--mb-accent-soft, #3A3A42) !important;
    color: #ffffff !important;
    border-left-color: var(--primary-color, #4F46E5) !important;
}

.mailbox-container[data-theme="dark"] .folder-item.selected:hover {
    background: color-mix(in srgb, var(--mb-accent-strong, #4F46E5) 26%, var(--mb-panel, #4a4a55)) !important;
}

.mailbox-container[data-theme="dark"] .folder-name {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .folder-item.selected .folder-name {
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .folder-count {
    background: color-mix(in srgb, var(--mb-accent-strong, #4F46E5) 12%, var(--mb-panel-2, #3A3A42)) !important;
    color: #9ca3af !important;
}

.mailbox-container[data-theme="dark"] .folder-item.selected .folder-count {
    background: color-mix(in srgb, var(--mb-accent-strong, #4F46E5) 30%, var(--mb-panel-2, transparent)) !important;
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .folder-toggle {
    color: #9ca3af !important;
}

.mailbox-container[data-theme="dark"] .folder-item:hover .folder-toggle {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .folder-item.selected .folder-toggle {
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .folder-loading {
    color: #9ca3af !important;
}

.mailbox-container[data-theme="dark"] .folder-actions {
    background: var(--mb-panel-2, #1f1f24) !important;
    border-top: 1px solid var(--mb-border, #3C3C44) !important;
}

.mailbox-container[data-theme="dark"] .btn-all-folders {
    background: var(--primary-color, #4F46E5) !important;
    color: #ffffff !important;
    border: none !important;
}

.mailbox-container[data-theme="dark"] .btn-all-folders:hover {
    background: var(--primary-color-dark, #4338CA) !important;
}

/* Email list surface. */

#email-list-view[data-theme="dark"],
.mailbox-container[data-theme="dark"] #email-list-view {
    background: var(--mb-panel, #1A1A1E) !important;
}

/* Toolbar and filters. */

.mailbox-container[data-theme="dark"] .mailbox-toolbar,
#email-list-view[data-theme="dark"] .mailbox-toolbar {
    background: var(--mb-panel-2, #2A2A2F) !important;
    border: 1px solid var(--mb-border-strong, #3C3C44) !important;
    border-radius: 8px !important;
}

.mailbox-container[data-theme="dark"] .btn-refresh,
#email-list-view[data-theme="dark"] .btn-refresh {
    background-color: var(--primary-color, #4F46E5) !important;
    color: #ffffff !important;
    border: none !important;
}

.mailbox-container[data-theme="dark"] .btn-refresh:hover,
#email-list-view[data-theme="dark"] .btn-refresh:hover {
    background-color: var(--primary-color-dark, #4338CA) !important;
}

.mailbox-container[data-theme="dark"] .select-all-wrapper,
#email-list-view[data-theme="dark"] .select-all-wrapper {
    background: transparent !important;
}

.mailbox-container[data-theme="dark"] .select-all-checkbox-main,
#email-list-view[data-theme="dark"] .select-all-checkbox-main {
    background-color: var(--mb-control-bg-soft, var(--mb-panel-2, #2A2A2F)) !important;
    border: 1px solid var(--mb-border, #3C3C44) !important;
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .select-all-checkbox-main:hover,
#email-list-view[data-theme="dark"] .select-all-checkbox-main:hover {
    background-color: var(--mb-control-bg-hover-soft, var(--mb-panel-3, #3A3A42)) !important;
    border-color: var(--primary-color, #4F46E5) !important;
}

.mailbox-container[data-theme="dark"] .select-all-checkbox-main span,
#email-list-view[data-theme="dark"] .select-all-checkbox-main span {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .filters-container,
#email-list-view[data-theme="dark"] .filters-container {
    background: transparent !important;
}

.mailbox-container[data-theme="dark"] .filter-dropdown,
#email-list-view[data-theme="dark"] .filter-dropdown {
    background: var(--mb-control-bg-soft, var(--mb-panel-2, #2A2A2F)) !important;
    color: #ffffff !important;
    border: 1px solid #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .filter-dropdown:focus,
#email-list-view[data-theme="dark"] .filter-dropdown:focus {
    border-color: var(--primary-color, #4F46E5) !important;
}

.mailbox-container[data-theme="dark"] .filter-dropdown option,
#email-list-view[data-theme="dark"] .filter-dropdown option {
    background: var(--mb-panel-2, #2A2A2F) !important;
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .filter-checkbox,
#email-list-view[data-theme="dark"] .filter-checkbox {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .filter-input,
.mailbox-container[data-theme="dark"] .filter-input-group input,
#email-list-view[data-theme="dark"] .filter-input,
#email-list-view[data-theme="dark"] .filter-input-group input {
    background: var(--mb-control-bg-soft, var(--mb-panel-2, #2A2A2F)) !important;
    color: #ffffff !important;
    border: 1px solid #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] #filter-keywords-trigger,
#email-list-view[data-theme="dark"] #filter-keywords-trigger {
    background: transparent !important;
}

.mailbox-container[data-theme="dark"] .filter-input::placeholder,
.mailbox-container[data-theme="dark"] .filter-input-group input::placeholder,
#email-list-view[data-theme="dark"] .filter-input::placeholder,
#email-list-view[data-theme="dark"] .filter-input-group input::placeholder {
    color: #6b7280 !important;
}

.mailbox-container[data-theme="dark"] .filter-input:focus,
.mailbox-container[data-theme="dark"] .filter-input-group input:focus,
#email-list-view[data-theme="dark"] .filter-input:focus,
#email-list-view[data-theme="dark"] .filter-input-group input:focus {
    border-color: var(--primary-color, #4F46E5) !important;
}

.mailbox-container[data-theme="dark"] .email-count,
#email-list-view[data-theme="dark"] .email-count {
    color: #9ca3af !important;
}

/* Selection toolbar. */

.mailbox-container[data-theme="dark"] .selection-toolbar,
#email-list-view[data-theme="dark"] .selection-toolbar {
    background: var(--mb-panel-2, #1f1f24) !important;
    border-bottom: 1px solid var(--mb-border, #3C3C44) !important;
}

.mailbox-container[data-theme="dark"] .selection-toolbar-header,
#email-list-view[data-theme="dark"] .selection-toolbar-header {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .selection-toolbar button,
#email-list-view[data-theme="dark"] .selection-toolbar button {
    background: var(--mb-control-bg-soft, var(--mb-panel-3, #3A3A42)) !important;
    color: #ffffff !important;
    border: 1px solid #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .btn-delete-selected,
#email-list-view[data-theme="dark"] .btn-delete-selected {
    background: #dc2626 !important;
    color: #ffffff !important;
    border: none !important;
}

.mailbox-container[data-theme="dark"] .btn-delete-selected:hover,
#email-list-view[data-theme="dark"] .btn-delete-selected:hover {
    background: #b91c1c !important;
}

/* Scrollable email list. */

.mailbox-container[data-theme="dark"] .email-list,
#email-list-view[data-theme="dark"] .email-list {
    background: #1A1A1E !important;
    border: 1px solid #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .email-list::-webkit-scrollbar-track,
#email-list-view[data-theme="dark"] .email-list::-webkit-scrollbar-track {
    background: #1f1f24 !important;
}

.mailbox-container[data-theme="dark"] .email-list::-webkit-scrollbar-thumb,
#email-list-view[data-theme="dark"] .email-list::-webkit-scrollbar-thumb {
    background: #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .email-list::-webkit-scrollbar-thumb:hover,
#email-list-view[data-theme="dark"] .email-list::-webkit-scrollbar-thumb:hover {
    background: #4a4a55 !important;
}

/* Email rows and category colors. */

.mailbox-container[data-theme="dark"] .email-item,
.mailbox-container[data-theme="dark"] .email-item:not([style*="background-color"]),
#email-list-view[data-theme="dark"] .email-item:not([style*="background-color"]) {
    background-color: #2A2A2F !important;
    border-bottom: 1px solid #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .email-item[style*="background-color"],
#email-list-view[data-theme="dark"] .email-item[style*="background-color"] {
    border-bottom: 1px solid #3C3C44;
    background-color: unset;
}

.mailbox-container[data-theme="dark"] .email-item:not([style*="background-color"]):hover,
#email-list-view[data-theme="dark"] .email-item:not([style*="background-color"]):hover {
    background-color: #3A3A42 !important;
    box-shadow: inset -2px 0 0 rgba(79, 70, 229, 0.4) !important;
}

.mailbox-container[data-theme="dark"] .email-item[style*="background-color"]:hover,
#email-list-view[data-theme="dark"] .email-item[style*="background-color"]:hover {
    filter: brightness(0.9);
    box-shadow: inset -2px 0 0 rgba(79, 70, 229, 0.4) !important;
}

.mailbox-container[data-theme="dark"] .email-item.unread:not([style*="background-color"]),
#email-list-view[data-theme="dark"] .email-item.unread:not([style*="background-color"]) {
    background-color: #2d2d35 !important;
}

.mailbox-container[data-theme="dark"] .email-item.unread[style*="background-color"],
#email-list-view[data-theme="dark"] .email-item.unread[style*="background-color"] {
    font-weight: 600;
}

.mailbox-container[data-theme="dark"] .email-item.unread:not([style*="background-color"]):hover,
#email-list-view[data-theme="dark"] .email-item.unread:not([style*="background-color"]):hover {
    background-color: #3A3A42 !important;
}

.mailbox-container[data-theme="dark"] .email-item:not(.email-colored) .email-sender,
#email-list-view[data-theme="dark"] .email-item:not(.email-colored) .email-sender {
    color: #e5e7eb !important;
}

.mailbox-container[data-theme="dark"] .email-item:not(.email-colored) .email-subject,
#email-list-view[data-theme="dark"] .email-item:not(.email-colored) .email-subject {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .email-item:not(.email-colored) .email-date,
#email-list-view[data-theme="dark"] .email-item:not(.email-colored) .email-date {
    color: #9ca3af !important;
}

.mailbox-container[data-theme="dark"] .no-emails,
#email-list-view[data-theme="dark"] .no-emails {
    color: #9ca3af !important;
}

/* Category badge. */

.mailbox-container[data-theme="dark"] .email-item:not(.email-colored) .category-badge,
#email-list-view[data-theme="dark"] .email-item:not(.email-colored) .category-badge {
    background: rgba(79, 70, 229, 0.2) !important;
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .email-item:not(.email-colored) .category-badge:hover,
#email-list-view[data-theme="dark"] .email-item:not(.email-colored) .category-badge:hover {
    background: var(--primary-color, #4F46E5) !important;
    color: #ffffff !important;
}

/* Email row actions. */

.mailbox-container[data-theme="dark"] .btn-delete-email-item,
#email-list-view[data-theme="dark"] .btn-delete-email-item {
    color: #ffffff !important;
}

/* Loading and error states. */

/* Keep the global user dropdown readable on dark surfaces. */
body[data-theme="dark"] .topbar .dropdown li a,
html[data-theme="dark"] .topbar .dropdown li a,
.topbar[data-theme="dark"] .dropdown li a {
    color: #ffffff !important;
}

.mailbox-container[data-theme="dark"] .loading,
#email-list-view[data-theme="dark"] .loading {
    background: transparent !important;
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .spinner,
#email-list-view[data-theme="dark"] .spinner {
    border: 3px solid #3C3C44 !important;
    border-top-color: var(--primary-color, #4F46E5) !important;
}

.mailbox-container[data-theme="dark"] .progress-bar-container,
#email-list-view[data-theme="dark"] .progress-bar-container {
    background-color: #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .progress-bar,
#email-list-view[data-theme="dark"] .progress-bar {
    background: linear-gradient(90deg, var(--primary-color, #4F46E5) 0%, var(--primary-color-dark, #4338CA) 100%) !important;
}

.mailbox-container[data-theme="dark"] .progress-text,
#email-list-view[data-theme="dark"] .progress-text {
    color: #9ca3af !important;
}

.mailbox-container[data-theme="dark"] .error-message,
#email-list-view[data-theme="dark"] .error-message {
    background-color: #4a1a1a !important;
    color: #f87171 !important;
}

/* Pagination. */

.mailbox-container[data-theme="dark"] .pagination-controls,
#email-list-view[data-theme="dark"] .pagination-controls {
    background: var(--mb-panel-2, #2A2A2F) !important;
    border-top: 1px solid var(--mb-border, #3C3C44) !important;
}

.mailbox-container[data-theme="dark"] .btn-pagination,
#email-list-view[data-theme="dark"] .btn-pagination {
    background-color: var(--primary-color, #4F46E5) !important;
    color: #ffffff !important;
    border: none !important;
}

.mailbox-container[data-theme="dark"] .btn-pagination:hover:not(:disabled),
#email-list-view[data-theme="dark"] .btn-pagination:hover:not(:disabled) {
    background-color: var(--primary-color-dark, #4338CA) !important;
}

.mailbox-container[data-theme="dark"] .btn-pagination:disabled,
#email-list-view[data-theme="dark"] .btn-pagination:disabled {
    background-color: var(--mb-control-bg-soft, var(--mb-panel-3, #3C3C44)) !important;
    color: #6b7280 !important;
    opacity: 0.6 !important;
}

.mailbox-container[data-theme="dark"] .page-info,
.mailbox-container[data-theme="dark"] .goto-page,
#email-list-view[data-theme="dark"] .page-info,
#email-list-view[data-theme="dark"] .goto-page {
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .goto-page-input,
#email-list-view[data-theme="dark"] .goto-page-input {
    background: var(--mb-control-bg-soft, var(--mb-panel-2, #2A2A2F)) !important;
    color: #ffffff !important;
    border: 1px solid #3C3C44 !important;
}

.mailbox-container[data-theme="dark"] .goto-page-input:focus,
#email-list-view[data-theme="dark"] .goto-page-input:focus {
    border-color: var(--primary-color, #4F46E5) !important;
}

.mailbox-container[data-theme="dark"] .btn-goto-page,
#email-list-view[data-theme="dark"] .btn-goto-page {
    background-color: var(--primary-color, #4F46E5) !important;
    color: #ffffff !important;
    border: none !important;
}

.mailbox-container[data-theme="dark"] .btn-goto-page:hover,
#email-list-view[data-theme="dark"] .btn-goto-page:hover {
    background-color: var(--primary-color-dark, #4338CA) !important;
}

/* Email detail view. */

.mailbox-container[data-theme="dark"] #email-detail-view {
    background: var(--mb-panel, #2A2A2F) !important;
}

.mailbox-container[data-theme="dark"] .email-detail-header {
    background: var(--mb-panel-2, #2A2A2F) !important;
    border-bottom: 1px solid var(--mb-border, #3C3C44) !important;
}

.mailbox-container[data-theme="dark"] .email-detail-header h2,
.mailbox-container[data-theme="dark"] .mailbox-title {
    color: #e5e7eb !important;
}

/* Back action in every theme. */
.btn-back,
button.btn-back,
#email-detail-view .btn-back,
.email-detail-header .btn-back,
.mailbox-container .btn-back {
    background-color: #4F46E5 !important;
    background: #4F46E5 !important;
    color: #ffffff !important;
    border: 1px solid #4F46E5 !important;
    height: 40px !important;
    box-sizing: border-box !important;
}

.btn-back:hover,
button.btn-back:hover,
#email-detail-view .btn-back:hover,
.email-detail-header .btn-back:hover,
.mailbox-container .btn-back:hover {
    background-color: #4338CA !important;
    background: #4338CA !important;
    border-color: #4338CA !important;
}

.mailbox-container[data-theme="dark"] .btn-delete-email {
    background: #dc2626 !important;
    color: #ffffff !important;
    border: none !important;
}

/* Delete action hover in every theme. */
.btn-delete-email:hover,
#delete-email-btn:hover,
button.btn-delete-email:hover,
.email-detail-header .btn-delete-email:hover,
.mailbox-container .btn-delete-email:hover,
.mailbox-container[data-theme="dark"] .btn-delete-email:hover {
    background-color: #dc2626 !important;
    background: #dc2626 !important;
    color: #ffffff !important;
    border-color: #dc2626 !important;
}

.mailbox-container[data-theme="dark"] .email-detail-content {
    background: var(--mb-panel, #2A2A2F) !important;
    color: #d1d5db !important;
}

.mailbox-container[data-theme="dark"] .email-detail-meta {
    background: var(--mb-panel-2, #1f1f24) !important;
    border-bottom: 1px solid var(--mb-border, #3C3C44) !important;
}

.mailbox-container[data-theme="dark"] .meta-label {
    color: #9ca3af !important;
}

.mailbox-container[data-theme="dark"] .meta-value {
    color: #e5e7eb !important;
}

.mailbox-container[data-theme="dark"] .email-detail-body {
    background: #2A2A2F !important;
    color: #d1d5db !important;
}

/* Shared account pages. */

/* Statistics. */
.main-content[data-theme="dark"] .metric-card,
.main-content[data-theme="dark"] .chart-card {
    background: #2A2A2F !important;
    border: 1px solid #3C3C44 !important;
}

/* Appearance. */
.main-content[data-theme="dark"] .appearance-section {
    background: #2A2A2F !important;
    border-color: #3C3C44 !important;
}

/* Shared typography. */
.main-content[data-theme="dark"] h1,
.main-content[data-theme="dark"] h2,
.main-content[data-theme="dark"] h3,
.mailbox-container[data-theme="dark"] h1,
.mailbox-container[data-theme="dark"] h2,
.mailbox-container[data-theme="dark"] h3 {
    color: #e5e7eb !important;
}

.main-content[data-theme="dark"] p,
.mailbox-container[data-theme="dark"] p {
    color: #d1d5db !important;
}
