/* ==========================================================================
   SpekTicket - Gorgias-inspired Ticketing UI
   ========================================================================== */

/* --- CSS Variables --- */
:root {
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
    --sidebar-active: #3b82f6;
    --sidebar-text: #94a3b8;
    --sidebar-text-bright: #e2e8f0;
    --sidebar-width: 260px;

    --bg-primary: #f8fafc;
    --bg-white: #ffffff;
    --bg-hover: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --blue: #3b82f6;
    --blue-light: #dbeafe;
    --blue-dark: #1d4ed8;
    --green: #22c55e;
    --green-light: #dcfce7;
    --amber: #f59e0b;
    --amber-light: #fef3c7;
    --red: #ef4444;
    --red-light: #fee2e2;
    --purple: #a855f7;
    --purple-light: #f3e8ff;
    --gray: #6b7280;
    --gray-light: #e5e7eb;
    --bg-gray: #f3f4f6;
    --primary: #3b82f6;

    --border: #e2e8f0;
    --border-color: #e2e8f0;
    --bg-secondary: #f1f5f9;
    --input-bg: #ffffff;
    --input-border: #d1d5db;
    --card-bg: #ffffff;
    --primary-hover: #2563eb;
    --primary-light: #dbeafe;
    /* Orphan tokens that were referenced as fallbacks across the codebase
       but never defined. Define them here so dark mode can override them. */
    --surface: #ffffff;
    --hover-bg: #f1f5f9;
    --bg-muted: #f3f4f6;
    --bg-tertiary: #f3f4f6;
    --border-light: #e5e7eb;
    --danger: #ef4444;
    --orange: #f59e0b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;

    --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Consolas', 'Monaco', monospace;

    --transition: 150ms ease;
}

/* --- Reset --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--blue);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- App Layout --- */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
    transition: width 0.25s ease, min-width 0.25s ease, opacity 0.2s ease;
}

.sidebar.sidebar-hidden {
    width: 0;
    min-width: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
}

/* Expand button (visible when sidebar is collapsed) */
.sidebar-expand-btn {
    position: fixed;
    /* Sits BETWEEN the back arrow (~top:14px) and the first message
       header (~top:80px). top:14 overlapped the back arrow, top:60 sat
       on the sender row — top:46 is the sweet spot. */
    top: 46px;
    left: 8px;
    z-index: 30;
    display: none;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text-bright);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: background var(--transition), transform var(--transition);
}

.sidebar-expand-btn:hover {
    background: var(--sidebar-hover);
    transform: scale(1.1);
}

/* Collapse button inside sidebar header */
.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: transparent;
    color: var(--sidebar-text);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-bright);
}

.sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Microsoft degraded-services indicator (red pulsing dot → public status page) */
.ms-health-dot {
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 6px;
    flex-shrink: 0;
    cursor: pointer;
}
.ms-health-pulse {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger, #ef4444);
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
    animation: ms-health-pulse 1.6s infinite;
}
@keyframes ms-health-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    70%  { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

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

.logo-icon {
    color: var(--blue);
}

.logo-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--sidebar-text-bright);
    letter-spacing: -0.3px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

.sidebar-section {
    margin-bottom: 4px;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--sidebar-text);
    padding: 12px 16px 4px;
    text-transform: uppercase;
}

.sidebar-list {
    list-style: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-bright);
    text-decoration: none;
}

.sidebar-link.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--blue);
    border-left-color: var(--blue);
}

.sidebar-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link.active .sidebar-icon {
    opacity: 1;
}

.sidebar-badge {
    margin-left: auto;
    background: rgba(255,255,255,0.1);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.sidebar-badge.badge-green {
    background: rgba(34, 197, 94, 0.2);
    color: var(--green);
}

.sidebar-badge.badge-amber {
    background: rgba(245, 158, 11, 0.2);
    color: var(--amber);
}

.sidebar-badge.badge-gray {
    background: rgba(107, 114, 128, 0.2);
    color: var(--gray);
}

.sidebar-folder-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.team-avatar {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent, #4f46e5);
    color: white;
    font-size: 10px;
    font-weight: 600;
    flex-shrink: 0;
    margin-right: 6px;
}
.sidebar-team-link {
    display: flex;
    align-items: center;
    gap: 4px;
}
.sidebar-team-member-static {
    cursor: default;
}
.sidebar-team-member-static:hover {
    background: transparent;
    color: inherit;
}
.badge-blue {
    background: #3b82f6 !important;
    color: white !important;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 8px 0;
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.user-name {
    font-size: 13px;
    color: var(--sidebar-text-bright);
}

/* ==========================================================================
   MAIN CONTENT
   ========================================================================== */
.main-content {
    flex: 1;
    min-height: 0;       /* Flex scroll containment */
    overflow-y: auto;
    background: var(--bg-primary);
}

/* ==========================================================================
   INBOX VIEW
   ========================================================================== */
.inbox-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.inbox-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}

.inbox-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.inbox-title {
    font-size: 20px;
    font-weight: 700;
}

.inbox-count {
    font-size: 13px;
    color: var(--text-muted);
}

.inbox-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Search */
.search-box {
    position: relative;
    width: 300px;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--bg-primary);
    transition: border-color var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* Search Suggestions Dropdown */
.search-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 200;
    max-height: 380px;
    overflow-y: auto;
}

.search-suggestion-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--bg-hover);
    transition: background var(--transition);
    text-decoration: none;
    color: inherit;
}

.search-suggestion-item:last-child {
    border-bottom: none;
}

.search-suggestion-item:hover,
.search-suggestion-item.active {
    background: var(--bg-hover);
}

.search-suggestion-ref {
    font-size: 11px;
    font-weight: 700;
    color: var(--blue);
    background: var(--blue-light);
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
    min-width: 42px;
    text-align: center;
}

.search-suggestion-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.search-suggestion-subject {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-suggestion-meta {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.search-suggestion-status {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 4px;
    padding: 2px 6px;
    white-space: nowrap;
}

.search-suggestion-status.open { background: var(--green-light); color: #16a34a; }
.search-suggestion-status.closed { background: var(--bg-hover); color: var(--text-muted); }
.search-suggestion-status.snoozed { background: var(--amber-light); color: #d97706; }

.search-suggestion-highlight {
    background: #fef08a;
    border-radius: 2px;
    padding: 0 1px;
}

.search-suggestions-footer {
    padding: 8px 14px;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    cursor: pointer;
}

.search-suggestions-footer:hover {
    background: var(--bg-hover);
    color: var(--blue);
}

.search-suggestions-empty {
    padding: 16px 14px;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

/* Bulk Actions */
/* Bulk actions sit on the filters row but are ABSOLUTELY positioned against
   #filters-bar (position:relative), anchored just to the RIGHT of the Filtres
   button — `left` is set in JS (updateBulkActions) from that button's measured
   width so it lands beside it regardless of locale/badge. Out of flow means
   entering selection mode adds ZERO height, so the ticket list never shifts.
   JS toggles inline display:none<->flex. No own background — the filters bar
   provides it. */
.bulk-actions {
    position: absolute;
    top: 50%;
    left: 90px;
    right: auto;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 2;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
}

.bulk-buttons {
    display: flex;
    gap: 6px;
}

/* Ticket Table */
.ticket-table-wrapper {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-white);
}

.ticket-table {
    width: 100%;
    border-collapse: collapse;
}

.ticket-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-primary);
}

.ticket-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

/* Column resize handle */
.ticket-table th .col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    background: transparent;
    z-index: 2;
}
.ticket-table th .col-resize-handle:hover,
.ticket-table th .col-resize-handle.resizing {
    background: var(--primary);
    opacity: 0.5;
}
.ticket-table.resizing {
    cursor: col-resize;
    user-select: none;
}

.ticket-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: middle;
}

.ticket-table tbody tr {
    cursor: pointer;
    transition: background var(--transition);
}

.ticket-table tbody tr:hover {
    background: var(--bg-hover);
}

.ticket-table tbody tr.unread {
    font-weight: 600;
}

/* SLA tier — admin-driven via Settings; --sla-color set inline by JS; color-mix auto-flips in dark mode (phase 04).
   Color strip lives on the first <td> (not <tr>) because border-left on a row
   with border-collapse: collapse renders inconsistently across browsers; the
   cell-level border is reliable and visually identical (it spans the full row height). */
.ticket-table tbody tr[data-sla-tier] { background: color-mix(in srgb, var(--sla-color) 10%, var(--bg-secondary)); }
.ticket-table tbody tr[data-sla-tier] > td:first-child { border-left: 5px solid var(--sla-color); }
.ticket-table tbody tr[data-sla-tier]:hover { background: color-mix(in srgb, var(--sla-color) 18%, var(--bg-secondary)); }
.ticket-table tbody tr[data-sla-tier] .status-dot { box-shadow: 0 0 0 2px var(--sla-color); }
.ticket-table tbody tr.sla-tier-last .status-dot { animation: sla-pulse 2s ease-in-out infinite; }
@keyframes sla-pulse {
    0%, 100% { box-shadow: 0 0 0 2px var(--sla-color); }
    50%      { box-shadow: 0 0 0 4px var(--sla-color); }
}
.sla-detail-badge {
    display: inline-flex; align-items: center; white-space: nowrap;
    font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-left: 8px;
    background: color-mix(in srgb, var(--sla-color) 18%, var(--bg-secondary));
    color: color-mix(in srgb, var(--sla-color) 70%, var(--text-primary));
}
.sla-detail-badge.sla-tier-last { animation: sla-pulse 2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
    .ticket-table tbody tr.sla-tier-last .status-dot,
    .sla-detail-badge.sla-tier-last { animation: none; }
}

/* Transferred ticket (direction=note) — distinctive styling */
.ticket-table tbody tr.ticket-transfer {
    background: #fffbeb;
    border-left: 3px solid var(--orange);
    position: relative;
}

.ticket-table tbody tr.ticket-transfer:hover {
    background: #fef3c7;
    box-shadow: inset 0 1px 3px rgba(249, 115, 22, 0.08);
}

.ticket-table tbody tr.ticket-transfer::before {
    content: '↗';
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--orange);
    font-weight: 600;
    opacity: 0.6;
}

.ticket-table tbody tr.ticket-transfer .status-dot {
    background: var(--orange) !important;
    box-shadow: 0 0 0 2px var(--amber-light);
}

/* Transfer badge in subject area */
.ticket-table tbody tr.ticket-transfer .subject-text::before {
    content: 'TRANSFERT ';
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--orange);
    margin-right: 6px;
    padding: 2px 6px;
    background: var(--amber-light);
    border-radius: 3px;
    display: inline-block;
}

.col-check {
    width: 44px;
    padding-left: 16px !important;
}

/* Inbox selection — large, easy-to-hit checkbox. The whole .col-check cell is
   a click target (toggle handled in tickets.js), so a misclick beside the box
   selects the row instead of opening the ticket. */
.col-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
    vertical-align: middle;
}
.ticket-table tbody td.col-check {
    cursor: pointer;
}
.bulk-actions .checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* ── Inbox selection mode ──────────────────────────────────────────────────
   Active whenever ≥1 ticket is checked (the .selection-mode class is toggled
   on #ticket-table by updateBulkActions). Row clicks then toggle selection
   instead of navigating, so we drop the pointer cursor as a signal and tint
   the chosen rows. !important + color-mix beats the SLA-tier / transfer row
   backgrounds above in both light and dark themes. */
.ticket-table.selection-mode tbody tr {
    cursor: default;
}
.ticket-table tbody tr.row-selected,
.ticket-table tbody tr.row-selected:hover {
    background: color-mix(in srgb, var(--primary) 15%, var(--bg-white)) !important;
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.col-status {
    width: 50px;
}

.col-sender {
    width: 200px;
}

.col-tags {
    width: 160px;
}

.col-subject {
    min-width: 200px;
}

.col-opened, .col-reply {
    width: 100px;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 12px;
}

/* Paperclip pin shown in the "Ouvert" column when a ticket carries at
   least one non-inline attachment. Sits flush-left of the relative-time
   text and inherits the column's muted color. */
.col-opened .attach-pin {
    display: inline-block;
    vertical-align: -2px;
    margin-right: 6px;
    color: var(--text-secondary);
    opacity: 0.8;
}
.ticket-table tbody tr:hover .col-opened .attach-pin {
    color: var(--primary);
    opacity: 1;
}

/* Sortable column headers */
.ticket-table th.sortable { cursor: pointer; user-select: none; }
.ticket-table th.sortable:hover { color: var(--primary); }
.ticket-table th .sort-arrow { font-size: 10px; margin-left: 4px; opacity: 0.7; }

/* Status dots */
.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot.open { background: var(--text-muted); opacity: 0.4; }
.status-dot.pending { background: var(--amber); }
.status-dot.closed { background: var(--gray); }

/* Sender cell */
.sender-info {
    display: flex;
    flex-direction: column;
}

.sender-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 100%;
}

.sender-email {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

/* Subject cell */
.subject-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 350px;
    display: block;
}

/* Tag badges */
.tag-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    color: white;
    margin-right: 4px;
    margin-bottom: 2px;
}

.tags-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 80px 24px;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h3 {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    margin-bottom: 24px;
}

/* Loading state */
.loading-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px 24px;
    background: var(--bg-white);
    border-top: 1px solid var(--border);
}

.pagination-info {
    font-size: 13px;
    color: var(--text-muted);
}

/* ==========================================================================
   TICKET DETAIL VIEW
   ========================================================================== */
.ticket-detail-layout {
    display: flex;
    height: 100%;
}

.ticket-conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;   /* Required for nested flex scroll — prevents overflow from expanding parent */
    border-right: 1px solid var(--border);
}

.context-panel {
    width: 320px;
    min-width: 320px;
    overflow-y: auto;
    background: var(--bg-primary);
    padding: 16px;
}

/* Top bar */
.ticket-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.btn-back {
    flex-shrink: 0;
}

.ticket-subject {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1 1 auto;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ticket-status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.ticket-status-badge.open {
    background: var(--green-light);
    color: #15803d;
}

.ticket-status-badge.pending {
    background: var(--amber-light);
    color: #92400e;
}

.ticket-status-badge.closed {
    background: var(--gray-light);
    color: var(--gray);
}

.assign-select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--bg-white);
}

/* Legacy — kept for fallback */
.ticket-tags-inline {
    display: none;
}

/* Actions dropdown (next to tags) */
.topbar-actions-dropdown {
    position: relative;
    flex-shrink: 0;
    margin-left: 4px;
}

.btn-actions-trigger {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-actions-trigger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.actions-menu {
    position: absolute;
    top: calc(100% + 4px);
    /* Right-anchored: the trigger moved to the far right of the topbar,
       so the menu must drop down aligned to the right edge of its
       wrapper — otherwise it opens off-screen to the right. */
    right: 0;
    z-index: 200;
    min-width: 220px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 4px 0;
}

.actions-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: none;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: background var(--transition);
}

.actions-menu-item:hover {
    background: var(--bg-hover);
}

.actions-menu-item svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.actions-menu-divider {
    margin: 4px 0;
    border: none;
    border-top: 1px solid var(--border);
}

.actions-menu-danger {
    color: var(--red);
}

.actions-menu-danger svg {
    color: var(--red);
}

.actions-menu-danger:hover {
    background: var(--red-light);
}

/* Tag badges container */
.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    margin: 2px;
    border-radius: 12px;
    font-size: 12px;
    background-color: #e5e7eb;
    color: #374151;
    font-weight: 500;
}

.tag-badge .remove {
    margin-left: 6px;
    cursor: pointer;
    font-weight: bold;
    opacity: 0.6;
    padding: 0 2px;
}

.tag-badge .remove:hover {
    opacity: 1;
}

/* Autocomplete input */
.tag-input-container {
    position: relative;
    display: inline-block;
    min-width: 200px;
    flex-shrink: 0;
    /* Promote to a stacking context above the topbar's neighbors
       (status badges, banners) so the dropdown renders cleanly on top. */
    z-index: 9000;
}

/* SharePoint per-team config: scope banner + inherited grid marker.
   Prevents the "which config am I editing?" confusion when toggling
   between default and team scopes. */
.sp-scope-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--bg-muted, #f3f4f6);
    border-left: 3px solid var(--primary, #3b82f6);
    font-size: 13px;
    color: var(--text-primary);
    margin: 6px 0 14px;
}
.sp-scope-banner .sp-scope-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary, #3b82f6);
    flex-shrink: 0;
}
.sp-scope-banner .sp-scope-inherits {
    color: var(--text-muted);
    font-size: 12px;
    font-style: italic;
    margin-left: auto;
}
body.dark-theme .sp-scope-banner {
    background: var(--bg-tertiary);
}

/* Grid rendered in "inherited" state — the team has no override for
   this dimension, so the checkboxes are a preview of the global defaults,
   NOT the team's own selection. Dashed border + opacity + prefix line
   communicate this at a glance. The one-time change listener removes
   the class when the user edits anything. */
.checkbox-grid.is-inherited {
    opacity: 0.65;
    border-left: 2px dashed var(--border-light, #cbd5e1);
    padding-left: 10px;
    position: relative;
    transition: opacity 0.15s ease;
}
.checkbox-grid.is-inherited::before {
    content: "Hérité des défauts — cochez pour créer un override pour cette équipe";
    display: block;
    grid-column: 1 / -1;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 4px;
}
body.dark-theme .checkbox-grid.is-inherited { opacity: 0.55; }

/* Access picker — used by macro modal and folder modal to pick which
   teams / users can see the entity. Checkbox list with team color dots. */
.access-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 8px 10px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius-sm, 4px);
    background: var(--bg-secondary, #f8fafc);
    max-height: 160px;
    overflow-y: auto;
}
.access-picker-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    padding: 3px 6px;
    border-radius: 3px;
}
.access-picker-item:hover { background: var(--hover-bg, #f1f5f9); }
.access-picker-item input[type="checkbox"] { margin: 0; }
.access-picker-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tag-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

.tag-input:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

/* Suggestions dropdown */
.tag-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    /* Width: don't constrain to input width — many tag names + "Créer le
       tag" + 8 swatches need room. The min-width matches the compact
       input footprint; auto-grow up to the max for readability. */
    min-width: 240px;
    max-width: 360px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    /* z-index 9999 escapes any ancestor stacking context (DEV banners
       sit at 99999 — we deliberately stay below that). */
    z-index: 9999;
    margin-top: 2px;
}

.tag-suggestion-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tag-suggestion-item:last-child {
    border-bottom: none;
}

.tag-suggestion-item:hover,
.tag-suggestion-item.selected {
    background-color: var(--bg-hover);
}

.tag-suggestion-item.create-new {
    color: var(--blue);
    font-weight: 500;
    /* Become a column so the color-swatch row can sit under the label. */
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px 12px 10px;
}

.tag-suggestion-item.create-new .tag-create-label {
    cursor: pointer;
    /* Avoid the label looking unclickable next to the bright swatches. */
    color: var(--blue);
}

/* Inline color picker shown inside the "Créer le tag" suggestion. Eight
   preset swatches in a horizontal row. Clicking a swatch creates the tag
   with that color; clicking the label or pressing Enter uses the first
   preset (gray) as default. */
.tag-color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.tag-color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.15);
    padding: 0;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
    flex-shrink: 0;
}

.tag-color-swatch:hover {
    transform: scale(1.18);
    box-shadow: 0 0 0 2px var(--bg-white), 0 0 0 3px rgba(59, 130, 246, 0.45);
}

.tag-color-swatch:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-white), 0 0 0 3px var(--blue);
}

/* Muted hint row for "Aucun tag correspondant" when the user has no
   create rights — visually distinct from actionable suggestions so users
   don't try to click it. */
.tag-suggestion-item.tag-suggestion-empty {
    color: var(--text-muted, #94a3b8);
    font-style: italic;
    cursor: default;
    background: transparent;
}

.tag-suggestion-item.tag-suggestion-empty:hover {
    background: transparent;
}

/* Legacy tag-chip for ticket list compatibility */
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    color: white;
}

.tag-chip-remove {
    cursor: pointer;
    opacity: 0.7;
    font-size: 14px;
    line-height: 1;
}

.tag-chip-remove:hover {
    opacity: 1;
}

/* ==========================================================================
   Message Thread — Crisp/Zendesk-inspired clean layout
   ========================================================================== */
.message-thread {
    flex: 1;
    min-height: 0;       /* Required for flex scroll containment */
    overflow-y: auto;
    /* Phase 17 — native-pin backstop: keep overflow-anchor:auto (browser default) explicit
       so a future edit cannot silently disable it. Works only when a pre-paint scroll has
       established scrollTop > 0 first (Plan 17-01). The js-delta pin in tickets.js setHeight
       is the deterministic primary (spike 002a: 1 px); this is the free belt-and-suspenders
       (spike 002b: 0 px). NEVER set this to none on this element or any ancestor. */
    overflow-anchor: auto;
    padding: 12px 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-secondary, #f8fafc);
}

