@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary-color: hsl(175, 77%, 26%);
    --primary-hover: hsl(175, 77%, 30%);
    --primary-glow: hsla(175, 77%, 26%, 0.15);

    --bg-main: hsl(210, 40%, 98%);
    --bg-card: hsl(0, 0%, 100%);
    --bg-sidebar: hsl(0, 0%, 100%);
    --bg-hover: hsl(210, 40%, 95%);
    --border-color: hsl(210, 40%, 91%);

    --text-primary: hsl(222, 47%, 11%);
    --text-secondary: hsl(215, 25%, 27%);
    --text-muted: hsl(215, 16%, 47%);

    --font-family: 'IBM Plex Sans Arabic', 'Inter', sans-serif;
    --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    --shadow-sm: 0 1px 2px hsla(0, 0%, 0%, 0.05);
    --shadow-md: 0 4px 12px hsla(222, 47%, 11%, 0.05);
    --shadow-lg: 0 10px 25px -5px hsla(222, 47%, 11%, 0.08), 0 8px 10px -6px hsla(222, 47%, 11%, 0.08);
}

body.dark-mode {
    --bg-main: hsl(222, 47%, 6%);
    --bg-card: hsl(222, 47%, 10%);
    --bg-sidebar: hsl(222, 47%, 6%);
    --bg-hover: hsl(222, 47%, 15%);
    --border-color: hsl(222, 47%, 16%);

    --text-primary: hsl(210, 40%, 98%);
    --text-secondary: hsl(215, 20%, 80%);
    --text-muted: hsl(215, 16%, 60%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    overscroll-behavior-y: contain;
}

.glass {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

/* ===== Pull-to-Refresh Indicator ===== */
@keyframes ptr-spin {
    0% {
        transform: translateX(-50%) rotate(0deg);
    }

    100% {
        transform: translateX(-50%) rotate(360deg);
    }
}

.ptr-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 42px;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    color: var(--primary-color, #0f766e);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.10), 0 1px 4px rgba(0, 0, 0, 0.06);
    z-index: 99999;
    transition: top 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.ptr-indicator.refreshing {
    animation: ptr-spin 0.8s linear infinite;
}

.ptr-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.18s ease;
}

body.dark-mode .ptr-indicator {
    background: var(--bg-card, #1e293b);
    border-color: var(--border-color, #334155);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.30);
}

/* =================================----------------=========================
   LOGIN PAGE STYLING (FIXED & RESTORED)
   ========================================================================== */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    position: relative;
    background-color: var(--bg-main);
}

.login-bg-shapes {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 1;
}

.shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.15;
}

.shape-1 {
    top: -15%;
    right: -10%;
    width: 450px;
    height: 450px;
    background: var(--primary-color);
}

.shape-2 {
    bottom: -15%;
    left: -10%;
    width: 500px;
    height: 500px;
    background: #0284c7;
}

.login-card {
    width: 100%;
    max-width: 480px;
    padding: 35px 30px;
    z-index: 2;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    max-height: 90vh;
    overflow-y: auto;
}

.login-header {
    text-align: center;
    margin-bottom: 25px;
}

.login-logo {
    width: 80px;
    height: auto;
    margin-bottom: 12px;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.form-group {
    margin-bottom: 16px;
}

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

.form-control {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.92rem;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Tabs for Server Settings in Login */
.tabs {
    display: flex;
    gap: 8px;
    margin: 18px 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.tab-btn {
    flex: 1;
    padding: 8px 12px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition);
}

.tab-btn.active {
    color: var(--primary-color);
    background: var(--primary-glow);
    font-weight: 700;
}

.tab-content {
    display: none;
}

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

.error-message {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 0.88rem;
    display: none;
}

/* Secondary Button (PWA Install Button) */
.btn-secondary {
    width: 100%;
    padding: 11px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-hover);
    color: var(--text-primary);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--primary-glow);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: #ffffff;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
    margin-top: 10px;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25);
}

.btn-primary:active {
    transform: translateY(0);
}

/* =================================----------------=========================
   APP MAIN CONTAINER & INBOX LAYOUT
   ========================================================================== */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

/* Sidebar Styling */
.inbox-sidebar {
    width: 250px;
    min-width: 250px;
    background: var(--bg-sidebar);
    border-inline-end: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    z-index: 50;
    transition: var(--transition);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.logo-container img {
    width: 40px;
    height: 40px;
}

.logo-container h2 {
    font-size: 1.35rem;
    font-weight: 800;
}

.btn-compose {
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.folder-list {
    list-style: none;
    flex-grow: 1;
    overflow-y: auto;
}

.folder-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.92rem;
    margin-bottom: 4px;
    transition: var(--transition);
}

.folder-item-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.folder-item:hover,
.folder-item.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.folder-item.active {
    background: var(--primary-glow);
    color: var(--primary-color);
}

.sidebar-footer {
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.user-info-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-grow: 1;
}

.user-email {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}

/* Status Indicator Dot */
.status-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.status-indicator.online .status-dot {
    background-color: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.8);
}

.status-indicator.offline .status-dot {
    background-color: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.8);
}

