/* ============================================================
 * OS 2045 — Outlook-style Email Client
 * Layered on top of theme-os2045.css inline `.email-*` rules.
 * Adds: 3-pane refinements, threading, compose window, context-menu, action bar.
 * ============================================================ */

/* Outer wrapper must be flex-column at full height so .email-3pane can
   flex:1 to consume the rest after the tabs row. Without this the pane
   only renders at its natural content height and the bottom of the
   window stays empty. The parent .os-window-body has padding+block by
   default — we strip that for windows containing email so the layout
   reaches edge-to-edge and full-height. */
body[data-theme-mode="os2045"] .os-window-body:has(> .email-container.email-outlook),
body[data-theme-mode="os2045"] .os-window-body:has(.email-container.email-outlook) {
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    min-height: 0 !important;
    overflow: hidden !important;
}
.email-container.email-outlook {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    height: 100% !important;
    min-height: 0 !important;
}
.email-outlook .email-tabs {
    flex: 0 0 auto;
}
.email-outlook .email-tab-content {
    min-height: 0;
}
.email-outlook .email-tab-content.active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

.email-outlook .email-3pane {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.email-outlook .email-folder-pane {
    width: 240px;
    flex: 0 0 240px;
    background: var(--glass-2);
    border-right: 1px solid var(--glass-edge);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0;
}

.email-outlook .email-list-pane {
    width: 380px;
    flex: 0 0 380px;
    background: var(--glass);
    border-right: 1px solid var(--glass-edge);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.email-outlook .email-detail-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* --- Folder Tree --- */
.email-outlook .email-folder {
    padding: 7px 10px 7px 10px;
    color: var(--ink);
    cursor: pointer;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.12s ease;
    user-select: none;
}
.email-outlook .email-folder-icon {
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}
.email-outlook .email-folder-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.email-outlook .email-folder .badge {
    background: var(--theme-accent);
    color: var(--ink);
    font-size: 0.68rem;
    padding: 1px 6px;
    border-radius: 9px;
    min-width: 18px;
    text-align: center;
    flex-shrink: 0;
}
.email-outlook .email-folder.active {
    background: color-mix(in srgb, var(--theme-accent) 18%, transparent);
    color: var(--theme-accent);
    border-right: 2px solid var(--theme-accent);
    font-weight: 600;
}
.email-outlook .email-folder:hover:not(.active) {
    background: color-mix(in srgb, var(--theme-accent) 7%, transparent);
    color: var(--ink);
}

/* --- List Toolbar --- */
.email-outlook .email-list-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--glass-2);
    border-bottom: 1px solid var(--glass-edge);
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* --- List Items --- */
.email-outlook .email-list-scroll {
    flex: 1;
    overflow-y: auto;
    background: var(--glass);
    outline: none;
    min-height: 0;
}
.email-outlook .email-list-scroll:focus {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--theme-accent) 30%, transparent);
}
.email-outlook .email-list-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--glass-edge);
    cursor: pointer;
    transition: background 0.1s ease;
    position: relative;
}
.email-outlook .email-list-item:hover {
    background: color-mix(in srgb, var(--theme-accent) 6%, transparent);
}
.email-outlook .email-list-item.active {
    background: color-mix(in srgb, var(--theme-accent) 18%, transparent);
    border-left: 3px solid var(--theme-accent);
    padding-left: 9px;
}
.email-outlook .email-list-item.selected {
    background: color-mix(in srgb, var(--a-amber) 8%, transparent);
}
.email-outlook .email-list-item.unread {
    background: var(--glass-hi);
}
.email-outlook .email-list-item.unread .email-item-from,
.email-outlook .email-list-item.unread .email-item-subject {
    font-weight: 700;
    color: var(--ink);
}
.email-outlook .email-list-item .email-item-content {
    flex: 1;
    min-width: 0;
}
.email-outlook .email-item-header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
}
.email-outlook .email-item-from {
    color: var(--ink);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.email-outlook .email-item-date {
    color: var(--ink-3);
    font-size: 0.72rem;
    flex-shrink: 0;
}
.email-outlook .email-item-subject {
    color: var(--ink-2);
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Threading row decoration */
.email-outlook .email-thread-row .email-item-from .email-thread-count {
    background: var(--glass-hi);
    color: var(--ink);
    font-size: 0.68rem;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
    font-weight: 500;
}

/* --- Detail Pane --- */
.email-outlook .email-reader {
    background: var(--glass);
}
.email-outlook .email-reader-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-3);
    font-size: 1rem;
    padding: 40px;
}
.email-outlook .email-reader-header {
    padding: 14px 18px;
    background: var(--glass-2);
    border-bottom: 1px solid var(--glass-edge);
    flex-shrink: 0;
}
.email-outlook .email-reader-header .subject {
    font-size: 1.1rem;
    color: var(--ink);
    margin-bottom: 8px;
    font-weight: 600;
    word-break: break-word;
}
.email-outlook .email-reader-header .meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.82rem;
    color: var(--ink-2);
}
.email-outlook .email-reader-header .meta span strong {
    color: var(--ink);
    margin-right: 4px;
}