/* --- Inbound / Outbound messages --- */
.msg-item {
    width: 100%;
    background: var(--bg-white, #fff);
    border-bottom: 1px solid var(--border, #e2e8f0);
    border-radius: 4px;
}

.msg-item.msg-inbound {
    border-left: 3px solid var(--primary);
}

.msg-item.msg-outbound {
    border-left: 1px solid var(--border-light);
    /* D-02: outbound background NEUTRE — tint rgba(59,130,246,0.03) removed for sobriety */
}

.msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-hover, #f1f5f9);
    border-bottom: 1px solid var(--border, #e2e8f0);
    font-size: 12px;
    min-height: 32px;
}

.msg-recipients {
    padding: 2px 14px 4px;
    font-size: 11px;
    color: var(--text-muted, #64748b);
    line-height: 1.4;
    background: var(--bg-hover, #f1f5f9);
    border-bottom: 1px solid var(--border, #e2e8f0);
    word-break: break-all;
}
.msg-recip-sep {
    margin: 0 6px;
    color: var(--border, #cbd5e1);
}

.msg-sender-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* --- Email autocomplete dropdown --- */
.email-ac-wrapper {
    position: relative;
    display: inline-block;
}
.email-autocomplete-dropdown {
    position: absolute;
    left: 0;
    top: 100%;
    z-index: 1000;
    min-width: 280px;
    background: var(--bg-white, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,.12);
    max-height: 220px;
    overflow-y: auto;
    margin-top: 2px;
}
.email-ac-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    cursor: pointer;
    font-size: 13px;
    transition: background .1s;
}
.email-ac-item:hover,
.email-ac-item.selected {
    background: var(--blue-light, #dbeafe);
}
.email-ac-email {
    color: var(--text-primary, #0f172a);
    font-weight: 500;
}
.email-ac-name {
    color: var(--text-muted, #94a3b8);
    font-size: 12px;
    margin-left: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

/* --- Email chips (Outlook-style recipient pills) ---
   SpekTicket.emailChips (app.js) wraps a recipient <input> in .email-chips;
   each confirmed address renders as a removable .email-chip pill. The inner
   input keeps typing/autocomplete duty — its own chrome is neutralized so
   the container carries the border. Two flavors:
   --line  → underline style (reply CC/CCI rows, .reply-addr-input)
   --box   → boxed style (compose modal, .form-input) */
.email-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
    cursor: text;
}
.email-chips--line {
    border-bottom: 1px solid var(--border);
    padding: 2px 4px;
}
.email-chips--line:focus-within {
    border-bottom-color: var(--blue);
}
.email-chips--box {
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    background: var(--bg-white, #fff);
    padding: 4px 6px;
}
.email-chips--box:focus-within {
    border-color: var(--blue);
}
.email-chips .email-chips-input {
    flex: 1 1 140px;
    min-width: 120px;
    width: auto;
    border: none !important;
    outline: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 2px;
}
/* When tickets.js wraps the input for contact autocomplete, the wrapper
   becomes the growing flex item instead */
.email-chips .email-ac-wrapper {
    flex: 1 1 140px;
    min-width: 140px;
}
.email-chips .email-ac-wrapper .email-chips-input {
    width: 100%;
}
.email-chip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 100%;
    padding: 1px 2px 1px 8px;
    border-radius: 12px;
    background: var(--blue-light, #dbeafe);
    color: var(--blue-dark, #1d4ed8);
    font-size: 12px;
    line-height: 18px;
    white-space: nowrap;
    transition: box-shadow .15s;
}
.email-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 260px;
}
.email-chip.invalid {
    background: #fee2e2;
    color: #b91c1c;
}
.email-chip.dup-flash {
    box-shadow: 0 0 0 2px var(--blue, #3b82f6);
}
.email-chip-x {
    border: none;
    background: transparent;
    cursor: pointer;
    color: inherit;
    font-size: 14px;
    line-height: 1;
    padding: 1px 6px;
    border-radius: 50%;
}
.email-chip-x:hover {
    background: rgba(0, 0, 0, .12);
}

.msg-sender-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary, #1e293b);
}

/* Internal org sender (blue) — @spekty.fr, @mutta.fr */
.sender-internal {
    color: #2563eb !important;
}

.msg-via {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    background: var(--bg-secondary, #f1f5f9);
    padding: 1px 6px;
    border-radius: 3px;
}

.msg-time {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    white-space: nowrap;
}

.msg-body {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-primary, #1e293b);
    word-break: break-word;
    overflow: hidden;
}

.msg-body p {
    margin: 0 0 2px 0;
}

.msg-body p:last-child {
    margin-bottom: 0;
}

.msg-spacer {
    height: 8px;
}

.msg-empty-placeholder {
    color: var(--text-muted, #94a3b8);
    font-style: italic;
    font-size: 13px;
    padding: 4px 0;
}

.msg-attachments {
    padding: 6px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.att-sender-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    padding-bottom: 2px;
}
.att-sender-label svg { color: var(--text-muted); flex-shrink: 0; }
.att-count { font-weight: 400; color: var(--text-muted); font-size: 11px; }
.att-chip-list {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* --- Notes / Forwards — compact amber banner --- */
.msg-note-banner {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    margin: 4px 0;
    font-size: 13px;
}

.msg-note-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    color: #92400e;
}

.msg-note-header svg {
    flex-shrink: 0;
    color: #d97706;
}

.msg-note-label {
    font-weight: 600;
    font-size: 12px;
}

.msg-note-time {
    margin-left: auto;
    font-size: 11px;
    color: #92400e;
}

.msg-note-body {
    padding: 0 12px 8px 32px;
    font-size: 13px;
    line-height: 1.45;
    color: #78350f;
    font-style: italic;
}

.msg-note-body p {
    margin: 0 0 2px 0;
}

/* --- Forward banner — same amber style, different label --- */
.msg-forward-banner {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 3px solid #f59e0b;
    border-radius: 4px;
    margin: 4px 0;
    font-size: 13px;
}

.msg-forward-label {
    font-weight: 600;
    font-size: 12px;
}

.msg-forward-via {
    font-size: 11px;
    font-weight: 400;
    color: #92400e;
    margin-left: 6px;
    font-style: italic;
}

.msg-fwd-subject {
    font-style: italic;
    color: #92400e;
}

.msg-note-author {
    font-size: 12px;
    color: #b45309;
    font-weight: 400;
}

.btn-note-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    padding: 2px 4px;
    border-radius: 4px;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}
.msg-note-banner:hover .btn-note-delete { opacity: 1; }
.btn-note-delete:hover { color: #ef4444; background: #fef2f2; }

/* --- Editable inline fields --- */
.editable-field {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.15s;
}
.editable-field:hover {
    background: var(--bg-hover, #f1f5f9);
}
.editable-field-input {
    font-size: 12px;
    padding: 2px 6px;
    border: 1px solid var(--blue, #3b82f6);
    border-radius: 4px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
}

/* --- System notices --- */
.msg-system {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: center;
    padding: 4px 12px;
    color: var(--text-muted, #94a3b8);
    font-size: 11px;
    font-style: italic;
}

.msg-system svg {
    opacity: 0.5;
    flex-shrink: 0;
}

.msg-system-time {
    opacity: 0.6;
    margin-left: 4px;
}

.msg-system-merge {
    background: #FEF3C7;
    border: 1px solid #F59E0B;
    border-radius: 8px;
    padding: 12px;
    color: #92400e;
    font-style: normal;
    font-size: 12px;
}
.msg-system-merge svg {
    opacity: 0.8;
    color: #F59E0B;
}

/* Per-message merge-origin label — a thin line rendered directly above each
   merged-in copy ("Fusionné depuis #X"), replacing the old stack of
   full-width merge banners. See static/js/tickets.js _buildMergeOriginLabel.
   Theme variables resolve correctly in both light and dark. */
.msg-merge-label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 12px 0 1px;
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    font-style: italic;
}
.msg-merge-label svg {
    flex-shrink: 0;
    opacity: 0.75;
    color: var(--primary, #6366f1);
}
.msg-merge-label-text { white-space: nowrap; }
.btn-unmerge-inline {
    margin-left: 6px;
    padding: 1px 8px;
    font-size: 10px;
    font-style: normal;
    line-height: 1.6;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary, #64748b);
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
}
.btn-unmerge-inline:hover {
    background: var(--hover-bg, #f1f5f9);
    color: var(--danger, #ef4444);
    border-color: var(--danger, #ef4444);
}

/* Macro bar */
.macro-bar {
    border-top: 1px solid var(--border);
    background: var(--bg-white);
}

.macro-bar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background var(--transition);
}

.macro-bar-header:hover {
    background: var(--bg-hover);
}

.macro-chevron {
    margin-left: auto;
    transition: transform var(--transition);
}

.macro-bar.expanded .macro-chevron {
    transform: rotate(180deg);
}

.macro-bar-content {
    padding: 0 20px 12px;
}

.macro-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 8px;
}

.macro-list {
    list-style: none;
    max-height: 160px;
    overflow-y: auto;
}

.macro-list li {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: background var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.macro-list li:hover {
    background: var(--bg-hover);
}

.macro-name {
    font-weight: 500;
}

.macro-shortcut {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.macro-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Category headers (Gorgias-like) */
.macro-category-header {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: var(--radius-sm);
    user-select: none;
}
.macro-category-header:hover {
    background: var(--bg-hover);
}
.macro-cat-chevron {
    font-size: 9px;
    width: 12px;
    text-align: center;
}
.macro-cat-count {
    margin-left: auto;
    font-size: 10px;
    background: var(--bg-hover);
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 500;
}

/* ===== Gorgias-style two-pane macro layout ===== */
.macro-list.macro-gorgias-layout {
    display: flex;
    padding: 0;
    margin: 0;
    list-style: none;
    min-height: 320px;
    max-height: 420px;
    overflow: hidden;
    background: var(--bg-white);
    border-radius: 8px;
    border: 1px solid var(--border-light, #e5e7eb);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.macro-cat-pane {
    flex: 0 0 220px;
    overflow-y: auto;
    border-right: 1px solid var(--border-light, #e5e7eb);
    background: var(--bg-secondary);
    padding: 6px 0;
    scrollbar-width: thin;
}

.macro-items-pane {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
}

.macro-items-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-light, #e5e7eb);
    z-index: 1;
}

.macro-items-header-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: capitalize;
    color: var(--text-primary);
    letter-spacing: 0.2px;
}

.macro-items-header-count {
    font-size: 11px;
    color: var(--text-muted, #9ca3af);
    font-weight: 500;
}

.macro-cat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px 9px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    border-left: 3px solid transparent;
    transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
    user-select: none;
    position: relative;
}

.macro-cat-item:hover {
    background: var(--bg-hover);
}

.macro-cat-item.active {
    background: var(--bg-white);
    border-left-color: var(--primary, #3b82f6);
    font-weight: 600;
    color: var(--primary, #3b82f6);
}

.macro-cat-item.active .macro-cat-count {
    background: var(--primary-light, #dbeafe);
    color: var(--primary, #3b82f6);
}

.macro-cat-name {
    flex: 1;
    text-transform: capitalize;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.macro-cat-arrow {
    color: var(--text-muted, #9ca3af);
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.08s ease, transform 0.08s ease;
}

.macro-cat-item:hover .macro-cat-arrow,
.macro-cat-item.active .macro-cat-arrow {
    opacity: 1;
    transform: translateX(2px);
}

.macro-items-list {
    list-style: none;
    padding: 4px 0;
    margin: 0;
    flex: 1;
}

.macro-items-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light, #f3f4f6);
    transition: background 0.1s ease, padding-left 0.1s ease;
}

.macro-items-list li:hover {
    background: var(--bg-hover);
    padding-left: 18px;
}

.macro-items-list li:last-child {
    border-bottom: none;
}

.macro-items-list .macro-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.macro-items-list .macro-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.macro-hint {
    padding: 24px 16px;
    font-size: 12px;
    color: var(--text-muted, #9ca3af);
    font-style: italic;
    text-align: center;
}

/* Dark-mode overrides */
body.dark-theme .macro-list.macro-gorgias-layout {
    background: var(--bg-white);
    border-color: var(--border-light);
}
body.dark-theme .macro-cat-pane {
    background: var(--bg-secondary);
    border-right-color: var(--border-light);
}
body.dark-theme .macro-cat-item:hover,
body.dark-theme .macro-cat-item.active {
    background: var(--bg-hover);
}

/* Action badge in macro list */
.macro-action-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 500;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--accent);
    color: white;
    vertical-align: middle;
}

.macro-empty {
    padding: 12px 10px;
    color: var(--text-muted);
    font-size: 13px;
    cursor: default !important;
}

/* Macro actions editor (settings modal) */
.macro-actions-editor {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.macro-action-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.macro-action-row .macro-action-type {
    flex: 0 0 180px;
}
.macro-action-row .macro-action-value {
    flex: 1;
    min-width: 0;
}
.macro-action-row .macro-action-value select,
.macro-action-row .macro-action-value input {
    width: 100%;
}
.macro-action-remove {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}
.form-input-sm {
    padding: 4px 8px !important;
    font-size: 12px !important;
    height: 30px;
}
.form-help-inline {
    font-weight: 400;
    font-size: 12px;
    color: var(--text-muted);
}

/* Reply box */
.reply-box {
    border-top: 1px solid var(--border);
    background: var(--bg-white);
}

.reply-header {
    padding: 8px 20px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.reply-to {
    font-weight: 500;
}

.reply-textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px 20px;
    border: none;
    resize: vertical;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.6;
}

.reply-textarea:focus {
    outline: none;
}

.reply-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px 12px;
}

.reply-actions-left, .reply-actions-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.forward-panel {
    padding: 8px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-main);
}
.forward-panel-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
}

.signature-select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    background: var(--bg-white);
}

/* Reply mode toggle bar */
.reply-mode-bar {
    display: flex;
    border-top: 1px solid var(--border);
    background: var(--bg-white);
}

.reply-mode-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    border-bottom: 2px solid transparent;
}

.reply-mode-tab:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.reply-mode-tab.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}

.reply-mode-tab[data-mode="note"].active {
    color: var(--amber);
    border-bottom-color: var(--amber);
}

/* Per-pane draft indicator: a small "•" appears next to the inactive tab's
 * label whenever that pane has unsent compose state in localStorage. The
 * .has-draft class is toggled by tickets.js on every switch + auto-save. */
.reply-mode-tab.has-draft::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    margin-left: 4px;
    border-radius: 50%;
    background: var(--blue);
    flex-shrink: 0;
}
.reply-mode-tab[data-mode="note"].has-draft::after {
    background: var(--amber);
}

/* Reply header compact — De: and A: on same line */
.reply-header-compact {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* Reply header rows — De, A, CC, CCI on separate lines */
.reply-header-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.reply-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}

.reply-addr-input {
    flex: 1;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 3px 6px;
    font-size: 12px;
    color: var(--text-primary);
    background: transparent;
    outline: none;
    min-width: 0;
}
.reply-addr-input:focus {
    border-bottom-color: var(--blue);
}

.reply-addr-toggle {
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
}
.reply-addr-toggle:hover {
    background: var(--border);
    color: var(--text-primary);
}
.reply-addr-toggle.active {
    background: var(--blue-light);
    color: var(--blue);
    border-color: var(--blue);
}

.reply-sep {
    color: var(--text-muted);
    font-size: 12px;
    margin: 0 2px;
}
.from-select {
    max-width: 250px;
}
.reply-label {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 30px;
}

.reply-sep {
    color: var(--border);
    font-size: 14px;
    margin: 0 2px;
}

.reply-to-value {
    font-size: 12px;
    color: var(--text-secondary);
}

.from-select {
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    background: var(--bg-white);
    max-width: 280px;
}

/* Note header */
.note-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: var(--amber-light);
    border-bottom: 1px solid rgba(245,158,11,0.2);
    font-size: 12px;
    color: #92400e;
    font-weight: 500;
}

/* Note mode styling */
.reply-box.note-mode {
    border-color: rgba(245,158,11,0.3);
}

.reply-box.note-mode .reply-editor {
    background: #fffbeb;
}

/* Rich text toolbar */
.richtext-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
}

.rt-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

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

.rt-btn.active {
    background: var(--blue-light);
    color: var(--blue);
}

.rt-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 4px;
}

/* Rich text editor (contenteditable) */
.reply-editor {
    min-height: 80px;
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: auto;  /* Phase 06 bug fix: wide grid-editor tables scroll
                          horizontally inside the editor instead of overflowing
                          past the composer edge. Pairs with removal of
                          .spk-grid `max-width: 100%` at line 2592. */
    padding: 10px 16px;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    outline: none;
    word-break: break-word;
    display: flex;
    flex-direction: column;
}

.reply-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
}

.reply-editor p { margin: 0 0 8px; }
.reply-editor ul, .reply-editor ol { margin: 0 0 8px; padding-left: 24px; }
.reply-editor li { margin-bottom: 2px; }

/* Signature separator in editor — margin-top:auto pushes it to the
   bottom of the flex column so resizing the editor adds space ABOVE
   the signature (typing area), not below it. */
.reply-editor .signature-block {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
}
.reply-editor .signature-block p:empty { display: none; margin: 0; padding: 0; }
.reply-editor .signature-block img[style*="display: none"],
.reply-editor .signature-block img[style*="display:none"] { width: 0; height: 0; margin: 0; padding: 0; }

/* ============ Phase 06 — Grid editor picker popover chrome (REQ-06-11 — first slice of in-editor preview chrome) ============ */
/* Popover anchored below the ⊞ toolbar button. position:fixed so it
   escapes any overflow:auto editor parent. Built by buildPicker() in
   static/js/grid-editor.js. Sketch source:
   .planning/sketches/001-grid-picker/index.html (variant B winner).
   Dark mode parity comes for free from the var(--*) tokens — no
   override needed in CONSOLIDATED FIXES for this section. */
.spk-grid-picker {
    position: fixed;
    z-index: 200;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 12px;
    min-width: 220px;
    font-size: 13px;
    color: var(--text-primary);
}

.spk-grid-picker-label {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.spk-grid-picker-cells {
    display: grid;
    grid-template-columns: repeat(4, 24px);
    grid-template-rows: repeat(4, 24px);
    gap: 2px;
    margin: 0 auto 10px;
    justify-content: center;
}

.spk-grid-picker-cell {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    cursor: pointer;
    border-radius: 2px;
    transition: background var(--transition), border-color var(--transition);
}

.spk-grid-picker-cell.active {
    background: var(--primary-light);
    border-color: var(--primary);
}

.spk-grid-picker-header-toggle {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

.spk-grid-picker-manual {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
}

.spk-grid-picker-manual label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.spk-grid-picker-manual input[type=number] {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 12px;
    background: var(--bg-white);
    color: var(--text-primary);
    font-family: inherit;
}

.spk-grid-picker-manual button {
    margin-left: auto;
    padding: 4px 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}

.spk-grid-picker-manual button:hover {
    background: var(--primary-hover);
}

/* In-editor preview chrome for inserted <table class="spk-grid">.
Minimal first slice — plans 06-05 / 06-06 / 06-07 / 06-08 / 06-09
   add selection visuals (.spk-grid-cell-selected,
.spk-grid-cell-anchor),
column resize handles,
context-menu,
and ribbon styling.

   BUG FIX (post-ship): `max-width: 100%` was forcing the table to fit the
   editor width,
so column drag-resize compressed neighboring columns
   instead of growing the table horizontally (the user expected Outlook-
   style: drag a column wider,
table grows,
horizontal scroll appears in
   the editor). Removed max-width; the editors get `overflow-x:auto` near
   the bottom of this file so wide tables scroll within the composer
   instead of overflowing it.

   Scope-broadened from `.reply-editor` to also `.compose-editor` so the
   inbox compose modal (plan 06-12 extension) gets the same chrome — the
   reply-editor-only scope was a plan 06-12 oversight. */
.reply-editor table.spk-grid,
horizontal scroll appears in
   the editor). Removed max-width; the editors get `overflow-x:auto` near
   the bottom of this file so wide tables scroll within the composer
   instead of overflowing it.

   Scope-broadened from `.reply-editor` to also `.compose-editor` so the
   inbox compose modal (plan 06-12 extension) gets the same chrome — the
   reply-editor-only scope was a plan 06-12 oversight. */
.macro-body-editor table.spk-grid,
.compose-editor table.spk-grid{
    margin: 12px 0;
    border-collapse: collapse;
    /* BUG FIX (post-ship round 3): the parent editors are
       `display: flex; flex-direction: column;` — without overriding
       align-self, the table inherits the default `stretch` cross-axis
       alignment and is forced to the editor's full width. Result: when
       the user drag-resized one column smaller, the table couldn't
       shrink (locked at editor-width), so the browser redistributed the
       freed space across the OTHER columns — looking like a fixed-width
       table with proportional columns. `align-self: flex-start` opts
       the table out of the flex stretch, letting it size to its own
       content width (`table-layout: auto` + the per-cell widths emitted
       by the drag-resize handler in grid-editor.js). Now drag-shrink
       narrows the column AND the whole table. Drag-grow widens both. */
    align-self: flex-start;
}
.reply-editor table.spk-grid td,
.macro-body-editor table.spk-grid td,
.reply-editor table.spk-grid th,
.macro-body-editor table.spk-grid th,
.compose-editor table.spk-grid td,
.compose-editor table.spk-grid th{
    position: relative;
    min-width: 40px;
}

/* Phase 06 plan 05 — multi-cell selection visual overlay
(REQ-06-11 in-editor preview chrome slice — selection overlay).

   .spk-grid-cell-selected: every cell in the rectangle from anchor to focus.
     1px inset border (via box-shadow so it doesn't shift layout) + light
     bg overlay tinted with the brand primary.
   .spk-grid-cell-anchor: the anchor cell additionally — 2px inset border
     (heavier ring to mark "this is where the drag started").

   !important on background-color defeats any inline style="background-color:#X"
   that plan 06-07 (color picker) writes onto the cell — the selection overlay
   must remain visible while the user is making a multi-cell pick. After
   deselection the inline style takes back over (cascade resumes).

   Class-strip leakage: the `.spk-grid-cell-*` classes are removed from the
   DOM when selection clears (mousedown outside any .spk-grid),
so they
   normally never reach _cleanupEditorHtml on send. Plan 06-13's class-strip
   pass in _cleanupEditorHtml is the belt-and-braces guard for the
   ribbon-action mid-selection edge case. */
.reply-editor table.spk-grid td.spk-grid-cell-selected,
so they
   normally never reach _cleanupEditorHtml on send. Plan 06-13's class-strip
   pass in _cleanupEditorHtml is the belt-and-braces guard for the
   ribbon-action mid-selection edge case. */
.macro-body-editor table.spk-grid td.spk-grid-cell-selected,
.reply-editor table.spk-grid th.spk-grid-cell-selected,
.macro-body-editor table.spk-grid th.spk-grid-cell-selected,
.compose-editor table.spk-grid td.spk-grid-cell-selected,
.compose-editor table.spk-grid th.spk-grid-cell-selected{
    box-shadow: inset 0 0 0 1px var(--primary);
    background-color: var(--primary-light) !important;
}
.reply-editor table.spk-grid td.spk-grid-cell-anchor,
.macro-body-editor table.spk-grid td.spk-grid-cell-anchor,
.reply-editor table.spk-grid th.spk-grid-cell-anchor,
.macro-body-editor table.spk-grid th.spk-grid-cell-anchor,
.compose-editor table.spk-grid td.spk-grid-cell-anchor,
.compose-editor table.spk-grid th.spk-grid-cell-anchor{
    box-shadow: inset 0 0 0 2px var(--primary) !important;
    background-color: var(--primary-light) !important;
}

/* Phase 06 plan 06 — context menu + nested submenu chrome
   (REQ-06-11 in-editor preview chrome slice — context menu surface).

   Right-click on a .spk-grid cell opens .spk-grid-ctx-menu via JS; hovering
   a row with [data-submenu] mounts a .spk-grid-ctx-submenu to its right.
   Both menus are position:fixed (viewport coords), appended to <body> so
   they aren't trapped inside overflow:auto editor parents. Z-index 9999
   mirrors the .entity-context-menu precedent (single tier for floating
   menus — always defeats other UI in the page).

   Theme tokens only — zero hardcoded hex except the rgba(239,68,68,0.1)
   red-tint for danger hover (matches .entity-context-menu .menu-item.danger
   :hover at line 8930 of this file — semantic constant for "danger states
   on hover", not a theme color).

   Dark-mode parity comes for free: all tokens used here have per-theme
   definitions in :root and body.dark-theme. */
.spk-grid-ctx-menu,
.spk-grid-ctx-submenu {
    position: fixed;
    z-index: 9999;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    padding: 4px 0;
    min-width: 220px;
    font-size: 13px;
    color: var(--text-primary);
    user-select: none;
}

.spk-grid-ctx-submenu {
    /* Submenu sits visually above its parent menu — bump z so the parent
       row's hover tint doesn't bleed through if they overlap on small
       viewports after viewport-overflow flip. */
    z-index: 10000;
    min-width: 200px;
}

.spk-grid-ctx-header {
    padding: 6px 14px 6px 14px;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 4px;
}

.spk-grid-ctx-header .sel-count {
    color: var(--primary);
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}

.spk-grid-ctx-item {
    padding: 8px 14px;
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    gap: 10px;
}

.spk-grid-ctx-item:hover,
.spk-grid-ctx-item.hovered {
    background: var(--hover-bg);
}

.spk-grid-ctx-item .label {
    flex: 1;
}

.spk-grid-ctx-item .kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    padding: 1px 4px;
    background: var(--bg-secondary);
    border-radius: 3px;
    border: 1px solid var(--border-light);
}

.spk-grid-ctx-item .chevron {
    color: var(--text-muted);
    font-size: 10px;
}

.spk-grid-ctx-item.danger {
    color: var(--danger);
}

.spk-grid-ctx-item.danger:hover {
    /* Semantic red-tint hover state — mirrors .entity-context-menu .menu-item.danger:hover */
    background: rgba(239, 68, 68, 0.1);
}

.spk-grid-ctx-sep {
    height: 1px;
    background: var(--border-light);
    margin: 4px 0;
}

.spk-grid-ctx-align-row {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.spk-grid-ctx-align-btn {
    flex: 1;
    padding: 6px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.1s ease;
}

.spk-grid-ctx-align-btn:hover {
    background: var(--hover-bg);
}

.spk-grid-ctx-align-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.spk-grid-ctx-colors-stub {
    padding: 12px 14px;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

/* Phase 06 plan 07 — color picker submenu chrome (REQ-06-11 in-editor
   preview chrome slice — color picker surface).

   The Couleurs ▸ submenu hosts three stacked sections (Fond / Texte /
   Bordures). Each section: title row (label + Effacer link aligned right)
   + swatch row (8 presets + 1 ⊕ custom-picker). All values use existing
   theme tokens — no new hardcoded colors except the checkerboard pattern
   for 'transparent' swatches (a 6×6 gray-on-white checker is a UI
   convention for "no fill", not a theme color). Dark-mode parity is
   automatic via the tokens.

   The .spk-grid-color-submenu selector inherits all of .spk-grid-ctx-submenu's
   base chrome (background, border, shadow, z-index, padding) from plan
   06-06's CSS — this block only adds the layout / sizing / swatch-grid
   styling specific to the color picker. */
.spk-grid-color-submenu {
    min-width: 240px;
    padding: 4px 0;
}

.spk-grid-color-section {
    padding: 8px 12px 10px;
    border-bottom: 1px solid var(--border-light);
}

.spk-grid-color-section:last-child {
    border-bottom: none;
}

.spk-grid-color-section-title {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.spk-grid-color-clear {
    margin-left: auto;
    padding: 2px 6px;
    font-size: 10px;
    color: var(--text-muted);
    text-decoration: underline;
    cursor: pointer;
}

.spk-grid-color-clear:hover {
    color: var(--danger);
    text-decoration: underline;
}

.spk-grid-color-swatches {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    align-items: center;
}

.spk-grid-color-swatch {
    width: 22px;
    height: 22px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    position: relative;
}

.spk-grid-color-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px var(--primary-light);
    z-index: 1;
}

.spk-grid-color-swatch.selected {
    box-shadow: 0 0 0 2px var(--primary);
}

/* Checkerboard pattern marking the "transparent" swatch (Fond + Bordure
   sections include it as their first swatch). 6×6 gray-on-white checker
   is a standard UI convention for "no fill" — not a theme color, so the
   hardcoded #ccc / transparent here is a semantic pattern, not a chrome
   color. */
.spk-grid-color-swatch.transparent {
    background:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 6px 6px;
    background-position: 0 0, 0 3px, 3px -3px, -3px 0;
}

.spk-grid-color-swatch-custom {
    border: 1px dashed var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-weight: bold;
}

.spk-grid-color-swatch-custom:hover {
    color: var(--primary);
    border-color: var(--primary);
}

/* Phase 06 plan 08 — column drag-resize handle + guide overlay
(REQ-06-11 in-editor preview chrome slice — drag handles + guide).

   The handle (.spk-grid-col-resize) is a 6px-wide absolute-positioned
   child of every <th>/<td>,
anchored to the cell's right edge. Hidden
   by default (opacity 0); revealed on cell hover and on direct handle
   hover. The parent cell already has position: relative (declared in
   the .reply-editor/.compose-editor table.spk-grid td/th rule near
   line 2592).

   The guide (.spk-grid-drag-guide) is appended to <body> at drag start
   and removed at drag end. position: fixed + height: 100vh so it spans
   the viewport regardless of scroll position. pointer-events: none so
   the document-level mouseup still fires correctly (the guide is
   visual-only — never an event target).

   The label (.spk-grid-drag-guide-label) floats at the vertical center
   of the guide and uses monospace for stable digit alignment as the
   delta animates. Hardcoded `monospace` (no project --font-mono var). */
.reply-editor table.spk-grid .spk-grid-col-resize,
anchored to the cell's right edge. Hidden
   by default (opacity 0); revealed on cell hover and on direct handle
   hover. The parent cell already has position: relative (declared in
   the .reply-editor/.compose-editor table.spk-grid td/th rule near
   line 2592).

   The guide (.spk-grid-drag-guide) is appended to <body> at drag start
   and removed at drag end. position: fixed + height: 100vh so it spans
   the viewport regardless of scroll position. pointer-events: none so
   the document-level mouseup still fires correctly (the guide is
   visual-only — never an event target).

   The label (.spk-grid-drag-guide-label) floats at the vertical center
   of the guide and uses monospace for stable digit alignment as the
   delta animates. Hardcoded `monospace` (no project --font-mono var). */
.macro-body-editor table.spk-grid .spk-grid-col-resize,
.compose-editor table.spk-grid .spk-grid-col-resize{
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    opacity: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
    z-index: 2;
}
.reply-editor table.spk-grid td:hover .spk-grid-col-resize,
.macro-body-editor table.spk-grid td:hover .spk-grid-col-resize,
.compose-editor table.spk-grid td:hover .spk-grid-col-resize,
.reply-editor table.spk-grid th:hover .spk-grid-col-resize,
.macro-body-editor table.spk-grid th:hover .spk-grid-col-resize,
.compose-editor table.spk-grid th:hover .spk-grid-col-resize{
    opacity: 1;
    background-color: var(--primary);
}
.reply-editor table.spk-grid .spk-grid-col-resize:hover,
.macro-body-editor table.spk-grid .spk-grid-col-resize:hover,
.compose-editor table.spk-grid .spk-grid-col-resize:hover{
    background-color: var(--primary-hover);
}

.spk-grid-drag-guide {
    position: fixed;
    top: 0;
    width: 0;
    height: 100vh;
    border-left: 1px dashed var(--primary);
    pointer-events: none;
    z-index: 10000;
}

.spk-grid-drag-guide-label {
    position: absolute;
    top: 50%;
    left: 8px;
    transform: translateY(-50%);
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    white-space: nowrap;
}

/* Phase 06 plan 09 — contextual table ribbon + help popover (REQ-06-03 /
   REQ-06-11 in-editor preview chrome slice — slide-in toolbar for tables).

   The ribbon sits between #richtext-toolbar and #reply-editor in
   templates/ticket_detail.html. JS controls visibility via the `hidden`
   HTML attribute — we OVERRIDE the browser default `[hidden]{display:none}`
   so the element stays in layout and we can animate max-height + opacity
   on the [hidden] toggle. Without the override, display:none would skip
   the transition entirely (display has no animatable value).

   Button states reuse the project's --primary / --hover-bg / --border-light
   semantic tokens — dark-mode parity is automatic via the cascade since
   those tokens flip in body.dark-theme. No explicit dark-mode override
   needed in CONSOLIDATED FIXES for this section. */

.spk-grid-ribbon {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    overflow: hidden;
    max-height: 40px;
    opacity: 1;
    transition: max-height 180ms ease, opacity 180ms ease, padding 180ms ease;
    z-index: 10;
}

/* Override the browser's default `[hidden] { display: none }` — we need
   the element to stay in layout so max-height + opacity can animate.
   The `display: flex` mirrors the visible state. The transition still
   applies (matches the rule above) — toggling `hidden` triggers the
   180ms slide-in or slide-out. pointer-events:none ensures buttons
   aren't accidentally clickable during the collapsed state. */
.spk-grid-ribbon[hidden] {
    display: flex !important;
    max-height: 0 !important;
    opacity: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    pointer-events: none !important;
    border-bottom-width: 0 !important;
}

.spk-grid-ribbon-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0 6px;
    user-select: none;
}

.spk-grid-ribbon-sep {
    width: 1px;
    height: 18px;
    background: var(--border-light);
    margin: 0 4px;
    flex-shrink: 0;
}

.spk-grid-ribbon-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
}

.spk-grid-ribbon-btn:hover {
    background: var(--hover-bg);
    border-color: var(--border-light);
}

.spk-grid-ribbon-btn.active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.spk-grid-ribbon-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}

.spk-grid-ribbon-spacer {
    flex: 1;
}

.spk-grid-ribbon-help {
    width: 22px;
    height: 22px;
    padding: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    flex-shrink: 0;
}

.spk-grid-ribbon-help:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Help popover — six-row keyboard shortcuts list anchored below the ?
   pill (or flipped above if no room below). Mirrors sketch 003's
   .kbd-popover visual style adapted to project semantic tokens. */
.spk-grid-help-popover {
    position: fixed;
    z-index: 100;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 12px 16px;
    min-width: 280px;
    font-size: 12px;
    color: var(--text-primary);
}

.spk-grid-help-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
}

.spk-grid-help-popover table {
    width: 100%;
    border-collapse: collapse;
}

.spk-grid-help-popover td {
    padding: 4px 0;
    color: var(--text-secondary);
}

.spk-grid-help-popover td:first-child {
    font-family: monospace;
    color: var(--primary);
    padding-right: 16px;
    font-weight: 500;
    white-space: nowrap;
}

/* Context panel */
.context-section {
    margin-bottom: 16px;
}

.context-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.context-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.client-field {
    margin-bottom: 10px;
}

.client-field:last-child {
    margin-bottom: 0;
}

.client-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.client-field span {
    font-size: 13px;
    color: var(--text-primary);
}

.client-note {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
    resize: vertical;
    min-height: 60px;
}

.no-data {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 12px;
}

/* CRM source badge (SharePoint / Excel indicator) */
.crm-source-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.crm-source-sharepoint {
    background: #e0f2fe;
    color: #0369a1;
}

.crm-source-excel {
    background: #dcfce7;
    color: #15803d;
}

.excel-field {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.excel-field:last-child {
    border-bottom: none;
}

.excel-field-label {
    color: var(--text-muted);
    font-weight: 500;
}

.excel-field-value {
    color: var(--text-primary);
    text-align: right;
}

.lots-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 12px 0 6px 0;
    padding-top: 8px;
    border-top: 2px solid var(--border);
}

/* CRM multi-match display */
.crm-match-header {
    padding: 6px 0;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.crm-match-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
}
.crm-match-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    margin: 2px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}
.crm-match-row:hover {
    background: var(--bg-hover, #f3f4f6);
    border-color: var(--border);
}
.crm-match-row.crm-match-active {
    background: var(--primary-light, #eff6ff);
    border-color: var(--primary);
}
.crm-match-source {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    color: #fff;
    background: var(--primary);
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}
.crm-match-summary {
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.crm-match-tooltip {
    /* position:fixed escapes ALL ancestor stacking contexts (including the
       central message-thread panel, which has its own z-index context).
       Without this, a `position:absolute; z-index:2500` tooltip stays trapped
       inside the CRM panel's stacking context and gets drawn UNDER siblings of
       any positioned ancestor that sits above it in the DOM — visible only
       at the leftmost edge.
       JS sets top/left on hover (see _renderCrmSection in tickets.js) since
       fixed positioning is viewport-relative. */
    display: none;
    position: fixed;
    min-width: 300px;
    max-width: 400px;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bg-card, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    padding: 10px;
    z-index: 9999;
    font-size: 12px;
    pointer-events: auto;
}
.crm-detail-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* Floating cleanup pattern button (text selection) */
#cleanup-selection-btn {
    transition: opacity 0.15s ease, transform 0.15s ease;
    animation: cleanupBtnAppear 0.15s ease;
}
#cleanup-selection-btn:hover {
    background: var(--blue-hover, #2554c7) !important;
    transform: translateY(-1px);
}
@keyframes cleanupBtnAppear {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.folder-select, .priority-select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    background: var(--bg-white);
}

/* ==========================================================================
   DASHBOARD
   ========================================================================== */
.dashboard-container {
    padding: 24px;
    max-width: 1400px;
}

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.dashboard-title {
    font-size: 24px;
    font-weight: 700;
}

.period-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.period-btn {
    background: var(--bg-white);
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.period-btn.active {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
}

.custom-date-range {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
}

.date-input {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* KPI Cards */
.kpi-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon-blue {
    background: var(--blue-light);
    color: var(--blue);
}

.kpi-icon-amber {
    background: var(--amber-light);
    color: var(--amber);
}

.kpi-icon-green {
    background: var(--green-light);
    color: var(--green);
}

.kpi-icon-purple {
    background: var(--purple-light);
    color: var(--purple);
}

.kpi-content {
    display: flex;
    flex-direction: column;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text-primary);
}

.kpi-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.chart-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    min-height: 280px;
    max-height: 380px;
    overflow: hidden;
}

.chart-card canvas {
    max-height: 300px !important;
}

.chart-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

/* SLA Cards */
.sla-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}

.sla-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-radius: var(--radius);
}

.sla-ok { background: var(--green-light); }
.sla-warning { background: var(--amber-light); }
.sla-critical { background: var(--red-light); }

.sla-count {
    font-size: 24px;
    font-weight: 700;
}

.sla-ok .sla-count { color: #15803d; }
.sla-warning .sla-count { color: #92400e; }
.sla-critical .sla-count { color: #b91c1c; }

.sla-label {
    font-size: 13px;
    font-weight: 500;
}

.sla-ok .sla-label { color: #15803d; }
.sla-warning .sla-label { color: #92400e; }
.sla-critical .sla-label { color: #b91c1c; }

/* Stats table */
.stats-table-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th {
    padding: 10px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stats-table td {
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.stats-table .empty-row td {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 24px;
}

/* ==========================================================================
   SETTINGS
   ========================================================================== */
.settings-container {
    padding: 24px;
}

.settings-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 20px;
}

/* --- Settings 2-column layout --- */
.settings-layout {
    display: flex;
    gap: 0;
    min-height: calc(100vh - 140px);
}

/* --- Vertical sidebar navigation --- */
.settings-sidebar {
    width: 220px;
    min-width: 220px;
    border-right: 1px solid var(--border);
    padding: 8px 0;
    overflow-y: auto;
    background: var(--bg-white);
}

.settings-nav-group {
    margin-bottom: 8px;
}

.settings-nav-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 12px 16px 4px;
    user-select: none;
}

.settings-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 16px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all var(--transition);
    text-align: left;
    white-space: nowrap;
}

.settings-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.settings-tab.active {
    color: var(--blue);
    border-left-color: var(--blue);
    background: var(--blue-light);
    font-weight: 600;
}

.settings-tab svg {
    flex-shrink: 0;
}

/* --- Content panel (right side) --- */
.settings-content {
    flex: 1;
    min-width: 0;
    padding: 0 0 0 28px;
    max-width: 900px;
}
/* When users-management panel is active, allow full width for organigramme */
.settings-content.organigramme-fullwidth {
    max-width: none;
}

.settings-panel {
    display: none;
}

.settings-panel.active {
    display: block;
}

.panel-section {
    margin-bottom: 28px;
}

.panel-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.panel-description {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    margin-bottom: 0;
}

/* Mailbox management cards */
#mailbox-mgmt-cards {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}
.mbx-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: box-shadow var(--transition);
}
.mbx-card:hover {
    box-shadow: var(--shadow-md);
}
.mbx-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}
.mbx-card-header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.mbx-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.mbx-card-account {
    font-size: 12px;
    color: var(--text-muted);
}
.mbx-card-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    background: var(--green-light);
    color: #16a34a;
    letter-spacing: 0.3px;
}
.mbx-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    padding: 16px 20px;
}
.mbx-field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mbx-field-group > label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}
.mbx-field-group .form-input {
    font-size: 13px;
    padding: 7px 10px;
}
.mbx-sidebar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.mbx-sidebar-row input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}
.mbx-features-section {
    padding: 12px 20px 4px;
    border-top: 1px solid var(--border);
}
.mbx-features-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: block;
}
.mbx-features-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.mbx-feature-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    user-select: none;
    font-size: 13px;
    background: var(--bg-white);
}
.mbx-feature-item:hover {
    border-color: var(--blue);
    background: var(--blue-light);
}
.mbx-feature-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--blue);
}
.mbx-feature-item input[type="checkbox"]:checked ~ .mbx-feature-text {
    color: var(--text-primary);
    font-weight: 500;
}
.mbx-feature-icon {
    font-size: 14px;
}
.mbx-feature-text {
    font-size: 12px;
    color: var(--text-secondary);
}
.mbx-card-footer {
    display: flex;
    justify-content: flex-end;
    padding: 10px 20px 14px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
    transition: border-color var(--transition);
    background: var(--bg-white);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-input-lg, .form-select-lg {
    padding: 12px 16px;
    font-size: 15px;
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    font-family: var(--font-mono);
    font-size: 12px;
}

/* Macro body is a contenteditable (so it can hold a pasted grid), not a
   textarea. Override the .form-textarea mono/12px with the normal editor
   font, give it scroll + a comfortable min-height, and a placeholder via
   data-placeholder (mirrors .reply-editor:empty::before). */
.macro-body-editor {
    min-height: 160px;
    max-height: 360px;
    overflow-y: auto;
    overflow-x: auto;
    resize: vertical;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.5;
    text-align: left;
    cursor: text;
}
.macro-body-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted);
    pointer-events: none;
}
.macro-body-editor:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

/* File upload */
.file-upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    transition: all var(--transition);
    cursor: pointer;
}

.file-upload-zone:hover,
.file-upload-zone.dragover {
    border-color: var(--blue);
    background: var(--blue-light);
}

.file-upload-zone p {
    margin-top: 8px;
    font-size: 13px;
}

.file-browse {
    color: var(--blue);
    cursor: pointer;
    font-weight: 500;
}

.file-name {
    display: block;
    margin-top: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Rules list */
.rules-list, .macros-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rule-item, .macro-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: box-shadow var(--transition);
}

.rule-item:hover, .macro-item:hover {
    box-shadow: var(--shadow);
}

.rule-info, .macro-info {
    display: flex;
    flex-direction: column;
}

.rule-name, .macro-item-name {
    font-weight: 500;
    font-size: 14px;
}

.rule-sender, .macro-item-category {
    font-size: 12px;
    color: var(--text-muted);
}

.rule-actions, .macro-actions {
    display: flex;
    gap: 6px;
}

/* Signatures list */
.signatures-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.signature-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.signature-item:hover {
    box-shadow: var(--shadow);
    border-color: var(--blue);
}

.signature-item.active {
    border-color: var(--blue);
    background: var(--blue-light);
}

.signature-name {
    font-weight: 500;
}

.signature-preview {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-height: 100px;
}

/* Settings table */
.settings-table {
    width: 100%;
    border-collapse: collapse;
}

.settings-table th {
    padding: 8px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
}

.settings-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.settings-table input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

/* Preview table */
.table-scroll {
    overflow-x: auto;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.preview-table th, .preview-table td {
    padding: 6px 10px;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.preview-table th {
    background: var(--bg-primary);
    font-weight: 600;
}

/* Sync status */
.sync-status {
    font-size: 13px;
    color: var(--text-muted);
}

.sync-status.syncing {
    color: var(--blue);
}

.sync-status.success {
    color: var(--green);
}

.sync-status.error {
    color: var(--red);
}

.reprocess-status {
    font-size: 13px;
    color: var(--text-muted);
}

.reprocess-status.success {
    color: var(--green);
}

.reprocess-status.error {
    color: var(--red);
}

/* ==========================================================================
   SETUP WIZARD
   ========================================================================== */
.setup-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 40px 24px;
}

.setup-card {
    width: 100%;
    max-width: 640px;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
}

.setup-header {
    text-align: center;
    margin-bottom: 32px;
}

.setup-logo {
    color: var(--blue);
    margin-bottom: 16px;
}

.setup-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.setup-header p {
    color: var(--text-muted);
}

/* Steps indicator */
.setup-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 32px;
}

.setup-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.step-number {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gray-light);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    transition: all var(--transition);
}