/* Mail List Pane */
.mail-list-pane {
    width: 360px;
    min-width: 340px;
    background: var(--bg-main);
    border-inline-end: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.pane-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-sidebar);
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.mail-items-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
}

/* Mail Card Items */
.mail-item {
    padding: 14px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    gap: 12px;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.mail-item:hover {
    border-color: var(--primary-color);
}

.mail-item.active {
    background: var(--primary-glow);
    border-color: var(--primary-color);
}

.mail-item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-glow);
    color: var(--primary-color);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.mail-item-content {
    flex-grow: 1;
    min-width: 0;
}

.mail-item.unread .mail-subject {
    font-weight: 800;
    color: var(--text-primary);
}

.mail-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.mail-sender {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mail-subject {
    font-size: 0.86rem;
    color: var(--text-secondary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-snippet {
    font-size: 0.78rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-snippet:empty {
    display: none;
}

/* Detail Pane Column */
.message-detail-pane {
    flex: 1;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.detail-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: var(--bg-sidebar);
}

.mobile-back-btn {
    display: none !important;
}

.detail-subject {
    font-size: 1.2rem;
    font-weight: 800;
    margin-bottom: 6px;
}

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

.message-iframe {
    width: 100%;
    height: auto;
    border: none;
    background: transparent;
}

/* Composer Modal Backdrop Container */
.composer-modal-backdrop {
    position: fixed;
    inset: 0;
    pointer-events: none;
    /* Allow interaction with background when composer is open */
    z-index: 300;
    display: none;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 24px;
}

/* COMPOSER MODAL - Floating Panel style */
.composer-modal {
    width: 100%;
    max-width: 580px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px 12px 0 0;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 85vh;
    pointer-events: auto;
    /* Re-enable clicks inside modal */
    border-bottom: none;
}

.composer-header {
    padding: 14px 20px;
    background: var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
}

.composer-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    flex-grow: 1;
}

.composer-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    padding: 10px 0;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}

.composer-input:focus {
    outline: none;
    border-bottom-color: var(--primary-color);
}

/* CC / BCC Toggle Link Button */
.btn-link-cc {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    padding: 4px;
}

/* LTR and RTL alignment overrides for To field and CC/BCC toggle */
html[dir="rtl"] .btn-link-cc {
    left: 12px;
    right: auto;
}

html[dir="ltr"] .btn-link-cc {
    right: 12px;
    left: auto;
}

html[dir="rtl"] #composeTo {
    padding-left: 80px !important;
}

html[dir="ltr"] #composeTo {
    padding-right: 80px !important;
}

/* Image Resizer Floating Popover */
.image-resize-popover {
    position: absolute;
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    padding: 6px 10px;
    gap: 6px;
    z-index: 10000;
    align-items: center;
    transition: opacity 0.15s ease;
}

/* Editor Toolbar */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 6px 8px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 10px 10px 0 0;
    flex-wrap: wrap;
}

.toolbar-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.toolbar-divider {
    width: 1px;
    height: 22px;
    background: var(--border-color);
    margin: 0 4px;
    flex-shrink: 0;
}

.editor-toolbar .toolbar-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    padding: 0;
    line-height: 1;
}

.editor-toolbar .toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.editor-toolbar .toolbar-btn.active {
    background: var(--primary-glow);
    color: var(--primary-color);
    border-color: rgba(15, 118, 110, 0.2);
}

.editor-toolbar .toolbar-btn i {
    font-size: 0.92rem;
}

.toolbar-select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 2px 6px;
    height: 30px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    max-width: 110px;
    transition: border-color 0.15s;
}

.toolbar-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.toolbar-color-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.toolbar-color-wrap:hover {
    background: var(--bg-hover);
}

.toolbar-color-wrap i {
    font-size: 0.92rem;
    color: var(--text-secondary);
}

.toolbar-color-wrap .color-bar {
    position: absolute;
    bottom: 3px;
    left: 6px;
    right: 6px;
    height: 3px;
    border-radius: 2px;
    pointer-events: none;
}

