/* ==========================================================================
   GridMail 2.15.0 — Modular Feature Stylesheet (Light & Dark Mode + Mobile)
   Covers:
     1. Inbound Email Auth Badges (SPF/DKIM/DMARC) & Anti-Spoofing Banner
     2. Search Filter Popover & Operator Chips
     3. Attachment Lightbox Preview & Download All (.zip)
     4. Command Palette (Ctrl+K / Cmd+K) & Drag-and-Drop Triage
     5. Workflow Dialogs (Snooze, Send Later, Scheduled & Snoozed Manager)
     6. Email-to-Calendar Event Modal
     7. OpenPGP Keyring Studio & Inline Reader Decrypt/Verify Banner
     8. AI Selection Polish Popover & Streaming Thread Brief
     9. Offline SWR Snapshot Banner & Contact Group Badges
   ========================================================================== */

/* --- 1. Inbound Email Authentication & Anti-Spoofing Banner --- */
.gm-auth-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    vertical-align: middle;
    border: 1px solid transparent;
    white-space: nowrap;
}
.gm-auth-badge-verified {
    background: rgba(22, 163, 74, 0.12);
    color: #15803d;
    border-color: rgba(22, 163, 74, 0.28);
}
.gm-auth-badge-unverified {
    background: rgba(217, 119, 6, 0.12);
    color: #b45309;
    border-color: rgba(217, 119, 6, 0.28);
}
.gm-auth-badge-fail {
    background: rgba(220, 38, 38, 0.12);
    color: #b91c1c;
    border-color: rgba(220, 38, 38, 0.32);
}
[data-theme="dark"] .gm-auth-badge-verified {
    background: rgba(34, 197, 94, 0.16);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.35);
}
[data-theme="dark"] .gm-auth-badge-unverified {
    background: rgba(245, 158, 11, 0.16);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.35);
}
[data-theme="dark"] .gm-auth-badge-fail {
    background: rgba(248, 113, 113, 0.18);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.4);
}

.gm-auth-warning-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 10px 0 12px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.45;
    box-sizing: border-box;
    max-width: 100%;
}
.gm-auth-warning-warning {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 4px solid #d97706;
    color: #92400e;
}
.gm-auth-warning-danger {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid #dc2626;
    color: #991b1b;
}
[data-theme="dark"] .gm-auth-warning-warning {
    background: #2c2210;
    border-color: #854d0e;
    border-left-color: #f59e0b;
    color: #fde68a;
}
[data-theme="dark"] .gm-auth-warning-danger {
    background: #331618;
    border-color: #991b1b;
    border-left-color: #ef4444;
    color: #fecaca;
}
.gm-auth-warning-content {
    flex: 1;
    min-width: 0;
}
.gm-auth-warning-list {
    margin: 4px 0 0;
    padding-left: 18px;
}