.setup-step.active .step-number {
    background: var(--blue);
    color: white;
}

.setup-step.completed .step-number {
    background: var(--green);
    color: white;
}

.step-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.setup-step.active .step-label {
    color: var(--blue);
}

.step-connector {
    width: 48px;
    height: 2px;
    background: var(--gray-light);
    margin: 0 4px;
    margin-bottom: 18px;
}

/* Setup panels */
.setup-panel {
    display: none;
}

.setup-panel.active {
    display: block;
}

.setup-panel h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.setup-panel > p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: 14px;
}

.setup-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.quick-periods {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.quick-period.active {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
}

/* Progress */
.progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 24px 0;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--gray-light);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--blue);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 40px;
}

.import-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 20px;
}

.import-stat {
    text-align: center;
}

.import-stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.import-stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

/* ==========================================================================
   MODAL
   ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    font-size: 24px;
    color: var(--text-muted);
    line-height: 1;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* Link-confirm modal — phishing defense (quick 260527-eaf) */
.link-confirm-url {
    display: block;
    background: var(--bg-secondary, #f3f4f6);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--radius-sm, 6px);
    padding: 10px 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: var(--text-primary, #111827);
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    user-select: all;
}

.link-confirm-text-mismatch {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(245, 158, 11, 0.08);
    border-left: 3px solid var(--amber, #f59e0b);
    border-radius: var(--radius-sm, 6px);
    font-size: 13px;
    color: var(--text-primary, #111827);
}

.link-confirm-text-mismatch .link-confirm-visible-text {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    padding: 1px 4px;
    background: rgba(245, 158, 11, 0.15);
    border-radius: 3px;
    word-break: break-all;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--blue);
    color: white;
    border-color: var(--blue);
}

.btn-primary:hover:not(:disabled) {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
}

.btn-success {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

.btn-success:hover:not(:disabled) {
    background: #16a34a;
}

.btn-outline {
    background: var(--bg-white);
    color: var(--text-secondary);
    border-color: var(--border);
}

.btn-outline:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    color: var(--red);
    border-color: var(--red-light);
}

.btn-danger:hover:not(:disabled) {
    background: var(--red-light);
}

.btn-warning {
    background: var(--amber);
    color: white;
    border-color: var(--amber);
}

.btn-warning:hover:not(:disabled) {
    background: #d97706;
    border-color: #d97706;
}

.btn-ghost {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 4px 8px;
}

.btn-ghost:hover {
    color: var(--blue);
    background: var(--blue-light);
}

.btn-icon {
    padding: 6px;
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

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

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-xs {
    padding: 2px 6px;
    font-size: 11px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 15px;
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--bg-white);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    min-width: 280px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid;
}

.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--amber); }
.toast.info { border-left-color: var(--blue); }

.toast-close {
    margin-left: auto;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    background: none;
    border: none;
    padding: 0 4px;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ==========================================================================
   UTILITIES
   ========================================================================== */
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-blue { color: var(--blue); }

.hidden { display: none !important; }

/* ==========================================================================
   SIDEBAR SECTION HEADER (with add button)
   ========================================================================== */
.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-right: 12px;
}

.btn-sidebar-add {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    opacity: 0;
    transition: all var(--transition);
}

.sidebar-section:hover .btn-sidebar-add {
    opacity: 1;
}

.btn-sidebar-add:hover {
    color: var(--blue);
    background: rgba(59, 130, 246, 0.15);
}

.sidebar-inline-form {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 16px 8px;
}

.sidebar-inline-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.08);
    color: var(--sidebar-text-bright);
    font-size: 12px;
    font-family: var(--font);
}

.sidebar-inline-input:focus {
    outline: none;
    border-color: var(--blue);
}

.sidebar-color-picker {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: none;
}

.btn-sidebar-confirm,
.btn-sidebar-cancel {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
}

.btn-sidebar-confirm {
    color: var(--green);
}

.btn-sidebar-cancel {
    color: var(--red);
}

.btn-sidebar-confirm:hover {
    background: rgba(34, 197, 94, 0.15);
}

.btn-sidebar-cancel:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Badge purple for waiting_client */
.sidebar-badge.badge-purple {
    background: rgba(168, 85, 247, 0.2);
    color: var(--purple);
}

/* ==========================================================================
   STATUS SELECT (in ticket topbar)
   ========================================================================== */
.status-dropdown-wrap {
    position: relative;
}

.status-select {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    background: var(--bg-white);
    cursor: pointer;
    font-family: var(--font);
}

.status-select:focus {
    outline: none;
    border-color: var(--blue);
}

/* ==========================================================================
   SNOOZE DROPDOWN
   ========================================================================== */
.snooze-dropdown-wrap {
    position: relative;
}

.snooze-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 100;
    overflow: hidden;
}

.snooze-option {
    display: block;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: none;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font);
    transition: background var(--transition);
}

.snooze-option:hover {
    background: var(--bg-hover);
}

.snooze-info {
    font-size: 11px;
    color: var(--amber);
    font-weight: 500;
}

/* ==========================================================================
   PARSING MODAL FIELDS
   ========================================================================== */
.parsing-field-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
}

.parsing-field-name {
    width: 140px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
}

.parsing-field-pattern {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-mono);
}

.parsing-field-name:focus,
.parsing-field-pattern:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.1);
}

/* Status dot colors for new statuses */
.status-dot.paused {
    background: var(--amber);
}

.status-dot.waiting_client {
    background: var(--purple);
}

/* ==========================================================================
   GROUPED CONVERSATION
   ========================================================================== */
.conversation-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--purple-light);
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.conversation-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--purple);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.conversation-header-info {
    display: flex;
    flex-direction: column;
}

.conversation-header-name {
    font-weight: 600;
    color: var(--text-primary);
}

.conversation-header-count {
    font-size: 12px;
    color: var(--text-muted);
}

.ticket-group-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 12px;
    position: relative;
}

.separator-line {
    flex: 1;
    height: 1px;
    background: var(--border);
}

.separator-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.separator-content a {
    font-weight: 600;
    color: var(--blue);
    text-decoration: none;
}

.separator-content a:hover {
    text-decoration: underline;
}

.separator-subject {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.separator-date {
    color: var(--text-muted);
}

.separator-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.separator-status.status-open {
    background: var(--green-light);
    color: #15803d;
}

.separator-status.status-paused {
    background: var(--amber-light);
    color: #92400e;
}

.separator-status.status-waiting_client {
    background: var(--purple-light);
    color: var(--purple);
}

.separator-status.status-closed {
    background: var(--gray-light);
    color: var(--gray);
}

.separator-current {
    border-color: var(--blue);
    background: var(--blue-light);
    color: var(--blue-dark);
    font-weight: 600;
}

.message-bubble.related-ticket {
    border-left: 3px solid var(--purple);
    opacity: 0.85;
}

.message-bubble.related-ticket .message-header {
    color: var(--purple);
}

/* ==========================================================================
   COLLISION DETECTION BANNER
   ========================================================================== */
.collision-banner {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #fef3c7 0%, #fff7ed 100%);
    border: 1px solid #fbbf24;
    border-radius: 8px;
    margin: 8px 16px;
    color: #92400e;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 1px 4px rgba(245,158,11,0.12);
}
.collision-banner .collision-avatars {
    display: flex;
    gap: 0;
}
.collision-banner .collision-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: #f59e0b;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px;
    font-weight: 700;
    border: 2px solid #fef3c7;
    margin-left: -6px;
}
.collision-banner .collision-avatar:first-child {
    margin-left: 0;
}

/* ==========================================================================
   CONTACT HISTORY PAGE
   ========================================================================== */
.contact-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px;
}

.contact-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--purple);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    flex-shrink: 0;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
}

.contact-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--text-muted);
}

.contact-meta span::before {
    margin-right: 4px;
}

.contact-email-display {
    color: var(--blue);
}

.contact-ticket-count {
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary, #f0f0f0);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Ticket cards */
.contact-ticket-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    transition: box-shadow 0.15s;
}

.contact-ticket-card:hover {
    box-shadow: var(--shadow-sm);
}

.contact-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.contact-card-subject {
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-card-subject:hover {
    color: var(--blue);
    text-decoration: underline;
}

.contact-status-badge {
    font-size: 11px;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    flex-shrink: 0;
}

.contact-card-date {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.contact-card-tags {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* Message accordion */
.contact-msg-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fafafa;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.contact-msg-toggle::before {
    content: '\25B6';
    font-size: 8px;
    transition: transform 0.2s;
}

.contact-msg-toggle.expanded::before {
    transform: rotate(90deg);
}

.contact-msg-toggle:hover {
    background: #f0f0f0;
    color: var(--text-primary);
}

.contact-messages {
    margin-top: 12px;
    padding-left: 8px;
    border-left: 2px solid #e5e7eb;
}

.contact-msg-bubble {
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: var(--radius);
    font-size: 13px;
}

.contact-msg-bubble.inbound {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
}

.contact-msg-bubble.outbound {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

.contact-msg-bubble.note {
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.contact-msg-header {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
}

.contact-msg-sender {
    font-weight: 600;
    color: var(--text-primary);
}

.contact-msg-dir {
    color: var(--text-muted);
    font-style: italic;
}

.contact-msg-time {
    color: var(--text-muted);
    margin-left: auto;
}

.contact-msg-body p {
    margin: 0 0 4px 0;
    line-height: 1.5;
    color: var(--text-primary);
}

/* Rendered HTML body (via DOMParser) inside the contact history accordion.
   Inherit the bubble's colors so inbound/outbound/note tinting stays
   consistent, and tame Outlook's generous default margins. */
.contact-msg-html {
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}
.contact-msg-html p { margin: 0 0 0.5em 0; color: inherit; }
.contact-msg-html p:empty { margin: 0; min-height: 0.4em; }
.contact-msg-html div { margin: 0; }
.contact-msg-html img { max-width: 100%; height: auto; }
.contact-msg-html table {
    border-collapse: collapse;
    max-width: 100% !important;
    table-layout: fixed;
}
.contact-msg-html td, .contact-msg-html th { word-break: break-word; }
.contact-msg-html a { color: var(--primary, #3b82f6); }
body.dark-theme .contact-msg-html { color: var(--text-primary); }

.contact-msg-spacer { height: 0.5em; }

.contact-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-size: 14px;
}

/* ==========================================================================
   DRAG & DROP
   ========================================================================== */
tr.dragging {
    opacity: 0.4;
    background: #e0e7ff !important;
}
tr[draggable="true"] {
    cursor: default;
}
tr[draggable="true"]:active {
    cursor: default;
}
body.is-dragging,
body.is-dragging * {
    cursor: grabbing !important;
}
.sidebar-link.drag-over,
li.drag-over .sidebar-link {
    background: var(--blue) !important;
    color: white !important;
    border-radius: var(--radius);
    transition: background 0.15s;
}

/* ==========================================================================
   CLICKABLE TAGS
   ========================================================================== */
.tag-badge.tag-clickable {
    cursor: pointer;
    transition: opacity 0.15s, box-shadow 0.15s;
}
.tag-badge.tag-clickable:hover {
    opacity: 0.85;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

/* ==========================================================================
   FILTERS BAR — Filtres button + active chip row + popover panel
   (replaces the standalone ACTIVE FILTER BAR; chip row now lives inline next
   to the Filtres trigger and shares the bar background.)
   ========================================================================== */
.filters-bar {
    position: relative;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
}
.filters-bar-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    flex-wrap: wrap;
}

/* Hide the whole bar when no filters AND no panel open. We leave the
   button always visible — handled in JS by only hiding on empty state. */
.filters-bar.is-empty .active-filters { display: none; }

/* Filtres trigger button */
.btn-filtres {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-white);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.4;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-filtres:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}
.btn-filtres[aria-expanded="true"] {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}
.btn-filtres svg { opacity: 0.75; }
.btn-filtres-badge {
    background: var(--primary);
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    line-height: 1.3;
}

/* Active filter chip container — inline, no own background (filters-bar handles it) */
.active-filters {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

/* Chip — uses --blue so it re-tints per theme (violet/emerald/rose/etc.) */
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--blue);
    color: white;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}
.filter-chip-body {
    cursor: pointer;
    transition: opacity 0.12s;
}
.filter-chip-body:hover { opacity: 0.85; }
.filter-chip-remove {
    cursor: pointer;
    margin-left: 4px;
    font-size: 14px;
    opacity: 0.8;
    line-height: 1;
    padding: 0 2px;
}
.filter-chip-remove:hover { opacity: 1; }

/* Clear-all action */
.active-filters-clear {
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    background: transparent;
    border: none;
    font-family: inherit;
}
.active-filters-clear:hover {
    background: var(--bg-hover);
    color: var(--danger);
}

/* ==========================================================================
   FILTER PANEL (popover anchored to .filters-bar, variant B from sketch 004)
   ========================================================================== */
.filter-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 16px;
    z-index: 100;
    width: 400px;
    max-width: calc(100vw - 32px);
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    color: var(--text-primary);
}
.filter-panel[hidden] { display: none; }

/* Tabs row */
.filter-panel-tabs {
    display: flex;
    gap: 0;
    padding: 4px 6px 0 6px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-primary);
}
.filter-panel-tab {
    background: transparent;
    border: none;
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: color 0.15s, border-color 0.15s;
}
.filter-panel-tab[hidden] { display: none; }
.filter-panel-tab:hover { color: var(--text-primary); }
.filter-panel-tab.is-active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.filter-panel-tab-count {
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 8px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 600;
    min-width: 14px;
    text-align: center;
    line-height: 1.4;
}
.filter-panel-tab-count[hidden] { display: none; }

/* Section body */
.filter-panel-body {
    min-height: 160px;
    max-height: 360px;
    overflow-y: auto;
}
.filter-panel-section {
    padding: 12px 14px;
}
.filter-panel-section[hidden] { display: none; }
.filter-panel-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.filter-panel-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-muted);
}
.filter-panel-actions { display: flex; gap: 4px; }
.filter-panel-mini {
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
    font-family: inherit;
}
.filter-panel-mini:hover { background: var(--primary-light); }

/* Tag search input */
.filter-panel-search {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 12px;
    outline: none;
    margin-bottom: 6px;
    font-family: inherit;
}
.filter-panel-search:focus { border-color: var(--primary); }

/* Checkbox list */
.filter-panel-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.filter-panel-list-scroll {
    max-height: 180px;
    overflow-y: auto;
    margin-right: -4px;
    padding-right: 4px;
}
.filter-panel-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.1s;
}
.filter-panel-row:hover { background: var(--bg-hover); }
.filter-panel-row input[type="checkbox"] {
    margin: 0;
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
}
.filter-panel-row[hidden] { display: none; }
.filter-panel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.filter-panel-dot.s-open { background: #22c55e; }
.filter-panel-dot.s-paused { background: #f59e0b; }
.filter-panel-dot.s-waiting { background: #3b82f6; }
.filter-panel-dot.s-closed { background: #94a3b8; }
.filter-panel-empty {
    padding: 12px 4px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

/* Footer */
.filter-panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-light);
    font-size: 11px;
}
.filter-panel-footer-info { color: var(--text-muted); }
.filter-panel-close {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}
.filter-panel-close:hover { background: var(--bg-hover); }

/* Responsive adjustments */
@media (max-width: 1200px) {
    .kpi-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }

    .context-panel {
        width: 280px;
        min-width: 280px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        width: 60px;
        min-width: 60px;
    }

    .sidebar .logo-text,
    .sidebar .sidebar-section-title,
    .sidebar-link span,
    .sidebar-badge,
    .sidebar .user-name {
        display: none;
    }

    .sidebar-link {
        justify-content: center;
        padding: 10px;
    }

    .ticket-detail-layout {
        flex-direction: column;
        overflow: hidden;   /* Constrain children in column mode */
    }

    .ticket-conversation {
        flex: 1 1 0%;
        min-height: 0;      /* Allow shrinking below content size */
        overflow: hidden;    /* Constrain message-thread */
    }

    .context-panel {
        width: 100%;
        min-width: 0;
        max-height: 40vh;    /* Cap panel height in mobile stacked layout */
        border-right: none;
        border-top: 1px solid var(--border);
    }
}

/* ==========================================================================
   LAN SHARING
   ========================================================================== */

.lan-share-card {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.lan-ip-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.lan-label { font-size: 0.9rem; color: #374151; }

.lan-ip {
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: #059669;
    background: #d1fae5;
    padding: 2px 8px;
    border-radius: 4px;
}

.lan-hostname {
    font-size: 0.8rem;
    color: #6b7280;
}

.lan-url-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.lan-url-input {
    flex: 1;
    font-family: monospace;
    font-size: 0.95rem;
}

.lan-security-row { margin-top: 0.75rem; }

.lan-security-hint {
    font-size: 0.8rem;
    color: #6b7280;
    margin: 0.25rem 0 0 1.75rem;
}

.settings-divider {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 1.5rem 0;
}

.lan-share-loading {
    text-align: center;
    padding: 1rem;
    color: #6b7280;
}

.lan-share-error {
    text-align: center;
    padding: 1rem;
    color: #dc2626;
}

/* ==========================================================================
   PUBLIC TUNNEL / SHARING
   ========================================================================== */

.tunnel-status-card {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

.tunnel-status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.tunnel-status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.tunnel-status-dot.dot-green {
    background: var(--green);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
    animation: tunnel-pulse 2s ease-in-out infinite;
}

.tunnel-status-dot.dot-red {
    background: var(--red);
}

.tunnel-status-dot.dot-gray {
    background: var(--gray-light);
}

.tunnel-status-dot.dot-amber {
    background: var(--amber);
    animation: tunnel-pulse 1s ease-in-out infinite;
}

@keyframes tunnel-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.tunnel-start-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    font-size: 1rem;
    font-weight: 600;
}

.tunnel-help-text {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Loading spinner */
.tunnel-loading {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 2rem;
    justify-content: center;
    font-size: 1rem;
    color: var(--text-secondary);
}

.tunnel-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--gray-light);
    border-top: 3px solid var(--blue);
    border-radius: 50%;
    animation: tunnel-spin 0.8s linear infinite;
}

@keyframes tunnel-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* URL card (when running) */
.tunnel-url-card {
    background: var(--bg-white);
    border: 2px solid var(--green);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.tunnel-url-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: block;
}

.tunnel-url-row {
    display: flex;
    gap: 8px;
    margin-bottom: 1.5rem;
}

.tunnel-url-input {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--blue-dark);
    background: #f0f7ff;
    border: 1px solid var(--blue-light);
}

.tunnel-url-input:focus {
    outline: none;
    border-color: var(--blue);
}

/* QR section */
.tunnel-qr-section {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 1rem 0;
}

.tunnel-qr-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.tunnel-qr-container {
    display: inline-block;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.tunnel-qr-container img,
.tunnel-qr-container canvas {
    display: block;
}

/* Action buttons row */
.tunnel-actions-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.tunnel-actions-row .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Info box */
.tunnel-info-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    padding: 1rem;
    font-size: 0.85rem;
    color: #166534;
}

.tunnel-info-box p {
    margin: 0;
}

.tunnel-info-box p + p {
    margin-top: 0.5rem;
}

/* ---- Folder edit row (ticket detail context panel) ---- */
.folder-edit-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.folder-edit-row .folder-select {
    flex: 1;
}

/* ---- Folder color dot (used in sidebar + Settings → Dossiers table) ---- */
.folder-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ---- Tag input compact ---- */
.ticket-tags-inline .tag-input {
    width: 60px;
    padding: 2px 6px;
    font-size: 11px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
}

.ticket-tags-inline .tag-input:focus {
    width: 120px;
    border-style: solid;
    border-color: var(--primary);
    outline: none;
}

/* ==========================================================================
   Mailbox Selector (sidebar)
   ========================================================================== */
.mailbox-selector-section {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.mailbox-current {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--sidebar-text-bright);
    transition: background 0.15s;
}

.mailbox-current:hover {
    background: var(--sidebar-hover);
}

.mailbox-name {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
}

.mailbox-chevron {
    opacity: 0.5;
    transition: transform 0.2s;
}

.mailbox-dropdown {
    margin-top: 4px;
    background: #273548;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.mailbox-list {
    list-style: none;
    padding: 4px 0;
    margin: 0;
}

.mailbox-item {
    padding: 8px 14px;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 13px;
    transition: background 0.1s, color 0.1s;
}

.mailbox-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-bright);
}

.mailbox-item.active {
    color: var(--sidebar-active);
    font-weight: 600;
}

.mailbox-add-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: none;
    color: var(--sidebar-text);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.mailbox-add-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-bright);
}

/* ==========================================================================
   System Notices (legacy — kept for backward compatibility)
   ========================================================================== */
.system-notice {
    text-align: center;
    padding: 4px 12px;
    margin: 4px auto;
    max-width: 80%;
    color: var(--text-muted);
    font-style: italic;
    font-size: 11px;
    background: var(--bg-hover);
    border-radius: 4px;
}

.system-notice-time {
    font-size: 11px;
    opacity: 0.7;
}

/* ==========================================================================
   Ticket ID column + badge
   ========================================================================== */
.col-id {
    width: 70px;
    white-space: nowrap;
}

.ticket-ref {
    font-weight: 600;
    color: var(--blue);
    font-size: 13px;
    font-family: monospace;
}

.ticket-id-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    background: var(--blue-light);
    color: var(--blue-dark);
    font-weight: 700;
    font-size: 13px;
    font-family: monospace;
    border-radius: 4px;
    margin-right: 8px;
    flex-shrink: 0;
}

/* ==========================================================================
   Merge Modal
   ========================================================================== */
.merge-results {
    margin-top: 12px;
    max-height: 300px;
    overflow-y: auto;
}