.toolbar-color-picker {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    border: none;
}

/* Rich Editable Area */
.composer-editor {
    width: 100%;
    min-height: 220px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 10px 10px;
    padding: 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--bg-card);
    line-height: 1.7;
    word-break: break-word;
}

.composer-editor:focus {
    outline: none;
    border-color: var(--primary-color);
}

.composer-editor[placeholder]:empty:before {
    content: attr(placeholder);
    color: var(--text-muted);
}

/* Link Insertion Modal */
.link-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100001;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.link-modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.link-modal h4 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.link-modal input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-main);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    margin-bottom: 12px;
    transition: border-color 0.15s;
}

.link-modal input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.link-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.link-modal-actions button {
    padding: 8px 18px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.link-modal-actions .btn-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.link-modal-actions .btn-confirm {
    background: var(--primary-color);
    border: none;
    color: #fff;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: none;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
}

/* --- Mobile Elements & Layout --- */
.mobile-top-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
    position: sticky;
    top: 0;
    z-index: 180;
}

.mobile-logo-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-hover);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.mobile-logo-img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(15, 118, 110, 0.15));
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    z-index: 190;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

.mobile-bottom-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    gap: 3px;
    flex: 1;
    height: 100%;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.mobile-bottom-item.active {
    color: var(--primary-color);
}

.mobile-bottom-item i {
    font-size: 1.35rem;
    transition: transform 0.2s;
}

.mobile-bottom-item.active i {
    transform: scale(1.1);
    color: var(--primary-color);
}