.email-outlook .email-action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.email-outlook .email-action-bar .brief-btn {
    padding: 5px 11px;
    font-size: 0.8rem;
}

.email-outlook .email-reader-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px;
    background: var(--glass);
    min-height: 0;
}
.email-outlook .email-reader-attachments {
    padding: 10px 18px;
    background: var(--glass-2);
    border-top: 1px solid var(--glass-edge);
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}
.email-outlook .att-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: color-mix(in srgb, var(--theme-accent) 8%, transparent);
    border: 1px solid color-mix(in srgb, var(--theme-accent) 20%, transparent);
    border-radius: 4px;
    color: var(--ink);
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s;
    margin-right: 4px;
}
.email-outlook .att-chip:hover {
    background: color-mix(in srgb, var(--theme-accent) 18%, transparent);
    color: var(--ink);
}

/* Thread strip (other messages of conversation) */
.email-outlook .email-thread-strip {
    padding: 10px 18px;
    background: var(--glass-2);
    border-bottom: 1px solid var(--glass-edge);
    flex-shrink: 0;
    max-height: 140px;
    overflow-y: auto;
}
.email-outlook .email-thread-step {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    background: var(--glass-hi);
    border-radius: 3px;
    margin-bottom: 3px;
    cursor: pointer;
    font-size: 0.78rem;
}
.email-outlook .email-thread-step:hover {
    background: color-mix(in srgb, var(--theme-accent) 10%, transparent);
}
.email-outlook .email-thread-step .step-from { color: var(--ink); }
.email-outlook .email-thread-step .step-date { color: var(--ink-3); }

/* ============================================================
 * Compose Window
 * ============================================================ */
.email-compose-window {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--glass);
    color: var(--ink);
    overflow: hidden;
    transition: background 0.15s;
}
.email-compose-window.drag-over {
    background: color-mix(in srgb, var(--theme-accent) 8%, transparent);
    box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--theme-accent) 40%, transparent);
}

.email-compose-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--glass-2);
    border-bottom: 1px solid var(--glass-edge);
    flex-shrink: 0;
}

.email-compose-fields {
    padding: 10px 14px;
    background: var(--glass-2);
    border-bottom: 1px solid var(--glass-edge);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}
.email-compose-fields .compose-field {
    display: flex;
    align-items: center;
    gap: 8px;
}
.email-compose-fields .compose-field label {
    width: 70px;
    flex-shrink: 0;
    color: var(--ink-2);
    font-size: 0.85rem;
}
.email-compose-fields .compose-field input,
.email-compose-fields .compose-field select {
    flex: 1;
    background: var(--glass-2-strong);
    border: 1px solid var(--glass-edge);
    color: var(--ink);
    padding: 5px 8px;
    border-radius: 3px;
    font-size: 0.85rem;
    min-width: 0;
}
.email-compose-fields .email-compose-toggle-cc {
    background: transparent;
    border: 1px solid var(--glass-edge);
    color: var(--ink-3);
    padding: 4px 9px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.72rem;
}
.email-compose-fields .email-compose-toggle-cc:hover {
    border-color: var(--theme-accent);
    color: var(--theme-accent);
}