.merge-result-item {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.merge-result-item:hover {
    background: var(--blue-light);
    border-color: var(--blue);
}

.merge-ref {
    font-weight: 600;
    color: var(--blue);
    font-size: 13px;
}

.merge-subject {
    color: var(--text-primary);
    font-size: 13px;
}

.merge-sender {
    color: var(--text-muted);
    font-size: 12px;
}

.merge-no-result {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ==========================================================================
   AUTH - Logout button & sidebar user
   ========================================================================== */
.btn-logout {
    color: #94a3b8;
    padding: 4px;
    border-radius: 4px;
    margin-left: auto;
    transition: color 0.2s;
    /* Reset <button> browser defaults so it looks like the previous <a> */
    background: transparent;
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    line-height: 0;
}
.btn-logout:hover { color: #f87171; }
.btn-logout:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
#logout-form { margin-left: auto; }
.sidebar-user { display: flex; align-items: center; gap: 8px; }

/* ==========================================================================
   ATTACHMENTS IN MESSAGES
   ========================================================================== */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.15s, box-shadow 0.15s, border-color 0.15s;
    max-width: 260px;
}

.attachment-chip:hover {
    background: #eff6ff;
    border-color: var(--blue);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    color: var(--blue-dark);
}

.attachment-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.attachment-chip:hover .attachment-icon {
    color: var(--blue);
}

.attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
    font-weight: 500;
}

.attachment-size {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.attachment-previewable {
    cursor: zoom-in;
}
.attachment-previewable:hover {
    border-color: var(--blue);
    background: #eff6ff;
}
.attachment-preview-badge {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    color: var(--blue);
    opacity: 0;
    transition: opacity 0.15s;
    margin-left: -2px;
}
.attachment-chip:hover .attachment-preview-badge {
    opacity: 1;
}

/* ==========================================================================
   ATTACHMENT PREVIEW LIGHTBOX
   ========================================================================== */
#attachment-preview-overlay {
    position: fixed;
    inset: 0;
    /* z-index 100000 ensures the lightbox is above any in-app overlay,
       including the DEV environment banner (z-index 99999). */
    z-index: 100000;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
#attachment-preview-overlay.ap-visible {
    display: block;
    opacity: 1;
}
.ap-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    /* Purely decorative — must not intercept pointer events.
       Click-to-close is handled at the overlay level in tickets.js. */
    pointer-events: none;
}
.ap-container {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 1;
}
.ap-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(0,0,0,0.4);
    flex-shrink: 0;
}
.ap-actions {
    display: flex;
    gap: 8px;
}
.ap-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.ap-btn:hover {
    background: rgba(255,255,255,0.3);
}
.ap-body {
    flex: 1;
    display: flex;
    /* align-items: stretch (default) — was 'center' which caused tall PDF
       content to overflow EQUALLY above and below the body. The upper
       overflow sat invisibly over the modal header, intercepting all clicks
       on the close/download/search/newtab buttons (live hit-test confirmed
       elementsFromPoint at button position returned .ap-content).
       overflow: hidden defensively clips any remaining overflow. */
    align-items: stretch;
    min-height: 0;
    position: relative;
    overflow: hidden;
}
.ap-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    min-height: 0;
    min-width: 0;
    overflow: auto;
}
.ap-image {
    max-width: 100%;
    max-height: calc(100vh - 140px);
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    cursor: zoom-in;
    transition: transform 0.25s ease;
}
.ap-image-zoomed {
    max-width: none;
    max-height: none;
    cursor: zoom-out;
    transform: scale(1);
}
.ap-pdf {
    width: 90%;
    height: calc(100vh - 140px);
    border: none;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.ap-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px 12px;
    background: rgba(0,0,0,0.4);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
}
.ap-info {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
}
.ap-counter {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    font-weight: 600;
}

/* ==========================================================================
   PROFILE PAGE
   ========================================================================== */
.profile-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 600;
    flex-shrink: 0;
}

/* ==========================================================================
   SIGNATURE CARDS
   ========================================================================== */
.sig-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sig-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    transition: border-color 0.15s;
}

.sig-card:hover {
    border-color: var(--blue);
}

.sig-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.sig-card-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 13px;
}

.sig-card-actions {
    display: flex;
    gap: 6px;
}

.sig-badge-default {
    font-size: 10px;
    background: var(--blue-light);
    color: var(--blue-dark);
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 500;
}

.sig-preview-frame {
    width: 100%;
    border: none;
    height: 80px;
    pointer-events: none;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

/* ==========================================================================
   MAILBOX SIGNATURES ADMIN (Settings)
   ========================================================================== */
.mailbox-sig-section {
    margin-bottom: 24px;
}

.mailbox-sig-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.mailbox-sig-toolbar select {
    min-width: 200px;
}

.mailbox-sig-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.mailbox-sig-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s;
}

.mailbox-sig-card:hover {
    border-color: var(--blue);
}

.mailbox-sig-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.mailbox-sig-info strong {
    font-weight: 600;
}

.mailbox-sig-actions {
    display: flex;
    gap: 6px;
}

/* ==========================================================================
   DRAG & DROP — Tag onto Ticket Row
   ========================================================================== */
.ticket-table tr.drag-over {
    background: rgba(59, 130, 246, 0.08) !important;
    outline: 2px dashed var(--blue);
    outline-offset: -2px;
}

.sidebar-tag[draggable="true"] {
    cursor: default;
}

.sidebar-tag[draggable="true"]:active {
    cursor: default;
}

/* ==========================================================================
   SPINNING ANIMATION (Refresh button)
   ========================================================================== */