/* --- 2. Search Filter Popover & Operator Chips --- */
button.gm-search-filter-btn,
.gm-search-filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    max-height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--sm-text-muted, #64748b);
    line-height: 1;
    box-shadow: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, color 0.15s ease;
}
button.gm-search-filter-btn svg,
.gm-search-filter-btn svg {
    flex-shrink: 0;
    display: block;
}
button.gm-search-filter-btn:hover,
button.gm-search-filter-btn[aria-expanded="true"],
.gm-search-filter-btn:hover,
.gm-search-filter-btn[aria-expanded="true"] {
    background: var(--sm-bg-hover, rgba(84, 168, 199, 0.14));
    border-color: transparent;
    color: var(--sm-primary, #0284c7);
}
button.gm-search-filter-btn:focus,
.gm-search-filter-btn:focus {
    border-color: transparent;
    box-shadow: none;
}
button.gm-search-filter-btn:focus-visible,
.gm-search-filter-btn:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: 1px;
}
.gm-search-filter-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 1200;
    background: var(--sm-bg-surface, #ffffff);
    border: 1px solid var(--sm-border, #cbd5e1);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    padding: 12px 14px;
    box-sizing: border-box;
    max-width: calc(100vw - 16px);
}
[data-theme="dark"] .gm-search-filter-popover {
    background: var(--sm-bg-surface, #1e293b);
    border-color: var(--sm-border, #334155);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
}
.gm-search-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
button.gm-search-op-chip,
.gm-search-op-chip {
    display: inline-flex;
    align-items: center;
    height: auto;
    min-height: 26px;
    max-height: none;
    line-height: 1.25;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--sm-border, #cbd5e1);
    background: var(--sm-bg-secondary, #f8fafc);
    color: var(--sm-text-primary, #1e293b);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.14s ease;
}
button.gm-search-op-chip:hover,
.gm-search-op-chip:hover {
    border-color: var(--sm-primary, #0284c7);
}
button.gm-search-op-chip.active,
button.gm-search-op-chip.active:hover,
.gm-search-op-chip.active {
    background: var(--sm-primary, #0284c7);
    border-color: var(--sm-primary, #0284c7);
    color: var(--sm-on-primary, #ffffff);
}
[data-theme="dark"] button.gm-search-op-chip,
[data-theme="dark"] .gm-search-op-chip {
    background: rgba(15, 23, 42, 0.55);
    color: var(--sm-text-primary, #e2e8f0);
}
[data-theme="dark"] button.gm-search-op-chip.active,
[data-theme="dark"] button.gm-search-op-chip.active:hover,
[data-theme="dark"] .gm-search-op-chip.active {
    background: var(--sm-primary, #38bdf8);
    border-color: var(--sm-primary, #38bdf8);
    color: var(--sm-on-primary, #0f172a);
}
.gm-search-builder-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}
.gm-search-field-input {
    width: 100%;
    min-width: 0;
    height: 34px;
    padding: 4px 10px;
    font-size: 12.5px;
    box-sizing: border-box;
}
.gm-search-popover-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}
.gm-search-syntax-hint {
    font-size: 11px;
    color: var(--sm-text-muted, #64748b);
    overflow-wrap: anywhere;
}

/* --- 3. Attachment Lightbox & Download All (.zip) --- */
button.gm-att-preview-link,
.gm-att-preview-link {
    background: none;
    border: none;
    padding: 0;
    height: auto;
    min-height: 0;
    max-height: none;
    line-height: inherit;
    box-shadow: none;
    font: inherit;
    font-weight: 600;
    color: var(--sm-primary, #0284c7);
    cursor: pointer;
    text-decoration: underline;
}
.gm-download-all-zip-btn {
    white-space: nowrap;
}

/* --- Shared Modal Dialog Shell (<dialog class="gm-modal-dialog">) --- */
dialog.gm-modal-dialog {
    border: 1px solid var(--sm-border, #cbd5e1);
    border-radius: 14px;
    padding: 0;
    background: var(--sm-bg-surface, #ffffff);
    color: var(--sm-text-primary, #0f172a);
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
    width: min(560px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 32px);
    box-sizing: border-box;
    overflow: hidden;
}
dialog.gm-modal-dialog::backdrop {
    background: rgba(15, 23, 42, 0.48);
    backdrop-filter: blur(2px);
}
[data-theme="dark"] dialog.gm-modal-dialog {
    background: var(--sm-bg-surface, #1e293b);
    color: var(--sm-text-primary, #f1f5f9);
    border-color: var(--sm-border, #334155);
}
.gm-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--sm-border, #e2e8f0);
}
.gm-modal-head h3 {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
button.gm-modal-close,
.gm-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    max-height: 30px;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--sm-text-muted, #64748b);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    flex-shrink: 0;
}
button.gm-modal-close:hover,
.gm-modal-close:hover {
    background: var(--sm-bg-hover, rgba(148, 163, 184, 0.16));
    border-color: transparent;
    color: var(--sm-text-primary, #0f172a);
}
button.gm-modal-close:focus,
.gm-modal-close:focus {
    border-color: transparent;
    box-shadow: none;
}
button.gm-modal-close:focus-visible,
.gm-modal-close:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: 1px;
}
.gm-modal-body {
    padding: 16px 18px;
    overflow-y: auto;
    max-height: calc(100vh - 160px);
    box-sizing: border-box;
}
.gm-modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--sm-border, #e2e8f0);
    flex-wrap: wrap;
}

/* Lightbox overrides */
dialog#gm-attachment-lightbox {
    width: min(920px, calc(100vw - 20px));
}
.gm-lightbox-stage {
    min-height: 260px;
    max-height: calc(100vh - 200px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: var(--sm-bg-secondary, #f8fafc);
    border-radius: 8px;
    padding: 12px;
}
[data-theme="dark"] .gm-lightbox-stage {
    background: #0f172a;
}
.gm-lightbox-stage img {
    max-width: 100%;
    max-height: calc(100vh - 230px);
    object-fit: contain;
    transition: transform 0.18s ease;
}
.gm-lightbox-stage iframe {
    width: 100%;
    height: min(68vh, 620px);
    border: none;
    border-radius: 6px;
    background: #ffffff;
}
.gm-lightbox-stage pre {
    width: 100%;
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    text-align: left;
}

/* --- 4. Command Palette (Ctrl+K / Cmd+K) & Drag-and-Drop Triage --- */
dialog#gm-command-palette {
    width: min(580px, calc(100vw - 20px));
}
.gm-cmd-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--sm-border, #e2e8f0);
}
input.gm-cmd-input,
.gm-cmd-input {
    flex: 1;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: none;
    outline: none;
    box-shadow: none;
    background: transparent;
    color: var(--sm-text-primary, #0f172a);
    font-size: 15px;
}
input.gm-cmd-input:focus,
.gm-cmd-input:focus {
    border: none;
    box-shadow: none;
}
[data-theme="dark"] input.gm-cmd-input,
[data-theme="dark"] .gm-cmd-input {
    background: transparent;
    color: #f8fafc;
}
.gm-cmd-list {
    max-height: 340px;
    overflow-y: auto;
    padding: 6px;
}
button.gm-cmd-item,
.gm-cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    height: auto;
    min-height: 38px;
    max-height: none;
    line-height: 1.3;
    padding: 9px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--sm-text-primary, inherit);
    box-shadow: none;
    text-align: left;
    font-size: 13.5px;
    cursor: pointer;
}
button.gm-cmd-item:hover,
button.gm-cmd-item.active,
.gm-cmd-item:hover,
.gm-cmd-item.active {
    background: var(--sm-bg-hover, rgba(84, 168, 199, 0.16));
    border-color: transparent;
    color: var(--sm-text-primary, inherit);
}
button.gm-cmd-item:focus,
.gm-cmd-item:focus {
    border-color: transparent;
    box-shadow: none;
}
button.gm-cmd-item:focus-visible,
.gm-cmd-item:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: -2px;
}
.gm-cmd-cat {
    font-size: 11px;
    font-weight: 600;
    color: var(--sm-text-muted, #64748b);
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--sm-bg-secondary, #f1f5f9);
}
[data-theme="dark"] .gm-cmd-cat {
    background: rgba(15, 23, 42, 0.6);
}

.gm-drop-target-active {
    outline: 2px dashed var(--sm-primary, #0284c7) !important;
    background: rgba(84, 168, 199, 0.2) !important;
    border-radius: 8px;
}
tr.sm-message-row.gm-dragging-row {
    opacity: 0.55;
}

/* --- 5. Snooze Presets & Queue Manager --- */
.gm-preset-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}
button.gm-preset-btn,
.gm-preset-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 2px;
    height: auto;
    min-height: 52px;
    max-height: none;
    line-height: 1.3;
    white-space: normal;
    padding: 10px 12px;
    border: 1px solid var(--sm-border, #cbd5e1);
    border-radius: 10px;
    background: var(--sm-bg-secondary, #f8fafc);
    color: var(--sm-text-primary, inherit);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease, background 0.15s ease;
}
button.gm-preset-btn:hover,
.gm-preset-btn:hover {
    border-color: var(--sm-primary, #0284c7);
    background: var(--sm-bg-hover, rgba(84, 168, 199, 0.1));
    color: var(--sm-text-primary, inherit);
}
[data-theme="dark"] button.gm-preset-btn,
[data-theme="dark"] .gm-preset-btn {
    background: rgba(15, 23, 42, 0.5);
}
.gm-preset-btn strong {
    font-size: 13px;
}
.gm-preset-btn span {
    font-size: 11.5px;
    color: var(--sm-text-muted, #64748b);
}
.gm-queue-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--sm-border, #e2e8f0);
    padding-bottom: 8px;
}
.gm-queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--sm-border, #e2e8f0);
    border-radius: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

/* --- 7. OpenPGP Banner & Studio --- */
.gm-pgp-reader-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 12px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(16, 185, 129, 0.35);
    background: rgba(16, 185, 129, 0.1);
    font-size: 13px;
}
[data-theme="dark"] .gm-pgp-reader-banner {
    background: rgba(16, 185, 129, 0.15);
    border-color: rgba(52, 211, 153, 0.35);
}

/* --- 8. Contact Group Badges & Offline Banner --- */
.gm-contact-group-badge {
    background: rgba(14, 165, 233, 0.12) !important;
    color: var(--sm-primary, #0284c7) !important;
}
.gm-offline-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 14px;
    background: #fef3c7;
    color: #92400e;
    font-size: 12.5px;
    font-weight: 600;
    border-bottom: 1px solid #fde68a;
}
[data-theme="dark"] .gm-offline-banner {
    background: #382c13;
    color: #fde68a;
    border-bottom-color: #854d0e;
}

/* --- 9. Multi-Account Switcher, Sidebar Mailboxes Bar & Add Account Modal --- */
.gm-acct-avatar,
.sm-avatar.gm-acct-color-0,
.sm-avatar.gm-acct-color-1,
.sm-avatar.gm-acct-color-2,
.sm-avatar.gm-acct-color-3,
.sm-avatar.gm-acct-color-4,
.sm-avatar.gm-acct-color-5 {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #ffffff;
    font-weight: 700;
    flex-shrink: 0;
}
.gm-acct-avatar {
    width: 28px;
    height: 28px;
    font-size: 12px;
}
.gm-acct-avatar-sm {
    width: 24px;
    height: 24px;
    font-size: 11px;
}
.gm-acct-color-0 { background: linear-gradient(135deg, #2563eb, #1d4ed8) !important; }
.gm-acct-color-1 { background: linear-gradient(135deg, #4f46e5, #4338ca) !important; }
.gm-acct-color-2 { background: linear-gradient(135deg, #059669, #047857) !important; }
.gm-acct-color-3 { background: linear-gradient(135deg, #0d9488, #0f766e) !important; }
.gm-acct-color-4 { background: linear-gradient(135deg, #e11d48, #be123c) !important; }
.gm-acct-color-5 { background: linear-gradient(135deg, #d97706, #b45309) !important; }

.gm-profile-multi-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--sm-primary, #54a8c7);
    color: var(--sm-on-primary, #ffffff);
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}
.gm-acct-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--sm-primary, #54a8c7);
    color: var(--sm-on-primary, #ffffff);
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
}
.gm-acct-unread-badge[hidden] {
    display: none;
}

/* Profile Popover Multi-Account Switcher */
.gm-popover-accounts-section {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 2px 0;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.gm-popover-accounts-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--sm-text-muted, #64748b);
    padding: 4px 10px 2px;
}
.gm-popover-accounts-label[hidden] {
    display: none;
}
.gm-popover-accounts-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 184px;
    overflow-x: hidden;
    overflow-y: auto;
    min-width: 0;
    scrollbar-width: thin;
}
.gm-popover-accounts-list[hidden] {
    display: none;
}
.gm-popover-acct-row {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
    border-radius: 8px;
    padding-right: 6px;
    box-sizing: border-box;
    transition: background-color 0.14s ease;
}
.gm-popover-acct-row:hover {
    background: var(--sm-hover-bg, rgba(148, 163, 184, 0.14));
}
button.gm-popover-acct-switch,
.gm-popover-acct-switch {
    flex: 1 1 auto;
    min-width: 0;
    height: auto;
    min-height: 44px;
    max-height: none;
    line-height: 1.25;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 7px 6px 7px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--sm-text-primary, #0f172a);
    box-shadow: none;
    text-align: left;
    cursor: pointer;
    font: inherit;
    box-sizing: border-box;
}
button.gm-popover-acct-switch:hover,
.gm-popover-acct-switch:hover {
    background: transparent;
    border-color: transparent;
    color: var(--sm-text-primary, #0f172a);
}
button.gm-popover-acct-switch:focus,
.gm-popover-acct-switch:focus {
    border-color: transparent;
    box-shadow: none;
}
button.gm-popover-acct-switch:focus-visible,
.gm-popover-acct-switch:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: -2px;
}
.gm-popover-acct-info {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.25;
}
.gm-popover-acct-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--sm-text-primary, #0f172a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gm-popover-acct-email {
    font-size: 11.5px;
    color: var(--sm-text-muted, #64748b);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
button.gm-popover-acct-remove,
.gm-popover-acct-remove {
    width: 26px;
    height: 26px;
    min-width: 26px;
    min-height: 26px;
    max-height: 26px;
    padding: 0;
    line-height: 1;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--sm-text-muted, #64748b);
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.14s ease, color 0.14s ease;
}
button.gm-popover-acct-remove svg,
.gm-popover-acct-remove svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    display: block;
}
button.gm-popover-acct-remove:hover,
.gm-popover-acct-remove:hover {
    background: var(--sm-danger-light, rgba(220, 38, 38, 0.12));
    border-color: transparent;
    color: var(--sm-danger, #dc2626);
}
button.gm-popover-acct-remove:focus,
.gm-popover-acct-remove:focus {
    border-color: transparent;
    box-shadow: none;
}
button.gm-popover-acct-remove:focus-visible,
.gm-popover-acct-remove:focus-visible {
    outline: 2px solid var(--sm-danger, #dc2626);
    outline-offset: 1px;
}
[data-theme="dark"] button.gm-popover-acct-remove:hover,
[data-theme="dark"] .gm-popover-acct-remove:hover {
    background: rgba(248, 113, 113, 0.18);
    color: #fca5a5;
}

/* Sidebar Quick Account Switcher (visible when 2+ accounts are signed in) */
.gm-sidebar-account-bar {
    margin: 12px 14px 0;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--sm-border, #e2e8f0);
    background: var(--sm-bg-surface, #ffffff);
    box-sizing: border-box;
    max-width: calc(100% - 28px);
}
[data-theme="dark"] .gm-sidebar-account-bar {
    background: var(--sm-bg-elevated, rgba(15, 23, 42, 0.45));
    border-color: var(--sm-border, #253247);
}
.gm-sidebar-acct-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 0 2px 6px;
}
.gm-sidebar-acct-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sm-text-muted, #64748b);
}
.gm-sidebar-acct-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--sm-bg-hover, rgba(148, 163, 184, 0.18));
    color: var(--sm-text-primary, #0f172a);
    font-size: 10px;
    font-weight: 700;
}
button.gm-sidebar-acct-add-btn,
.gm-sidebar-acct-add-btn {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    max-height: 24px;
    padding: 0;
    line-height: 1;
    border: 1px solid var(--sm-border, #cbd5e1);
    border-radius: 6px;
    background: transparent;
    color: var(--sm-text-muted, #64748b);
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: border-color 0.14s ease, color 0.14s ease, background-color 0.14s ease;
}
button.gm-sidebar-acct-add-btn svg,
.gm-sidebar-acct-add-btn svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    display: block;
}
button.gm-sidebar-acct-add-btn:hover,
.gm-sidebar-acct-add-btn:hover {
    border-color: var(--sm-primary, #54a8c7);
    color: var(--sm-primary, #54a8c7);
    background: var(--sm-primary-light, rgba(84, 168, 199, 0.12));
}
button.gm-sidebar-acct-add-btn:focus,
.gm-sidebar-acct-add-btn:focus {
    box-shadow: none;
}
button.gm-sidebar-acct-add-btn:focus-visible,
.gm-sidebar-acct-add-btn:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: 1px;
}
.gm-sidebar-acct-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-height: 164px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
}
button.gm-sidebar-acct-item,
.gm-sidebar-acct-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 40px;
    max-height: none;
    line-height: 1.25;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--sm-text-primary, #0f172a);
    box-shadow: none;
    text-align: left;
    cursor: pointer;
    font: inherit;
    box-sizing: border-box;
    transition: background-color 0.14s ease, border-color 0.14s ease;
}
button.gm-sidebar-acct-item:hover,
.gm-sidebar-acct-item:hover {
    background: var(--sm-hover-bg, rgba(148, 163, 184, 0.14));
    border-color: transparent;
    color: var(--sm-text-primary, #0f172a);
}
button.gm-sidebar-acct-item:focus,
.gm-sidebar-acct-item:focus {
    box-shadow: none;
}
button.gm-sidebar-acct-item:focus-visible,
.gm-sidebar-acct-item:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: -2px;
}
button.gm-sidebar-acct-item.is-active,
button.gm-sidebar-acct-item.is-active:hover,
.gm-sidebar-acct-item.is-active,
.gm-sidebar-acct-item.is-active:hover {
    background: var(--sm-primary-light, #eff7fa);
    border-color: var(--sm-primary-border, #cde4ee);
    color: var(--sm-text-primary, #0f172a);
    cursor: default;
}
button.gm-sidebar-acct-item.is-active .gm-sidebar-acct-label,
.gm-sidebar-acct-item.is-active .gm-sidebar-acct-label {
    font-weight: 700;
}
[data-theme="dark"] button.gm-sidebar-acct-item.is-active,
[data-theme="dark"] button.gm-sidebar-acct-item.is-active:hover,
[data-theme="dark"] .gm-sidebar-acct-item.is-active {
    background: var(--sm-primary-light, rgba(92, 183, 216, 0.16));
    border-color: var(--sm-primary-border, rgba(92, 183, 216, 0.38));
}
.gm-sidebar-acct-text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
    line-height: 1.2;
}
.gm-sidebar-acct-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--sm-text-primary, #0f172a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gm-sidebar-acct-email {
    font-size: 10.5px;
    color: var(--sm-text-muted, #64748b);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Add Mail Account Modal Dialog & Full-Page Banner */
dialog.gm-add-account-dialog {
    width: min(440px, calc(100vw - 24px));
}
.gm-add-acct-desc {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--sm-text-muted, #64748b);
    line-height: 1.45;
}
.gm-add-acct-error {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.32);
    color: #dc2626;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.4;
}
[data-theme="dark"] .gm-add-acct-error {
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(248, 113, 113, 0.4);
    color: #fca5a5;
}
.gm-add-acct-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 12px;
}
.gm-add-acct-field label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--sm-text-primary, #0f172a);
}
.gm-add-acct-field .sm-input {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 12px;
    font-size: 13.5px;
}
.gm-add-acct-pw-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.gm-add-acct-pw-wrap .sm-input {
    padding-right: 38px;
}
button.gm-add-acct-pw-toggle,
.gm-add-acct-pw-toggle {
    position: absolute;
    right: 6px;
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    max-height: 28px;
    padding: 0;
    line-height: 1;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--sm-text-muted, #64748b);
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
button.gm-add-acct-pw-toggle svg,
.gm-add-acct-pw-toggle svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: block;
}
button.gm-add-acct-pw-toggle:hover,
.gm-add-acct-pw-toggle:hover {
    background: var(--sm-hover-bg, rgba(148, 163, 184, 0.14));
    border-color: transparent;
    color: var(--sm-text-primary, #0f172a);
}
button.gm-add-acct-pw-toggle:focus,
.gm-add-acct-pw-toggle:focus {
    border-color: transparent;
    box-shadow: none;
}
button.gm-add-acct-pw-toggle:focus-visible,
.gm-add-acct-pw-toggle:focus-visible {
    outline: 2px solid var(--sm-primary, #54a8c7);
    outline-offset: 1px;
}
.gm-add-acct-remember {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--sm-text-secondary, #475569);
    cursor: pointer;
    margin-top: 2px;
}
.gm-add-acct-foot {
    justify-content: space-between;
}
.gm-add-acct-foot-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.gm-add-acct-fullpage-link {
    font-size: 12px;
    color: var(--sm-text-muted, #64748b);
    text-decoration: none;
}
.gm-add-acct-fullpage-link:hover {
    color: var(--sm-primary, #2563eb);
    text-decoration: underline;
}
.gm-login-add-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    margin-bottom: 16px;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.22);
    font-size: 12.5px;
    color: var(--sm-text-primary, #0f172a);
}
[data-theme="dark"] .gm-login-add-banner {
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.3);
    color: #e2e8f0;
}
.gm-login-add-banner-text {
    min-width: 0;
    overflow-wrap: anywhere;
}
.gm-login-back-link {
    font-weight: 600;
    color: var(--sm-primary, #2563eb);
    text-decoration: none;
    white-space: nowrap;
}
.gm-login-back-link:hover {
    text-decoration: underline;
}

/* --- Mobile Viewport Safety (390x844 zero-overflow guarantee) --- */
@media (max-width: 768px) {
    #sm-header .sm-profile-trigger.gm-has-multi-accounts {
        position: relative;
        overflow: visible;
    }
    #sm-header .sm-profile-trigger .gm-profile-multi-badge {
        position: absolute;
        top: -4px;
        right: -4px;
        min-width: 16px;
        height: 16px;
        font-size: 9.5px;
        box-shadow: 0 0 0 2px var(--sm-bg-surface, #ffffff);
    }
}
@media (max-width: 640px) {
    .gm-search-builder-grid,
    .gm-preset-grid {
        grid-template-columns: 1fr;
    }
    .gm-search-filter-popover {
        position: fixed;
        top: 58px;
        left: 8px;
        right: 8px;
        max-width: calc(100vw - 16px);
    }
    #gm-cmd-palette-btn {
        display: none;
    }
}
