/* ==========================================================================
   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;

    --border: #e2e8f0;
    --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;
}

.sidebar-header {
    padding: 20px 16px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.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 {
    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;
}
.badge-blue {
    background: #3b82f6 !important;
    color: white !important;
}

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

.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);
}

/* Bulk Actions */
.bulk-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 24px;
    background: var(--blue-light);
    border-bottom: 1px solid var(--border);
}

.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;
}

.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;
}

.ticket-table tbody tr.sla-breach {
    background: #fff7ed;
    border-left: 3px solid #f97316;
}

.ticket-table tbody tr.sla-breach:hover {
    background: #ffedd5;
}

.ticket-table tbody tr.sla-breach .status-dot {
    box-shadow: 0 0 0 2px #f97316;
}

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

.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;
}

/* 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(--green); }
.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);
}

.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;
}

.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);
}

/* Tags in topbar */
.topbar-tags {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
}
/* Legacy — kept for fallback */
.ticket-tags-inline {
    display: none;
}

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

.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;
}

.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;
    right: 0;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    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;
}

/* 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;
    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(--border, #cbd5e1);
}

.msg-item.msg-outbound {
    border-left: 3px solid var(--blue, #3b82f6);
    background: #f8fbff;
}

.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;
}

.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;
}

.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;
}

/* --- 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;
}

/* 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;
}

/* 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);
}

/* 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: 120px;
    max-height: 400px;
    overflow-y: auto;
    padding: 12px 20px;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.6;
    outline: none;
    word-break: break-word;
}

.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 */
.reply-editor .signature-block {
    margin-top: 16px;
    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; }

/* 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);
}

/* 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;
}

.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;
}

.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);
}

/* ==========================================================================
   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-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: 8px;
    padding: 8px 16px;
    background: #fef3c7;
    border-bottom: 1px solid #f59e0b;
    color: #92400e;
    font-size: 13px;
    font-weight: 500;
}

/* ==========================================================================
   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: white;
    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: #f0f0f0;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Ticket cards */
.contact-ticket-card {
    background: white;
    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);
}

.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: grab;
}
tr[draggable="true"]:active {
    cursor: grabbing;
}
.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);
}

/* ==========================================================================
   ACTIVE FILTER BAR
   ========================================================================== */
.active-filters {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: #f0f4ff;
    border-bottom: 1px solid #e0e7ff;
    align-items: center;
    flex-wrap: wrap;
}
.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-remove {
    cursor: pointer;
    margin-left: 4px;
    font-size: 14px;
    opacity: 0.8;
    line-height: 1;
}
.filter-chip-remove:hover {
    opacity: 1;
}

/* 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 Manager Modal ---- */
.folder-manager-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.folder-manager-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

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

.folder-manager-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.folder-manager-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-white);
    padding: 1px 6px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.folder-manager-actions {
    display: flex;
    gap: 4px;
    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;
}
.btn-logout:hover { color: #f87171; }
.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: 10000;
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
#attachment-preview-overlay.ap-visible {
    opacity: 1;
}
.ap-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
}
.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-filename {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}
.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: center;
    min-height: 0;
    position: relative;
}
.ap-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    min-height: 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-nav {
    flex-shrink: 0;
    background: rgba(255,255,255,0.12);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 12px;
    transition: background 0.15s, transform 0.1s;
}
.ap-nav:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.08);
}
.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;
}
.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: grab;
}

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

/* ==========================================================================
   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;
    align-items: center;
    justify-content: center;
}
.message-iframe-placeholder:not([data-loaded])::before {
    content: 'Chargement...';
    color: var(--text-muted, #94a3b8);
    font-size: 12px;
}

/* ---- 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: grab;
}
#sidebar-folders li[draggable="true"]:active {
    cursor: grabbing;
}
#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: 640px;
    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;
    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: flex; flex-direction: column; gap: 12px; }
.team-card {
    background: var(--bg-secondary, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    padding: 16px;
}
.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; }
.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.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);
}

/* 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;
}

/* ---- 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: var(--sidebar-active, rgba(37,99,235,0.08));
    color: var(--primary, #2563eb);
    border-left-color: var(--primary, #2563eb);
}

/* ---- Notification Bell ---- */
.notif-bell-wrapper {
    position: relative;
    display: inline-flex;
}
.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: 1000;
    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-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;
}

/* 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-x: 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;
}
.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-children-count {
    font-size: 9px;
    color: var(--text-muted, #9ca3af);
    margin-top: 2px;
}

/* 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;
}