.btn-icon.spinning svg,
.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ---- Toggle Switch ---- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: #475569;
    border-radius: 24px;
    transition: background 0.25s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.25s;
}
.toggle-switch input:checked + .toggle-slider {
    background: #2563eb;
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* --- Message iframe lazy-load placeholder --- */
.message-iframe-placeholder {
    background: var(--bg-secondary, #f8fafc);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}
.message-iframe-placeholder:not([data-loaded])::before {
    content: 'Chargement...';
    color: var(--text-muted, #94a3b8);
    font-size: 12px;
}
/* ---- Undo-Send Banner ---- */
/* Gmail-style always-dark toast: text is white on a dark surface in
   BOTH themes so it stays highly visible. Using var(--bg-tertiary)
   before resolved to a pale grey in light mode, producing white-on-
   white text. The palette below is hard-coded to a neutral slate so
   it reads consistently regardless of theme. */
.undo-send-banner {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3100;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: #1f2937;
    color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
    font-size: 13.5px;
    font-weight: 500;
    min-width: 340px;
    animation: undo-slide-in .3s ease-out;
}
body.dark-theme .undo-send-banner {
    background: #111827;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
@keyframes undo-slide-in {
    from { transform: translateX(-50%) translateY(40px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}
.undo-send-banner .undo-label { flex: 1; white-space: nowrap; }
.undo-send-banner .undo-timer {
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    text-align: right;
    color: rgba(255,255,255,.7);
}
.undo-send-banner .undo-cancel-btn {
    background: none;
    border: 1px solid rgba(255,255,255,.4);
    color: #fff;
    padding: 5px 14px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.undo-send-banner .undo-cancel-btn:hover {
    background: rgba(255,255,255,.15);
    border-color: rgba(255,255,255,.7);
}
.undo-send-banner .undo-progress {
    position: absolute;
    bottom: 0; left: 0;
    height: 3px;
    background: var(--primary, #2563eb);
    border-radius: 0 0 10px 10px;
    transition: width linear;
}
/* Pending message in thread — 60% opacity + spinner */
.msg-pending-send {
    opacity: 0.6;
    position: relative;
    pointer-events: none;
}
.msg-pending-send::after {
    content: '';
    position: absolute;
    top: 12px;
    right: 12px;
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(0,0,0,.15);
    border-top-color: var(--primary, #2563eb);
    border-radius: 50%;
    animation: undo-spin .7s linear infinite;
}
@keyframes undo-spin { to { transform: rotate(360deg); } }

/* ---- Quick Actions Bar ---- */
.quick-actions-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary, #f8fafc);
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    flex-wrap: wrap;
}
.qa-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1;
}
.qa-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border: 1.5px solid;
    border-radius: 6px;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.qa-action-btn:hover {
    filter: brightness(0.85);
    background: rgba(37, 99, 235, 0.06);
}
.qa-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.qa-action-btn svg {
    flex-shrink: 0;
}
/* Accounting status section */
.qa-accounting {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
    margin-left: auto;
}
.qa-accounting-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.qa-accounting-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}
.qa-accounting-badge:hover {
    filter: brightness(0.9);
    transform: scale(1.04);
}
.qa-status-pending {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #f59e0b;
}
.qa-status-done {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}
.qa-status-none {
    background: var(--bg-secondary, #f1f5f9);
    color: var(--text-secondary, #64748b);
    border: 1px solid var(--border-color, #e2e8f0);
}
.qa-accounting-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    min-width: 130px;
    margin-top: 4px;
    overflow: hidden;
}
.qa-accounting-dropdown button {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary, #1e293b);
}
.qa-accounting-dropdown button:hover {
    background: var(--bg-secondary, #f1f5f9);
}

/* ---- Sidebar Folder Drag Reorder ---- */
#sidebar-folders li[draggable="true"] {
    cursor: default;
}
#sidebar-folders li[draggable="true"]:active {
    cursor: default;
}
#sidebar-folders li.dragging {
    opacity: 0.4;
}
#sidebar-folders li.drag-over {
    border-top: 2px solid var(--blue, #2563eb);
}

/* ---- Sidebar Mailbox Sub-views ---- */
#sidebar-mailbox-views {
    padding-top: 2px;
}
#sidebar-mailbox-views li {
    list-style: none;
}
.sidebar-mailbox-view {
    padding-left: 8px;
}
.sidebar-mailbox-view .sidebar-icon {
    opacity: 0.6;
}

/* --- Sync progress widget --- */
.sync-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 9999;
    overflow: hidden;
    font-size: 13px;
    transition: opacity 0.3s;
}
.sync-widget-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg-secondary, #f9fafb);
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    font-weight: 600;
    font-size: 12px;
    color: var(--text-primary, #1a1a1a);
}
.sync-widget-header svg {
    animation: sync-spin 1.5s linear infinite;
    flex-shrink: 0;
}
@keyframes sync-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.sync-widget-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-secondary, #6b7280);
    padding: 0 2px;
    line-height: 1;
}
.sync-widget-close:hover { color: var(--danger, #ef4444); }
.sync-widget-body {
    padding: 10px 12px;
}
.sync-widget-label {
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sync-widget-bar-bg {
    height: 6px;
    background: var(--bg-secondary, #e5e7eb);
    border-radius: 3px;
    overflow: hidden;
}
.sync-widget-bar {
    height: 100%;
    background: var(--primary, #2563eb);
    border-radius: 3px;
    transition: width 0.3s ease;
    min-width: 0;
}
.sync-widget-stats {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-secondary, #6b7280);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.sync-widget-stats span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}
.sync-widget[data-phase="done"] .sync-widget-header svg {
    animation: none;
}
.sync-widget[data-phase="error"] .sync-widget-header svg {
    animation: none;
    stroke: var(--danger, #ef4444);
}
.sync-widget[data-phase="error"] .sync-widget-bar {
    background: var(--danger, #ef4444);
}
.sync-widget[data-phase="done"] .sync-widget-bar {
    background: var(--success, #10b981);
}

/* ---- Compose Modal ---- */
.compose-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.compose-modal {
    background: var(--bg-white, #fff);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 860px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.compose-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}
.compose-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-muted, #9ca3af);
    line-height: 1;
    padding: 0 4px;
}
.compose-close:hover {
    color: var(--text-primary, #111827);
}
.compose-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}
.compose-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.compose-label {
    width: 50px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary, #6b7280);
    flex-shrink: 0;
    text-align: right;
}
.compose-input {
    flex: 1;
    font-size: 13px;
}
.compose-cc-toggles {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    padding-left: 58px;
}
.btn-text {
    background: none;
    border: none;
    color: var(--blue, #3b82f6);
    font-size: 12px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.btn-text:hover {
    background: var(--blue-light, #eff6ff);
}
.compose-editor-field {
    flex-direction: column;
    align-items: stretch;
}
.compose-toolbar {
    display: flex;
    gap: 2px;
    padding: 4px 6px;
    border: 1px solid var(--border, #e5e7eb);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: var(--bg-subtle, #f9fafb);
}
.toolbar-btn {
    background: none;
    border: none;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-secondary, #6b7280);
}
.toolbar-btn:hover {
    background: var(--bg-hover, #f3f4f6);
    color: var(--text-primary, #111827);
}
.toolbar-sep {
    width: 1px;
    background: var(--border, #e5e7eb);
    margin: 2px 4px;
}
.compose-editor {
    min-height: 200px;
    max-height: 350px;
    overflow-y: auto;
    overflow-x: auto;  /* Phase 06 bug fix: wide grid-editor tables scroll
                          horizontally inside the editor instead of overflowing
                          past the composer edge. */
    padding: 12px;
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 0 0 8px 8px;
    font-size: 13px;
    line-height: 1.6;
    outline: none;
}
.compose-editor:focus {
    border-color: var(--blue, #3b82f6);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.compose-footer {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border, #e5e7eb);
    justify-content: flex-start;
}
.compose-footer .btn {
    font-size: 13px;
}

/* Compose button in inbox header */
.btn-compose {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 8px;
    white-space: nowrap;
}
.btn-compose svg {
    flex-shrink: 0;
}

/* ---- Teams ---- */
.teams-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
@media (max-width: 1200px) { .teams-list { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px)  { .teams-list { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px)  { .teams-list { grid-template-columns: 1fr; } }
.team-card {
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 14px;
    transition: box-shadow .15s, border-color .15s;
}
.team-card:hover {
    border-color: var(--blue, #3b82f6);
    box-shadow: 0 2px 8px rgba(59,130,246,0.10);
}
.team-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.team-card-name { font-weight: 600; font-size: 15px; }
.team-card-desc { display: block; font-size: 13px; color: var(--text-secondary, #6b7280); margin-bottom: 4px; }
.team-card-stats { display: block; font-size: 12px; color: var(--text-secondary, #6b7280); }
.team-card-actions { display: flex; gap: 6px; }
.team-card-members { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.team-member-badge {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--primary, #2563eb); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600;
}
.team-member-row {
    display: flex; align-items: center; gap: 8px; padding: 6px 0;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.team-member-row:last-child { border-bottom: none; }
.team-member-name { flex: 1; font-size: 14px; }
.team-members-modal-list { max-height: 200px; overflow-y: auto; }
.team-add-member { display: flex; gap: 8px; align-items: center; }
.team-add-member select { flex: 1; }

/* Sidebar team groups */
.sidebar-team-group-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 12px; margin: 2px 0; cursor: default;
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    color: var(--text-secondary, #6b7280); letter-spacing: 0.3px;
}
.sidebar-team-group-header.drag-over { background: rgba(37,99,235,0.08); }
.sidebar-team-group-name { flex: 1; font-size: 13px; font-weight: 600; }

/* Badge for "recipient" teams (teams this user's team has delegated work to) */
.sidebar-team-recipient-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 3px;
    background: rgba(249, 115, 22, 0.12);
    color: #d97706;
    margin-left: 4px;
    flex-shrink: 0;
}
body.dark-theme .sidebar-team-recipient-badge {
    background: rgba(249, 115, 22, 0.2);
    color: #fbbf24;
}

.empty-state-small { text-align: center; padding: 24px; color: var(--text-secondary, #6b7280); }

/* ---- Collapsible sidebar sections ---- */
.sidebar-collapse-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sidebar-chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}
.sidebar-collapsible.collapsed .sidebar-chevron {
    transform: rotate(-90deg);
}
.sidebar-collapse-body {
    transition: none;
}
.sidebar-collapsible.collapsed .sidebar-collapse-body {
    display: none;
}

/* ---- Team sub-views in sidebar ---- */
.sidebar-team-block {
    margin-bottom: 4px;
}
.sidebar-team-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 12px 5px 16px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--sidebar-text);
    border-left: 3px solid var(--team-color, #6b7280);
    transition: background 0.15s;
}
.sidebar-team-block-header:hover {
    background: var(--sidebar-hover, rgba(0,0,0,0.04));
}
.sidebar-team-block-header .team-chevron {
    width: 10px;
    height: 10px;
    transition: transform 0.2s ease;
    color: var(--text-secondary, #6b7280);
    flex-shrink: 0;
}
.sidebar-team-block-header .team-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    margin-left: 6px;
    margin-right: 4px;
}
.sidebar-team-block.collapsed .team-chevron {
    transform: rotate(-90deg);
}
.sidebar-team-block.collapsed .sidebar-team-block-body {
    display: none;
}
.sidebar-team-block-body .sidebar-link {
    padding: 4px 16px 4px 28px;
    font-size: 12.5px;
    gap: 8px;
}
.sidebar-team-block-body .sidebar-link .sidebar-badge {
    font-size: 11px;
    min-width: 18px;
}
.sidebar-team-block-header .sidebar-badge {
    font-size: 11px;
    min-width: 18px;
}
.sidebar-team-block-header.drag-over {
    background: rgba(37,99,235,0.08);
}

/* Personal mailbox sidebar block */
.sidebar-personal-block {
    margin-bottom: 4px;
}
.sidebar-personal-header {
    gap: 6px;
}
.sidebar-personal-header .sidebar-personal-icon {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    color: #2563eb;
}
.sidebar-personal-block .sidebar-collapse-body .sidebar-link {
    padding: 4px 16px 4px 28px;
    font-size: 12.5px;
    gap: 8px;
}
.sidebar-personal-block .sidebar-collapse-body .sidebar-badge {
    font-size: 11px;
    min-width: 18px;
}

/* Sortable views container */
.sidebar-views-sortable .sidebar-link {
    cursor: default;
}
.sidebar-views-sortable .sidebar-link.dragging {
    opacity: 0.4;
}
.sidebar-views-sortable .sidebar-link[draggable="true"]:active {
    cursor: default;
}

/* Global VUES drag-reorder */
#sidebar-global-views li[draggable="true"] {
    cursor: default;
    transition: opacity 0.15s;
}
#sidebar-global-views li.dragging {
    opacity: 0.4;
}
#sidebar-global-views li[draggable="true"]:active {
    cursor: default;
}

/* Team member items inside team block */
.sidebar-team-members-sep {
    font-size: 10px;
    color: var(--text-secondary, #6b7280);
    padding: 4px 28px 2px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Collapsible members toggle */
.sidebar-team-members-toggle {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: 4px;
    transition: background 0.15s;
}
.sidebar-team-members-toggle:hover {
    background: var(--sidebar-hover, rgba(0,0,0,0.04));
}
.sidebar-team-members-toggle .members-chevron {
    width: 9px;
    height: 9px;
    transition: transform 0.2s ease;
}
.sidebar-team-members-toggle.collapsed .members-chevron {
    transform: rotate(-90deg);
}
.sidebar-team-members-body {
    transition: all 0.15s ease;
}

/* Green online indicator on team member avatar */
.team-avatar-online {
    position: relative;
    box-shadow: 0 0 0 2px #22c55e;
}
.team-avatar-online::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 7px;
    height: 7px;
    background: #22c55e;
    border-radius: 50%;
    border: 1.5px solid var(--sidebar-bg, #fff);
}

/* ---- Hierarchy groups ---- */
.sidebar-hierarchy-group {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}
.sidebar-hierarchy-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary, #6b7280);
    padding: 4px 16px 2px;
    font-weight: 600;
}
.sidebar-hierarchy-user {
    padding: 3px 16px 3px 24px;
    font-size: 12px;
    color: var(--sidebar-text);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}
.sidebar-hierarchy-user:hover {
    background: var(--sidebar-hover, rgba(0,0,0,0.04));
}
.sidebar-hierarchy-user .hierarchy-chevron {
    width: 10px;
    height: 10px;
    transition: transform 0.2s ease;
    color: var(--text-secondary, #6b7280);
    flex-shrink: 0;
}
.sidebar-hierarchy-user.collapsed .hierarchy-chevron {
    transform: rotate(-90deg);
}
.sidebar-hierarchy-user-body {
    padding-left: 8px;
}
.sidebar-hierarchy-user.collapsed + .sidebar-hierarchy-user-body {
    display: none;
}

/* Assigned to me in team section */
.sidebar-assigned-me-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13px;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    font-weight: 500;
}
.sidebar-assigned-me-link:hover {
    background: var(--sidebar-hover, rgba(0,0,0,0.04));
}
.sidebar-assigned-me-link.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--blue);
    border-left-color: var(--blue);
}

/* ---- Notification Bell ---- */
.notif-bell-wrapper {
    position: relative;
    display: inline-flex;
    z-index: 1100;
}
.notif-badge {
    position: absolute;
    top: 2px; right: 2px;
    min-width: 16px; height: 16px;
    background: #ef4444;
    color: #fff;
    font-size: 10px; font-weight: 700;
    border-radius: 999px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
    pointer-events: none;
    line-height: 1;
}
.notif-dropdown {
    position: absolute;
    top: 100%; right: 0;
    width: 360px;
    max-height: 440px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    z-index: 9999;
    overflow: hidden;
}
.notif-dropdown-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border, #e5e7eb);
    font-weight: 600; font-size: 14px;
}
.notif-mark-all {
    font-size: 12px; font-weight: 500;
    color: var(--primary, #2563eb);
    text-decoration: none;
}
.notif-mark-all:hover { text-decoration: underline; }
.notif-list {
    max-height: 380px;
    overflow-y: auto;
}
.notif-item {
    display: flex; gap: 10px;
    padding: 10px 16px;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border-light, #f3f4f6);
    transition: background .15s;
}
.notif-item:hover { background: var(--hover-bg, #f9fafb); }
.notif-unread { background: #eff6ff; }
.notif-unread:hover { background: #dbeafe; }
.notif-icon {
    flex-shrink: 0;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-muted, #f3f4f6);
    border-radius: 50%;
    font-size: 14px;
    color: var(--text-secondary, #6b7280);
}
.notif-icon.notif-icon-avatar {
    background: var(--blue, #3b82f6);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
/* Send-failure notification: red warning icon so it stands out in the bell. */
.notif-send-failed .notif-icon {
    background: var(--danger, #ef4444);
    color: #fff;
}
.notif-content { flex: 1; min-width: 0; }
.notif-title {
    font-size: 13px; font-weight: 500;
    color: var(--text-primary, #111827);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-message {
    font-size: 12px; color: var(--text-secondary, #6b7280);
    margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-time {
    font-size: 11px; color: var(--text-tertiary, #9ca3af);
    margin-top: 2px;
}
.notif-empty {
    text-align: center; padding: 24px;
    color: var(--text-secondary, #6b7280);
    font-size: 13px;
}

/* Notification dropdown — small screens: escape overflow clipping */
@media (max-width: 900px) {
    .notif-dropdown {
        position: fixed;
        top: 48px;
        right: 8px;
        left: auto;
        width: min(360px, calc(100vw - 76px));
    }
}

/* Badge blue for "Assignés à moi" */
.badge-blue {
    background: #2563eb !important;
    color: #fff !important;
}

/* ---- @Mention Tags ---- */
.mention-tag {
    display: inline;
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 600;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 13px;
    white-space: nowrap;
    cursor: default;
    user-select: all;
}
.mention-dropdown {
    position: fixed;
    min-width: 200px;
    max-width: 300px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    z-index: 2000;
    overflow: hidden;
}
.mention-option {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-primary, #111827);
    transition: background .1s;
}
.mention-option:hover,
.mention-option.active {
    background: #eff6ff;
    color: #1d4ed8;
}

/* ---- Drag & drop attachments ---- */
.reply-editor.drag-over {
    outline: 2px dashed var(--blue, #2563eb) !important;
    outline-offset: -2px;
    background: rgba(37, 99, 235, 0.04) !important;
}
.pending-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
}
.pending-attachment-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    font-size: 12px;
}
.pending-att-name {
    color: var(--text-primary, #111827);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pending-att-size {
    color: var(--text-muted, #9ca3af);
    font-size: 11px;
}
.pending-att-remove {
    background: none;
    border: none;
    color: var(--text-muted, #9ca3af);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}
.pending-att-remove:hover {
    color: var(--danger, #ef4444);
}

/* ==========================================================================
   MULTI-SELECT DROPDOWN (mailbox access)
   ========================================================================== */
.multiselect-wrapper {
    position: relative;
    min-width: 140px;
}
.multiselect-display {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-items: center;
    padding: 3px 6px;
    border: 1px solid var(--border, #d1d5db);
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
    min-height: 28px;
    font-size: 11px;
    background: white;
}
.multiselect-display:hover {
    border-color: var(--blue, #3b82f6);
}
.multiselect-tag {
    background: var(--blue-50, #eff6ff);
    color: var(--blue-700, #1d4ed8);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}
.multiselect-tag .tag-remove {
    cursor: pointer;
    font-weight: bold;
    font-size: 12px;
    line-height: 1;
    opacity: 0.6;
}
.multiselect-tag .tag-remove:hover {
    opacity: 1;
}
.multiselect-chevron {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted, #9ca3af);
    flex-shrink: 0;
}
.multiselect-placeholder {
    color: var(--text-muted, #9ca3af);
    font-size: 11px;
}
.multiselect-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 50;
    background: white;
    border: 1px solid var(--border, #d1d5db);
    border-radius: var(--radius-sm, 4px);
    box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0,0,0,0.1));
    max-height: 200px;
    overflow-y: auto;
    display: none;
    margin-top: 2px;
}
.multiselect-dropdown.open {
    display: block;
}
.multiselect-dropdown label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    margin: 0;
}
.multiselect-dropdown label:hover {
    background: var(--hover-bg, #f5f5f5);
}

/* ==========================================================================
   HIERARCHY TREE (org chart)
   ========================================================================== */
.hierarchy-tree-container {
    overflow: auto;
    padding: 20px 16px;
    background: var(--bg-secondary, #fafafa);
    border-radius: var(--radius-md, 6px);
    border: 1px solid var(--border, #d1d5db);
    margin-bottom: 20px;
    min-height: 80px;
    max-height: 75vh;
    position: relative;
}
/* When the organigramme panel is active, allow it to use full width */
#hierarchy-tree-section {
    max-width: none;
}
/* Zoom wrapper inside the container */
.hierarchy-zoom-wrapper {
    transform-origin: top center;
    transition: transform 0.2s ease;
    display: inline-block;
    min-width: 100%;
}
/* Zoom controls floating over the organigramme */
.hierarchy-zoom-controls {
    position: sticky;
    top: 0;
    right: 0;
    z-index: 20;
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    margin-bottom: 8px;
    pointer-events: none;
}
.hierarchy-zoom-controls button {
    pointer-events: auto;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border, #d1d5db);
    border-radius: var(--radius-sm, 4px);
    background: white;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #111827);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: background 0.15s, border-color 0.15s;
}
.hierarchy-zoom-controls button:hover {
    background: var(--hover-bg, #f5f5f5);
    border-color: var(--blue, #3b82f6);
}
.hierarchy-zoom-controls .zoom-level-label {
    pointer-events: auto;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    display: flex;
    align-items: center;
    padding: 0 6px;
    background: white;
    border: 1px solid var(--border, #d1d5db);
    border-radius: var(--radius-sm, 4px);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    min-width: 42px;
    justify-content: center;
}
.hierarchy-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: fit-content;
}
.hierarchy-node {
    background: white;
    border: 2px solid var(--border, #d1d5db);
    border-radius: var(--radius-md, 6px);
    padding: 10px 16px;
    min-width: 130px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    position: relative;
}
.hierarchy-node:hover {
    border-color: var(--blue, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}
.hierarchy-node.selected {
    border-color: var(--blue, #3b82f6);
    background: var(--blue-50, #eff6ff);
}
.hierarchy-node .node-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: white;
    margin: 0 auto 4px;
}
.hierarchy-node .node-avatar.admin {
    background: #f59e0b;
}
.hierarchy-node .node-avatar.gestionnaire {
    background: #3b82f6;
}
.hierarchy-node .node-avatar.user {
    background: #6b7280;
}
.hierarchy-node .node-name {
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 2px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.hierarchy-node .node-role-badge {
    font-size: 9px;
    padding: 1px 6px;
    border-radius: 3px;
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 600;
}
.hierarchy-node .node-role-badge.admin {
    background: #fef3c7;
    color: #92400e;
}
.hierarchy-node .node-role-badge.gestionnaire {
    background: #dbeafe;
    color: #1e40af;
}
.hierarchy-node .node-role-badge.user {
    background: #f3f4f6;
    color: #374151;
}
.hierarchy-node .node-role-badge.manager {
    background: #d1fae5;
    color: #065f46;
}
.hierarchy-node .node-children-count {
    font-size: 9px;
    color: var(--text-muted, #9ca3af);
    margin-top: 2px;
}
.hierarchy-node .node-teams {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    justify-content: center;
    margin-top: 3px;
}
.hierarchy-node .node-team-badge {
    font-size: 8px;
    padding: 0px 5px;
    border-radius: 3px;
    border: 1px solid;
    background: white;
    font-weight: 500;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tree lines: branch container */
.hierarchy-children {
    display: flex;
    gap: 16px;
    justify-content: center;
    position: relative;
    padding-top: 28px;
}
/* Vertical line from parent down */
.hierarchy-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 14px;
    background: var(--border-color, #d1d5db);
}
.hierarchy-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}
/* Vertical line from horizontal bar to child */
.hierarchy-branch::before {
    content: '';
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 14px;
    background: var(--border-color, #d1d5db);
}
/* Horizontal bar connecting siblings */
.hierarchy-children.multi > .hierarchy-branch::after {
    content: '';
    position: absolute;
    top: -14px;
    height: 2px;
    background: var(--border-color, #d1d5db);
}
.hierarchy-children.multi > .hierarchy-branch:first-child::after {
    left: 50%;
    right: -8px;
}
.hierarchy-children.multi > .hierarchy-branch:last-child::after {
    left: -8px;
    right: 50%;
}
.hierarchy-children.multi > .hierarchy-branch:not(:first-child):not(:last-child)::after {
    left: -8px;
    right: -8px;
}

/* Context menu for hierarchy nodes */
.node-context-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border: 1px solid var(--border, #d1d5db);
    border-radius: var(--radius-sm, 4px);
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,0.1));
    z-index: 60;
    min-width: 180px;
    overflow: hidden;
}
.node-context-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-primary, #111827);
}
.node-context-menu button:hover {
    background: var(--hover-bg, #f5f5f5);
}
.node-context-menu button.danger {
    color: var(--danger, #ef4444);
}
.node-context-menu button.danger:hover {
    background: #fef2f2;
}

/* Change-referent modal within hierarchy */
.hierarchy-referent-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
}
.hierarchy-referent-modal .modal {
    max-width: 360px;
}

/* ═══════════════════════════════════════════════════════════════════
   ENTITIES LIST PAGE
   ═══════════════════════════════════════════════════════════════════ */

.entities-page {
    padding: 24px 32px;
    max-width: 1200px;
}

.entities-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.entities-header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.entities-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.entities-count {
    font-size: 13px;
    color: var(--text-muted);
}

.entities-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.entities-search-wrap {
    position: relative;
}

.entities-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.entities-search {
    padding-left: 34px !important;
    width: 260px;
}

/* Entity card (list item) */
.entity-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.entity-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.entity-card-avatar {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

.entity-card-info {
    flex: 1;
    min-width: 0;
}

.entity-card-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entity-card-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.entity-card-meta span::before {
    content: "";
}

.entity-card-domain {
    color: var(--primary);
    font-weight: 500;
}

.entity-card-stats {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.entity-stat strong {
    color: var(--text-primary);
}

.entities-empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.entities-empty p {
    margin: 4px 0;
}

/* ═══════════════════════════════════════════════════════════════════
   ENTITY DETAIL PAGE
   ═══════════════════════════════════════════════════════════════════ */

.entity-page {
    padding: 24px 32px;
    max-width: 1200px;
}

.entity-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.entity-avatar {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 22px;
    flex-shrink: 0;
}

.entity-info {
    flex: 1;
}

.entity-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px 0;
}

.entity-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.entity-meta span::before {
    content: "";
}

.entity-domain {
    color: var(--primary);
    font-weight: 500;
}

.entity-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Entity KPIs */
.entity-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* Entity panels (contacts + notes) */
.entity-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.entity-panel {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
}

.entity-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.entity-panel-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.entity-panel-count {
    background: var(--bg-gray);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Contacts list inside entity */
.entity-contact-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light, #f0f0f0);
}

.entity-contact-row:last-child {
    border-bottom: none;
}

.entity-contact-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-gray);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.entity-contact-info {
    flex: 1;
    min-width: 0;
}

.entity-contact-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}

.entity-contact-detail {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    flex-wrap: wrap;
}

.entity-contact-detail span::before {
    content: "";
}

.entity-contact-email {
    color: var(--primary);
}

.entity-contact-title {
    font-style: italic;
}

.entity-contact-last-seen {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.entity-contact-remove {
    flex-shrink: 0;
    color: var(--danger, #ef4444);
    border-color: var(--danger, #ef4444);
}

.entity-contact-remove:hover {
    background: #fef2f2;
}

/* Notes panel */
.entity-notes-input {
    width: 100%;
    min-height: 100px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    background: var(--bg-white);
    color: var(--text-primary);
}

.entity-notes-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* Ticket history section */
.entity-tickets-section {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
}

.entity-ticket-ref {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    margin-right: 4px;
}

.entity-empty-msg {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    padding: 20px 0;
}

@media (max-width: 768px) {
    .entities-page,
    .entity-page {
        padding: 16px;
    }
    .entities-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .entity-panels {
        grid-template-columns: 1fr;
    }
    .entity-kpis {
        grid-template-columns: 1fr 1fr;
    }
}

/* --- Activity Log --- */
.activity-list { display:flex; flex-direction:column; gap:0; }
.activity-item { display:flex; gap:8px; padding:6px 0; border-bottom:1px solid var(--border); font-size:12px; }
.activity-item:last-child { border-bottom:none; }
.activity-icon { flex-shrink:0; width:20px; height:20px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:10px; }
.activity-content { flex:1; }
.activity-actor { font-weight:600; color:var(--text-primary); }
.activity-time { color:var(--text-muted); font-size:11px; }
.activity-icon.act-created { background:#dcfce7; color:#16a34a; }
.activity-icon.act-status { background:#dbeafe; color:#2563eb; }
.activity-icon.act-assign { background:#fef3c7; color:#d97706; }
.activity-icon.act-tag { background:#f3e8ff; color:#9333ea; }
.activity-icon.act-reply { background:#e0e7ff; color:#4f46e5; }
.activity-icon.act-note { background:#fce7f3; color:#db2777; }
.activity-icon.act-merge { background:#fff7ed; color:#ea580c; }

/* ==========================================================================
   DARK THEME
   ========================================================================== */
body.dark-theme {
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #3b82f6;
    --sidebar-text: #94a3b8;
    --sidebar-text-bright: #e2e8f0;
    --bg-primary: #0f172a;
    --bg-white: #1e293b;
    --bg-hover: #334155;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --blue: #60a5fa;
    --blue-light: #1e3a5f;
    --blue-dark: #93c5fd;
    --green: #4ade80;
    --green-light: #14532d;
    --amber: #fbbf24;
    --amber-light: #451a03;
    --red: #f87171;
    --red-light: #450a0a;
    --purple: #c084fc;
    --purple-light: #3b0764;
    --gray: #9ca3af;
    --gray-light: #374151;
    --bg-gray: #1e293b;
    --primary: #60a5fa;
    --border: #334155;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5), 0 4px 6px rgba(0,0,0,0.3);
    --bg-secondary: #1e293b;
    --border-color: #334155;
    --input-bg: #0f172a;
    --input-border: #475569;
    --card-bg: #1e293b;
    color-scheme: dark;
}
/* Dark: cards, forms, tables, modals */
body.dark-theme .team-card { background: var(--bg-secondary); border-color: var(--border); color: var(--text-primary); }
body.dark-theme .team-card-name { color: var(--text-primary); }
body.dark-theme input, body.dark-theme select, body.dark-theme textarea { background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border); }
body.dark-theme .form-input, body.dark-theme .form-select, body.dark-theme .form-textarea { background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border); }
body.dark-theme .btn-outline { color: var(--text-primary); border-color: var(--border); }
body.dark-theme .btn-outline:hover { background: var(--bg-hover); }
body.dark-theme .context-card { background: var(--bg-secondary); border-color: var(--border); }
body.dark-theme .context-section { color: var(--text-primary); }
body.dark-theme .settings-panel { color: var(--text-primary); }
body.dark-theme .panel-section { color: var(--text-primary); }
body.dark-theme .hierarchy-tree-container { background: var(--bg-secondary); }
body.dark-theme .hierarchy-node { background: var(--bg-secondary); border-color: var(--border); color: var(--text-primary); }
body.dark-theme .hierarchy-node-name { color: var(--text-primary); }
body.dark-theme .hierarchy-node-role { color: var(--text-secondary); }
body.dark-theme table th { color: var(--text-secondary); border-color: var(--border); }
body.dark-theme table td { color: var(--text-primary); border-color: var(--border); }
body.dark-theme .dropdown-menu { background: var(--bg-secondary); border-color: var(--border); }
body.dark-theme .dropdown-item { color: var(--text-primary); }
body.dark-theme .dropdown-item:hover { background: var(--bg-hover); }
body.dark-theme .modal-content { background: var(--bg-primary); color: var(--text-primary); border-color: var(--border); }
body.dark-theme .tag { opacity: 0.9; }
body.dark-theme a { color: var(--blue); }
body.dark-theme .settings-tab { color: var(--text-secondary); }
body.dark-theme .settings-tab:hover, body.dark-theme .settings-tab.active { color: var(--text-primary); }
body.dark-theme .empty-state { color: var(--text-secondary); }
body.dark-theme .topbar { background: var(--bg-secondary); border-color: var(--border); }
body.dark-theme .breadcrumb { color: var(--text-secondary); }
body.dark-theme .ticket-table thead { background: var(--bg-primary); }
body.dark-theme .ticket-table tbody tr:hover { background: var(--bg-hover); }
body.dark-theme .ticket-table tbody tr { border-bottom-color: var(--border); }
/* Dark: email body + ticket content */
body.dark-theme .email-body, body.dark-theme .message-body { background: var(--bg-secondary) !important; color: var(--text-primary) !important; }
body.dark-theme .email-body *, body.dark-theme .message-body * { color: inherit !important; }
body.dark-theme .email-body a, body.dark-theme .message-body a { color: var(--blue) !important; }
body.dark-theme .message-card { background: var(--bg-secondary); border-color: var(--border); }
body.dark-theme .message-card .message-header { color: var(--text-secondary); }
body.dark-theme .reply-editor, body.dark-theme .reply-box { background: var(--bg-secondary); color: var(--text-primary); border-color: var(--border); }
body.dark-theme .reply-editor [contenteditable] { color: var(--text-primary); }
/* REMOVED: was double-inverting dark-mode srcdoc content */
body.dark-theme .note-card { background: rgba(245, 158, 11, 0.06) !important; border-color: rgba(245, 158, 11, 0.15) !important; }
body.dark-theme .note-card * { color: var(--text-primary) !important; }
body.dark-theme .forward-card { background: rgba(96, 165, 250, 0.06) !important; border-color: rgba(96, 165, 250, 0.15) !important; }
body.dark-theme .forward-card * { color: var(--text-primary) !important; }
/* Dark: hardcoded color overrides */
body.dark-theme .sidebar-footer { border-top-color: rgba(255,255,255,0.06); }
body.dark-theme .modal-overlay { background: rgba(0,0,0,0.7); }
body.dark-theme .search-suggestion-status.open { background: var(--green-light); color: #4ade80; }
body.dark-theme .search-suggestion-status.snoozed { background: var(--amber-light); color: #fbbf24; }
body.dark-theme .search-suggestion-highlight { background: rgba(245, 158, 11, 0.3); color: #fef08a; }
body.dark-theme .sla-ok .sla-count { color: #4ade80; }
body.dark-theme .sla-warning .sla-count { color: #fbbf24; }
body.dark-theme .sla-critical .sla-count { color: #f87171; }
body.dark-theme .sla-ok .sla-label { color: #4ade80; }
body.dark-theme .sla-warning .sla-label { color: #fbbf24; }
body.dark-theme .sla-critical .sla-label { color: #f87171; }
body.dark-theme .activity-icon.act-created { background: #14532d; color: #4ade80; }
body.dark-theme .activity-icon.act-status { background: var(--primary-light); color: var(--primary); }
body.dark-theme .activity-icon.act-assign { background: #451a03; color: #fbbf24; }
body.dark-theme .activity-icon.act-tag { background: #3b0764; color: #c084fc; }
body.dark-theme .activity-icon.act-reply { background: #1e1b4b; color: #818cf8; }
body.dark-theme .activity-icon.act-note { background: #500724; color: #f472b6; }
body.dark-theme .activity-icon.act-merge { background: #431407; color: #fb923c; }
/* Dark: form elements */
/* Removed: duplicate hardcoded input styles */
body.dark-theme input:focus,
body.dark-theme select:focus,
body.dark-theme textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(96,165,250,0.15); }
body.dark-theme input::placeholder,
body.dark-theme textarea::placeholder { color: var(--text-muted); }
body.dark-theme .btn-secondary,
body.dark-theme .btn-ghost { background: var(--bg-secondary); color: var(--text-primary); border-color: var(--border); }
body.dark-theme .btn-secondary:hover,
body.dark-theme .btn-ghost:hover { background: var(--bg-hover); }
body.dark-theme .compose-modal { background: var(--bg-secondary); }
body.dark-theme .compose-input { background: var(--input-bg); color: var(--text-primary); border-color: var(--input-border); }
body.dark-theme .compose-editor { background: var(--input-bg); color: var(--text-primary); }
body.dark-theme .compose-toolbar { background: var(--bg-secondary); border-color: var(--border); }
body.dark-theme .tag { background: var(--bg-hover); color: var(--text-primary); }
body.dark-theme ::-webkit-scrollbar { width: 6px; height: 6px; }
body.dark-theme ::-webkit-scrollbar-track { background: var(--bg-primary); }
body.dark-theme ::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
body.dark-theme ::-webkit-scrollbar-thumb:hover { background: var(--input-border); }
/* REMOVED: duplicate of above, also caused double-inversion */
body.dark-theme .ticket-row:hover,
body.dark-theme .ticket-row.active { background: var(--bg-hover) !important; }
body.dark-theme .dropdown-menu,
body.dark-theme .context-menu { background: var(--bg-secondary); border-color: var(--border); }
body.dark-theme .dropdown-item:hover,
body.dark-theme .context-menu-item:hover { background: var(--bg-hover); }
/* Theme toggle switch */
.theme-toggle-wrapper {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 16px; margin: 4px 0;
    font-size: 12px; color: var(--sidebar-text);
}
.theme-toggle-wrapper:hover { color: var(--sidebar-text-bright); }
.theme-toggle-label {
    display: flex; align-items: center; gap: 6px;
    cursor: pointer; user-select: none; flex: 1;
}
.theme-toggle-icon { width: 16px; height: 16px; flex-shrink: 0; }
.theme-switch { position: relative; width: 32px; height: 18px; flex-shrink: 0; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.theme-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: #475569; border-radius: 9px;
    transition: background var(--transition);
}
.theme-slider::before {
    content: ''; position: absolute;
    height: 14px; width: 14px; left: 2px; bottom: 2px;
    background: white; border-radius: 50%;
    transition: transform var(--transition);
}
.theme-switch input:checked + .theme-slider { background: var(--blue); }
.theme-switch input:checked + .theme-slider::before { transform: translateX(14px); }
/* ===== COLOR THEMES ===== */
/* Each theme overrides --primary and --sidebar-* via data-theme attribute */

/* Theme: Violet */
[data-theme="violet"] { --primary: #8b5cf6; --primary-hover: #7c3aed; --primary-light: #ede9fe; --sidebar-bg: #1e1b2e; --sidebar-hover: #2d2640; --sidebar-active: #8b5cf6; --sidebar-text: #a095b8; --sidebar-text-bright: #e8e0f0; --blue: #8b5cf6; --blue-light: #ede9fe; }
body.dark-theme[data-theme="violet"] { --primary: #a78bfa; --primary-hover: #c4b5fd; --primary-light: #2e1065; --bg-primary: #0f0d1a; --bg-secondary: #1e1b2e; --bg-white: #1e1b2e; --bg-hover: #2d2640; --sidebar-bg: #0f0d1a; --sidebar-hover: #1e1b2e; --sidebar-active: #a78bfa; --border: #3d3555; --border-color: #3d3555; --input-bg: #0f0d1a; --input-border: #4a3f66; --card-bg: #1e1b2e; --blue: #a78bfa; --blue-light: #2e1065; --sidebar-text: #a095b8; --sidebar-text-bright: #e8e0f0;}

/* Theme: Cyan */
[data-theme="cyan"] { --primary: #06b6d4; --primary-hover: #0891b2; --primary-light: #cffafe; --sidebar-bg: #0f2027; --sidebar-hover: #1a3a40; --sidebar-active: #06b6d4; --sidebar-text: #7fbbc8; --sidebar-text-bright: #d4f0f5; --blue: #06b6d4; --blue-light: #cffafe; }
body.dark-theme[data-theme="cyan"] { --primary: #22d3ee; --primary-hover: #67e8f9; --primary-light: #0c3644; --bg-primary: #071318; --bg-secondary: #0f2027; --bg-white: #0f2027; --bg-hover: #1a3a40; --sidebar-bg: #071318; --sidebar-hover: #0f2027; --sidebar-active: #22d3ee; --border: #1e4a52; --border-color: #1e4a52; --input-bg: #071318; --input-border: #2a5a64; --card-bg: #0f2027; --blue: #22d3ee; --blue-light: #0c3644; --sidebar-text: #7fbbc8; --sidebar-text-bright: #d4f0f5;}

/* Theme: Rose */
[data-theme="rose"] { --primary: #f43f5e; --primary-hover: #e11d48; --primary-light: #ffe4e6; --sidebar-bg: #2a1520; --sidebar-hover: #3d1f30; --sidebar-active: #f43f5e; --sidebar-text: #c09aaa; --sidebar-text-bright: #f0dce4; --blue: #f43f5e; --blue-light: #ffe4e6; }
body.dark-theme[data-theme="rose"] { --primary: #fb7185; --primary-hover: #fda4af; --primary-light: #4c0519; --bg-primary: #1a0b14; --bg-secondary: #2a1520; --bg-white: #2a1520; --bg-hover: #3d1f30; --sidebar-bg: #1a0b14; --sidebar-hover: #2a1520; --sidebar-active: #fb7185; --border: #4a2535; --border-color: #4a2535; --input-bg: #1a0b14; --input-border: #5a3045; --card-bg: #2a1520; --blue: #fb7185; --blue-light: #4c0519; --sidebar-text: #c09aaa; --sidebar-text-bright: #f0dce4;}

/* Theme: Emerald */
[data-theme="emerald"] { --primary: #10b981; --primary-hover: #059669; --primary-light: #d1fae5; --sidebar-bg: #0f2318; --sidebar-hover: #1a3d2a; --sidebar-active: #10b981; --sidebar-text: #7fb8a0; --sidebar-text-bright: #d4f0e0; --blue: #10b981; --blue-light: #d1fae5; }
body.dark-theme[data-theme="emerald"] { --primary: #34d399; --primary-hover: #6ee7b7; --primary-light: #064e3b; --bg-primary: #071510; --bg-secondary: #0f2318; --bg-white: #0f2318; --bg-hover: #1a3d2a; --sidebar-bg: #071510; --sidebar-hover: #0f2318; --sidebar-active: #34d399; --border: #1e4a30; --border-color: #1e4a30; --input-bg: #071510; --input-border: #2a5a3a; --card-bg: #0f2318; --blue: #34d399; --blue-light: #064e3b; --sidebar-text: #7fb8a0; --sidebar-text-bright: #d4f0e0;}

/* Theme: Amber */
[data-theme="amber"] { --primary: #f59e0b; --primary-hover: #d97706; --primary-light: #fef3c7; --sidebar-bg: #271a05; --sidebar-hover: #3d2a0e; --sidebar-active: #f59e0b; --sidebar-text: #c8a87a; --sidebar-text-bright: #f5e6cc; --blue: #f59e0b; --blue-light: #fef3c7; }
body.dark-theme[data-theme="amber"] { --primary: #fbbf24; --primary-hover: #fcd34d; --primary-light: #451a03; --bg-primary: #1a1005; --bg-secondary: #271a05; --bg-white: #271a05; --bg-hover: #3d2a0e; --sidebar-bg: #1a1005; --sidebar-hover: #271a05; --sidebar-active: #fbbf24; --border: #4a3510; --border-color: #4a3510; --input-bg: #1a1005; --input-border: #5a4520; --card-bg: #271a05; --blue: #fbbf24; --blue-light: #451a03; --sidebar-text: #c8a87a; --sidebar-text-bright: #f5e6cc;}

/* Theme: Crimson */
[data-theme="crimson"] { --primary: #ef4444; --primary-hover: #dc2626; --primary-light: #fee2e2; --sidebar-bg: #2a1215; --sidebar-hover: #3d1c20; --sidebar-active: #ef4444; --sidebar-text: #c09096; --sidebar-text-bright: #f0d8dc; --blue: #ef4444; --blue-light: #fee2e2; }
body.dark-theme[data-theme="crimson"] { --primary: #f87171; --primary-hover: #fca5a5; --primary-light: #450a0a; --bg-primary: #1a0a0c; --bg-secondary: #2a1215; --bg-white: #2a1215; --bg-hover: #3d1c20; --sidebar-bg: #1a0a0c; --sidebar-hover: #2a1215; --sidebar-active: #f87171; --border: #4a2025; --border-color: #4a2025; --input-bg: #1a0a0c; --input-border: #5a2530; --card-bg: #2a1215; --blue: #f87171; --blue-light: #450a0a; --sidebar-text: #c09096; --sidebar-text-bright: #f0d8dc;}

/* Theme: Indigo */
[data-theme="indigo"] { --primary: #6366f1; --primary-hover: #4f46e5; --primary-light: #e0e7ff; --sidebar-bg: #1a1a2e; --sidebar-hover: #2a2a45; --sidebar-active: #6366f1; --sidebar-text: #9a9abe; --sidebar-text-bright: #e0e0f0; --blue: #6366f1; --blue-light: #e0e7ff; }
body.dark-theme[data-theme="indigo"] { --primary: #818cf8; --primary-hover: #a5b4fc; --primary-light: #1e1b4b; --bg-primary: #0e0e1a; --bg-secondary: #1a1a2e; --bg-white: #1a1a2e; --bg-hover: #2a2a45; --sidebar-bg: #0e0e1a; --sidebar-hover: #1a1a2e; --sidebar-active: #818cf8; --border: #33335a; --border-color: #33335a; --input-bg: #0e0e1a; --input-border: #44447a; --card-bg: #1a1a2e; --blue: #818cf8; --blue-light: #1e1b4b; --sidebar-text: #9a9abe; --sidebar-text-bright: #e0e0f0;}

/* Theme picker swatches */
.theme-picker { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.theme-swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; transition: border-color .2s, transform .15s; background: var(--swatch); position: relative; }
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { border-color: var(--text-primary); }
.theme-swatch.active::after { content: '✓'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }
.theme-swatch-label { font-size: 10px; text-align: center; margin-top: 4px; color: var(--text-secondary); }

/* Hide inbox and closed badges in global VUES — too noisy */
#badge-all, #badge-closed { display: none !important; }

/* ===== DARK MODE: Comprehensive overrides (148 fixes) ===== */
body.dark-theme .form-card,
body.dark-theme .contact-ticket-card,
body.dark-theme .message-editor-card,
body.dark-theme .sig-card,
body.dark-theme .sorting-indicator,
body.dark-theme .hierarchy-menu,
body.dark-theme .hierarchy-avatar-edit,
body.dark-theme .hierarchy-avatar-input,
body.dark-theme .hierarchy-node,
body.dark-theme .hierarchy-node-header-label,
body.dark-theme .hierarchy-tooltip,
body.dark-theme .template-line,
body.dark-theme .contact-msg-bubble,
body.dark-theme .contact-msg-bubble.inbound,
body.dark-theme .dropdown-option,
body.dark-theme .compose-modal,
body.dark-theme .modal-body { background: var(--bg-secondary) !important; color: var(--text-primary) !important; border-color: var(--border) !important; }

body.dark-theme .contact-msg-bubble.outbound { background: var(--primary-light, #1e3a5f) !important; border-color: var(--border) !important; }
body.dark-theme .contact-msg-bubble.note,
body.dark-theme .msg-note-banner,
body.dark-theme .msg-forward-banner,
body.dark-theme .reply-box.note-mode .reply-editor,
body.dark-theme .msg-system-merge,
body.dark-theme .compose-header-warn { background: rgba(245, 158, 11, 0.06) !important; border-color: rgba(245, 158, 11, 0.15) !important; color: var(--text-primary) !important; }

body.dark-theme .table-header { background-color: var(--bg-secondary) !important; }
body.dark-theme .hierarchy-node .node-role-badge.user { background: var(--bg-hover) !important; color: var(--text-secondary) !important; }
body.dark-theme .hierarchy-node .node-role-badge.admin { background: #451a03 !important; color: #fbbf24 !important; }
body.dark-theme .qa-status-done { background: #064e3b !important; color: #4ade80 !important; border-color: #10b981 !important; }
body.dark-theme .qa-status-pending { background: #451a03 !important; color: #fbbf24 !important; border-color: #f59e0b !important; }
body.dark-theme .lan-share-card,
body.dark-theme .tunnel-info-box { background: #064e3b !important; border-color: #10b981 !important; color: var(--text-primary) !important; }
body.dark-theme .progress-bar-bg { background: var(--bg-hover) !important; }
body.dark-theme .notif-unread { background: var(--primary-light, #1e3a5f) !important; }
body.dark-theme .spinner { border-color: var(--border) !important; border-top-color: var(--primary) !important; }
body.dark-theme .form-divider { border-color: var(--border) !important; }

/* Dark: email/message content */
body.dark-theme .email-body, body.dark-theme .message-body, body.dark-theme .message-content { background: var(--bg-secondary) !important; color: var(--text-primary) !important; }
body.dark-theme .email-body *, body.dark-theme .message-body *, body.dark-theme .message-content * { color: inherit !important; }
body.dark-theme .email-body a, body.dark-theme .message-body a { color: var(--primary) !important; }
body.dark-theme .compose-overlay .compose-modal { background: var(--bg-primary) !important; color: var(--text-primary) !important; }

/* Dark: inline style overrides for settings.js dynamic elements */
body.dark-theme [style*="background:#d4edda"],
body.dark-theme [style*="background:#f0fdf4"],
body.dark-theme [style*="background:#dcfce7"] { background: #064e3b !important; color: #4ade80 !important; }
body.dark-theme [style*="background:#fef2f2"],
body.dark-theme [style*="background:#fee2e2"],
body.dark-theme [style*="background:#fecaca"] { background: #450a0a !important; color: #f87171 !important; }
body.dark-theme [style*="background:#dbeafe"] { background: #1e3a5f !important; color: #93c5fd !important; }
body.dark-theme [style*="background:#fef3c7"],
body.dark-theme [style*="background:#fffbeb"] { background: rgba(245, 158, 11, 0.06) !important; color: #fbbf24 !important; }
body.dark-theme [style*="background:#f3f4f6"],
body.dark-theme [style*="background:#f9fafb"],
body.dark-theme [style*="background:#fafafa"],
body.dark-theme [style*="background: white"],
body.dark-theme [style*="background:white"],
body.dark-theme [style*="background: #fff"],
body.dark-theme [style*="background:#fff"] { background: var(--bg-secondary) !important; color: var(--text-primary) !important; }
body.dark-theme [style*="color:#888"],
body.dark-theme [style*="color: #888"],
body.dark-theme [style*="color:#aaa"],
body.dark-theme [style*="color: #aaa"] { color: var(--text-muted) !important; }
body.dark-theme [style*="color:#e53e3e"] { color: #f87171 !important; }
body.dark-theme [style*="color:#374151"],
body.dark-theme [style*="color: #374151"] { color: var(--text-secondary) !important; }
body.dark-theme [style*="color:#6b7280"],
body.dark-theme [style*="color: #6b7280"] { color: var(--text-muted) !important; }
body.dark-theme [style*="border-color:#e5e7eb"],
body.dark-theme [style*="border: 1px solid #e5e7eb"],
body.dark-theme [style*="border:1px solid #e5e7eb"] { border-color: var(--border) !important; }

/* Fix: assigned-to-me filter badge text visibility */
body.dark-theme .filter-badge { color: white !important; }
.sidebar-link.active { position: relative; z-index: 1; }


/* ===== DARK MODE FIXES — Batch 2 ===== */

/* Reply/Note editor */
body.dark-theme .reply-editor,
body.dark-theme .reply-textarea,
body.dark-theme [contenteditable] {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
}

/* Message cards — remove white border */
body.dark-theme .message-card,
body.dark-theme .msg-card,
body.dark-theme .msg-content {
    border-color: var(--border) !important;
    background: var(--bg-secondary) !important;
}
body.dark-theme .msg-body-wrapper {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
}

/* Email body iframe wrapper */
body.dark-theme .email-body-wrapper,
body.dark-theme .email-body {
    background: var(--bg-primary) !important;
    border-color: var(--border) !important;
}

/* Status bar / table header */
body.dark-theme .ticket-table thead,
body.dark-theme .ticket-table thead th {
    background: var(--bg-primary) !important;
    border-color: var(--border) !important;
}

/* Form cards and white backgrounds */
body.dark-theme .form-card,
body.dark-theme .contact-ticket-card,
body.dark-theme .sig-card,
body.dark-theme .message-editor-card {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
}

/* Note/forward banners */
body.dark-theme .msg-note-banner {
    background: rgba(245, 158, 11, 0.1) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
}
body.dark-theme .msg-forward-banner {
    background: rgba(96, 165, 250, 0.1) !important;
    border-color: rgba(96, 165, 250, 0.3) !important;
}

/* System merge message */
body.dark-theme .msg-system-merge {
    background: rgba(245, 158, 11, 0.1) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
}

/* Contact bubbles */
body.dark-theme .contact-msg-bubble.inbound {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
}
body.dark-theme .contact-msg-bubble.outbound {
    background: rgba(59, 130, 246, 0.1) !important;
    border-color: rgba(59, 130, 246, 0.3) !important;
}
body.dark-theme .contact-msg-bubble.note {
    background: rgba(245, 158, 11, 0.1) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
}

/* Hierarchy / organigramme */
body.dark-theme .hierarchy-node,
body.dark-theme .hierarchy-menu,
body.dark-theme .hierarchy-tooltip,
body.dark-theme .hierarchy-avatar-edit,
body.dark-theme .hierarchy-avatar-input {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}

/* Sorting indicator */
body.dark-theme .sorting-indicator {
    background: var(--bg-secondary) !important;
}

/* Compose modal */
body.dark-theme .compose-header-warn {
    background: rgba(245, 158, 11, 0.1) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
}

/* Note mode editor background */
body.dark-theme .reply-box.note-mode .reply-editor {
    background: rgba(245, 158, 11, 0.08) !important;
}

/* Spinner */
body.dark-theme .spinner {
    border-color: rgba(255, 255, 255, 0.15) !important;
    border-top-color: var(--primary) !important;
}

/* QA status badges */
body.dark-theme .qa-status-pending {
    background: rgba(245, 158, 11, 0.15) !important;
    color: #fbbf24 !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
}
body.dark-theme .qa-status-done {
    background: rgba(16, 185, 129, 0.15) !important;
    color: #34d399 !important;
    border-color: rgba(16, 185, 129, 0.3) !important;
}

/* Notification unread */
body.dark-theme .notif-unread {
    background: rgba(59, 130, 246, 0.1) !important;
}

/* Template lines */
body.dark-theme .template-line {
    background: var(--bg-secondary) !important;
}

/* Table header background */
body.dark-theme .table-header {
    background-color: var(--bg-secondary) !important;
}

/* Signature block in editor */
body.dark-theme .signature-block {
    border-color: var(--border) !important;
    color: var(--text-secondary) !important;
    background: transparent !important;
}
body.dark-theme .signature-block *:not(a):not(img) {
    background: transparent !important;
}

/* Macros panel */
body.dark-theme .macro-header {
    background: var(--primary) !important;
}

/* CRM match tooltip */
body.dark-theme .crm-match-tooltip {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
}

/* Auto-match label in contacts */
body.dark-theme [style*="background:#dbeafe"] {
    background: rgba(59, 130, 246, 0.2) !important;
    color: #93c5fd !important;
}


/* ===== Theme Picker ===== */
.theme-picker {
    display: flex;
    gap: 6px;
    padding: 6px 12px;
    flex-wrap: wrap;
    justify-content: center;
}
.theme-picker.visible {
    display: flex;
}
.theme-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    background: var(--swatch);
    transition: transform 0.15s, border-color 0.15s;
    position: relative;
}
.theme-swatch:hover {
    transform: scale(1.15);
    border-color: var(--text-secondary);
}
.theme-swatch.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--swatch);
}

/* Dark mode toggle — compact */
.theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px 8px;
    gap: 8px;
}
.theme-row.visible {
    display: flex;
}
.dark-toggle-compact {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 11px;
    color: var(--sidebar-text);
}
.dark-toggle-compact input {
    width: 32px;
    height: 16px;
    appearance: none;
    background: var(--sidebar-hover);
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}
.dark-toggle-compact input:checked {
    background: var(--primary);
}
.dark-toggle-compact input::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    transition: transform 0.2s;
}
.dark-toggle-compact input:checked::after {
    transform: translateX(16px);
}


/* ===== DARK MODE — White border fixes ===== */
body.dark-theme .msg-card,
body.dark-theme .message-card,
body.dark-theme .msg-body-wrapper,
body.dark-theme .msg-content,
body.dark-theme .email-body,
body.dark-theme .email-body-wrapper {
    border-color: var(--border) !important;
}

/* Fix any remaining hardcoded #e5e7eb borders */
body.dark-theme [style*="border"][style*="e5e7eb"],
body.dark-theme [style*="border"][style*="E5E7EB"] {
    border-color: var(--border) !important;
}

/* Muted text needs more contrast in dark */
body.dark-theme .text-muted,
body.dark-theme .sidebar-badge:not([class*="badge-"]) {
    color: var(--text-secondary) !important;
}

/* Inbox/ticket list active row */
body.dark-theme .ticket-table tbody tr.active,
body.dark-theme .ticket-table tbody tr:hover {
    background: var(--bg-hover) !important;
}

/* Context panel sections */
body.dark-theme .context-card {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
}
body.dark-theme .context-section {
    border-color: var(--border) !important;
}
body.dark-theme .context-title {
    color: var(--text-primary) !important;
}

/* Active filters bar */
body.dark-theme .active-filters {
    background: var(--bg-secondary) !important;
    border-bottom-color: var(--border) !important;
}

/* Email address text in inbox — lighter gray for dark mode */
body.dark-theme .col-sender .sender-email,
body.dark-theme .sender-info small,
body.dark-theme .sender-info .sender-email {
    color: #94a3b8 !important;  /* Lighter than default gray */
}

/* Signature block text in dark mode */
body.dark-theme .signature-block,
body.dark-theme .signature-block * {
    color: var(--text-secondary) !important;
}
body.dark-theme .signature-block a {
    color: var(--primary) !important;
}


/* Reply box resizable via drag handle */
.reply-box {
    resize: vertical;
    overflow: hidden;
    min-height: 150px;
}

/* Compact formatting toolbar */
.reply-toolbar, .rt-toolbar {
    padding: 4px 8px !important;
    gap: 2px !important;
}
.reply-toolbar .rt-btn, .rt-toolbar .rt-btn {
    padding: 3px 6px !important;
    font-size: 12px !important;
}

/* Narrower To: field */
.reply-recipients {
    max-width: 50%;
}
.reply-to-input, .compose-to-input {
    min-width: 150px;
}

/* CC/BCC buttons closer to center */
.reply-cc-btns {
    margin-left: auto;
    margin-right: auto;
}

/* White borders on messages in dark mode — comprehensive fix */
body.dark-theme .msg-card,
body.dark-theme .message-bubble,
body.dark-theme .msg-bubble,
body.dark-theme .msg-inbound,
body.dark-theme .msg-outbound,
body.dark-theme .msg-note,
body.dark-theme .msg-forward,
body.dark-theme [class*="msg-"] {
    border-color: var(--border) !important;
}
body.dark-theme iframe {
    border-color: var(--border) !important;
}

/* Dark mode: msg-item border + outbound background override */
body.dark-theme .msg-item {
    border-color: var(--border) !important;
    background: var(--bg-secondary) !important;
}
body.dark-theme .msg-item.msg-inbound {
    background: var(--bg-secondary) !important;
    border-left-color: var(--primary) !important;
}
body.dark-theme .msg-item.msg-outbound {
    background: var(--bg-secondary) !important;
    border-left-color: var(--border-light) !important;
}
body.dark-theme .msg-header {
    background: var(--bg-primary) !important;
    border-color: var(--border) !important;
}
/* DUPLICATE outbound tint removed (was lines 7960-7962): D-02 — outbound has no background fill in light mode either. */


/* Reply resize bar — sits above the Repondre/Note interne tabs */
.reply-resize-bar {
    height: 4px;
    cursor: ns-resize;
    background: transparent;
    transition: background 0.15s;
    flex-shrink: 0;
}
.reply-resize-bar:hover,
.reply-resize-bar.dragging {
    background: var(--primary);
    opacity: 0.5;
}


/* ===== ML Classification UI ===== */

/* Vocabulary cards */
.ml-vocab-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin: 16px 0;
}
.ml-vocab-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-white);
    transition: box-shadow 0.2s;
}
.ml-vocab-card:hover {
    box-shadow: var(--shadow-md);
}
.ml-vocab-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}
.ml-vocab-card.expanded .ml-vocab-header {
    border-bottom-color: var(--border);
}
.ml-vocab-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
}
.ml-vocab-meta {
    font-size: 11px;
    color: var(--text-muted);
}
.ml-vocab-body {
    display: none;
    padding: 10px 14px;
}
.ml-vocab-card.expanded .ml-vocab-body {
    display: block;
}
.ml-word-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-size: 12px;
}
.ml-word-name {
    flex: 0 0 120px;
    font-family: monospace;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ml-word-bar-bg {
    flex: 1;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}
.ml-word-bar {
    height: 100%;
    border-radius: 3px;
    background: var(--primary);
    transition: width 0.3s;
}
.ml-word-weight {
    flex: 0 0 40px;
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
}
.ml-word-remove {
    flex: 0 0 20px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    line-height: 1;
}
.ml-word-remove:hover {
    color: var(--red);
}

/* Actions auto table */
.ml-actions-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 12px 0;
}
.ml-actions-table th {
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 8px 10px;
    border-bottom: 2px solid var(--border);
}
.ml-actions-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.ml-actions-table select,
.ml-actions-table input {
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-white);
    color: var(--text-primary);
}

/* Confidence slider */
.ml-confidence-slider {
    width: 80px;
    accent-color: var(--primary);
}
.ml-confidence-value {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    min-width: 30px;
    display: inline-block;
}

/* Accuracy bars */
.ml-accuracy-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}
.ml-accuracy-label {
    flex: 0 0 80px;
    font-size: 12px;
    color: var(--text-secondary);
}
.ml-accuracy-track {
    flex: 1;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}
.ml-accuracy-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s;
}
.ml-accuracy-fill.good { background: var(--green); }
.ml-accuracy-fill.ok { background: var(--amber); }
.ml-accuracy-fill.low { background: var(--red); }
.ml-accuracy-pct {
    flex: 0 0 40px;
    font-size: 12px;
    font-weight: 600;
    text-align: right;
}

/* Validation encart (ticket sidebar) */
.ml-validation-card {
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
}
.ml-validation-card.high {
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.25);
}
.ml-validation-card.medium {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.25);
}
.ml-validation-card.low {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}
.ml-validation-label {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
}
.ml-validation-card.high .ml-validation-label { color: var(--green); }
.ml-validation-card.medium .ml-validation-label { color: var(--amber); }
.ml-validation-card.low .ml-validation-label { color: var(--text-muted); }
.ml-validation-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 6px 0;
}
.ml-keyword-chip {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-family: monospace;
}
.ml-validation-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}
.ml-validation-actions .btn {
    font-size: 11px;
    padding: 4px 10px;
}

/* Training progress */
.ml-training-progress {
    padding: 12px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    margin: 12px 0;
}
.ml-training-bar {
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    margin: 8px 0;
}
.ml-training-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
    animation: ml-pulse 1.5s ease-in-out infinite;
}
@keyframes ml-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}
.ml-training-status {
    font-size: 12px;
    color: var(--text-secondary);
}


/* Signature collapsed/expanded in editor */
.signature-block.collapsed {
    max-height: 24px;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    opacity: 0.5;
}
.signature-block.collapsed::after {
    content: '... (cliquez pour voir la signature)';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, var(--bg-secondary));
    padding: 2px 8px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}
.signature-block.collapsed:hover {
    opacity: 0.8;
}
.sig-collapse-btn {
    display: block;
    width: 100%;
    padding: 4px 8px;
    margin-top: 2px;
    background: var(--bg-tertiary, #f3f4f6);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 4px;
    color: var(--text-muted, #6b7280);
    font-size: 11px;
    cursor: pointer;
    text-align: center;
}
.sig-collapse-btn:hover {
    background: var(--bg-secondary, #e5e7eb);
    color: var(--text-primary, #374151);
}

/* Draggable widget highlight — title is draggable so the body can keep
   text selection (selecting client email in the card was previously blocked
   by draggable="true" on the whole section). */
.context-section .context-title[draggable="true"] { cursor: grab; }
.context-section.drag-over-widget { border-top: 2px solid var(--blue, #3b82f6); }
.context-card,
.context-card * {
    user-select: text;
}

/* Dark mode: contenteditable editors that may receive pasted Outlook HTML.
   Pasted content carries inline `style="background-color:white; color:#000"`
   on every <td>/<div>/<span>. CSS rules with regular `!important` lose to
   inline styles, so we cannot just declare `background:transparent` here —
   instead we use the `attr` selector trick: a very high-specificity selector
   that wraps the editor and forces children backgrounds. The contenteditable
   container itself uses a CSS variable so it follows the theme. */
body.dark-theme .signature-html-editor,
body.dark-theme #mailbox-sig-editor,
body.dark-theme #user-sig-editor,
body.dark-theme #reply-editor,
body.dark-theme #sc-message {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}
/* Force pasted Outlook elements to use the editor background.
   `html body` boost beats simple `body` from email <style> blocks. */
body.dark-theme .signature-html-editor *,
body.dark-theme #mailbox-sig-editor *,
body.dark-theme #user-sig-editor *,
body.dark-theme #reply-editor *,
body.dark-theme #sc-message * {
    background-color: transparent !important;
}
body.dark-theme .signature-html-editor td,
body.dark-theme .signature-html-editor th,
body.dark-theme .signature-html-editor table,
body.dark-theme #mailbox-sig-editor td,
body.dark-theme #mailbox-sig-editor th,
body.dark-theme #mailbox-sig-editor table,
body.dark-theme #reply-editor td,
body.dark-theme #reply-editor th,
body.dark-theme #reply-editor table {
    background-color: transparent !important;
    background: transparent !important;
    color: var(--text-primary) !important;
}
/* For text-color: span/font/p with inline color win over CSS. We can't
   defeat them with CSS alone — the JS paste handler strips inline color
   in dark mode (see _cleanSignatureHtml + reply paste handler). For text
   that is still dark after that, force readable color via filter as last
   resort on the EDITOR ONLY (does NOT affect images thanks to :not). */
body.dark-theme .signature-html-editor [style*="color"],
body.dark-theme #mailbox-sig-editor [style*="color"],
body.dark-theme #reply-editor [style*="color"] {
    color: var(--text-primary) !important;
}

/* Notification banner: ticket changed externally while user has it open */
.ticket-state-changed-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    margin: 8px 12px;
    background: var(--bg-tertiary, #fef3c7);
    border: 1px solid var(--orange, #f59e0b);
    border-left: 4px solid var(--orange, #f59e0b);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary);
    z-index: 50;
}
.state-changed-icon {
    font-size: 18px;
    color: var(--orange, #f59e0b);
}
.state-changed-text { flex: 1; }
body.dark-theme .ticket-state-changed-banner {
    background: rgba(245, 158, 11, 0.15);
    color: var(--text-primary);
}

/* Inbox date filter popover */
.date-filter-popover {
    position: absolute;
    top: 56px;
    right: 16px;
    z-index: 1000;
    width: 280px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 12px;
}
.date-filter-section { margin-bottom: 8px; }
.date-filter-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}
.date-filter-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: 11px;
    margin: 6px 0;
}
.date-filter-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.date-filter-range input { flex: 1; min-width: 0; }
.date-filter-range span { color: var(--text-muted); }
.date-filter-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 8px 0;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.date-filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 8px;
}
#btn-date-filter.active {
    background: var(--blue);
    color: white;
}

/* Tag source visual differentiation in sidebar */
.tag-source-ml {
    border: 1px dashed currentColor !important;
    opacity: 0.85;
}
.tag-source-ml::before {
    content: "🤖 ";
    font-size: 10px;
    margin-right: 2px;
}
.tag-source-import {
    border: 1px dotted currentColor !important;
    opacity: 0.75;
}
.tag-source-rule {
    border-left: 3px solid currentColor !important;
}
.sidebar-tag-group-header {
    list-style: none;
    margin-top: 6px;
}
.sidebar-tag-group-header:first-child {
    margin-top: 0;
}

/* CRM lookup loading state — replaces 'not found' message during request */
.no-data.crm-loading {
    color: var(--text-muted);
    font-style: italic;
    position: relative;
    padding-left: 22px;
}
.no-data.crm-loading::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border: 2px solid var(--border, #e5e7eb);
    border-top-color: var(--blue, #3b82f6);
    border-radius: 50%;
    animation: crmSpin 0.8s linear infinite;
}
@keyframes crmSpin {
    to { transform: rotate(360deg); }
}

/* Reply footer always visible */
.reply-footer {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--bg-white);
    z-index: 2;
}

/* ============================================================
   Merge modal — suggestion list (active tickets, same contact).
   Uses theme variables so light + dark both work without a
   dedicated CONSOLIDATED FIXES override.
   ============================================================ */
.merge-modal-intro {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}
.merge-suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 240px;
    overflow-y: auto;
    margin-top: 4px;
}
.merge-suggestions-empty {
    font-size: 13px;
    color: var(--text-muted);
    padding: 10px 4px;
}
.merge-suggestion-item {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md, 6px);
    padding: 8px 10px;
    cursor: pointer;
    font: inherit;
    color: var(--text-primary);
    transition: background 0.12s, border-color 0.12s;
}
.merge-suggestion-item:hover {
    background: var(--hover-bg);
    border-color: var(--primary);
}
.merge-suggestion-item.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary);
}
.merge-suggestion-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}
.merge-suggestion-id {
    font-weight: 600;
    font-size: 13px;
    color: var(--primary);
}
.merge-suggestion-status {
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    background: var(--bg-muted);
    color: var(--text-secondary);
}
.merge-suggestion-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}
.merge-suggestion-subject {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.merge-suggestion-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ============================================================
   DARK MODE — CONSOLIDATED FIXES (audit batch from theme review)
   This block lives at the END of the file so its rules win the
   cascade against any earlier hardcoded class-level color rules.
   ============================================================ */

/* Critical #1: missing tokens on body.dark-theme. Without these, the
   default "ocean" dark theme leaked the light-mode primary-hover/light
   into button hovers and badge washes. */
body.dark-theme {
    --primary-hover: #3b82f6;
    --primary-light: #1e3a5f;
    --surface: #1e293b;
    --hover-bg: #334155;
    --bg-muted: #1e293b;
    --bg-tertiary: #1e293b;
    --border-light: #334155;
    --danger: #f87171;
    --orange: #fbbf24;
}

/* Critical #3 + #11 + #12 + #4 + Important #7-9: hardcoded white bg classes */
body.dark-theme .profile-header,
body.dark-theme .mailbox-sig-card,
body.dark-theme .multiselect-display,
body.dark-theme .multiselect-dropdown,
body.dark-theme .hierarchy-zoom-controls button,
body.dark-theme .zoom-level-label,
body.dark-theme .node-context-menu,
body.dark-theme .node-team-badge,
body.dark-theme .tunnel-qr-container,
body.dark-theme #sig-html-editor,
body.dark-theme .notif-dropdown,
body.dark-theme .mention-dropdown {
    background: var(--bg-secondary) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
}

/* Multiselect tags inside dark dropdown */
body.dark-theme .multiselect-tag {
    background: var(--blue-light) !important;
    color: var(--blue) !important;
}

/* Mention/notification dropdown items hover */
body.dark-theme .mention-option:hover,
body.dark-theme .mention-option.active,
body.dark-theme .notif-item:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

/* Important #12: attachment chips */
body.dark-theme .attachment-chip {
    background: var(--bg-hover) !important;
    border-color: var(--border) !important;
    color: var(--text-primary) !important;
}
body.dark-theme .attachment-chip:hover {
    background: var(--bg-hover) !important;
    border-color: var(--primary) !important;
}

/* Important #13: CRM source badges */
body.dark-theme .crm-source-sharepoint {
    background: rgba(6, 182, 212, 0.15) !important;
    color: #22d3ee !important;
}
body.dark-theme .crm-source-excel {
    background: rgba(34, 197, 94, 0.15) !important;
    color: #4ade80 !important;
}

/* Critical #5: duplicate-banner injected by JS in tickets.js — define a
   real CSS class so dark mode can override the inline amber-on-white */
.duplicate-banner {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 12px;
    border-radius: 6px;
    margin: 8px 12px;
}
body.dark-theme .duplicate-banner {
    background: rgba(245, 158, 11, 0.10) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
    color: var(--text-primary) !important;
}
body.dark-theme .duplicate-banner * {
    color: var(--text-primary) !important;
}

/* Critical #2: entity context menu (built dynamically by entities.js) */
.entity-context-menu {
    position: fixed;
    z-index: 9999;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    padding: 4px 0;
    min-width: 160px;
    font-size: 13px;
}
.entity-context-menu .menu-item {
    padding: 8px 14px;
    cursor: pointer;
    color: var(--text-primary);
}
.entity-context-menu .menu-item:hover {
    background: var(--bg-hover);
}
.entity-context-menu .menu-item.danger {
    color: var(--red);
}
.entity-context-menu .menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Important #10: settings.html info alert (#e3f2fd was uncovered) */
body.dark-theme [style*="background: #e3f2fd"],
body.dark-theme [style*="background:#e3f2fd"] {
    background: rgba(33, 150, 243, 0.10) !important;
    border-left-color: rgba(33, 150, 243, 0.5) !important;
    color: var(--text-primary) !important;
}
body.dark-theme [style*="background: #e3f2fd"] *,
body.dark-theme [style*="background:#e3f2fd"] * {
    color: var(--text-primary) !important;
}

/* ============================================================
 * Help / User guide — editorial docs style (Stripe/Linear inspired)
 * ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* Local scope variables so help is independent of the app theme tokens */
.help-modal {
    --hlp-bg:           #fafaf7;
    --hlp-surface:      #ffffff;
    --hlp-ink:          #0f1115;
    --hlp-ink-dim:      #545861;
    --hlp-muted:        #8a8e96;
    --hlp-line:         #ecece5;
    --hlp-line-strong:  #d9d9cf;
    --hlp-accent:       #ef4444;       /* warm accent against the paper base */
    --hlp-accent-soft:  #fef3c7;
    --hlp-mono:         'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;
    --hlp-sans:         'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --hlp-display:      'Fraunces', 'New York', Georgia, serif;
}

/* ---- Floating "?" FAB ---- */
.help-fab {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.1);
    background: #0f1115;
    color: #fafaf7;
    font-family: var(--hlp-display, 'Fraunces', Georgia, serif);
    font-size: 20px;
    font-style: italic;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 10px 24px -8px rgba(15,17,21,0.45), 0 2px 4px rgba(15,17,21,0.15);
    z-index: 999;
    transition: transform 160ms cubic-bezier(.2,.8,.2,1), box-shadow 160ms;
    display: flex;
    align-items: center;
    justify-content: center;
}
.help-fab:hover {
    transform: translateY(-3px) rotate(-6deg);
    box-shadow: 0 16px 32px -8px rgba(15,17,21,0.5), 0 4px 8px rgba(15,17,21,0.2);
}
.help-fab:active { transform: translateY(-1px) rotate(0); }

/* ---- Modal shell ---- */
.help-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 180ms ease;
    font-family: var(--hlp-sans);
    color: var(--hlp-ink);
}
.help-modal.help-modal-visible { opacity: 1; }
.help-modal-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at top, rgba(15,17,21,0.25), rgba(15,17,21,0.7) 70%),
        rgba(15,17,21,0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.help-modal-window {
    position: relative;
    width: min(1180px, 96vw);
    height: min(84vh, 880px);
    background: var(--hlp-bg);
    border-radius: 18px;
    box-shadow:
        0 40px 90px -20px rgba(15,17,21,0.55),
        0 1px 0 rgba(255,255,255,0.8) inset,
        0 0 0 1px rgba(15,17,21,0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(16px) scale(0.98);
    transition: transform 220ms cubic-bezier(.2,.8,.2,1);
}
.help-modal.help-modal-visible .help-modal-window {
    transform: translateY(0) scale(1);
}

/* ---- Header with search ---- */
.help-modal-header {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--hlp-line);
    background:
        linear-gradient(180deg, rgba(255,255,255,0.7), transparent),
        var(--hlp-surface);
    flex-shrink: 0;
}
.help-modal-header h2 {
    margin: 0;
    font-family: var(--hlp-display);
    font-weight: 600;
    font-size: 22px;
    letter-spacing: -0.01em;
    color: var(--hlp-ink);
    white-space: nowrap;
}
.help-search {
    flex: 1;
    max-width: 520px;
    padding: 10px 14px;
    border: 1px solid var(--hlp-line-strong);
    border-radius: 10px;
    font-family: var(--hlp-sans);
    font-size: 13.5px;
    background: var(--hlp-bg);
    color: var(--hlp-ink);
    transition: border-color 140ms, box-shadow 140ms, background 140ms;
}
.help-search::placeholder { color: var(--hlp-muted); }
.help-search:focus {
    outline: none;
    border-color: var(--hlp-ink);
    box-shadow: 0 0 0 4px rgba(15,17,21,0.06);
    background: var(--hlp-surface);
}
.help-modal-close {
    border: 1px solid var(--hlp-line);
    background: var(--hlp-surface);
    font-size: 20px;
    line-height: 1;
    color: var(--hlp-ink-dim);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 140ms;
}
.help-modal-close:hover {
    color: var(--hlp-ink);
    border-color: var(--hlp-ink);
}

/* ---- Body layout ---- */
.help-modal-body {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

/* ---- Sidebar TOC ---- */
.help-toc {
    width: 310px;
    flex: 0 0 310px;
    overflow-y: auto;
    border-right: 1px solid var(--hlp-line);
    background: var(--hlp-surface);
    padding: 18px 0 40px;
    scrollbar-width: thin;
    scrollbar-color: var(--hlp-line-strong) transparent;
}
.help-toc::-webkit-scrollbar { width: 6px; }
.help-toc::-webkit-scrollbar-thumb { background: var(--hlp-line-strong); border-radius: 3px; }

.help-toc-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 22px;
    color: var(--hlp-ink-dim);
    text-decoration: none;
    font-size: 13.5px;
    line-height: 1.45;
    border-left: 2px solid transparent;
    transition: all 100ms ease;
}
.help-toc-item:hover {
    color: var(--hlp-ink);
    background: var(--hlp-bg);
}
.help-toc-item.active {
    color: var(--hlp-ink);
    border-left-color: var(--hlp-accent);
    background: var(--hlp-bg);
    font-weight: 600;
}
.help-toc-num {
    color: var(--hlp-muted);
    font-family: var(--hlp-mono);
    font-size: 11px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    min-width: 34px;
    letter-spacing: -0.02em;
}
.help-toc-item.active .help-toc-num { color: var(--hlp-accent); }
.help-toc-title { flex: 1; }

.help-toc-level-1 {
    font-weight: 700;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--hlp-muted);
    padding: 16px 22px 6px;
    border-left: none;
    background: transparent !important;
    pointer-events: none;
}
.help-toc-level-1 .help-toc-num {
    font-size: 11px;
    color: var(--hlp-muted);
}
.help-toc-level-1 .help-toc-title {
    font-weight: 700;
    color: var(--hlp-muted);
}
.help-toc-level-2 { padding-left: 34px; }
.help-toc-level-3 {
    padding-left: 58px;
    font-size: 12.5px;
    color: var(--hlp-muted);
}
.help-toc-level-3.active { color: var(--hlp-ink); }

.help-toc-empty {
    padding: 40px 22px;
    text-align: center;
    color: var(--hlp-muted);
    font-size: 13px;
    font-style: italic;
}

/* ---- Main content ---- */
.help-content {
    flex: 1;
    overflow-y: auto;
    padding: 48px 64px 96px;
    max-width: 780px;
    margin: 0 auto;
    scrollbar-width: thin;
}
.help-content::-webkit-scrollbar { width: 8px; }
.help-content::-webkit-scrollbar-thumb { background: var(--hlp-line-strong); border-radius: 4px; }

/* Welcome landing */
.help-welcome {
    padding: 20px 0;
}
.help-welcome-kicker {
    font-family: var(--hlp-mono);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--hlp-accent);
    margin-bottom: 14px;
}
.help-welcome-title {
    font-family: var(--hlp-display);
    font-weight: 600;
    font-size: 48px;
    line-height: 1.05;
    letter-spacing: -0.025em;
    margin: 0 0 20px;
    color: var(--hlp-ink);
}
.help-welcome-lead {
    font-size: 16px;
    line-height: 1.7;
    color: var(--hlp-ink-dim);
    margin: 0 0 24px;
    max-width: 540px;
}
.help-welcome-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--hlp-muted);
    margin-bottom: 48px;
}
.help-welcome-hint kbd {
    font-family: var(--hlp-mono);
    font-size: 11px;
    background: var(--hlp-surface);
    border: 1px solid var(--hlp-line-strong);
    border-bottom-width: 2px;
    border-radius: 5px;
    padding: 2px 6px;
    color: var(--hlp-ink);
}
.help-welcome-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 8px;
}
.help-welcome-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    border: 1px solid var(--hlp-line);
    border-radius: 12px;
    background: var(--hlp-surface);
    color: var(--hlp-ink);
    text-decoration: none;
    transition: all 160ms cubic-bezier(.2,.8,.2,1);
    position: relative;
}
.help-welcome-card:hover {
    border-color: var(--hlp-ink);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px -12px rgba(15,17,21,0.3);
}
.help-welcome-card-num {
    font-family: var(--hlp-display);
    font-weight: 600;
    font-size: 28px;
    color: var(--hlp-accent);
    min-width: 36px;
    line-height: 1;
}
.help-welcome-card-title {
    flex: 1;
    font-weight: 600;
    font-size: 15px;
    color: var(--hlp-ink);
}
.help-welcome-card-count {
    font-family: var(--hlp-mono);
    font-size: 11px;
    color: var(--hlp-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Breadcrumb */
.help-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--hlp-mono);
    font-size: 11px;
    color: var(--hlp-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 18px;
}
.help-breadcrumb-sep { opacity: 0.5; }

/* Title block */
.help-title-block {
    display: flex;
    align-items: baseline;
    gap: 18px;
    margin-bottom: 36px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--hlp-line);
}
.help-title-num {
    font-family: var(--hlp-mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--hlp-accent);
    background: var(--hlp-accent-soft);
    padding: 4px 10px;
    border-radius: 6px;
    line-height: 1;
    letter-spacing: -0.01em;
}
.help-title {
    font-family: var(--hlp-display);
    font-weight: 600;
    font-size: 36px;
    line-height: 1.1;
    letter-spacing: -0.02em;
    margin: 0;
    color: var(--hlp-ink);
    flex: 1;
}

/* Blocks wrapper */
.help-blocks {
    font-family: var(--hlp-sans);
    font-size: 15.5px;
    line-height: 1.72;
    color: var(--hlp-ink);
}

/* Paragraphs */
.help-para {
    margin: 0 0 18px;
    color: var(--hlp-ink-dim);
}
.help-para:last-child { margin-bottom: 0; }
.help-blocks strong { color: var(--hlp-ink); font-weight: 600; }
.help-blocks em { font-style: italic; }

/* Bullet lists */
.help-ul {
    list-style: none;
    padding: 0;
    margin: 0 0 22px;
}
.help-li {
    position: relative;
    padding: 5px 0 5px 28px;
    color: var(--hlp-ink-dim);
    line-height: 1.6;
}
.help-li::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 14px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--hlp-accent);
}
.help-li-lvl-1 { padding-left: 56px; }
.help-li-lvl-1::before { left: 36px; background: var(--hlp-muted); }
.help-li-lvl-2 { padding-left: 84px; }
.help-li-lvl-2::before { left: 64px; background: var(--hlp-muted); width: 4px; height: 4px; }

/* Inline code */
.help-code-inline {
    font-family: var(--hlp-mono);
    font-size: 0.88em;
    background: var(--hlp-surface);
    border: 1px solid var(--hlp-line);
    border-radius: 5px;
    padding: 1px 6px;
    color: var(--hlp-ink);
}

/* Code blocks */
.help-pre {
    background: var(--hlp-ink);
    color: #e8e8df;
    font-family: var(--hlp-mono);
    font-size: 13px;
    line-height: 1.6;
    padding: 18px 22px;
    border-radius: 10px;
    overflow-x: auto;
    margin: 0 0 24px;
}
.help-pre code { color: inherit; background: none; border: none; padding: 0; }

/* Callouts */
.help-callout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 20px;
    margin: 0 0 22px;
    border-radius: 10px;
    border: 1px solid var(--hlp-line);
    background: var(--hlp-surface);
    position: relative;
}
.help-callout::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    border-radius: 10px 0 0 10px;
}
.help-callout-tip::before     { background: #10b981; }
.help-callout-note::before    { background: #3b82f6; }
.help-callout-warning::before { background: #f59e0b; }
.help-callout-head {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--hlp-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--hlp-ink);
}
.help-callout-tip .help-callout-head     { color: #047857; }
.help-callout-note .help-callout-head    { color: #1e40af; }
.help-callout-warning .help-callout-head { color: #92400e; }
.help-callout-icon {
    font-size: 14px;
    text-transform: none;
    letter-spacing: 0;
}
.help-callout-body {
    font-size: 14.5px;
    line-height: 1.65;
    color: var(--hlp-ink-dim);
}

/* Tables */
.help-table-wrap {
    overflow-x: auto;
    margin: 0 0 24px;
    border: 1px solid var(--hlp-line);
    border-radius: 10px;
    background: var(--hlp-surface);
}
.help-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.help-table th,
.help-table td {
    padding: 12px 16px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--hlp-line);
    line-height: 1.55;
}
.help-table tr:last-child td { border-bottom: none; }
.help-table th {
    font-family: var(--hlp-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--hlp-muted);
    background: var(--hlp-bg);
    border-bottom: 1px solid var(--hlp-line-strong);
}
.help-table td { color: var(--hlp-ink-dim); }
.help-table tr:hover td { background: var(--hlp-bg); }

/* Sub-sections grid */
.help-subsec-header {
    font-family: var(--hlp-display);
    font-weight: 600;
    font-size: 22px;
    letter-spacing: -0.015em;
    margin: 48px 0 18px;
    color: var(--hlp-ink);
}
.help-subsec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}
.help-subsec-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--hlp-line);
    border-radius: 10px;
    background: var(--hlp-surface);
    color: var(--hlp-ink);
    text-decoration: none;
    font-size: 14px;
    transition: all 140ms;
}
.help-subsec-card:hover {
    border-color: var(--hlp-ink);
    transform: translateX(2px);
}
.help-subsec-num {
    font-family: var(--hlp-mono);
    font-size: 11px;
    color: var(--hlp-accent);
    font-weight: 500;
    min-width: 32px;
}
.help-subsec-title { flex: 1; font-weight: 500; }
.help-subsec-arrow {
    color: var(--hlp-muted);
    transition: transform 140ms, color 140ms;
}
.help-subsec-card:hover .help-subsec-arrow {
    color: var(--hlp-accent);
    transform: translateX(3px);
}

.help-empty-hint {
    color: var(--hlp-muted);
    font-style: italic;
    font-size: 14px;
}

body.help-modal-open { overflow: hidden; }

/* ---- Dark mode ---- */
body.dark-theme .help-modal {
    --hlp-bg:           #0f1115;
    --hlp-surface:      #171a20;
    --hlp-ink:          #f2f2ee;
    --hlp-ink-dim:      #b8bcc4;
    --hlp-muted:        #71767f;
    --hlp-line:         #252932;
    --hlp-line-strong:  #323844;
    --hlp-accent:       #fca5a5;
    --hlp-accent-soft:  #3a2020;
}
body.dark-theme .help-modal-backdrop {
    background:
        radial-gradient(ellipse at top, rgba(0,0,0,0.3), rgba(0,0,0,0.85) 70%),
        rgba(0,0,0,0.7);
}
body.dark-theme .help-modal-window {
    box-shadow:
        0 40px 90px -20px rgba(0,0,0,0.8),
        0 0 0 1px rgba(255,255,255,0.06);
}
body.dark-theme .help-pre {
    background: #060709;
    border: 1px solid var(--hlp-line);
}
body.dark-theme .help-fab {
    background: #fafaf7;
    color: #0f1115;
    border-color: rgba(0,0,0,0.1);
}

/* Responsive */
@media (max-width: 900px) {
    .help-toc { display: none; }
    .help-content { padding: 32px 24px 64px; }
    .help-welcome-title { font-size: 36px; }
    .help-title { font-size: 28px; }
    .help-welcome-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   PHASE 11 — Threading-report controls in message header
   - .msg-header-subject : divergent-subject label (italic, muted),
     centered between sender-info (or time) and the right edge.
     Truncates with ellipsis on narrow widths.
   - .msg-header-menu-btn : tiny ⋮ button on the right of the header,
     opens the "Signaler un mail mal placé" dropdown.
   ============================================================ */

.msg-header-subject {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0 12px;
    text-align: center;
    font-style: italic;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-header-menu-btn {
    flex: 0 0 auto;
    background: none;
    border: none;
    padding: 4px 6px;
    margin-left: 6px;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted, #64748b);
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.msg-header-menu-btn:hover {
    background: var(--bg-hover, #e2e8f0);
    color: var(--text-primary, #1e293b);
}

.msg-header-menu-btn:focus-visible {
    outline: 2px solid var(--primary, #3b82f6);
    outline-offset: 1px;
}

body.dark-theme .msg-header-subject {
    color: var(--text-muted, #94a3b8);
}

body.dark-theme .msg-header-menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary, #e2e8f0);
}

/* ============================================================
   DARK MODE — CONSOLIDATED FIXES (audit batch 2026-04-23)
   Fixes previously unreadable combos where a hardcoded dark text
   color sat on a *-light CSS var (which flips to a dark tint under
   body.dark-theme — see line 7197+). Background tweaks align with
   the existing sla-warning / admin-badge precedents.
   ============================================================ */

/* CRITICAL — status badges: dark ink on light pill became
   dark-on-dark in dark mode. Use bright semantic colors instead. */
body.dark-theme .ticket-status-badge.open { color: #4ade80 !important; }
body.dark-theme .ticket-status-badge.pending { color: #fbbf24 !important; }
body.dark-theme .mbx-card-badge { color: #4ade80 !important; }
body.dark-theme .separator-status.status-open { color: #4ade80 !important; }
body.dark-theme .separator-status.status-paused { color: #fbbf24 !important; }

/* CRITICAL — internal note/forward banner bodies: the amber wrapper
   was dark-overridden but the text colors inside stayed dark-ink. */
body.dark-theme .msg-note-banner .msg-note-header,
body.dark-theme .msg-note-banner .msg-note-body,
body.dark-theme .msg-note-banner .msg-note-time,
body.dark-theme .msg-forward-banner .msg-forward-label,
body.dark-theme .msg-forward-banner .msg-forward-via {
    color: var(--text-primary) !important;
}

/* CRITICAL — hierarchy node role badges: admin/user were overridden
   but gestionnaire/manager were not. */
body.dark-theme .hierarchy-node .node-role-badge.gestionnaire {
    background: rgba(59, 130, 246, 0.18) !important;
    color: #60a5fa !important;
}
body.dark-theme .hierarchy-node .node-role-badge.manager {
    background: rgba(16, 185, 129, 0.18) !important;
    color: #4ade80 !important;
}

/* IMPORTANT — transferred ticket row: cream highlight was too loud
   against dark inbox. Match the sla-warning treatment. */
body.dark-theme .ticket-table tbody tr.ticket-transfer {
    background: rgba(245, 158, 11, 0.06) !important;
}
body.dark-theme .ticket-table tbody tr.ticket-transfer:hover {
    background: rgba(245, 158, 11, 0.12) !important;
}

/* IMPORTANT — LAN / tunnel settings panel: hardcoded pale bg + dark
   text strings need a themed pair. */
body.dark-theme .lan-ip,
body.dark-theme .lan-label,
body.dark-theme .lan-hostname {
    background: rgba(16, 185, 129, 0.12) !important;
    color: #4ade80 !important;
}
body.dark-theme .tunnel-url-input {
    background: var(--bg-secondary) !important;
    border-color: var(--border-light) !important;
    color: var(--text-primary) !important;
}

/* IMPORTANT — contact-history accordion toggle: pale grey stripe in
   dark mode. Match the surrounding card surface. */
body.dark-theme .contact-msg-toggle {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-light) !important;
}
body.dark-theme .contact-msg-toggle:hover {
    background: var(--hover-bg) !important;
}

/* IMPORTANT — attachment previewable hover: sibling
   .attachment-chip:hover already has a dark override; add this one. */
body.dark-theme .attachment-previewable:hover {
    background: rgba(59, 130, 246, 0.12) !important;
}

/* IMPORTANT — danger hovers that showed as bright pink flashes */
body.dark-theme .node-context-menu button.danger:hover,
body.dark-theme .entity-contact-remove:hover {
    background: rgba(239, 68, 68, 0.15) !important;
}

/* IMPORTANT — default tag badge fallback (when JS didn't inject
   inline color): pale grey on dark was illegible. */
body.dark-theme .tag-badge {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* IMPORTANT — collision banner: amber gradient + dark-brown text
   still shows but reads too low-contrast in dark. */
body.dark-theme .collision-banner {
    color: var(--text-primary) !important;
}

/* IMPORTANT — help modal callout heads: emerald/navy/brown on the
   near-black help surface. */
body.dark-theme .help-modal .help-callout-tip .help-callout-head {
    color: #10b981 !important;
}
body.dark-theme .help-modal .help-callout-note .help-callout-head {
    color: #60a5fa !important;
}
body.dark-theme .help-modal .help-callout-warning .help-callout-head {
    color: #fbbf24 !important;
}

/* =====================================================================
   Phase 10 — Excel attachment viewer (REQ-10-02..08)
   Modal-scoped overrides so Tabulator's vendored CSS does not bleed into
   the inbox, plus search-hit + loading/error + sheet-tab placement.
   ===================================================================== */

/* IMPORTANT — search-hit highlight classes (REQ-10-06).
   Mirror .pdf-search-hit at ~line 10381 but drop color:transparent since
   Tabulator cells render real text (vs PDF.js's transparent text layers). */
.tabulator-cell.excel-search-hit {
    background-color: rgba(255, 213, 79, 0.5) !important;
    border-radius: 2px;
}
.tabulator-cell.excel-search-current-hit {
    background-color: rgba(255, 152, 0, 0.7) !important;
    outline: 2px solid var(--orange);
    border-radius: 2px;
}
body.dark-theme .tabulator-cell.excel-search-hit {
    background-color: rgba(255, 213, 79, 0.3) !important;
}
body.dark-theme .tabulator-cell.excel-search-current-hit {
    background-color: rgba(255, 152, 0, 0.5) !important;
}

/* IMPORTANT — merged-cell rendering. Per Wave 1 spike verdict
   (SPIKE-NOTES.md): the start cell shows the merged value via the
   formatter; covered cells get visibility:hidden so the value appears
   as a single cell with empty neighbours. */
.tabulator-cell.merge-covered { visibility: hidden; }
.tabulator-cell.merge-start { z-index: 2; position: relative; }

/* IMPORTANT — sheet tabs at the bottom of .ap-content (D-12).
   Excel viewer hand-builds .excel-sheet-tabs as a sibling of the grid host. */
#attachment-preview-overlay .ap-content .excel-sheet-tabs {
    order: 999;
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    border-top: 1px solid var(--border-light);
    background: var(--bg-secondary);
    overflow-x: auto;
    flex-shrink: 0;
}
#attachment-preview-overlay .ap-content .excel-sheet-tab {
    padding: 4px 12px;
    border: 1px solid var(--border-light);
    border-radius: 4px 4px 0 0;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    font-family: inherit;
}
#attachment-preview-overlay .ap-content .excel-sheet-tab.is-active {
    background: var(--primary-light, var(--bg-hover));
    border-bottom-color: transparent;
    font-weight: 600;
}
#attachment-preview-overlay .ap-content .excel-sheet-tab:hover:not(.is-active) {
    background: var(--bg-hover);
}
body.dark-theme #attachment-preview-overlay .ap-content .excel-sheet-tabs {
    border-top-color: var(--border-light);
    background: var(--bg-secondary);
}
body.dark-theme #attachment-preview-overlay .ap-content .excel-sheet-tab {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-light);
}

/* IMPORTANT — grid host fills the .ap-content area above the tab strip. */
#attachment-preview-overlay .ap-content .excel-grid-host {
    flex: 1;
    /* min-width: 0 is CRITICAL — without it, flex children can't shrink
       below their content's intrinsic width. Tabulator's .tabulator element
       expands to the sum of column widths (e.g., 80 cols × 150px = 12000px)
       and pushes the host beyond the modal width, making the user appear to
       land at column AG. With min-width:0, flex correctly constrains the
       host to its parent's width and Tabulator's internal tableholder
       handles horizontal scroll for the columns. */
    min-width: 0;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}
/* Belt-and-suspenders — explicitly cap Tabulator's root element so its
   layout:'fitData' (sum-of-column-widths) can't escape the grid host. */
#attachment-preview-overlay .ap-content .tabulator {
    width: 100% !important;
    max-width: 100% !important;
}

/* IMPORTANT — spinner (D-01) shown while library lazy-loads + sheet parses. */
.excel-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    color: var(--text-secondary);
    font-size: 14px;
}

/* IMPORTANT — inline error UX (D-02) replaces spinner on load/parse failure. */
.excel-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 100%;
    padding: 24px;
    color: var(--danger);
    text-align: center;
}
.excel-error svg { color: var(--danger); }
.excel-error p {
    margin: 0;
    color: var(--text-primary);
    font-size: 14px;
}
.excel-error button { margin-top: 4px; }

/* IMPORTANT — Tabulator scope isolation (Pitfall 7).
   Tabulator's vendored CSS uses naked selectors (.tabulator, .tabulator-row, etc.)
   that would bleed into the rest of the app if not modal-scoped. We re-declare
   each with #attachment-preview-overlay .ap-content prefix so the styling only
   applies inside the modal. */
#attachment-preview-overlay .ap-content .tabulator {
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-light);
}
#attachment-preview-overlay .ap-content .tabulator-header {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}
#attachment-preview-overlay .ap-content .tabulator-row {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}
#attachment-preview-overlay .ap-content .tabulator-row.tabulator-row-even {
    background: var(--bg-secondary);
}
#attachment-preview-overlay .ap-content .tabulator-cell {
    color: var(--text-primary);
    border-right-color: var(--border-light);
}

/* IMPORTANT — Tabulator dark-mode overrides. Variables flip automatically,
   but the naked-selector cascade needs explicit dark-theme prefixes to win
   over Tabulator's own light-default rules. NO filter:invert (CLAUDE.md
   "Iframe filter:invert" pitfall applies here too). */
body.dark-theme #attachment-preview-overlay .ap-content .tabulator {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-light);
}
body.dark-theme #attachment-preview-overlay .ap-content .tabulator-header {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-bottom-color: var(--border-light);
}
body.dark-theme #attachment-preview-overlay .ap-content .tabulator-row {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom-color: var(--border-light);
}
body.dark-theme #attachment-preview-overlay .ap-content .tabulator-row.tabulator-row-even {
    background: var(--bg-secondary);
}
body.dark-theme #attachment-preview-overlay .ap-content .tabulator-cell {
    color: var(--text-primary);
    border-right-color: var(--border-light);
}

/* Excel viewer — text wrap inside cells AND column-title headers so long
   French CEE labels (often 100-200 chars) wrap to multiple lines instead
   of being truncated by the fixed 150px column width. The previous attempt
   (display:flex; align-items:flex-start) broke Tabulator's cell measurement
   and rendered the body empty — those rules are NOT here. Wrap is applied
   inline on each cell element via the formatter (excel-viewer.js); CSS only
   needs to override the column-title default nowrap so column letters and
   any future longer header content can wrap. */
#attachment-preview-overlay .ap-content .tabulator-col-title {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

/* =====================================================================
   Collaborators (per-ticket grants) — topbar pill + popover
   ===================================================================== */
.collab-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.collab-trigger .collab-count-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--blue, #2563eb);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

.collab-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 210;
    min-width: 280px;
    max-width: 360px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 10px 12px;
    font-size: 13px;
}

.collab-popover-header {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.3px;
    margin-bottom: 6px;
}

.collab-popover-help {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
    padding: 6px 8px;
    background: var(--bg-secondary, #f8fafc);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.collab-list {
    list-style: none;
    padding: 0;
    margin: 0 0 8px;
    max-height: 180px;
    overflow-y: auto;
}

.collab-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.collab-list li:hover {
    background: var(--bg-hover, #f1f5f9);
}

.collab-list .collab-user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--blue, #2563eb);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
}

.collab-list .collab-user-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collab-list .collab-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.collab-list .collab-remove-btn:hover {
    background: var(--danger, #dc2626);
    color: #fff;
}

.collab-list .collab-empty {
    padding: 8px;
    color: var(--text-muted);
    font-style: italic;
    font-size: 12px;
    text-align: center;
}

.collab-add-row {
    display: flex;
    gap: 6px;
    align-items: center;
    border-top: 1px solid var(--border-light, var(--border));
    padding-top: 8px;
}

.collab-user-picker {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
}

body.dark-theme .collab-popover {
    background: var(--bg-secondary);
    border-color: var(--border);
}
body.dark-theme .collab-popover-help {
    background: var(--bg-tertiary, rgba(255,255,255,0.04));
}


/* ==========================================================================
   PDF VIEWER — Phase 2
   Canvas-based PDF rendering via PDF.js.
   New attachment preview modal styles: filename row, nav arrows, page info.
   ========================================================================== */

/* Filename row with flanking nav arrows */
.ap-filename-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
}
.ap-filename {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
/* PDF nav arrows (flanking filename) */
.ap-pdf-nav {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.ap-pdf-nav:hover {
    background: rgba(255,255,255,0.3);
}
.ap-pdf-nav:disabled {
    opacity: 0.3;
    cursor: default;
}

/* Page info indicator in footer */
.ap-page-info {
    color: rgba(255,255,255,0.7);
    font-size: 12px;
    font-weight: 500;
}

/* PDF canvas stack container */
.pdf-canvas-stack {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

/* Individual page canvas */
.pdf-page-canvas {
    background: #fff;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    max-width: 100%;
    cursor: zoom-in;
}

/* Loading placeholder */
.pdf-loading {
    color: rgba(255,255,255,0.85);
    font-size: 14px;
    padding: 40px;
}

/* PDF mode: canvas stack scrolls from top (image mode keeps default centering) */
#attachment-preview-overlay .ap-content.ap-content-pdf {
    align-items: flex-start;
    justify-content: flex-start;
    overflow-y: auto;
}

/* Dark mode: no additional overrides needed — modal is already dark-on-dark */
body.dark-theme #attachment-preview-overlay .ap-content {
    background: transparent;
}


/* ==========================================================================
   PDF VIEWER — Phase 3
   Zoom controls toolbar in footer: Adapter / − / badge% / +
   ========================================================================== */

.ap-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ap-zoom-btn,
.ap-zoom-badge {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.15s;
    min-width: 32px;
    text-align: center;
    line-height: 1.4;
}

.ap-zoom-btn:hover,
.ap-zoom-badge:hover {
    background: rgba(255,255,255,0.3);
}

.ap-zoom-btn:disabled,
.ap-zoom-badge:disabled {
    opacity: 0.4;
    cursor: default;
}

.ap-zoom-fit {
    font-size: 11px;
    min-width: auto;
    padding: 4px 8px;
}

.ap-zoom-badge {
    min-width: 48px;
}


/* ==========================================================================
   PDF VIEWER — Phase 4
   Text layer overlay + search highlights + search bar
   ========================================================================== */

/* Page wrapper: stacks canvas + text layer */
.pdf-page-wrapper {
    position: relative;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
    background: #fff;
    max-width: 100%;
    flex-shrink: 0;
}

/* Text layer overlay — transparent, sits over canvas.
   pointer-events: none so clicks/wheel pass through to canvas/page wrapper
   (text selection sacrificed in v1; search highlights still visible since
   they're rendered as background colors on the (invisible) span elements). */
.pdf-text-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    line-height: 1.0;
    color: transparent;
    pointer-events: none;
}

.pdf-text-layer > span {
    position: absolute;
    white-space: pre;
    transform-origin: 0% 0%;
    color: transparent;
    pointer-events: none;
}

/* Search highlight states */
.pdf-text-layer .pdf-search-hit {
    background: rgba(255, 245, 153, 0.65);
    color: transparent;
    border-radius: 2px;
}

.pdf-text-layer .pdf-search-current-hit {
    background: rgba(255, 149, 0, 0.75);
    color: transparent;
    border-radius: 2px;
}

/* ============================================================
   DARK MODE — email chips (recipient pills)
   End-of-file so these win the cascade (CONSOLIDATED FIXES rule).
   --blue-light flips to a dark tint in dark themes; pair it with
   the bright --blue for legible text (never --blue-dark on dark).
   ============================================================ */
body.dark-theme .email-chip {
    background: var(--blue-light) !important;
    color: var(--blue) !important;
}
body.dark-theme .email-chip.invalid {
    background: rgba(239, 68, 68, .18) !important;
    color: #fca5a5 !important;
}
body.dark-theme .email-chip-x:hover {
    background: rgba(255, 255, 255, .15);
}
body.dark-theme .email-chips--box {
    background: var(--input-bg, var(--bg-secondary));
    border-color: var(--input-border, var(--border));
}

/* Search bar — sticky between header and body */
.ap-search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.55);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.ap-search-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    padding: 6px 10px;
    font-size: 13px;
    min-width: 0;
}

.ap-search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.ap-search-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.15);
}

.ap-search-counter {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    min-width: 52px;
    text-align: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.ap-search-prev,
.ap-search-next,
.ap-search-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 6px;
    color: #fff;
    width: 28px;
    height: 28px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
    line-height: 1;
}

.ap-search-prev:hover,
.ap-search-next:hover,
.ap-search-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ap-search-prev:disabled,
.ap-search-next:disabled {
    opacity: 0.3;
    cursor: default;
}

/* Canvas shadow now on wrapper instead of bare canvas */
.pdf-page-wrapper .pdf-page-canvas {
    box-shadow: none;
    background: #fff;
    display: block;
}


/* ============================================================
   FTS Phase 3 — search snippet styling
   Yellow highlight on matched terms in search-suggest dropdown,
   inbox results, and (Phase 4) ticket detail body.
   ============================================================ */

.search-suggestion-snippet,
.ticket-row-snippet {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.search-suggestion-snippet mark,
.ticket-row-snippet mark,
.message-body mark {
    background: #fef3c7;
    color: #78350f;
    padding: 0 2px;
    border-radius: 2px;
    font-weight: 500;
}

body.dark-theme .search-suggestion-snippet mark,
body.dark-theme .ticket-row-snippet mark,
body.dark-theme .message-body mark {
    background: #78350f;
    color: #fef3c7;
}

/* ============================================================
   Inbox hover preview — tooltip with the first lines of the
   latest message body (tickets.js _attachRowPreview).
   Theme variables only: dark mode needs no override.
   ============================================================ */

.ticket-preview-tooltip {
    position: fixed;
    z-index: 3000;
    max-width: min(460px, calc(100vw - 24px));
    background: var(--bg-white);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 10px 12px;
    font-size: 12.5px;
    line-height: 1.45;
    pointer-events: none;
    word-break: break-word;
}

.ticket-preview-tooltip .ticket-preview-label {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.ticket-preview-tooltip .ticket-preview-body {
    white-space: pre-line;
}

/* ============================================================
   PHASE 02 — TICKET THREAD UI REWORK (Gorgias / Zendesk-inspired)
   New classes for: collapsed messages, latest-inbound saliency,
   "Voir N messages précédents" pill, attachments strip on top,
   topbar download-all button.
   D-01..D-15 locked. UI-SPEC §"Color" + §"Component States".
   APPENDED AFTER the LAST consolidated-fixes block (line 9247) at true EOF.
   ============================================================ */

/* --- D-03: Latest-inbound saliency (4px border + box-shadow) --- */
.msg-item.msg-latest-inbound {
    border-left-width: 4px;
    border-left-color: var(--primary);
    box-shadow: var(--shadow-sm);
}
body.dark-theme .msg-item.msg-latest-inbound {
    border-left-color: var(--primary) !important;
    box-shadow: var(--shadow-sm);
}

/* --- Collapsed message: hide body wrapper, rotate chevron --- */
.msg-item.msg-collapsed .msg-body {
    display: none !important;
}
.msg-item.msg-collapsed .msg-collapse-chevron {
    transform: rotate(0deg);
}
.msg-item:not(.msg-collapsed) .msg-collapse-chevron {
    transform: rotate(90deg);
}
.msg-collapse-chevron {
    transition: transform 0s; /* instant per UI-SPEC — no animation in MVP */
    color: var(--text-muted);
    margin-left: auto;
}

/* --- Collapsible header bar: pointer cursor + hover lift --- */
.msg-item.msg-collapsible .msg-header {
    cursor: pointer;
}
.msg-item.msg-collapsible .msg-header:hover {
    background: var(--bg-secondary);
}
body.dark-theme .msg-item.msg-collapsible .msg-header:hover {
    background: var(--bg-secondary) !important;
}
/* Latest-inbound is non-collapsable: cursor stays default */
.msg-item.msg-latest-inbound .msg-header {
    cursor: default;
}

/* --- Optional "Dernier message" pill (D-04 hides it on single-message tickets) --- */
.msg-latest-pill {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    margin-left: 8px;
}
body.dark-theme .msg-latest-pill {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
}

/* --- "Voir les N messages précédents" pill (UI-SPEC §"State 5") --- */
.thread-collapse-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    margin: 12px auto;
    width: fit-content;
}
.thread-collapse-pill:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
body.dark-theme .thread-collapse-pill {
    background: var(--surface) !important;
    border-color: var(--border-light) !important;
    color: var(--text-secondary) !important;
}
body.dark-theme .thread-collapse-pill:hover {
    background: var(--bg-hover) !important;
    color: var(--text-primary) !important;
}

/* --- Attachments strip (positioned BEFORE body, visible while collapsed) --- */
.msg-attachments-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
    color: var(--text-primary);
}
.msg-attachments-strip .clip-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}
.msg-attachments-strip .first-att-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 32ch;
}
.msg-attachments-strip .first-att-size {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: 4px;
}
.msg-attachments-strip .att-expand-dots {
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
}
.msg-attachments-strip .att-expand-dots:hover {
    color: var(--primary);
    background: var(--bg-hover);
}
.msg-attachments-strip .att-count-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    /* Sits immediately next to the .att-expand-dots (gap: 8px from parent flex);
       previously had margin-left: auto which pushed it to the far right. */
}
body.dark-theme .msg-attachments-strip {
    background: var(--surface) !important;
    border-bottom-color: var(--border-light) !important;
    color: var(--text-primary) !important;
}
body.dark-theme .msg-attachments-strip .first-att-size,
body.dark-theme .msg-attachments-strip .clip-icon,
body.dark-theme .msg-attachments-strip .att-expand-dots {
    color: var(--text-muted) !important;
}
body.dark-theme .msg-attachments-strip .att-expand-dots:hover {
    color: var(--primary) !important;
    background: var(--bg-hover) !important;
}
body.dark-theme .msg-attachments-strip .att-count-badge {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
}

/* --- Expanded variant: stacked rows with chip list inside the strip --- */
.msg-attachments-strip--expanded {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-bottom: 10px;
}
.msg-attachments-strip--expanded .att-chip-list-stacked {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
/* When expanded, hide the inline first-attachment chip so the full list
   below is the single source of truth (the first PJ would otherwise appear
   twice: once in the header and once in the expanded list). */
.msg-attachments-strip--expanded .first-att-link {
    display: none;
}
/* Per-message "Télécharger toutes les PJ" button at the bottom of the
   expanded list. Reuses --primary palette (consistent with the topbar
   download-all button) but kept compact and unobtrusive. */
.msg-attachments-strip .att-download-all {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    align-self: flex-start;
    margin-top: 4px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}
.msg-attachments-strip .att-download-all:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}
body.dark-theme .msg-attachments-strip .att-download-all {
    border-color: var(--border-light) !important;
    color: var(--primary) !important;
}
body.dark-theme .msg-attachments-strip .att-download-all:hover {
    background: var(--bg-hover) !important;
    border-color: var(--primary) !important;
}

/* --- Topbar download-all button (uses .btn .btn-sm .btn-outline base) --- */
.btn-download-all .btn-download-all-label {
    margin-left: 4px;
}
/* No new colour rules — .btn-outline already themed in dark mode at style.css line 7340. */

/* ============================================================
   DARK MODE — Inline tag-create UI (color swatches + empty hints)
   Added with the inline-tag-creation UX fix (2026-05-07).
   ============================================================ */

/* Swatch borders need to be lighter to remain visible against the dark
   suggestion background. The hover ring uses --bg-secondary to punch a
   visible "halo" around the picked swatch. */
body.dark-theme .tag-color-swatch {
    border-color: rgba(255, 255, 255, 0.18);
}

body.dark-theme .tag-color-swatch:hover {
    box-shadow: 0 0 0 2px var(--bg-secondary), 0 0 0 3px rgba(96, 165, 250, 0.6);
}

body.dark-theme .tag-color-swatch:focus {
    box-shadow: 0 0 0 2px var(--bg-secondary), 0 0 0 3px var(--blue);
}

/* "Aucun tag correspondant" hint stays readable on dark surfaces. */
body.dark-theme .tag-suggestion-item.tag-suggestion-empty {
    color: #94a3b8 !important;
}

/* "Créer le tag" label stays bright-blue legible on dark dropdown. */
body.dark-theme .tag-suggestion-item.create-new .tag-create-label {
    color: #60a5fa !important;
}

/* ============================================================
   DEFENSIVE — sidebar links never look like default <a> tags
   ============================================================
   Reported symptom: after focusing the topbar tag-input or the
   profile signature contenteditable and then re-expanding the
   sidebar (auto-collapse on detail view), every line in the
   sidebar started rendering with default <a> styling — bright
   blue color and underlined "visited link" appearance.
   The base rule `.sidebar-link { text-decoration:none }` (line
   232) has no `!important`, so any browser autofill helper,
   content-extension, or stale cascading rule that sets
   `text-decoration:underline` on `a` (or worse, on `a:focus` /
   `a:visited`) will defeat it. Hard-pin the sidebar's link
   styling so no edge case can leak through. */
#sidebar a,
#sidebar a:link,
#sidebar a:visited,
#sidebar a:hover,
#sidebar a:focus,
#sidebar a:active,
.sidebar a,
.sidebar a:link,
.sidebar a:visited,
.sidebar a:hover,
.sidebar a:focus,
.sidebar a:active {
    text-decoration: none !important;
}

/* The same elements should never inherit the global `a { color:
   var(--blue) }` from line 88 — they have their own theming via
   --sidebar-text / --sidebar-text-bright. Pin those too. */
#sidebar .sidebar-link,
.sidebar .sidebar-link {
    color: var(--sidebar-text);
}
#sidebar .sidebar-link:hover,
.sidebar .sidebar-link:hover {
    color: var(--sidebar-text-bright);
}
#sidebar .sidebar-link:visited,
.sidebar .sidebar-link:visited {
    color: var(--sidebar-text);
}
#sidebar .sidebar-link.active,
.sidebar .sidebar-link.active {
    color: var(--blue);
}

/* Tag pills inside the sidebar should always show with their
   inline background color — guarantee visibility even if a
   parent rule somehow strips inline styles. */
#sidebar .sidebar-link .tag-badge,
.sidebar .sidebar-link .tag-badge {
    text-decoration: none !important;
}

/* ============================================================
   CLOSED-TICKET LOCK STATE (audit batch 2026-05-07)
   ------------------------------------------------------------
   Applied to .ticket-detail-layout when a ticket is loaded with
   status='closed' AND the user did not just close it from this
   view (see `_justClosedThisView` in tickets.js). The state
   dims mutating actions, replaces "Fermer" with "Ré-ouvrir",
   and keeps read-only surfaces (message thread, back, notif
   bell, client info display) fully interactive.
   ============================================================ */

/* Dim & disable mutating action surfaces. The reply-box, status
   controls, snooze, assign, collaborators, and the actions
   dropdown all become non-interactive. The actual click blocking
   happens via pointer-events; opacity + saturate convey the
   visual cue without breaking text legibility on the thread. */
.ticket-detail--locked-closed .ticket-topbar .status-dropdown-wrap,
.ticket-detail--locked-closed .ticket-topbar .snooze-dropdown-wrap,
.ticket-detail--locked-closed #assign-select,
.ticket-detail--locked-closed .ticket-topbar .collab-wrapper,
.ticket-detail--locked-closed .context-section-assign-tags .tag-input-container,
.ticket-detail--locked-closed .context-section-assign-tags #tags-list,
.ticket-detail--locked-closed .quick-actions-bar,
.ticket-detail--locked-closed .reply-mode-bar,
.ticket-detail--locked-closed .macro-bar,
.ticket-detail--locked-closed .reply-box,
.ticket-detail--locked-closed .reply-resize-bar,
.ticket-detail--locked-closed .context-panel .editable-field,
.ticket-detail--locked-closed .context-panel #contact-type-select {
    opacity: 0.5;
    pointer-events: none;
    user-select: none;
    filter: saturate(0.6);
    transition: opacity 0.2s ease, filter 0.2s ease;
}

/* The reply editor itself gets a clearer "disabled" surface so
   users immediately understand they can't type. pointer-events
   on the parent .reply-box already blocks input — these rules
   add visual unambiguity. */
.ticket-detail--locked-closed .reply-editor {
    background: var(--bg-muted, var(--bg-secondary)) !important;
    cursor: not-allowed !important;
}
.ticket-detail--locked-closed .status-select {
    background-color: var(--bg-muted, var(--bg-secondary)) !important;
    color: var(--text-muted) !important;
    cursor: not-allowed !important;
}

/* The Ré-ouvrir button breaks out of the locked dim and is
   promoted to the visually dominant action — it's the only
   path to re-engage with the ticket. */
.ticket-detail--locked-closed #btn-close-ticket.btn-reopen {
    opacity: 1 !important;
    pointer-events: auto !important;
    user-select: auto !important;
    filter: none !important;
    background: var(--blue, var(--primary)) !important;
    color: #ffffff !important;
    border-color: var(--blue, var(--primary)) !important;
    font-weight: 600;
}
.ticket-detail--locked-closed #btn-close-ticket.btn-reopen:hover {
    background: var(--blue-dark, var(--primary-hover)) !important;
    border-color: var(--blue-dark, var(--primary-hover)) !important;
}
.ticket-detail--locked-closed #btn-close-ticket.btn-reopen svg {
    stroke: #ffffff !important;
}

/* Dark mode: muted backgrounds map to darker tints so the
   "disabled" look stays subtle (not blinding white surfaces). */
body.dark-theme .ticket-detail--locked-closed .reply-editor,
body.dark-theme .ticket-detail--locked-closed .status-select {
    background-color: var(--bg-tertiary, var(--bg-secondary)) !important;
    color: var(--text-muted) !important;
}

/* ============================================================
   PHASE 02 POLISH — Collapsed message rhythm + recipient legibility
   ------------------------------------------------------------
   Post-merge user feedback (2026-05-07):
   - Issue A: stacked collapsed messages all looked the same — no
     visual separation. Fix: 3px gap between collapsed items so
     the thread bg shows as a subtle rhythm stripe (Zendesk pattern,
     no color budget spent).
   - Issue B: recipient line ("Pour: ... · CC: ...") was rendered
     in --text-muted on --bg-hover — grey on grey, ~2:1 contrast.
     Fix: transparent background + --text-secondary text so the
     line sits cleanly on the message --surface (~7:1 contrast).
   ============================================================ */

/* --- Issue A: rhythm between stacked collapsed messages --- */
.msg-item.msg-collapsed {
    margin-bottom: 3px;
}
.msg-item.msg-collapsed:last-of-type {
    margin-bottom: 0;
}

/* --- Issue B: recipient line legibility (transparent bg + lifted color) --- */
.msg-recipients {
    background: transparent;
    color: var(--text-secondary);
    border-bottom: none;
}
body.dark-theme .msg-recipients {
    background: transparent !important;
    color: var(--text-secondary) !important;
}

/* Attachment pin — keep contrast in dark mode (muted blue-grey reads on
   both light and dark backgrounds without clashing with status dots). */
body.dark-theme .col-opened .attach-pin {
    color: var(--text-secondary);
    opacity: 0.85;
}
body.dark-theme .ticket-table tbody tr:hover .col-opened .attach-pin {
    color: var(--blue, #60a5fa);
    opacity: 1;
}

/* ------------------------------------------------------------
   Phase 06 plan 01: scope global body.dark-theme table th/td
   (lines 7441-7442) so it doesn't fight per-cell colors inside
   .spk-grid editor tables.

   The original lines 7441-7442 force --text-secondary/--text-primary
   and --border on EVERY <th>/<td> in dark mode — useful for
   settings/history tables, hostile to user-authored email-safe
   tables where the user has chosen specific cell colors.

   Strategy (locked in 06-PATTERNS.md "Open Question 5" → option b):
   add an exclusion rule that wins the cascade for non-.spk-grid
   tables. The original 7441-7442 rules are left intact so other
   table surfaces still get the dark-mode treatment.

   Inside .spk-grid the user's per-cell inline styles
   (style="color:#X;border-color:#Y;") take over with no override.
   ------------------------------------------------------------ */
body.dark-theme :not(.spk-grid):not(.spk-grid *) table th {
    color: var(--text-secondary) !important;
    border-color: var(--border) !important;
}
body.dark-theme :not(.spk-grid):not(.spk-grid *) table td {
    color: var(--text-primary) !important;
    border-color: var(--border) !important;}

/* ============================================================
   Phase 08 — auto-unmerge button on merge system notes
   Per-ticket "Defusionner" button rendered inside the
   .msg-system / .msg-system-merge note containers (tickets.js
   renderMessages, lines 3119+). Visual posture: compact,
   lower-stakes than .btn-note-delete; uses the warning orange
   color to signal a destructive-but-recoverable operation
   (orphan messages are deleted from the parent but the orphan
   ticket is reopened — recoverable via the manual merge flow).
   ============================================================ */
.btn-unmerge {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--orange, #ea580c);
    background: transparent;
    border: 1px solid var(--orange, #ea580c);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-unmerge:hover {
    background: var(--orange, #ea580c);
    color: white;
}
body.dark-theme .btn-unmerge {
    color: #fb923c;
    border-color: #fb923c;
}
body.dark-theme .btn-unmerge:hover {
    background: #fb923c;
    color: #18181b;
}

/* ============================================================
   Phase 12 — Click target hardening (D-01 + D-02)
   D-01: .msg-header-subject removed from click-handler exclusion
         in tickets.js — entire .msg-header bar now toggles.
   D-02: user-select: none on .msg-header-subject prevents the
         agent from accidentally drag-selecting the italic subject
         label when clicking the bar to toggle. Trade-off: rare
         copy use case is sacrificed for predictable click target.
   ============================================================ */
.msg-header-subject {
    user-select: none;
}

/* ============================================================
   Phase 12 — Saliency accent (D-03 + D-04) + polish items (D-08)

   D-03: Medium saliency recipe — color-mix tint (4% light / 8% dark)
         on collapsed header bars + 2px var(--primary) bottom border.
         Theme color appears as disciplined accent, not saturation.
   D-04: Accent ISOLATED to COLLAPSED bars only.
         - NOT applied on expanded bars (body provides anchoring).
         - NOT applied on latest-inbound (already saturated by phase
           02 4px border-left + box-shadow). Latest-inbound is never
           collapsed (guaranteed by tickets.js:4144 isLatestInbound
           shouldCollapse=false), so the .msg-collapsed > selector
           inherently excludes it. Phase-02 block at lines 10955-10963
           stays byte-identical (D-04 isolation invariant).
   D-07: Industry audit lock — 6 patterns REJECTED:
         - Avatar/initials disc (deferred phase 13 per D-05/D-06)
         - Smooth collapse animation (locked instant per phase 02 D-13)
         - Zendesk per-direction color-band (competes with border-left)
         - Read receipts (out of scope PHASE.md)
         - Sticky header on scroll (iframe srcdoc incompat)
         - Extra "last activity" pill (already have .msg-latest-pill)
   D-08: Three polish items TAKEN:
         1) Stronger inter-message separator: var(--border-light) on
            expanded .msg-item bottom border.
         2) Recipients line breathing room: padding 8px 16px.
         3) Header rhythm: padding 8px 16px + min-height 36px + gap
            12px (kills the "10:06Contrôles" glue from Bug 3).
   ============================================================ */

/* D-08 Polish Item 3 — .msg-header rhythm override (kills 10:06Contrôles glue) */
.msg-header {
    padding: 8px 16px;
    min-height: 36px;
    gap: 12px;
}

/* Phase 13 v5 — Direction-specific header tint, bumped intensities
   (2026-05-21 — previous v4 10%/8% mixes were below perception
   threshold against the conv bg per user feedback).
   - Inbound (external customer): achromatic gray at 22% — clearly
     darker than the conv bg, "weight signal".
   - Outbound (sent by SpekTicket team): theme color at 22% — clearly
     visible viewer-theme tint. --primary resolves per document so each
     operator sees their own theme accent.
   - Note / fallback: same as inbound.
   Bottom border 1px var(--border-light) preserves the click-affordance. */
.msg-header {
    background: color-mix(in srgb, var(--text-muted) 22%, var(--bg-white)) !important;
    border-bottom: 1px solid var(--border-light) !important;
}
.msg-item.msg-inbound .msg-header {
    background: color-mix(in srgb, var(--text-muted) 22%, var(--bg-white)) !important;
}
.msg-item.msg-outbound .msg-header {
    background: color-mix(in srgb, var(--primary) 22%, var(--bg-white)) !important;
}
.msg-item.msg-note .msg-header {
    background: color-mix(in srgb, var(--text-muted) 22%, var(--bg-white)) !important;
}
/* Dark mode parity — bumped to 28% for both since the dark card bg
   masks subtle tints even more aggressively. */
body.dark-theme .msg-header {
    background: color-mix(in srgb, var(--text-secondary) 28%, var(--bg-white)) !important;
    border-bottom: 1px solid var(--border) !important;
}
body.dark-theme .msg-item.msg-inbound .msg-header {
    background: color-mix(in srgb, var(--text-secondary) 28%, var(--bg-white)) !important;
}
body.dark-theme .msg-item.msg-outbound .msg-header {
    background: color-mix(in srgb, var(--primary) 28%, var(--bg-white)) !important;
}
body.dark-theme .msg-item.msg-note .msg-header {
    background: color-mix(in srgb, var(--text-secondary) 28%, var(--bg-white)) !important;
}
.msg-recipients {
    background: transparent !important;
    border-bottom: none !important;
}
body.dark-theme .msg-recipients {
    background: transparent !important;
    border-bottom: none !important;
}

/* D-08 Polish Item 1 — stronger inter-message separator on EXPANDED messages.
   Collapsed messages already carry their own 2px var(--primary) bottom border
   from the accent rule above, so no override needed for them.
   D-04 isolation note: this selector also matches .msg-item.msg-latest-inbound
   (latest-inbound is never collapsed — tickets.js:4144). The intended effect
   on latest-inbound is purely a bottom-border COLOR shift from var(--border)
   to var(--border-light) — NO accent tint, NO border-left change, NO box-shadow
   change. The phase-02 block at style.css:10955-10963 stays byte-identical. */
.msg-item:not(.msg-collapsed) {
    border-bottom-color: var(--border-light);
}
body.dark-theme .msg-item:not(.msg-collapsed) {
    border-bottom-color: var(--border-light) !important;
}

/* D-08 Polish Item 2 — recipients line breathing room (was 2px 14px 4px) */
.msg-recipients {
    padding: 8px 16px;
}

/* ============================================================
   ASSIGN & TAGS — sidebar widget (260521-lhy)
   ------------------------------------------------------------
   Le bloc tags + assign-select a migré du topbar vers un widget
   dédié en haut du panneau de droite. Ces overrides forcent un
   layout pleine largeur (au lieu du compact du topbar) et
   neutralisent l'`overflow:hidden` qui clippait les pills dans
   le topbar.
   ============================================================ */
.context-section-assign-tags .assign-select {
    width: 100%;
    font-size: 13px;
}
.context-section-assign-tags .tag-input-container {
    /* Pleine largeur dans la sidebar (override du min-width:200px et
       du compact 120-140px utilisé dans le topbar). */
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}
.context-section-assign-tags .tag-input {
    width: 100%;
    box-sizing: border-box;
}
.context-section-assign-tags .tags-list {
    /* Le clip overflow:hidden du topbar empêchait l'affichage complet
       des pills sur plusieurs lignes — ici on veut un wrap libre. */
    overflow: visible;
    min-height: 22px;
}
.context-section-assign-tags .client-field-tags label {
    margin-bottom: 6px;
}
/* Le dropdown d'autocomplete reste positionné par rapport au container
   (position:absolute / top:100%) — déjà OK car .tag-input-container reste
   relatif (héritage). On élargit juste sa max-width pour matcher la sidebar. */
.context-section-assign-tags .tag-suggestions {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

/* ============================================================
   Phase 13 — Avatar / initials disc (Zendesk row layout)
   (revised 2026-05-21 — moved OUT of .msg-header, now sibling of
    .msg-header inside .msg-item with CSS Grid layout)

   Layout (matches Zendesk Agent Workspace pattern):
     ┌────────┬──────────────────────────────┐
     │        │  [sender + via]  [time]      │   ← .msg-header
     │ AVATAR │  [recipients line]           │   ← .msg-recipients
     │ (col1) │  [attachments strip]         │   ← .msg-attachments-strip
     │        │  [body iframe]               │   ← body
     └────────┴──────────────────────────────┘

   The avatar lives in grid column 1, all other .msg-item children
   stack in column 2. This means the disc is ON the message body's
   white background (NOT on the tinted header bar), and body content
   indents to the right of the avatar — exactly like Zendesk.

   Color rules:
   - Outbound (sent by a SpekTicket team) → background = Team.color,
     initials = agent first name (Team.color resolved at ticket
     serialization time, served via ticket.team_color).
   - Inbound (external customer) → background = hash-of-email →
     12-color palette (deterministic, same sender = same color).
   ============================================================ */
.msg-item {
    /* Phase 13 v3: avatar in col 1 (page bg), .msg-frame in col 2 (card).
       The .msg-item itself is just a grid container — NO background, NO
       border, NO border-left. Card styling lives on .msg-frame so the
       avatar appears OUTSIDE the message card (Zendesk pattern). */
    display: grid !important;
    grid-template-columns: 56px 1fr !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-sizing: border-box;
    padding: 0 !important;
    margin-bottom: 8px;
}
/* Override phase 02 border-left polarity rules — these previously
   styled .msg-item directly; now they need to target .msg-frame so the
   color stripe appears ON THE CARD (right of the avatar), not on the
   row container (which would also wrap the avatar). */
.msg-item.msg-inbound {
    border-left: none !important;
}
.msg-item.msg-outbound {
    border-left: none !important;
}
.msg-item > .msg-avatar {
    /* Avatar sits at the top of col 1, aligned with the header text. */
    grid-column: 1;
    grid-row: 1;
    justify-self: center;
    align-self: start;
    margin-top: 10px;
}
.msg-item > .msg-frame {
    /* The card: white bg, border-left polarity (set per-direction
       below), bottom separator, rounded. Lives entirely in col 2. */
    grid-column: 2;
    grid-row: 1;
    background: var(--bg-white, #fff);
    border-bottom: 1px solid var(--border-light);
    border-radius: 4px;
    border-left: 3px solid var(--border-light);
    min-width: 0;
    overflow: hidden; /* prevent border-radius clipping issues on header bg */
}
.msg-item.msg-inbound > .msg-frame {
    border-left-color: var(--primary);
}
.msg-item.msg-outbound > .msg-frame {
    border-left-color: var(--border-light);
}
body.dark-theme .msg-item > .msg-frame {
    background: var(--bg-white) !important;
    border-bottom-color: var(--border) !important;
}
.msg-avatar {
    /* Belt-and-suspenders sizing: explicit width + height + aspect-ratio
       so the disc renders as a circle even if some external CSS tries
       to stretch one axis (cache-poisoned old rules, browser quirks). */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 50% !important;
    color: #ffffff !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    line-height: 1 !important;
    text-transform: uppercase !important;
    flex-shrink: 0 !important;
    /* Avoid font-style inheritance from .msg-header italic / muted children. */
    font-style: normal !important;
    /* Initials are a visual anchor, not an actionable element. */
    user-select: none !important;
    pointer-events: none !important;
    /* Subtle outer ring helps the disc read against the message bg. */
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06) !important;
    padding: 0 !important;
    margin: 0 !important;
}
body.dark-theme .msg-avatar {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) !important;
}

/* Link-confirm modal — dark mode (phishing-defense, quick 260527-eaf) */
body.dark-theme .link-confirm-url {
    background: var(--bg-tertiary, #0f172a) !important;
    border-color: var(--border-light, #334155) !important;
    color: var(--text-primary, #e2e8f0) !important;
}
body.dark-theme .link-confirm-text-mismatch {
    background: rgba(245, 158, 11, 0.15) !important;
    color: var(--text-primary, #e2e8f0) !important;
}
body.dark-theme .link-confirm-text-mismatch .link-confirm-visible-text {
    background: rgba(245, 158, 11, 0.25) !important;
    color: #fbbf24 !important;
}

/* ===========================================================================
   Quick-task 260522-nj6 — inbox row "recently-opened" highlight
   ---------------------------------------------------------------------------
   When the user navigates back from /ticket/{id} to the inbox, the row they
   just opened is briefly highlighted with a left border + tinted background,
   then fades over 4s. Gives a clear "you came from here" affordance.
   Applied by tickets.js:_restoreInboxState() on the matching row.
   Per CLAUDE.md convention: dark-mode override uses body.dark-theme prefix
   and a separate keyframe so the start tint reads correctly on the dark bg.
   =========================================================================== */
@keyframes spk-recently-opened-fade {
    0%   { background: var(--primary-light); }
    100% { background: transparent; }
}
/* Non-SLA rows keep the original bg-tint pulse. */
.ticket-table tr.recently-opened:not([data-sla-tier]) {
    box-shadow: inset 3px 0 0 var(--primary);
    animation: spk-recently-opened-fade 4s ease-out forwards;
}

@keyframes spk-recently-opened-fade-dark {
    0%   { background: rgba(59, 130, 246, 0.18); }
    100% { background: transparent; }
}
body.dark-theme .ticket-table tr.recently-opened:not([data-sla-tier]) {
    box-shadow: inset 3px 0 0 var(--primary);
    animation: spk-recently-opened-fade-dark 4s ease-out forwards;
}

/* SLA rows: shadow-only fade — MUST NOT touch the row's background or the
   keyframe's final `background: transparent` (with `forwards`) would eclipse
   the SLA tint set by `tr[data-sla-tier] { background: color-mix(...) }`.
   The bar pulse alone is enough "you came from here" affordance — the SLA
   color already makes the row stand out without needing extra bg highlight. */
@keyframes spk-recently-opened-fade-sla {
    0%   { box-shadow: inset 3px 0 0 var(--primary); }
    100% { box-shadow: inset 0 0 0 0 transparent; }
}
.ticket-table tr.recently-opened[data-sla-tier] {
    animation: spk-recently-opened-fade-sla 4s ease-out forwards;
}

/* === Avatar disc photos (profile pictures — quick-260527-mz5) === */
.msg-avatar-img { width:100%; height:100%; border-radius:50%; object-fit:cover; display:block; }
.team-avatar img { width:100%; height:100%; border-radius:50%; object-fit:cover; display:block; }
#user-avatar img { width:100%; height:100%; border-radius:50%; object-fit:cover; display:block; }
#assignee-avatar { display:inline-block; width:24px; height:24px; border-radius:50%; overflow:hidden; vertical-align:middle; }
#assignee-avatar img { width:100%; height:100%; object-fit:cover; display:block; }
.msg-avatar { overflow:hidden; }
body.dark-theme .msg-avatar-img,
body.dark-theme .team-avatar img,
body.dark-theme #user-avatar img { background:transparent; }

/* =====================================================================
   Macro slash-command prediction dropdown
   Triggered when user types "/x..." at the very start of #reply-editor.
   Positioned with `position: fixed` near the cursor by JS.
   ===================================================================== */
.macro-prediction-dropdown {
    position: fixed;
    z-index: 1100;
    min-width: 240px;
    max-width: 360px;
    background: var(--bg-white, #ffffff);
    border: 1px solid var(--border-light, #e5e7eb);
    border-radius: 8px;
    box-shadow: var(--shadow-md, 0 4px 12px rgba(0, 0, 0, 0.12));
    padding: 4px 0;
    font-size: 13px;
    overflow: hidden;
}

.macro-prediction-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    cursor: pointer;
    color: var(--text-primary, #111827);
    user-select: none;
}

.macro-prediction-item.selected {
    background: var(--primary-light, #eff6ff);
    color: var(--primary, #2563eb);
}

.macro-prediction-shortcut {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary, #2563eb);
    background: var(--bg-secondary, #f3f4f6);
    padding: 1px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.macro-prediction-item.selected .macro-prediction-shortcut {
    background: var(--primary, #2563eb);
    color: #ffffff;
}

.macro-prediction-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.macro-prediction-hint {
    padding: 5px 12px;
    font-size: 11px;
    color: var(--text-muted, #9ca3af);
    border-top: 1px solid var(--border-light, #e5e7eb);
    background: var(--bg-secondary, #f9fafb);
    user-select: none;
}

/* Dark mode */
body.dark-theme .macro-prediction-dropdown {
    background: var(--bg-white) !important;
    border-color: var(--border-light) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5) !important;
}

body.dark-theme .macro-prediction-item {
    color: var(--text-primary) !important;
}

body.dark-theme .macro-prediction-item.selected {
    background: var(--primary-light) !important;
    color: #93c5fd !important;
}

body.dark-theme .macro-prediction-shortcut {
    background: var(--bg-secondary) !important;
    color: #93c5fd !important;
}

body.dark-theme .macro-prediction-item.selected .macro-prediction-shortcut {
    background: var(--primary) !important;
    color: #ffffff !important;
}

body.dark-theme .macro-prediction-hint {
    background: var(--bg-secondary) !important;
    color: var(--text-muted) !important;
    border-top-color: var(--border-light) !important;
}

/* Phase 16 - signature chip + re-import nudge */
.sig-image-missing-chip {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    background: var(--amber-light);
    border: 1px solid var(--amber);
    color: #92400e;
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    gap: 4px;
}
body.dark-theme .sig-image-missing-chip {
    background: rgba(245, 158, 11, 0.08) !important;
    border-color: var(--amber) !important;
    color: #fbbf24 !important;
}

.sig-nudge-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--amber-light);
    border: 1px solid var(--amber-light);
    border-left: 3px solid var(--amber);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
}
.sig-nudge-icon {
    color: var(--amber);
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
    margin-top: 1px;
}
body.dark-theme .sig-nudge-banner {
    background: rgba(245, 158, 11, 0.06) !important;
    border-color: rgba(245, 158, 11, 0.3) !important;
    color: var(--text-primary) !important;
}
body.dark-theme .sig-nudge-banner .sig-nudge-icon {
    color: var(--amber) !important;
}
body.dark-theme .sig-nudge-banner p,
body.dark-theme .sig-nudge-banner strong {
    color: var(--text-primary) !important;
}

/* ============================================================
   Hyperlinks inside the message editors (paste-to-link feature)
   End-of-file so these win the cascade. The composer strips inline
   color styles, so anchors get their color from here — kept legible
   in both themes (a bright blue on dark, never the UA default navy).
   ============================================================ */
.reply-editor a,
.compose-editor a {
    color: var(--blue, #2563eb);
    text-decoration: underline;
    cursor: text;
}
body.dark-theme .reply-editor a,
body.dark-theme .compose-editor a {
    color: #6ab0ff !important;
}