body.settings-active .mobile-fab-compose,
.app-container:has(#settingsPane[style*="display: flex"])~.mobile-fab-compose,
.app-container:has(#settingsPane[style*="display: flex"])+.mobile-fab-compose {
    display: none !important;
}

@media (min-width: 769px) {
    .mobile-fab-compose {
        display: none !important;
    }
}

.mobile-fab-compose {
    display: none;
    position: fixed;
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 20px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #ffffff;
    border: none;
    font-size: 1.6rem;
    box-shadow: 0 4px 14px rgba(15, 118, 110, 0.35);
    z-index: 110;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-fab-compose:active {
    transform: scale(0.92);
    box-shadow: 0 2px 6px rgba(15, 118, 110, 0.25);
}

@media (max-width: 1024px) {
    .mail-list-pane {
        width: 320px;
        min-width: 320px;
    }
}

@media (max-width: 768px) {
    .mobile-top-bar {
        display: flex;
    }

    .mobile-bottom-bar {
        display: flex;
    }

    .mobile-fab-compose {
        display: flex;
    }

    .inbox-sidebar {
        position: fixed;
        top: 0;
        right: 0;
        width: 280px;
        height: 100%;
        z-index: 200;
        transform: translateX(100%);
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.15);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .inbox-sidebar.open {
        transform: translateX(0);
    }

    .mail-list-pane {
        width: 100%;
        min-width: 100%;
        padding-bottom: 60px;
    }

    .message-detail-pane {
        position: fixed;
        top: calc(53px + env(safe-area-inset-top));
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 150;
        display: flex;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        background: var(--bg-card);
    }

    .message-detail-pane.active {
        transform: translateX(0);
    }

    .mobile-back-btn {
        display: inline-flex !important;
        background: var(--bg-hover);
        border: 1px solid var(--border-color);
        border-radius: 20px;
        padding: 5px 12px;
        font-size: 0.8rem;
        font-weight: 700;
        color: var(--text-color);
        align-items: center;
        gap: 6px;
        transition: var(--transition);
        cursor: pointer;
        width: auto;
        margin-top: 12px;
        margin-bottom: 8px;
    }

    .mobile-back-btn:hover {
        background: var(--primary-glow);
        color: var(--primary-color);
        border-color: var(--primary-color);
    }

    .composer-modal {
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    .composer-modal-backdrop {
        padding: 0;
    }

    .login-card {
        padding: 24px 20px;
        max-width: calc(100% - 20px);
        margin: 10px auto;
        border-radius: 16px;
    }
}

/* Segmented Language Switch Toggle */
.lang-switch-toggle {
    display: inline-flex;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 700;
    user-select: none;
    transition: var(--transition);
    align-items: center;
    gap: 2px;
}

.lang-switch-toggle span {
    padding: 4px 12px;
    border-radius: 18px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.lang-switch-toggle span.active {
    background: var(--primary-color);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(15, 118, 110, 0.25);
}

.lang-switch-toggle:hover {
    border-color: var(--primary-color);
}

/* --- Image Preview Lightbox --- */
.image-preview-modal {
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.25s ease-out;
}

.image-preview-content {
    max-width: 90%;
    max-height: 75vh;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    object-fit: contain;
    animation: zoomIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.close-preview-btn {
    position: absolute;
    top: 20px;
    inset-inline-end: 30px;
    color: #f1f5f9;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    user-select: none;
    z-index: 2100;
}

.close-preview-btn:hover {
    color: #ef4444;
    transform: scale(1.1);
}

.image-preview-caption {
    margin-top: 15px;
    color: #cbd5e1;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    max-width: 80%;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mail card actions button visibility styling */
.mail-item .mail-card-actions-btn {
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    border-radius: 4px;
    padding: 2px 4px;
}

.mail-item:hover .mail-card-actions-btn {
    opacity: 1;
}

.mail-item .mail-card-actions-btn:hover {
    background-color: var(--bg-hover);
    color: var(--primary-color) !important;
}

@media (max-width: 768px) {
    .mail-item .mail-card-actions-btn {
        opacity: 0.8;
    }
}

/* Context menu nested submenu styling */
.desktop-context-menu ul li .context-submenu {
    display: none;
    position: absolute;
    top: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    padding: 6px 0;
    list-style: none;
    min-width: 160px;
    z-index: 10001;
}

html[dir="rtl"] .desktop-context-menu ul li .context-submenu {
    left: 100%;
    right: auto;
    margin-left: 5px;
}

html[dir="ltr"] .desktop-context-menu ul li .context-submenu {
    right: 100%;
    left: auto;
    margin-right: 5px;
}

.desktop-context-menu ul li.context-menu-has-submenu:hover .context-submenu {
    display: block;
}

.desktop-context-menu ul li .context-submenu li {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
}

.desktop-context-menu ul li .context-submenu li:hover {
    background-color: var(--bg-hover);
    color: var(--primary-color);
}

.mobile-logo-img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(15, 118, 110, 0.2));
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    z-index: 190;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

/* Standalone Settings Pane Responsive Layout */
.settings-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

.settings-tabs {
    width: 240px;
    border-inline-end: 1px solid var(--border-color);
    background: var(--bg-sidebar);
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.settings-tabs .folder-item {
    background: transparent !important;
    border: 1px solid transparent !important;
    color: var(--text-muted) !important;
    transition: all 0.2s ease;
    cursor: pointer;
    border-radius: 8px !important;
    margin: 2px 0 !important;
}

.settings-tabs .folder-item:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

.settings-tabs .folder-item.active {
    background: var(--primary-glow) !important;
    color: var(--primary-color) !important;
    font-weight: 700;
    border: 1px solid hsla(175, 77%, 26%, 0.15) !important;
}

body.dark-mode .settings-tabs .folder-item {
    color: var(--text-muted) !important;
}

body.dark-mode .settings-tabs .folder-item:hover {
    background: var(--bg-hover) !important;
    color: #ffffff !important;
}

body.dark-mode .settings-tabs .folder-item.active {
    background: hsla(175, 77%, 26%, 0.25) !important;
    color: #5eead4 !important;
    border: 1px solid rgba(94, 234, 212, 0.2) !important;
}

.settings-content {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

@media (max-width: 768px) {
    .settings-pane {
        margin-bottom: calc(56px + env(safe-area-inset-bottom)) !important;
        height: calc(100vh - 56px - env(safe-area-inset-bottom)) !important;
    }

    .settings-wrapper {
        flex-direction: column !important;
        overflow-y: auto;
        padding: 12px !important;
        gap: 12px !important;
    }

    .settings-tabs {
        width: 100% !important;
        border-inline-end: none !important;
        border-bottom: none !important;
        flex-direction: row !important;
        padding: 6px !important;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        overflow-x: auto;
        white-space: nowrap;
        flex-shrink: 0;
        gap: 6px;
        scrollbar-width: none;
        /* Hide scrollbar on Firefox */
    }

    .settings-tabs::-webkit-scrollbar {
        display: none;
        /* Hide scrollbar on Chrome/Safari */
    }

    .settings-tabs .folder-item {
        flex: 1;
        margin: 0 !important;
        padding: 10px 12px !important;
        justify-content: center;
        text-align: center;
        border-radius: 8px;
        font-size: 0.78rem;
        background: transparent !important;
        border: none;
        white-space: nowrap;
    }

    .settings-tabs .folder-item.active {
        background: hsla(175, 77%, 26%, 0.08) !important;
        color: var(--primary-color) !important;
        font-weight: 700;
    }

    .settings-tabs .folder-item-content {
        justify-content: center;
        gap: 4px;
    }

    .settings-content {
        padding: 16px !important;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.01);
        overflow-y: visible !important;
        gap: 16px;
    }

    #settingsPageFromName {
        width: 100% !important;
        max-width: 100% !important;
    }

    #settingsPageSignatureEditor {
        max-height: 180px !important;
        min-height: 120px !important;
    }

    .settings-content div[style*="margin-top: 25px"] {
        margin-top: 15px !important;
        padding-top: 15px !important;
        display: flex;
        flex-direction: row;
        gap: 10px;
        width: 100%;
    }

    .settings-content div[style*="margin-top: 25px"] button {
        flex: 1;
        justify-content: center;
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
    }
}

/* Thread / Conversation Grouping Styles */
.thread-count {
    background-color: var(--primary-color);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    margin-inline-start: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.thread-message-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 8px;
    overflow: hidden;
    transition: all 0.22s ease-in-out;
    flex-shrink: 0;
}

.thread-message-card.collapsed:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.thread-message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    gap: 12px;
}

.thread-message-sender-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.thread-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-hover);
    color: var(--primary-color);
    font-weight: 800;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.thread-message-sender-name {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-primary);
    display: block;
}

.thread-message-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.thread-message-summary-preview {
    flex: 1;
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.thread-message-card.expanded .thread-message-summary-preview {
    display: none;
    /* Hide snippet when expanded */
}

.thread-message-actions-icons {
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.thread-message-card.expanded .toggle-icon {
    transform: rotate(180deg);
}

.thread-message-body {
    border-top: 1px solid var(--border-color);
    padding: 16px;
    background: var(--bg-card);
}

/* Reply / Reply All Footer Actions */
.thread-message-footer-actions {
    margin-top: 16px;
    border-top: 1px solid var(--border-color);
    padding-top: 14px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-reply-action {
    flex: 1;
    min-width: 0;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-family: inherit;
}

.btn-reply-primary {
    background: var(--primary-color);
    color: #fff;
}

.btn-reply-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15, 118, 110, 0.25);
}

.btn-reply-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-reply-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

/* Ensure the scroll container has enough bottom padding so buttons are never cut off */
.detail-body.thread-conversation-container {
    padding-bottom: 40px !important;
}

@media (max-width: 768px) {
    .detail-body.thread-conversation-container {
        padding-bottom: calc(30px + env(safe-area-inset-bottom)) !important;
    }

    .btn-reply-action {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
}

/* --- New Composer Styling (Gmail/Outlook-like Layout) --- */
.composer-field-row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding: 6px 0;
    min-height: 40px;
    gap: 8px;
}

.composer-field-label {
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-muted);
    min-width: 50px;
    user-select: none;
}

html[dir="rtl"] .composer-field-label {
    text-align: right;
}

html[dir="ltr"] .composer-field-label {
    text-align: left;
}

.composer-field-value {
    flex-grow: 1;
    font-size: 0.9rem;
}

.composer-win-btn {
    transition: background 0.15s, color 0.15s, opacity 0.15s;
    border-radius: 4px;
    color: white !important;
    opacity: 0.8;
}

.composer-win-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    opacity: 1;
}

.composer-tool-icon-btn {
    transition: background 0.15s, color 0.15s;
    border-radius: 50%;
    padding: 6px;
}

.composer-tool-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--primary-color) !important;
}

.composer-editor-container {
    border-bottom: none !important;
}

.composer-editor {
    border: none !important;
    padding: 12px 0 !important;
    min-height: 180px;
    background: transparent !important;
}

.composer-send-btn-group button:hover {
    background: var(--primary-hover) !important;
}

.composer-modal {
    border-radius: 12px !important;
    max-height: 90vh !important;
    height: 600px; /* robust default height */
}

/* Align links correctly in CC/BCC */
html[dir="rtl"] .btn-link-cc {
    left: 0;
    right: auto;
}
html[dir="ltr"] .btn-link-cc {
    right: 0;
    left: auto;
}

.composer-field-row .composer-input {
    border: none !important;
    padding: 6px 0 !important;
}

.composer-field-row .email-chips-container {
    border-bottom: none !important;
    padding: 0 !important;
    min-height: auto !important;
}

.composer-modal.maximized {
    width: 95vw !important;
    max-width: 95vw !important;
    height: 95vh !important;
    max-height: 95vh !important;
    border-radius: 12px !important;
}