.email-compose-editor-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    background: var(--glass-2);
    border-bottom: 1px solid var(--glass-edge);
    flex-shrink: 0;
}
.email-compose-editor-bar button {
    background: transparent;
    border: 1px solid var(--glass-edge);
    color: var(--ink);
    padding: 3px 9px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.78rem;
    min-width: 28px;
}
.email-compose-editor-bar button:hover {
    background: color-mix(in srgb, var(--theme-accent) 10%, transparent);
    color: var(--theme-accent);
    border-color: var(--theme-accent);
}
.email-compose-editor-bar .sep {
    width: 1px;
    height: 16px;
    background: var(--glass-edge);
    margin: 0 3px;
}

/* Backlog 2f0521c7: Compose-Body theme-aware (was hardcoded #fff/#222 light-mode in dark-shell) */
.email-compose-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px;
    background: var(--glass-2-strong);
    color: var(--ink);
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 0.95rem;
    line-height: 1.5;
    min-height: 100px;
    outline: none;
}
.email-compose-body:focus {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--theme-accent) 30%, transparent);
}
.email-compose-body-plain {
    background: var(--glass-2-strong);
    border: none;
    color: var(--ink);
    padding: 14px 18px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    resize: none;
    outline: none;
}
.email-compose-body-plain:focus {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--theme-accent) 30%, transparent);
}

.email-compose-attachments {
    padding: 8px 14px;
    background: var(--glass-2);
    border-top: 1px solid var(--glass-edge);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}
.email-compose-attachments .att-chip {
    background: var(--glass-hi);
    border: 1px solid var(--glass-edge);
    color: var(--ink);
}

/* Backlog 2f0521c7: quoted-reply section reuses dark theme surface (was light-grey) */
.email-compose-quoted {
    padding: 10px 18px;
    background: var(--glass-1);
    color: var(--ink-2, var(--ink));
    border-top: 2px solid var(--glass-edge);
    max-height: 250px;
    overflow-y: auto;
    flex-shrink: 0;
    font-size: 0.88rem;
}

/* ============================================================
 * Context Menu
 * ============================================================ */
.email-context-menu {
    position: fixed;
    z-index: 100000;
    background: var(--glass-2-strong);
    border: 1px solid var(--glass-edge-strong);
    border-radius: 4px;
    padding: 4px 0;
    min-width: 200px;
    box-shadow: var(--glass-shadow, 0 4px 16px rgba(0, 0, 0, 0.6));
    font-size: 0.85rem;
    color: var(--ink);
}
.email-context-menu .menu-item {
    padding: 6px 14px;
    cursor: pointer;
    transition: background 0.1s;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.email-context-menu .menu-item:hover {
    background: color-mix(in srgb, var(--theme-accent) 18%, transparent);
    color: var(--ink);
}
.email-context-menu .menu-item.has-submenu::after {
    content: '▸';
    margin-left: auto;
    color: var(--ink-3);
}
.email-context-menu .menu-item.danger {
    color: var(--a-err, #ff6b6b);
}
.email-context-menu .menu-item.danger:hover {
    background: color-mix(in srgb, var(--a-err) 25%, transparent);
}
.email-context-menu .menu-divider {
    height: 1px;
    background: var(--glass-edge);
    margin: 4px 0;
}

/* ============================================================
 * Responsive — collapse folder pane on narrow widows
 * ============================================================ */
@media (max-width: 980px) {
    .email-outlook .email-folder-pane {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }
    .email-outlook .email-folder-pane.show {
        transform: translateX(0);
    }
    .email-outlook .email-list-pane {
        width: 100%;
        flex: 1 1 auto;
    }
}

@media (max-width: 700px) {
    .email-outlook .email-list-pane {
        flex: 0 0 100%;
    }
    .email-outlook .email-detail-pane {
        display: none;
    }
}

/* ------------------------------------------------------------------
 * Keyboard accessibility (a11y / WCAG 2.4.7 — focus visible)
 * Generic outline for all interactive elements inside the Outlook
 * Email tool. Uses --theme-accent so user accent applies.
 * ------------------------------------------------------------------ */
.email-outlook button:focus-visible,
.email-outlook [tabindex]:focus-visible,
.email-outlook input:focus-visible,
.email-outlook select:focus-visible,
.email-outlook textarea:focus-visible,
.email-outlook .email-thread:focus-visible,
.email-outlook .email-toolbar-btn:focus-visible {
    outline: 2px solid var(--theme-accent, #5fd1ff);
    outline-offset: 2px;
}
