/* ========================================
   AsysaCRM - Global Styles
   Elegant CRM Design System
   ======================================== */

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --success: #059669;
    --success-light: #ecfdf5;
    --warning: #d97706;
    --warning-light: #fffbeb;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --info: #0284c7;
    --info-light: #f0f9ff;
    --sidebar-width: 260px;
    --header-height: 56px;
    --border-color: #e5e7eb;
    --bg-main: #f9fafb;
    --bg-card: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-800);
    background: var(--bg-main);
    -webkit-font-smoothing: antialiased;
    height: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 50;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: var(--header-height);
}

.sidebar-brand .brand-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-brand .brand-name { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; }

.sidebar-section { padding: 16px 12px 8px; }

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255,255,255,0.4);
    padding: 0 8px;
    margin-bottom: 6px;
}

.sidebar-nav { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.7);
    font-size: 13.5px;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
}

.sidebar-nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav-item.active { background: var(--primary); color: #fff; }
.sidebar-nav-item i { width: 20px; text-align: center; font-size: 15px; flex-shrink: 0; }

.sidebar-nav-item .badge {
    margin-left: auto;
    background: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.9);
    padding: 1px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.sidebar-nav-item.active .badge { background: rgba(255,255,255,0.25); }

/* MAIN CONTENT */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* HEADER */
.top-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
}

.global-search { position: relative; flex: 1; max-width: 480px; }

.global-search input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--gray-50);
    transition: all 0.15s ease;
    color: var(--gray-800);
}

.global-search input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: #fff;
}

.global-search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray-400); font-size: 13px; }

.global-search .search-shortcut {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: var(--gray-100); border: 1px solid var(--gray-200);
    border-radius: 4px; padding: 1px 6px; font-size: 11px; color: var(--gray-500); font-weight: 500;
}

.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.header-btn {
    width: 36px; height: 36px; border: none; background: transparent;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--gray-500);
    display: flex; align-items: center; justify-content: center; font-size: 16px;
    transition: all 0.15s ease; position: relative;
}

.header-btn:hover { background: var(--gray-100); color: var(--gray-700); }

.header-btn .notification-dot {
    position: absolute; top: 6px; right: 6px; width: 8px; height: 8px;
    background: var(--danger); border-radius: 50%; border: 2px solid var(--bg-card);
}

.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; cursor: pointer;
}
.user-avatar-img {
    width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
    object-fit: cover; border: 2px solid var(--gray-200); transition: border-color .15s;
}
.user-avatar-img:hover { border-color: var(--primary); }
.header-dropdown-user-avatar-img {
    width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
    border: 2px solid var(--primary-light);
}

/* HEADER DROPDOWNS */
.header-dropdown-wrapper { position: relative; }

.header-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0; min-width: 320px;
    background: var(--white); border: 1px solid var(--gray-200); border-radius: 12px;
    box-shadow: 0 12px 36px rgba(0,0,0,.12); z-index: 1000; overflow: hidden;
}
.header-dropdown-right { right: 0; }

.header-dropdown-title {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; font-size: 13px; font-weight: 600; color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
}
.header-dropdown-badge {
    background: var(--primary); color: #fff; font-size: 11px; font-weight: 600;
    padding: 2px 8px; border-radius: 10px;
}

.header-dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    cursor: pointer; text-decoration: none; color: var(--gray-700); transition: background 0.12s;
}
.header-dropdown-item:hover { background: var(--gray-50); }
.header-dropdown-item-icon { width: 16px; color: var(--gray-400); font-size: 14px; flex-shrink: 0; }
.header-dropdown-item-title { font-size: 13px; font-weight: 500; color: var(--gray-800); }
.header-dropdown-item-sub { font-size: 11px; color: var(--gray-400); margin-top: 1px; }

.header-dropdown-item-danger .header-dropdown-item-icon { color: var(--danger); }
.header-dropdown-item-danger .header-dropdown-item-title { color: var(--danger); }
.header-dropdown-item-danger:hover { background: var(--danger-light); }

.header-dropdown-divider { height: 1px; background: var(--gray-100); margin: 4px 0; }

.header-dropdown-user {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
}
.header-dropdown-user-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.header-dropdown-user-name { font-size: 13px; font-weight: 600; color: var(--gray-800); }
.header-dropdown-user-email { font-size: 12px; color: var(--gray-400); }

.header-dropdown-empty {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 32px 16px; color: var(--gray-400); font-size: 13px;
}
.header-dropdown-empty i { font-size: 24px; }

a.header-btn {
    width: 36px; height: 36px; border: none; background: transparent;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--gray-500);
    display: flex; align-items: center; justify-content: center; font-size: 16px;
    transition: all 0.15s ease; position: relative; text-decoration: none;
}
a.header-btn:hover { background: var(--gray-100); color: var(--gray-700); }

/* LOGIN PAGE */
.login-container {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #0f0c29 0%, #1a1a2e 40%, #24243e 100%); padding: 24px;
    position: relative; overflow: hidden;
}
.login-container::before {
    content: ''; position: absolute; width: 600px; height: 600px;
    background: radial-gradient(circle, rgba(99,102,241,.15) 0%, transparent 70%);
    top: -200px; right: -100px; pointer-events: none;
}
.login-container::after {
    content: ''; position: absolute; width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(99,102,241,.1) 0%, transparent 70%);
    bottom: -100px; left: -50px; pointer-events: none;
}
.login-card {
    width: 100%; max-width: 440px; background: rgba(255,255,255,.97);
    border-radius: 20px; box-shadow: 0 25px 60px rgba(0,0,0,.3), 0 0 0 1px rgba(255,255,255,.1);
    overflow: hidden; position: relative; z-index: 1; backdrop-filter: blur(20px);
}
.login-logo {
    text-align: center; padding: 44px 24px 28px; position: relative;
}
.login-logo-glow {
    position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
    width: 80px; height: 80px; border-radius: 50%;
    background: radial-gradient(circle, rgba(99,102,241,.2) 0%, transparent 70%);
    pointer-events: none;
}
.login-logo-icon { width: 52px; height: 52px; object-fit: contain; margin-bottom: 14px; position: relative; }
.login-logo h1 { font-size: 24px; font-weight: 800; color: var(--gray-900); margin: 0; letter-spacing: -0.5px; }
.login-logo p { font-size: 13px; color: var(--gray-400); margin: 6px 0 0; font-weight: 400; }

.login-google-section { padding: 0 28px; margin-bottom: 4px; }
.login-google-btn {
    display: flex; align-items: center; justify-content: center; gap: 12px;
    width: 100%; padding: 12px 16px; border: 2px solid var(--gray-200);
    border-radius: 12px; background: #fff; color: var(--gray-700);
    font-size: 15px; font-weight: 600; font-family: inherit;
    cursor: pointer; transition: all .2s ease; text-decoration: none;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.login-google-btn:hover {
    border-color: var(--gray-300); background: var(--gray-50);
    box-shadow: 0 4px 12px rgba(0,0,0,.08); transform: translateY(-1px);
}
.login-google-btn:active { transform: translateY(0); box-shadow: 0 1px 3px rgba(0,0,0,.05); }

.login-divider {
    display: flex; align-items: center; gap: 16px; padding: 16px 28px;
    color: var(--gray-400); font-size: 12px; font-weight: 500;
}
.login-divider::before, .login-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--gray-200);
}

.login-form { padding: 0 28px 16px; display: flex; flex-direction: column; gap: 14px; }
.login-field label { font-size: 11px; font-weight: 600; color: var(--gray-600); margin-bottom: 5px; display: block; letter-spacing: .3px; text-transform: uppercase; }
.login-input-wrapper {
    position: relative; display: flex; align-items: center;
}
.login-input-wrapper i {
    position: absolute; left: 14px; color: var(--gray-400); font-size: 14px; transition: color .15s;
}
.login-input-wrapper input {
    width: 100%; padding: 12px 14px 12px 42px; border: 1.5px solid var(--gray-200);
    border-radius: 10px; font-size: 14px; font-family: inherit; color: var(--gray-800);
    background: var(--gray-50); transition: all 0.2s ease; outline: none;
}
.login-input-wrapper input:focus {
    border-color: var(--primary); background: var(--white);
    box-shadow: 0 0 0 4px rgba(99,102,241,.1);
}
.login-input-wrapper:focus-within i { color: var(--primary); }
.login-input-wrapper input::placeholder { color: var(--gray-300); }

.login-submit {
    width: 100%; padding: 13px; border: none; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: #fff; font-size: 14px; font-weight: 600;
    font-family: inherit; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 8px; transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(79,70,229,.25);
}
.login-submit:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #3730a3 100%);
    transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,70,229,.35);
}
.login-submit:active { transform: translateY(0); }

.login-security-badge {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 28px; color: var(--gray-400); font-size: 11px; font-weight: 500;
}
.login-security-badge i { color: #059669; font-size: 12px; }

.login-error {
    margin: 0 28px 12px; padding: 12px 16px; background: var(--danger-light);
    color: var(--danger); border-radius: 10px; font-size: 13px; font-weight: 500;
    display: flex; align-items: center; gap: 8px;
}

.login-hint {
    margin: 0 28px 16px; padding: 10px 14px; background: var(--info-light, rgba(56,189,248,.08));
    color: var(--gray-500); border-radius: 10px; font-size: 12px;
    display: flex; align-items: center; gap: 8px;
}
.login-hint i { color: var(--info, #38bdf8); }
.login-hint strong { color: var(--gray-700); }

.login-footer {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 16px; border-top: 1px solid var(--gray-100);
    font-size: 10px; font-weight: 500; color: var(--gray-300); letter-spacing: 1px;
    text-transform: uppercase;
}
.login-footer img { height: 14px; opacity: 0.3; }

/* PAGE CONTENT */
.page-content { flex: 1; overflow-y: auto; padding: 24px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.3px; }
.page-subtitle { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* 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; cursor: pointer; transition: all 0.15s ease; white-space: nowrap; font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: #fff; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; width: 32px; height: 32px; justify-content: center; }

/* CARDS */
.card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: space-between;
}

.card-title { font-size: 15px; font-weight: 600; color: var(--gray-800); }
.card-body { padding: 20px; }

/* STAT CARDS */
.stat-grid, .stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }

.stat-card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s ease;
    display: flex; align-items: center; gap: 12px;
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card .stat-icon {
    width: 36px; height: 36px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
}

.stat-card .stat-icon.purple { background: var(--primary-light); color: var(--primary); }
.stat-card .stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-card .stat-icon.amber { background: var(--warning-light); color: var(--warning); }
.stat-card .stat-icon.orange { background: var(--warning-light); color: var(--warning); }
.stat-card .stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-card .stat-icon.blue { background: var(--info-light); color: var(--info); }

.stat-value { font-size: 20px; font-weight: 700; color: var(--gray-900); letter-spacing: -0.3px; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--gray-500); margin-top: 1px; }

.stat-change { font-size: 12px; font-weight: 500; margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* TABLES */
.data-table-wrapper {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}

.table-toolbar {
    padding: 12px 16px; display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid var(--border-color); flex-wrap: wrap;
}

.table-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border-color); padding: 0 16px; background: var(--bg-card); }

.table-tab {
    padding: 10px 16px; font-size: 13px; font-weight: 500; color: var(--gray-500);
    border-bottom: 2px solid transparent; cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}

.table-tab:hover { color: var(--gray-700); }
.table-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.table-search { position: relative; }

.table-search input {
    padding: 6px 10px 6px 32px; border: 1px solid var(--gray-200); border-radius: var(--radius-sm);
    font-size: 13px; width: 240px; background: var(--gray-50); transition: all 0.15s ease;
}

.table-search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); background: #fff; }

.table-search i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--gray-400); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }

table th {
    padding: 10px 16px; font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--gray-500); text-align: left;
    border-bottom: 1px solid var(--border-color); background: var(--gray-50); white-space: nowrap;
}

table td { padding: 12px 16px; font-size: 13px; border-bottom: 1px solid var(--border-color); color: var(--gray-700); }
table tbody tr { transition: background 0.1s ease; }
table tbody tr:hover { background: var(--gray-50); }
table tbody tr:last-child td { border-bottom: none; }

.table-footer {
    position: relative;
    padding: 10px 16px; display: flex; align-items: center; justify-content: space-between;
    font-size: 13px; color: var(--gray-500); border-top: 1px solid var(--border-color);
}
/* Paginador centrado: deja libre la esquina inferior derecha donde flota el botón del chat IA,
   así el robot nunca tapa los controles de página (en cualquier ancho de pantalla). */
.table-pager {
    position: absolute; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 8px;
}

/* BADGES */
.badge-status {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px;
    border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap;
}

.badge-nuevo { background: var(--info-light); color: var(--info); }
.badge-enprogreso { background: var(--primary-light); color: var(--primary); }
.badge-esperando { background: var(--warning-light); color: var(--warning); }
.badge-resuelto { background: var(--success-light); color: var(--success); }
.badge-cerrado { background: var(--gray-100); color: var(--gray-500); }
/* Archivado: distinto de cerrado (gris plano) — tono slate con borde para "guardado, no resuelto". */
.badge-archivado { background: var(--gray-100); color: var(--gray-600); border: 1px dashed var(--gray-300); }
.badge-urgente { background: var(--danger-light); color: var(--danger); }
.badge-alta { background: #fff7ed; color: #ea580c; }
.badge-media { background: var(--warning-light); color: var(--warning); }
.badge-baja { background: var(--gray-100); color: var(--gray-500); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* AVATARS */
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600; color: #fff; flex-shrink: 0;
}

.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }
.avatar.purple { background: var(--primary); }
.avatar.green { background: var(--success); }
.avatar.amber { background: var(--warning); }
.avatar.red { background: var(--danger); }
.avatar.blue { background: var(--info); }
.avatar.gray { background: var(--gray-400); }

/* INBOX TRI-PANEL */
.inbox-layout { display: grid; grid-template-columns: var(--inbox-list-w, 320px) 6px 1fr 300px; height: calc(100vh - var(--header-height)); overflow: hidden; }
/* Divisor arrastrable entre la lista de conversaciones y el cuerpo del correo */
.inbox-resizer { cursor: col-resize; background: var(--border-color); position: relative; transition: background .15s; user-select: none; }
.inbox-resizer:hover, .inbox-resizer.dragging { background: var(--primary, #2563eb); }
.inbox-resizer::after { content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 2px; height: 28px; border-radius: 2px; background: rgba(255,255,255,.55); }
body.inbox-resizing { cursor: col-resize; user-select: none; }
body.inbox-resizing iframe { pointer-events: none; }

.inbox-list { border-right: 1px solid var(--border-color); background: var(--bg-card); display: flex; flex-direction: column; overflow: hidden; }
.inbox-conversations { flex: 1; overflow-y: auto; }
.inbox-empty { padding: 28px 16px; text-align: center; font-size: 13px; color: var(--gray-400); }

.inbox-list-header { padding: 16px; border-bottom: 1px solid var(--border-color); background: var(--bg-card); z-index: 5; flex-shrink: 0; }
.inbox-list-header h3 { font-size: 15px; font-weight: 600; margin: 0; }

.inbox-title-row {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}

/* Filter "+" button */
.inbox-filter-btn {
    width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border-color);
    background: var(--bg-card); color: var(--gray-500); cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 12px;
    transition: all .15s ease;
}
.inbox-filter-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* Filter dropdown */
.inbox-filter-dropdown {
    position: absolute; top: calc(100% + 6px); right: 0; z-index: 100;
    background: white; border: 1px solid var(--border-color);
    border-radius: 10px; box-shadow: 0 12px 36px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
    min-width: 220px; padding: 6px; overflow: hidden;
}
.inbox-filter-dropdown-title {
    padding: 8px 10px 6px; font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .8px; color: var(--gray-400);
}
.inbox-filter-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 7px; cursor: pointer;
    font-size: 13px; color: var(--gray-600); transition: all .12s ease;
}
.inbox-filter-item:hover { background: var(--gray-50); color: var(--gray-800); }
.inbox-filter-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.inbox-filter-item i { width: 16px; text-align: center; font-size: 12px; opacity: .7; }
.inbox-filter-item.active i { opacity: 1; }
.inbox-filter-count {
    margin-left: auto; font-size: 11px; font-weight: 600;
    min-width: 22px; height: 20px; display: flex; align-items: center; justify-content: center;
    border-radius: 10px; padding: 0 6px;
    background: var(--gray-100); color: var(--gray-500);
}
.inbox-filter-count.accent { background: var(--primary-light); color: var(--primary); font-weight: 700; }
.inbox-filter-count.danger { background: var(--danger-light); color: var(--danger); font-weight: 700; }
.inbox-filter-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

.inbox-views { display: flex; gap: 0; border-bottom: 1px solid var(--border-color); padding: 0 12px; }
.inbox-view-tab {
    padding: 9px 12px; font-size: 12px; font-weight: 500;
    color: var(--gray-500); border-bottom: 2px solid transparent;
    cursor: pointer; display: flex; align-items: center; gap: 6px;
    white-space: nowrap; transition: color .12s;
}
.inbox-view-tab:hover { color: var(--gray-700); }
.inbox-view-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.inbox-tab-badge {
    font-size: 10px; font-weight: 700; line-height: 1;
    min-width: 16px; height: 16px; padding: 0 4px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px; background: var(--gray-200); color: var(--gray-500);
}
.inbox-view-tab.active .inbox-tab-badge { background: var(--primary-light); color: var(--primary); }
.inbox-tab-badge.accent { background: var(--primary); color: white; }
.inbox-view-tab.active .inbox-tab-badge.accent { background: var(--primary); color: white; }

.inbox-item { padding: 12px 16px; border-bottom: 1px solid var(--border-color); cursor: pointer; transition: background 0.1s ease; }
.inbox-item:hover { background: var(--gray-50); }
.inbox-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }

.inbox-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; gap: 8px; }
.inbox-item-sender { font-size: 13px; font-weight: 600; color: var(--gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
/* Grupo derecho (iconos de estado + hora): no se encoge ni se recorta al angostar la columna */
.inbox-item-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.inbox-item-time { font-size: 11px; color: var(--gray-400); white-space: nowrap; }
.inbox-item-subject { font-size: 13px; color: var(--gray-700); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item-preview { font-size: 12px; color: var(--gray-400); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.inbox-detail { display: flex; flex-direction: column; overflow: hidden; background: var(--bg-card); }
.inbox-detail-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); }
.inbox-detail-header h2 { font-size: 16px; font-weight: 600; color: var(--gray-900); }

.inbox-messages { flex: 1; overflow-y: auto; padding: 16px 20px; }

.inbox-message { margin-bottom: 20px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--border-color); }
.inbox-message.incoming { background: var(--gray-50); }
.inbox-message.outgoing { background: var(--primary-50); border-color: var(--primary-100); }
.inbox-message.comment { background: var(--warning-light); border-color: #fde68a; }

.inbox-message-header { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.inbox-message-meta { flex: 1; }
.inbox-message-from { font-size: 13px; font-weight: 600; color: var(--gray-800); }
.inbox-message-date { font-size: 11px; color: var(--gray-400); }
.inbox-message-body { font-size: 13px; color: var(--gray-700); line-height: 1.65; word-wrap: break-word; overflow-wrap: anywhere; }
.inbox-message-body.is-text { white-space: pre-wrap; font-family: inherit; }
/* HTML emails are designed for light backgrounds: render them on white regardless of theme */
.inbox-message-body.is-html {
    background: #ffffff;
    color: #1f2937;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}
.inbox-message-body.is-html * { color: inherit; }
.inbox-message-body.is-html img { max-width: 100%; height: auto; border-radius: 4px; }
.inbox-message-body.is-html table { max-width: 100%; border-collapse: collapse; margin: 8px 0; }
.inbox-message-body.is-html td, .inbox-message-body.is-html th { padding: 4px 8px; }
.inbox-message-body.is-html a { color: #2563eb; text-decoration: underline; }
.inbox-message-body.is-html a:hover,
.inbox-message-body.is-html a:focus,
.inbox-message-body.is-html a:active,
.inbox-message-body.is-html a:visited { color: #1d4ed8; text-decoration: underline; }
.inbox-message-body.is-html p { margin: 0 0 10px 0; }
.inbox-message-body.is-html blockquote {
    border-left: 3px solid #e5e7eb; margin: 10px 0; padding: 4px 12px;
    color: #6b7280; font-size: 12px;
}
.inbox-message-body.is-html hr { display: none; }
.inbox-message-body.is-html pre { white-space: pre-wrap; background: #f3f4f6; padding: 8px; border-radius: 4px; }
/* Neutralize global table hover/striping inside email HTML (signatures use <table> for layout) */
.inbox-message-body.is-html table tbody tr:hover,
.inbox-message-body.is-html table tr:hover,
.inbox-message-body.is-html table tr:nth-child(even) { background: transparent !important; }
.inbox-message-body.is-html table td, .inbox-message-body.is-html table th { background: transparent !important; border-color: transparent !important; }

.inbox-reply { border-top: 1px solid var(--border-color); padding: 16px 20px; }
.inbox-reply textarea {
    width: 100%; min-height: 100px; padding: 12px; border: 1px solid var(--gray-200);
    border-radius: var(--radius); font-size: 13px; font-family: inherit; resize: vertical; margin-bottom: 10px;
}
.inbox-reply textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.inbox-reply-actions { display: flex; align-items: center; gap: 8px; }

/* Attachment chips */
.attachment-chips {
    display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px;
}
.attachment-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 6px;
    background: var(--gray-50); border: 1px solid var(--border-color);
    font-size: 12px; color: var(--gray-700); transition: all .12s;
}
.attachment-chip i { color: var(--primary); font-size: 11px; }
.attachment-chip-remove {
    width: 16px; height: 16px; border: none; background: var(--gray-200);
    border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 8px; color: var(--gray-500); margin-left: 2px; transition: all .12s;
}
.attachment-chip-remove:hover { background: var(--danger-light); color: var(--danger); }

/* Message attachments display */
.message-attachments {
    display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}
.message-attachment-link {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 6px;
    background: var(--primary-light); border: 1px solid transparent;
    font-size: 12px; color: var(--primary); text-decoration: none;
    font-weight: 500; transition: all .15s;
}
.message-attachment-link:hover { background: var(--primary-50); border-color: var(--primary); }
.message-attachment-link i { font-size: 12px; }

/* Template dropdown */
.template-dropdown {
    position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 100;
    background: white; border: 1px solid var(--border-color);
    border-radius: 10px; box-shadow: 0 12px 36px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
    width: 340px; padding: 6px; overflow: hidden;
    animation: ctxFadeIn .12s ease;
}
.template-dropdown-title {
    padding: 8px 10px 6px; font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .8px; color: var(--gray-400);
}
.template-item {
    padding: 9px 10px; border-radius: 7px; cursor: pointer;
    transition: all .12s ease;
}
.template-item:hover { background: var(--gray-50); }
.template-item-name {
    font-size: 13px; font-weight: 600; color: var(--gray-800);
    display: flex; align-items: center; gap: 6px; margin-bottom: 2px;
}
.template-item-name i { color: var(--primary); font-size: 11px; }
.template-item-preview {
    font-size: 11px; color: var(--gray-400); line-height: 1.4;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.inbox-context { border-left: 1px solid var(--border-color); overflow-y: auto; background: var(--bg-card); padding: 16px; }
.context-section { margin-bottom: 20px; }
.context-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gray-400); margin-bottom: 10px; }
.context-field { margin-bottom: 8px; }
.context-field-label { font-size: 11px; color: var(--gray-400); margin-bottom: 2px; }
.context-field-value { font-size: 13px; color: var(--gray-800); font-weight: 500; }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }

.form-input, .form-select, .form-textarea {
    width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm);
    font-size: 13px; font-family: inherit; color: var(--gray-800); background: #fff; transition: all 0.15s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-textarea { resize: vertical; min-height: 80px; }

/* DEAL PIPELINE BOARD */
.pipeline-board { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 16px; }

.pipeline-column {
    min-width: 280px; max-width: 300px; background: var(--gray-50);
    border-radius: var(--radius-lg); border: 1px solid var(--border-color); flex-shrink: 0;
}

.pipeline-column-header {
    padding: 12px 16px; font-size: 13px; font-weight: 600; color: var(--gray-700);
    display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-color);
}

.pipeline-column-header .count { background: var(--gray-200); color: var(--gray-600); padding: 1px 8px; border-radius: 10px; font-size: 11px; }

.pipeline-column-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; min-height: 100px; }

.pipeline-deal-card {
    background: #fff; border: 1px solid var(--border-color); border-radius: var(--radius);
    padding: 12px; cursor: pointer; transition: box-shadow 0.15s ease;
}

.pipeline-deal-card:hover { box-shadow: var(--shadow-md); }
.pipeline-deal-name { font-size: 13px; font-weight: 600; color: var(--gray-800); margin-bottom: 6px; }
.pipeline-deal-amount { font-size: 14px; font-weight: 700; color: var(--success); margin-bottom: 6px; }
.pipeline-deal-meta { font-size: 12px; color: var(--gray-400); display: flex; align-items: center; gap: 8px; }

/* DASHBOARD */
.dashboard-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 24px; }

@media (max-width: 1200px) { .dashboard-grid { grid-template-columns: 1fr; } }

.mini-chart { display: flex; align-items: flex-end; gap: 6px; height: 80px; padding-top: 8px; }
.mini-chart .bar { flex: 1; border-radius: 3px 3px 0 0; min-height: 4px; transition: height 0.3s ease; }
.mini-chart .bar.purple { background: var(--primary); }
.mini-chart .bar.green { background: var(--success); }

.progress-bar { height: 8px; background: var(--gray-100); border-radius: 4px; overflow: hidden; }
.progress-bar .fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }
.progress-bar .fill.purple { background: var(--primary); }
.progress-bar .fill.green { background: var(--success); }
.progress-bar .fill.amber { background: var(--warning); }

/* ACTIVITY LIST */
.activity-list { display: flex; flex-direction: column; }
.activity-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-color); }
.activity-item:last-child { border-bottom: none; }

.activity-icon {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}

.activity-content { flex: 1; min-width: 0; }
.activity-text { font-size: 13px; color: var(--gray-700); }
.activity-text strong { color: var(--gray-800); }
.activity-time { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* EMPTY STATE */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-state i { font-size: 48px; margin-bottom: 16px; display: block; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--gray-600); margin-bottom: 4px; }
.empty-state p { font-size: 13px; max-width: 300px; margin-inline: auto; }

/* ADMIN */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

.admin-card {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); padding: 20px; transition: box-shadow 0.15s ease; cursor: pointer;
}
.admin-card:hover { box-shadow: var(--shadow-md); }

.admin-card-icon {
    width: 44px; height: 44px; border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 14px;
}

.admin-card h3 { font-size: 14px; font-weight: 600; color: var(--gray-800); margin-bottom: 4px; }
.admin-card p { font-size: 12px; color: var(--gray-500); line-height: 1.5; }

/* UTILS */
.text-muted { color: var(--gray-500); }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-sm { font-size: 12px; }
.fw-600 { font-weight: 600; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem; color: white;
}
.blazor-error-boundary::after { content: "Ha ocurrido un error." }

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background: var(--danger, #dc3545);
    color: #fff;
    padding: 6px 16px;
    font-size: 13px;
    text-align: center;
}
#blazor-error-ui .reload { color: #fff; text-decoration: underline; margin-left: 8px; }
#blazor-error-ui .dismiss { color: #fff; cursor: pointer; position: absolute; right: 16px; top: 4px; font-size: 18px; text-decoration: none; }

.sidebar-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
}
.sidebar-footer-text {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
}
.sidebar-footer-logo {
    height: 16px;
    object-fit: contain;
    opacity: 0.6;
    filter: brightness(0) invert(1);
}

/* ========================================
   Contracts Module - Premium Styles
   ======================================== */

/* Contract type badge */
.contract-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: color-mix(in srgb, var(--ct-color, #6b7280) 12%, transparent);
    color: var(--ct-color, #6b7280);
    border: 1px solid color-mix(in srgb, var(--ct-color, #6b7280) 25%, transparent);
}

/* Signature indicators */
.signature-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.sig-complete { background: var(--success-light); color: var(--success); }
.sig-pending { background: var(--warning-light); color: var(--warning); }

/* Signature cards */
.signatures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.signature-card {
    padding: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    transition: all 0.2s;
}

.signature-card:hover { border-color: var(--gray-300); box-shadow: var(--shadow-sm); }
.sig-card-done { border-left: 3px solid var(--success); background: var(--success-light); }
.sig-card-rejected { border-left: 3px solid var(--danger); background: var(--danger-light); }

/* Contract detail grid */
.contract-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--gray-50);
    border-radius: var(--radius);
}

.detail-item { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: 11px; font-weight: 600; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.5px; }
.detail-value { font-size: 14px; color: var(--gray-800); }

/* Contract timeline */
.contract-timeline {
    display: flex;
    gap: 0;
    margin: 20px 0;
    padding: 16px 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.contract-timeline::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 20px;
    right: 20px;
    height: 2px;
    background: var(--gray-200);
    transform: translateY(-50%);
    z-index: 0;
}

.timeline-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
    z-index: 1;
}

.timeline-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--gray-300);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.timeline-done .timeline-dot {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}

.timeline-done .timeline-dot::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: 700;
}

.timeline-content { text-align: center; }
.timeline-title { font-size: 12px; font-weight: 600; color: var(--gray-700); display: block; }
.timeline-date { font-size: 11px; color: var(--gray-400); display: block; }

/* Section titles in modals */
.section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.mt-4 { margin-top: 16px; }
.mt-1 { margin-top: 4px; }

/* Contract types grid (config page) */
.contract-types-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.contract-type-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    padding: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: hidden;
}

.contract-type-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.ct-selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }

.ct-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
}

.ct-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--ct-accent, #6b7280) 12%, transparent);
    color: var(--ct-accent, #6b7280);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.ct-name { font-size: 14px; font-weight: 700; color: var(--gray-800); margin: 0; }
.ct-desc { font-size: 12px; color: var(--gray-500); margin: 2px 0 0; }

.ct-stats {
    display: flex;
    gap: 16px;
    padding: 10px 16px;
    background: var(--gray-50);
    border-top: 1px solid var(--border-color);
    align-items: center;
}

.ct-stat { display: flex; flex-direction: column; align-items: center; }
.ct-stat-value { font-size: 16px; font-weight: 700; color: var(--gray-800); }
.ct-stat-label { font-size: 10px; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.5px; }

/* Clauses list */
.clauses-list { display: flex; flex-direction: column; gap: 8px; }

.clause-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    transition: all 0.15s;
}

.clause-item:hover { border-color: var(--gray-300); }
.clause-inactive { opacity: 0.5; }

.clause-order {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.clause-content { flex: 1; min-width: 0; }
.clause-title { font-size: 13px; font-weight: 700; color: var(--gray-800); margin: 0 0 2px; }
.clause-text { font-size: 12px; color: var(--gray-500); line-height: 1.5; margin: 0; }

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 40px;
    text-align: center;
}

/* Module access grid (admin page) */
.module-access-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
}

.module-access-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--gray-50);
}

.module-name { font-size: 13px; font-weight: 600; min-width: 80px; }

/* Row active state */
.row-active { background: var(--primary-50) !important; }

/* Slide in animation */
.slide-in {
    animation: slideIn 0.25s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Modal Large */
.modal-lg {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: min(90vw, 800px);
    max-height: 90vh;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title { font-size: 18px; font-weight: 700; color: var(--gray-900); margin: 0; }

.modal-body { padding: 20px 24px; }

/* Admin grid improvements */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

/* ========================================
   EMAIL CONFIG
   ======================================== */
.email-provider-grid {
    display: flex; gap: 10px; flex-wrap: wrap;
}

.email-provider-btn {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 14px 24px; border-radius: var(--radius);
    border: 2px solid var(--border-color); background: var(--bg-card);
    cursor: pointer; transition: all 0.15s ease; font-size: 13px; color: var(--gray-600);
}

.email-provider-btn:hover { border-color: var(--primary-light); background: var(--gray-50); }
.email-provider-btn.active { border-color: var(--primary); background: var(--primary-light); color: var(--primary); font-weight: 600; }
.email-provider-btn i { font-size: 24px; }

.email-accounts-list { display: flex; flex-direction: column; }

.email-account-card {
    padding: 16px 20px; border-bottom: 1px solid var(--border-color);
    transition: background 0.1s;
}

.email-account-card:hover { background: var(--gray-50); }
.email-account-card:last-child { border-bottom: none; }
.email-account-inactive { opacity: 0.55; }

.email-account-main { display: flex; align-items: center; gap: 14px; }
.email-account-icon {
    width: 44px; height: 44px; border-radius: var(--radius);
    background: var(--gray-50); display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.email-account-info { flex: 1; min-width: 0; }

.email-account-actions {
    display: flex; gap: 4px; margin-top: 10px; padding-top: 8px;
    border-top: 1px dashed var(--border-color);
}

.email-account-error {
    margin-top: 8px; padding: 8px 12px; border-radius: var(--radius);
    background: var(--danger-light); color: var(--danger); font-size: 12px;
}

.email-account-result {
    margin-top: 8px; padding: 8px 12px; border-radius: var(--radius); font-size: 12px;
}

.email-account-result.result-ok { background: var(--success-light); color: var(--success); }
.email-account-result.result-error { background: var(--danger-light); color: var(--danger); }

.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: var(--success-light); color: var(--success); }
.alert-danger { background: var(--danger-light); color: var(--danger); }

/* ===== Inbox Enhancements ===== */

/* Assignment dropdown */
.dropdown-menu-custom {
    position: absolute; top: 100%; right: 0; z-index: 100;
    background: white; border: 1px solid var(--border-color);
    border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12);
    min-width: 240px; padding: 6px 0; margin-top: 4px;
}
.dropdown-header {
    padding: 8px 14px; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .5px; color: var(--gray-400);
}
.dropdown-item-custom {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px; cursor: pointer; font-size: 13px;
    transition: background .15s;
}
.dropdown-item-custom:hover { background: var(--gray-50); }
.dropdown-item-custom.active { background: var(--primary-light); }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

/* Close-ticket summary card */
.close-ticket-summary {
    background: var(--gray-50); padding: 16px; border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

/* SLA indicator */
.sla-indicator {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
}
.sla-ok { background: var(--success-light); color: var(--success); }
.sla-warn { background: #fff8e1; color: #f59e0b; }
.sla-breach { background: var(--danger-light); color: var(--danger); }

/* Context ticket card */
.context-ticket-card {
    padding: 10px 12px; border-radius: var(--radius);
    border: 1px solid var(--border-color); background: white;
    margin-bottom: 8px; transition: box-shadow .15s;
}
.context-ticket-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.06); }

/* Closed conversation item */
.inbox-item-closed { opacity: .55; }

/* Unread conversation item */
.inbox-item-unread .inbox-item-sender { font-weight: 700; color: var(--gray-900); }
.inbox-item-unread .inbox-item-subject { font-weight: 600; color: var(--gray-800); }
.inbox-item { position: relative; }
.unread-dot {
    position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
    width: 8px; height: 8px; border-radius: 50%; background: var(--primary);
    box-shadow: 0 0 0 2px var(--bg-card);
}
.inbox-item-unread { padding-left: 22px; }

/* Dropdown backdrop (close on outside click) */
.dropdown-backdrop {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 99; background: transparent;
}

/* Context menu (right-click) */
.ctx-menu-backdrop {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9998; background: transparent;
}
.ctx-menu {
    position: fixed; z-index: 9999;
    background: white; border: 1px solid var(--border-color);
    border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.15);
    min-width: 200px; padding: 4px 0;
    animation: ctxFadeIn .12s ease;
}
@keyframes ctxFadeIn {
    from { opacity: 0; transform: scale(.96); }
    to { opacity: 1; transform: scale(1); }
}
.ctx-menu-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px; cursor: pointer; font-size: 13px;
    color: var(--gray-700); transition: background .12s;
}
.ctx-menu-item:hover { background: var(--gray-50); color: var(--gray-900); }
.ctx-menu-item i { width: 16px; text-align: center; color: var(--gray-400); font-size: 12px; }
.ctx-menu-item:hover i { color: var(--primary); }
.ctx-menu-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

/* Utilities */
.text-xs { font-size: 11px; }
.mt-3 { margin-top: 12px; }
.fw-700 { font-weight: 700; }

/* ========================================
   DARK MODE
   ======================================== */
[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: rgba(99,102,241,.15);
    --primary-50: rgba(99,102,241,.1);
    --primary-100: rgba(99,102,241,.18);
    --primary-500: #818cf8;
    --primary-600: #6366f1;
    --primary-700: #4f46e5;
    --gray-50: #1e1e2e;
    --gray-100: #252538;
    --gray-200: #2e2e42;
    --gray-300: #3b3b52;
    --gray-400: #6b6b80;
    --gray-500: #9494a8;
    --gray-600: #b0b0c2;
    --gray-700: #cdcde0;
    --gray-800: #e2e2f0;
    --gray-900: #f0f0f8;
    --success: #34d399;
    --success-light: rgba(52,211,153,.12);
    --warning: #fbbf24;
    --warning-light: rgba(251,191,36,.1);
    --danger: #f87171;
    --danger-light: rgba(248,113,113,.1);
    --info: #38bdf8;
    --info-light: rgba(56,189,248,.1);
    --border-color: #2e2e42;
    --bg-main: #141420;
    --bg-card: #1a1a2e;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,.5);
    --shadow-lg: 0 10px 25px rgba(0,0,0,.6);
    color-scheme: dark;
}

[data-theme="dark"] body { color: var(--gray-800); }

[data-theme="dark"] .sidebar { background: #0f0f1a; border-right: 1px solid var(--border-color); }

[data-theme="dark"] .global-search input { background: var(--gray-100); border-color: var(--border-color); color: var(--gray-800); }
[data-theme="dark"] .global-search input:focus { background: var(--bg-card); }
[data-theme="dark"] .global-search .search-shortcut { background: var(--gray-200); border-color: var(--gray-300); color: var(--gray-500); }

[data-theme="dark"] .btn-secondary { background: var(--gray-100); color: var(--gray-700); border-color: var(--gray-300); }
[data-theme="dark"] .btn-secondary:hover { background: var(--gray-200); }
[data-theme="dark"] .btn-ghost:hover { background: var(--gray-200); }

[data-theme="dark"] .form-input,
[data-theme="dark"] .form-select,
[data-theme="dark"] .form-textarea,
[data-theme="dark"] .inbox-reply textarea,
[data-theme="dark"] .table-search input { background: var(--gray-100); border-color: var(--gray-300); color: var(--gray-800); }
[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="dark"] .form-textarea:focus,
[data-theme="dark"] .inbox-reply textarea:focus,
[data-theme="dark"] .table-search input:focus { background: var(--bg-card); border-color: var(--primary); }

[data-theme="dark"] table th { background: var(--gray-100); }

[data-theme="dark"] .pipeline-column { background: var(--gray-100); }
[data-theme="dark"] .pipeline-deal-card { background: var(--bg-card); }

[data-theme="dark"] .dropdown-menu-custom { background: var(--bg-card); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
[data-theme="dark"] .dropdown-item-custom:hover { background: var(--gray-100); }
[data-theme="dark"] .inbox-filter-dropdown { background: var(--bg-card); box-shadow: 0 12px 36px rgba(0,0,0,.5); }
[data-theme="dark"] .inbox-filter-item:hover { background: var(--gray-100); }
[data-theme="dark"] .inbox-filter-count { background: var(--gray-200); color: var(--gray-500); }
[data-theme="dark"] .inbox-filter-btn { background: var(--gray-100); border-color: var(--gray-300); }
[data-theme="dark"] .inbox-tab-badge { background: var(--gray-300); color: var(--gray-500); }
[data-theme="dark"] .context-ticket-card { background: var(--bg-card); }
[data-theme="dark"] .close-ticket-summary { background: var(--gray-100); }

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.55);
    animation: crm-modal-fade .2s ease-out;
}
@keyframes crm-modal-fade { from { opacity: 0; } to { opacity: 1; } }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.7); }

[data-theme="dark"] .ctx-menu { background: var(--bg-card); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
[data-theme="dark"] .ctx-menu-item:hover { background: var(--gray-100); }
[data-theme="dark"] .inbox-item-unread .inbox-item-sender { color: var(--gray-900); }
[data-theme="dark"] .inbox-item-unread .inbox-item-subject { color: var(--gray-800); }
[data-theme="dark"] .template-dropdown { background: var(--bg-card); box-shadow: 0 12px 36px rgba(0,0,0,.5); }
[data-theme="dark"] .template-item:hover { background: var(--gray-100); }
[data-theme="dark"] .attachment-chip { background: var(--gray-100); border-color: var(--gray-300); }
[data-theme="dark"] .attachment-chip-remove { background: var(--gray-300); }
[data-theme="dark"] .message-attachment-link { background: rgba(99,102,241,.12); }

[data-theme="dark"] .sla-warn { background: rgba(251,191,36,.1); color: #fbbf24; }

[data-theme="dark"] .header-dropdown { background: var(--bg-card); border-color: var(--border-color); box-shadow: 0 12px 36px rgba(0,0,0,.5); }
[data-theme="dark"] .header-dropdown-title { border-color: var(--border-color); }
[data-theme="dark"] .header-dropdown-item:hover { background: var(--gray-100); }
[data-theme="dark"] .header-dropdown-divider { background: var(--border-color); }
[data-theme="dark"] .header-dropdown-item-danger:hover { background: rgba(248,113,113,.1); }
[data-theme="dark"] a.header-btn:hover { background: var(--gray-200); color: var(--gray-700); }

[data-theme="dark"] .login-card { background: var(--bg-card); box-shadow: 0 12px 40px rgba(0,0,0,.4); }
[data-theme="dark"] .login-user-card { background: var(--gray-100); }
[data-theme="dark"] .login-user-card:hover { background: rgba(99,102,241,.1); border-color: var(--primary); }
[data-theme="dark"] .login-footer { border-color: var(--border-color); }

[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--gray-300); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Theme toggle button */
.theme-toggle {
    width: 36px; height: 36px; border: none; background: transparent;
    border-radius: var(--radius-sm); cursor: pointer; color: var(--gray-500);
    display: flex; align-items: center; justify-content: center; font-size: 16px;
    transition: all 0.15s ease; position: relative;
}
.theme-toggle:hover { background: var(--gray-100); color: var(--gray-700); }
[data-theme="dark"] .theme-toggle:hover { background: var(--gray-200); }

/* ===== EMPRESAS — Cards, Domains, Detail ===== */
.emp-form-card { background: var(--surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); margin-bottom: 20px; overflow: hidden; }
.emp-form-header { padding: 14px 20px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border-color); background: var(--gray-50); color: var(--text-primary); }
.emp-form-body { padding: 20px; }
.emp-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.emp-form-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-color); }

.emp-domain-add-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.emp-domains-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.emp-domain-chip { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--gray-50); border: 1px solid var(--border-color); border-radius: 20px; font-size: 13px; transition: all .15s; }
.emp-domain-chip:hover { border-color: var(--primary); background: rgba(99,102,241,.05); }
.emp-domain-chip-url { font-weight: 500; color: var(--text-primary); }
.emp-domain-chip-tipo { font-size: 11px; color: var(--text-muted); background: var(--gray-100); padding: 1px 8px; border-radius: 10px; }
.emp-domain-chip-remove { border: none; background: none; cursor: pointer; color: var(--text-muted); font-size: 11px; padding: 2px; line-height: 1; border-radius: 50%; transition: all .15s; }
.emp-domain-chip-remove:hover { color: var(--danger); background: rgba(239,68,68,.1); }

.emp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.emp-card { background: var(--surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; transition: all .2s; }
.emp-card:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(99,102,241,.1); transform: translateY(-2px); }
.emp-card-top { display: flex; align-items: center; gap: 12px; padding: 16px; cursor: pointer; }
.emp-card-avatar { width: 44px; height: 44px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; flex-shrink: 0; }
.emp-card-info { flex: 1; min-width: 0; }
.emp-card-name { font-weight: 700; font-size: 15px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emp-card-industry { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.emp-card-actions { display: flex; gap: 2px; flex-shrink: 0; }

.emp-card-stats { display: flex; border-top: 1px solid var(--border-color); }
.emp-card-stat { flex: 1; text-align: center; padding: 8px 0; font-size: 12px; color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 5px; border-right: 1px solid var(--border-color); }
.emp-card-stat:last-child { border-right: none; }
.emp-card-stat i { font-size: 11px; opacity: .7; }
.emp-card-stat-contract { color: var(--success); font-weight: 600; }
.emp-card-stat-contract i { opacity: 1; }

.emp-card-domains { padding: 8px 16px 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.emp-domain-tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; font-size: 11px; background: var(--gray-50); border: 1px solid var(--border-color); border-radius: 12px; color: var(--text-secondary); }
.emp-domain-tag i { font-size: 10px; color: var(--primary); }
.emp-domain-tag-more { font-size: 11px; color: var(--text-muted); padding: 3px 8px; }

/* Detail */
.emp-detail-card { background: var(--surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 28px 20px; text-align: center; margin-bottom: 16px; }
.emp-detail-avatar { width: 72px; height: 72px; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; color: #fff; margin: 0 auto 14px; }
.emp-detail-name { font-weight: 700; font-size: 20px; color: var(--text-primary); margin-bottom: 4px; }
.emp-detail-industry { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; justify-content: center; gap: 5px; margin-bottom: 16px; }
.emp-detail-fields { text-align: left; display: grid; gap: 10px; font-size: 13px; }
.emp-detail-field { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.emp-detail-field i { width: 18px; text-align: center; color: var(--text-muted); }

/* Domains sidebar card */
.emp-domains-card { background: var(--surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.emp-domains-card-header { padding: 12px 16px; font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); }
.emp-domain-add-inline { display: flex; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border-color); background: var(--gray-
/* ====== Rich text editor (comentarios de tickets) ====== */
.rich-editor-wrap {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface, #fff);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.rich-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--border-color);
}
.rich-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--gray-500, #555);
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
}
.rich-btn:hover {
    background: var(--gray-100);
    color: var(--primary, #6366f1);
    border-color: var(--gray-200);
}
.rich-btn:active { background: var(--gray-200); }
.rich-toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border-color);
    margin: 0 4px;
}
.rich-editor-content {
    min-height: 110px;
    max-height: 320px;
    overflow-y: auto;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--gray-700, #222);
    outline: none;
    background: var(--surface, #fff);
}
.rich-editor-content:empty::before {
    content: attr(data-placeholder);
    color: var(--gray-400);
    pointer-events: none;
}
.rich-editor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    display: inline-block;
}
.rich-editor-content blockquote {
    border-left: 3px solid var(--gray-300);
    margin: 6px 0;
    padding: 4px 10px;
    color: var(--gray-500);
}
.rich-editor-content a { color: var(--primary, #6366f1); text-decoration: underline; }
.rich-editor-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--gray-50);
}
.rich-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--surface, #fff);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    font-size: 11.5px;
    color: var(--gray-700, #333);
    max-width: 220px;
}
.rich-attachment-chip .chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.rich-attachment-chip .chip-remove {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--gray-400);
    padding: 0 2px;
    font-size: 11px;
}
.rich-attachment-chip .chip-remove:hover { color: var(--danger, #dc2626); }
.rich-editor-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    background: var(--gray-50);
}

[data-theme="dark"] .rich-editor-wrap { background: var(--surface); }
[data-theme="dark"] .rich-editor-toolbar,
[data-theme="dark"] .rich-editor-attachments,
[data-theme="dark"] .rich-editor-footer { background: var(--gray-100); }
[data-theme="dark"] .rich-editor-content { background: var(--surface); color: var(--gray-700); }
[data-theme="dark"] .rich-btn { color: var(--gray-500); }
[data-theme="dark"] .rich-btn:hover { background: var(--gray-200); }
50); }
.emp-domains-detail-list { padding: 4px 0; }
.emp-domain-item { display: flex; align-items: center; gap: 10px; padding: 8px 16px; transition: background .15s; }
.emp-domain-item:hover { background: var(--gray-50); }
.emp-domain-inactive { opacity: .5; }
.emp-domain-icon { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: rgba(99,102,241,.08); font-size: 13px; }
.emp-domain-info { flex: 1; min-width: 0; }
.emp-domain-url { font-weight: 500; font-size: 13px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emp-domain-tipo { font-size: 11px; color: var(--text-muted); }
.emp-domain-actions { display: flex; gap: 2px; flex-shrink: 0; }
.emp-domains-empty { padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 12px; line-height: 1.8; }

/* ===== UNIFIED CRM MODAL SYSTEM ===== */
.crm-modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    animation: crm-modal-slide .25s ease-out;
}
@keyframes crm-modal-slide { from { opacity: 0; transform: translateY(-12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.crm-modal-sm { width: 420px; }
.crm-modal-md { width: 600px; }
.crm-modal-lg { width: min(90vw, 800px); }
.crm-modal-xl { width: min(92vw, 960px); }
.crm-modal-xxl { width: min(96vw, 1280px) !important; max-height: 90vh !important; overflow: hidden !important; }

/* ===== TICKET DETAIL MODAL ===== */
.ticket-detail { display: grid !important; grid-template-columns: 1fr 340px !important; gap: 0; flex: 1; min-height: 0; overflow: hidden; }
.ticket-main { display: flex; flex-direction: column; overflow: hidden; min-height: 0; min-width: 0; }
.ticket-main-scroll { flex: 1; overflow-y: auto; padding: 24px; min-height: 0; }
.ticket-sidebar { overflow-y: auto; padding: 20px; background: var(--gray-50); border-left: 1px solid var(--border-color); min-height: 0; }

/* Ticket info header */
.ticket-info-bar {
    display: flex; flex-wrap: wrap; gap: 12px; padding: 12px 16px;
    background: var(--gray-50); border-radius: var(--radius); margin-bottom: 20px;
    border: 1px solid var(--border-color); align-items: center;
}
.ticket-info-chip {
    display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--gray-600);
}
.ticket-info-chip i { font-size: 11px; color: var(--gray-400); }
.ticket-info-chip strong { color: var(--gray-800); font-weight: 600; }
.ticket-info-divider { width: 1px; height: 20px; background: var(--border-color); }

/* Description block */
.ticket-description {
    background: #fff; border: 1px solid var(--border-color); border-radius: var(--radius);
    padding: 16px 20px; margin-bottom: 24px; font-size: 13px; line-height: 1.7;
    color: var(--gray-700); white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow-y: auto;
}

/* Activity thread */
.ticket-thread { margin-bottom: 20px; }
.ticket-thread-title {
    font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 12px;
    display: flex; align-items: center; gap: 8px;
}
.ticket-thread-title .count-badge {
    background: var(--primary-light); color: var(--primary); font-size: 11px; font-weight: 700;
    padding: 1px 8px; border-radius: 10px;
}

.thread-item {
    display: flex; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border-color);
}
.thread-item:last-child { border-bottom: none; }
.thread-avatar {
    width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; flex-shrink: 0; color: #fff;
}
.thread-avatar.agent { background: var(--primary); }
.thread-avatar.system { background: var(--gray-300); color: var(--gray-600); }
.thread-avatar.time { background: var(--success); }
.thread-body { flex: 1; min-width: 0; }
.thread-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.thread-author { font-size: 13px; font-weight: 600; color: var(--gray-800); }
.thread-type {
    font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
    padding: 2px 6px; border-radius: 4px;
}
.thread-type.comment { background: var(--primary-light); color: var(--primary); }
.thread-type.time-entry { background: rgba(16,185,129,.1); color: var(--success); }
.thread-type.status-change { background: rgba(245,158,11,.1); color: #d97706; }
.thread-date { font-size: 11px; color: var(--gray-400); margin-left: auto; }
.thread-text { font-size: 13px; color: var(--gray-700); line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

/* Reply box */
.ticket-reply-box {
    border-top: 1px solid var(--border-color); padding: 16px 24px; background: var(--gray-50);
    flex-shrink: 0;
}
.ticket-reply-tabs { display: flex; gap: 0; margin-bottom: 10px; }
.ticket-reply-tab {
    padding: 6px 14px; font-size: 12px; font-weight: 600; color: var(--gray-400);
    cursor: pointer; border-bottom: 2px solid transparent; transition: all .15s;
}
.ticket-reply-tab:hover { color: var(--gray-600); }
.ticket-reply-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.ticket-reply-input {
    width: 100%; min-height: 70px; max-height: 160px; resize: vertical; padding: 10px 14px;
    border: 1px solid var(--border-color); border-radius: var(--radius); font-size: 13px;
    font-family: inherit; color: var(--gray-800); background: #fff; transition: border-color .15s;
}
.ticket-reply-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.ticket-reply-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }

/* Sidebar sections */
.sidebar-section { margin-bottom: 20px; }
.sidebar-section-title {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--gray-400); margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border-color);
}
.sidebar-field { margin-bottom: 10px; }
.sidebar-field-label { font-size: 11px; color: var(--gray-400); margin-bottom: 3px; }
.sidebar-field-value { font-size: 13px; color: var(--gray-800); font-weight: 500; }

/* Time tracking mini */
.time-input-row {
    display: grid; grid-template-columns: 60px 1fr; gap: 6px; margin-bottom: 6px;
}
.time-input-row .form-input { font-size: 12px; padding: 5px 8px; }
.crm-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.crm-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
.crm-modal-title i { color: var(--primary); font-size: 15px; }
.crm-modal-title .modal-icon-danger { color: var(--danger); }
.crm-modal-body { padding: 20px; }
.crm-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}
/* Backward compat aliases */
.emp-edit-modal { background: var(--bg-card); border-radius: var(--radius-lg); width: 680px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: crm-modal-slide .25s ease-out; }
.emp-edit-modal-header { padding: 16px 20px; font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); justify-content: space-between; }
.emp-edit-modal-header i { color: var(--primary); }
.emp-edit-modal-body { padding: 20px; }

/* Dark mode overrides */
[data-theme="dark"] .emp-form-header { background: var(--gray-100); }
[data-theme="dark"] .emp-domain-chip { background: var(--gray-100); border-color: var(--gray-200); }
[data-theme="dark"] .emp-domain-chip:hover { background: rgba(99,102,241,.12); }
[data-theme="dark"] .emp-domain-chip-tipo { background: var(--gray-200); }
[data-theme="dark"] .emp-card { background: var(--surface); }
[data-theme="dark"] .emp-card:hover { box-shadow: 0 4px 16px rgba(99,102,241,.15); }
[data-theme="dark"] .emp-domain-tag { background: var(--gray-100); border-color: var(--gray-200); }
[data-theme="dark"] .emp-domain-add-inline { background: var(--gray-100); }
[data-theme="dark"] .emp-domain-item:hover { background: var(--gray-100); }
[data-theme="dark"] .emp-domain-icon { background: rgba(99,102,241,.15); }
[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,.7); }
[data-theme="dark"] .crm-modal, [data-theme="dark"] .emp-edit-modal { box-shadow: 0 20px 60px rgba(0,0,0,.5); }

/* ====== Firma Preview & Google Button ====== */
.firma-preview {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 20px;
    min-height: 120px;
}

/* ====== HubSpot-style Send From & Signature ====== */
.hubspot-send-from {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    align-items: start;
}
.hubspot-send-left {}
.hubspot-send-right {}
.hs-preview-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--gray-800);
    margin: 0 0 6px;
}
.hs-preview-desc {
    font-size: 13px;
    color: var(--gray-500);
    margin: 0 0 16px;
    line-height: 1.5;
}
.hs-info-icon {
    color: var(--gray-400);
    font-size: 13px;
    cursor: help;
    margin-left: 4px;
}
.hs-from-preview-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.hs-tag-agent {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--primary-lighter, #e8f0fe);
    color: var(--primary);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 4px;
    white-space: nowrap;
    border: 1px solid var(--primary-light, #b6d4fe);
}
.hs-de-label {
    font-size: 14px;
    color: var(--gray-500);
    font-weight: 500;
}

/* Email preview card (HubSpot style) */
.hs-email-preview-card {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.hs-email-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.hs-email-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--primary-lighter, #e8f0fe);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.hs-email-from-name {
    font-size: 15px;
    color: var(--gray-800);
}
.hs-email-from-addr {
    font-size: 13px;
    color: var(--gray-400);
}

/* Simulated email body lines */
.hs-email-body-lines {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}
.hs-line {
    height: 10px;
    border-radius: 5px;
    background: #f0f2f5;
}
.hs-line-long { width: 85%; }
.hs-line-full { width: 100%; }
.hs-line-medium { width: 65%; }
.hs-line-short { width: 40%; }

/* Firma inside email preview */
.hs-email-firma-preview {
    border-top: 1px solid var(--gray-200);
    padding-top: 16px;
    margin-top: 4px;
}
.hs-email-logo {
    text-align: center;
    padding-top: 14px;
    border-top: 1px solid var(--gray-100);
    margin-top: 14px;
}

/* Firma section (left/right split) */
.hubspot-firma-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    align-items: start;
}
.hubspot-firma-left {}
.hubspot-firma-right {}
.btn-google {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    color: #ea4335;
    border: 2px solid #ea4335;
    border-radius: 6px;
    padding: 8px 18px;
    font-weight: 600;
    font-size: .95rem;
    cursor: pointer;
    transition: background .2s, color .2s;
}
.btn-google:hover {
    background: #ea4335;
    color: #fff;
}
.firma-tabs { display: flex; gap: 0; margin-bottom: 12px; }
.firma-tab {
    padding: 6px 16px;
    border: 1px solid var(--gray-300);
    background: var(--gray-50);
    cursor: pointer;
    font-size: .85rem;
    font-weight: 500;
    transition: background .15s;
}
.firma-tab:first-child { border-radius: 6px 0 0 6px; }
.firma-tab:last-child { border-radius: 0 6px 6px 0; }
.firma-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ========================================
   TEMPLATE EDITOR - Professional Design
   ======================================== */

/* Filter buttons */
.tpl-filter-btn {
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--gray-200);
    background: white;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    transition: all .2s;
}
.tpl-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.tpl-filter-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Template cards grid */
.tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}
.tpl-card {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    overflow: hidden;
    cursor: pointer;
    transition: all .25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}
.tpl-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.08);
    border-color: var(--gray-300);
}
.tpl-card-accent {
    height: 4px;
    width: 100%;
}
.tpl-card-body { padding: 20px; }
.tpl-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}
.tpl-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.tpl-card-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .2s;
}
.tpl-card:hover .tpl-card-actions { opacity: 1; }
.tpl-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-800);
    margin: 0 0 6px;
}
.tpl-card-subject {
    font-size: 12px;
    color: var(--gray-500);
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tpl-card-preview {
    font-size: 13px;
    color: var(--gray-500);
    line-height: 1.5;
    margin: 0 0 16px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tpl-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--gray-100);
}
.tpl-card-cat {
    background: var(--gray-100);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.tpl-card-date {
    font-size: 11px;
    color: var(--gray-400);
}

/* Empty state */
.tpl-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}
.tpl-empty i { font-size: 48px; margin-bottom: 12px; display: block; }
.tpl-empty p { margin: 0 0 16px; font-size: 14px; }

/* ======= Template Editor Modal ======= */
.tpl-editor-modal {
    width: min(96vw, 1200px) !important;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
}
.tpl-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #f8f9ff 0%, #fff 100%);
    border-bottom: 1px solid var(--gray-200);
}
.tpl-editor-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.tpl-editor-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.tpl-editor-left {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    border-right: 1px solid var(--gray-200);
}
.tpl-editor-right {
    display: flex;
    flex-direction: column;
    background: var(--gray-50);
    overflow-y: auto;
}

/* Config section */
.tpl-config-section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-100);
}
.tpl-config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* Visual config */
.tpl-visual-config {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-100);
}
.tpl-color-picker {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.tpl-color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all .2s;
}
.tpl-color-dot:hover { transform: scale(1.2); }
.tpl-color-dot.active { border-color: var(--gray-800); box-shadow: 0 0 0 2px white, 0 0 0 4px var(--gray-400); }

.tpl-icon-picker {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.tpl-icon-opt {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--gray-500);
    transition: all .2s;
}
.tpl-icon-opt:hover { border-color: var(--primary); color: var(--primary); }
.tpl-icon-opt.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Toolbar */
.tpl-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 24px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
}
.tpl-toolbar-group { display: flex; gap: 2px; align-items: center; }
.tpl-toolbar-sep { width: 1px; height: 24px; background: var(--gray-200); margin: 0 6px; }
.tpl-tb-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--gray-600);
    transition: all .15s;
}
.tpl-tb-btn:hover { background: var(--gray-200); color: var(--gray-800); }
.tpl-var-btn {
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px dashed var(--primary-light);
    background: rgba(102, 126, 234, 0.06);
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    font-family: 'SF Mono', 'Fira Code', monospace;
}
.tpl-var-btn:hover { background: rgba(102, 126, 234, 0.15); border-style: solid; }

/* Editor area */
.tpl-editor-area { flex: 1; min-height: 250px; padding: 0; }
.tpl-textarea {
    width: 100%;
    height: 100%;
    min-height: 250px;
    border: none;
    outline: none;
    padding: 20px 24px;
    font-size: 14px;
    font-family: 'Inter', -apple-system, sans-serif;
    line-height: 1.7;
    resize: none;
    color: var(--gray-800);
    background: white;
}
.tpl-textarea::placeholder { color: var(--gray-300); }

/* Image attached bar */
.tpl-image-attached {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 24px;
    background: #f0f5ff;
    border-top: 1px solid #d6e0ff;
    font-size: 12px;
    color: var(--primary);
}
.tpl-image-link { color: var(--primary); text-decoration: underline; font-weight: 600; }

/* Image modal options */
.tpl-img-options { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.tpl-img-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--gray-600);
    cursor: pointer;
}

/* Image upload tabs & zone */
.img-upload-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    overflow: hidden;
}
.img-upload-tab {
    flex: 1;
    padding: 10px 12px;
    border: none;
    background: var(--gray-50);
    color: var(--gray-500);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all .15s;
}
.img-upload-tab:first-child { border-right: 1px solid var(--gray-200); }
.img-upload-tab.active {
    background: var(--primary);
    color: #fff;
}
.img-upload-tab:not(.active):hover { background: var(--gray-100); }

.img-upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: 10px;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .2s, background .2s;
}
.img-upload-zone.uploading {
    border-color: var(--primary);
    background: rgba(99,102,241,.04);
}

.img-upload-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 100%;
    min-height: 160px;
    cursor: pointer;
    padding: 24px;
    text-align: center;
}
.img-upload-dropzone i {
    font-size: 32px;
    color: var(--primary);
    opacity: .7;
}
.img-upload-dropzone:hover i { opacity: 1; }
.img-upload-text {
    font-size: 13px;
    color: var(--gray-600);
}
.img-upload-text strong { color: var(--primary); }
.img-upload-hint {
    font-size: 11px;
    color: var(--gray-400);
}

.img-upload-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--primary);
    font-size: 14px;
}
.img-upload-progress i { font-size: 24px; }

.img-upload-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px;
    width: 100%;
}
.img-upload-preview img {
    max-width: 100%;
    max-height: 180px;
    border-radius: 8px;
    object-fit: contain;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.img-upload-preview-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    justify-content: center;
}
.img-upload-filename {
    font-size: 12px;
    color: var(--gray-500);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.img-upload-error {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    background: rgba(239,68,68,.08);
    color: #dc2626;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ======= Preview panel ======= */
.tpl-preview-header {
    padding: 14px 20px;
    font-size: 12px;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 8px;
}
.tpl-preview-content {
    padding: 20px;
    flex: 1;
}
.tpl-preview-email {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--gray-200);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.tpl-preview-email-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
}
.tpl-preview-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.tpl-preview-from {
    font-size: 13px;
    font-weight: 700;
    color: var(--gray-800);
}
.tpl-preview-to {
    font-size: 11px;
    color: var(--gray-400);
}
.tpl-preview-subject {
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 700;
    color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
}
.tpl-preview-image {
    padding: 0;
}
.tpl-preview-image img {
    width: 100%;
    display: block;
    object-fit: cover;
    max-height: 200px;
}
.tpl-preview-body {
    padding: 20px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--gray-700);
    word-break: break-word;
}
.tpl-preview-firma {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-100);
}

/* Editor footer */
.tpl-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* Responsive */
@media (max-width: 900px) {
    .tpl-editor-layout { grid-template-columns: 1fr; }
    .tpl-editor-right { max-height: 300px; }
    .tpl-grid { grid-template-columns: 1fr; }
}

/* ========================================
   TEMPLATE EDITOR - Dark Mode
   ======================================== */
[data-theme="dark"] .tpl-filter-btn { background: var(--gray-100); border-color: var(--gray-300); color: var(--gray-500); }
[data-theme="dark"] .tpl-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
[data-theme="dark"] .tpl-filter-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

[data-theme="dark"] .tpl-card { background: var(--bg-card); border-color: var(--gray-200); }
[data-theme="dark"] .tpl-card:hover { box-shadow: 0 12px 40px rgba(0,0,0,0.3); border-color: var(--gray-300); }
[data-theme="dark"] .tpl-card-title { color: var(--gray-800); }
[data-theme="dark"] .tpl-card-subject { color: var(--gray-500); }
[data-theme="dark"] .tpl-card-preview { color: var(--gray-500); }
[data-theme="dark"] .tpl-card-footer { border-top-color: var(--gray-200); }
[data-theme="dark"] .tpl-card-cat { background: var(--gray-200); color: var(--gray-500); }
[data-theme="dark"] .tpl-card-date { color: var(--gray-400); }

[data-theme="dark"] .tpl-empty { color: var(--gray-400); }

[data-theme="dark"] .tpl-editor-modal { background: var(--bg-card); }
[data-theme="dark"] .tpl-editor-header { background: linear-gradient(135deg, var(--gray-100) 0%, var(--bg-card) 100%); border-bottom-color: var(--gray-200); }
[data-theme="dark"] .tpl-editor-left { border-right-color: var(--gray-200); }
[data-theme="dark"] .tpl-editor-right { background: var(--gray-50); }

[data-theme="dark"] .tpl-config-section { border-bottom-color: var(--gray-200); }
[data-theme="dark"] .tpl-visual-config { border-top-color: var(--gray-200); }
[data-theme="dark"] .tpl-color-dot.active { border-color: var(--gray-600); box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--gray-400); }
[data-theme="dark"] .tpl-icon-opt { background: var(--gray-100); border-color: var(--gray-300); color: var(--gray-500); }
[data-theme="dark"] .tpl-icon-opt:hover { border-color: var(--primary); color: var(--primary); }
[data-theme="dark"] .tpl-icon-opt.active { background: var(--primary); color: white; border-color: var(--primary); }

[data-theme="dark"] .tpl-toolbar { background: var(--gray-100); border-bottom-color: var(--gray-200); }
[data-theme="dark"] .tpl-toolbar-sep { background: var(--gray-300); }
[data-theme="dark"] .tpl-tb-btn { color: var(--gray-500); }
[data-theme="dark"] .tpl-tb-btn:hover { background: var(--gray-200); color: var(--gray-700); }
[data-theme="dark"] .tpl-var-btn { background: rgba(129,140,248,.1); border-color: rgba(129,140,248,.3); color: var(--primary); }
[data-theme="dark"] .tpl-var-btn:hover { background: rgba(129,140,248,.2); }

[data-theme="dark"] .tpl-textarea { background: var(--bg-card); color: var(--gray-800); }
[data-theme="dark"] .tpl-textarea::placeholder { color: var(--gray-400); }

[data-theme="dark"] .tpl-image-attached { background: rgba(129,140,248,.08); border-top-color: rgba(129,140,248,.2); color: var(--primary); }

[data-theme="dark"] .tpl-preview-header { color: var(--gray-500); border-bottom-color: var(--gray-200); }
[data-theme="dark"] .tpl-preview-email { background: var(--gray-100); border-color: var(--gray-200); box-shadow: 0 4px 20px rgba(0,0,0,0.15); }
[data-theme="dark"] .tpl-preview-email-header { border-bottom-color: var(--gray-200); }
[data-theme="dark"] .tpl-preview-from { color: var(--gray-800); }
[data-theme="dark"] .tpl-preview-to { color: var(--gray-400); }
[data-theme="dark"] .tpl-preview-subject { color: var(--gray-800); border-bottom-color: var(--gray-200); }
[data-theme="dark"] .tpl-preview-body { color: var(--gray-700); }
[data-theme="dark"] .tpl-preview-firma { border-top-color: var(--gray-200); }
[data-theme="dark"] .tpl-preview-firma p { color: var(--gray-500) !important; }

[data-theme="dark"] .tpl-editor-footer { background: var(--gray-100); border-top-color: var(--gray-200); }

[data-theme="dark"] .tpl-img-option { color: var(--gray-600); }

/* Image upload dark mode */
[data-theme="dark"] .img-upload-tabs { border-color: var(--gray-300); }
[data-theme="dark"] .img-upload-tab { background: var(--gray-100); color: var(--gray-500); }
[data-theme="dark"] .img-upload-tab:first-child { border-right-color: var(--gray-300); }
[data-theme="dark"] .img-upload-tab:not(.active):hover { background: var(--gray-200); }
[data-theme="dark"] .img-upload-zone { border-color: var(--gray-300); }
[data-theme="dark"] .img-upload-zone.uploading { border-color: var(--primary); background: rgba(99,102,241,.08); }
[data-theme="dark"] .img-upload-text { color: var(--gray-500); }
[data-theme="dark"] .img-upload-hint { color: var(--gray-400); }
[data-theme="dark"] .img-upload-filename { color: var(--gray-500); }
[data-theme="dark"] .img-upload-error { background: rgba(239,68,68,.12); color: #f87171; }

/* ========================================
   Rich Text Editor (Gmail-like reply editor)
   ======================================== */
.rich-editor-wrap { border:1px solid var(--border-color); border-radius:8px; background:var(--gray-50); overflow:hidden; }
.rich-editor-toolbar { display:flex; flex-wrap:wrap; gap:2px; align-items:center; padding:6px 8px; border-bottom:1px solid var(--border-color); background:var(--white, #fff); }
.rich-btn { background:transparent; border:none; color:var(--gray-500); padding:5px 8px; border-radius:4px; cursor:pointer; font-size:13px; line-height:1; }
.rich-btn:hover { background:var(--primary-light); color:var(--primary); }
.rich-btn:disabled { opacity:.4; cursor:not-allowed; }
.rich-toolbar-sep { width:1px; height:18px; background:var(--border-color); margin:0 4px; }
.rich-editor-content { min-height:100px; max-height:280px; overflow-y:auto; padding:10px 12px; font-size:13px; line-height:1.5; outline:none; background:var(--white, #fff); color:var(--text-primary); }
.rich-editor-content:empty:before { content: attr(data-placeholder); color:var(--gray-400); pointer-events:none; }
.rich-editor-content img { max-width:100%; height:auto; border-radius:4px; margin:4px 0; }
.rich-editor-content p { margin:0 0 6px 0; }
.rich-editor-content a { color:var(--primary); }
.rich-editor-attachments { display:flex; flex-wrap:wrap; gap:6px; padding:6px 10px; border-top:1px solid var(--border-color); background:var(--gray-50); }
.rich-attachment-chip { display:inline-flex; align-items:center; gap:8px; background:var(--white, #fff); border:1px solid var(--border-color); border-radius:6px; padding:4px 10px; font-size:12px; max-width:260px; }
.rich-attachment-chip i { color:var(--primary); }
.rich-attachment-chip .chip-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.rich-attachment-chip .chip-remove { background:none; border:none; color:var(--danger); cursor:pointer; padding:0; font-size:12px; }
.rich-editor-footer { display:flex; align-items:center; gap:8px; padding:8px 10px; border-top:1px solid var(--border-color); background:var(--gray-50); }
.comment-html { font-size:13px; color:var(--gray-700); line-height:1.5; word-break:break-word; }
.comment-html img { max-width:100%; height:auto; border-radius:4px; margin:4px 0; }
.comment-html a { color:var(--primary); }
.comment-html p { margin:0 0 6px 0; }
.comment-html ul, .comment-html ol { margin:0 0 6px 20px; }
.comment-attachments { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.comment-attachment-chip { display:inline-flex; align-items:center; gap:6px; background:var(--gray-50); border:1px solid var(--border-color); border-radius:6px; padding:4px 8px; font-size:12px; color:var(--primary); text-decoration:none; }
.comment-attachment-chip:hover { background:var(--primary-light); }
[data-theme="dark"] .rich-editor-toolbar { background:var(--gray-100); }
[data-theme="dark"] .rich-editor-content { background:var(--gray-100); }
[data-theme="dark"] .rich-attachment-chip { background:var(--gray-100); }

/* ===== Asistente IA flotante ===== */
.ai-chat-fab {
    position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #7c3aed); color: #fff; border: none;
    box-shadow: 0 8px 24px rgba(124, 58, 237, .35); cursor: pointer; z-index: 9999;
    font-size: 22px; display: flex; align-items: center; justify-content: center;
    transition: transform .2s, box-shadow .2s;
}
.ai-chat-fab:hover { transform: scale(1.06); box-shadow: 0 10px 32px rgba(124, 58, 237, .5); }
.ai-chat-fab--abierto { background: #4b5563; }

.ai-chat-panel {
    position: fixed; bottom: 96px; right: 24px; width: 420px; max-width: calc(100vw - 32px);
    height: 620px; max-height: calc(100vh - 140px);
    background: var(--bg-card, #fff); border: 1px solid var(--border-color); border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0,0,0,.18); display: flex; flex-direction: column;
    transform: translateY(20px) scale(.96); opacity: 0; pointer-events: none;
    transition: transform .2s, opacity .2s; z-index: 9998; overflow: hidden;
}
.ai-chat-panel--abierto { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }

.ai-chat-header {
    background: linear-gradient(135deg, #6366f1, #7c3aed); color: #fff;
    padding: 12px 14px; display: flex; justify-content: space-between; align-items: center;
}
.ai-chat-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.ai-chat-btn-icon {
    background: rgba(255,255,255,.12); color: #fff; border: none; width: 28px; height: 28px;
    border-radius: 6px; cursor: pointer; font-size: 12px;
}
.ai-chat-btn-icon:hover { background: rgba(255,255,255,.25); }

.ai-chat-body {
    flex: 1; overflow-y: auto; padding: 14px; background: var(--gray-50);
    display: flex; flex-direction: column; gap: 12px;
}
.ai-chat-empty { text-align: center; padding: 24px 16px; color: var(--gray-600); }
.ai-chat-suggest {
    padding: 10px 12px; margin-bottom: 6px; background: var(--bg-card, #fff);
    border: 1px solid var(--border-color); border-radius: 8px; font-size: 12px;
    cursor: pointer; transition: background .15s; text-align: left;
}
.ai-chat-suggest:hover { background: #f5f3ff; border-color: #c7d2fe; }

.ai-chat-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.ai-chat-msg--user { justify-content: flex-end; }
.ai-chat-msg--assistant { justify-content: flex-start; }
.ai-chat-msg-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #6366f1); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0;
}
.ai-chat-msg-bubble {
    max-width: 76%; padding: 10px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5;
    word-break: break-word;
}
.ai-chat-msg--user .ai-chat-msg-bubble {
    background: linear-gradient(135deg, #6366f1, #7c3aed); color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-chat-msg--assistant .ai-chat-msg-bubble {
    background: var(--bg-card, #fff); color: var(--gray-800); border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}
.ai-chat-msg-text { white-space: pre-wrap; }
.ai-chat-msg-text strong { font-weight: 600; }
.ai-chat-msg-text ul { margin: 6px 0 6px 18px; padding: 0; }
.ai-chat-msg-text code { background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.ai-chat-img-attach { max-width: 100%; border-radius: 6px; margin-bottom: 6px; display: block; }

.ai-chat-typing { display: flex; gap: 4px; padding: 4px 0; }
.ai-chat-typing span {
    width: 6px; height: 6px; background: var(--gray-400); border-radius: 50%;
    animation: ai-typing 1.2s infinite ease-in-out;
}
.ai-chat-typing span:nth-child(2) { animation-delay: .2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ai-typing { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

.ai-chat-input-area {
    padding: 10px 12px; border-top: 1px solid var(--border-color); background: var(--bg-card, #fff);
}
.ai-chat-input {
    flex: 1; resize: none; min-height: 36px; max-height: 120px; padding: 8px 10px;
    border: 1px solid var(--border-color); border-radius: 8px; font-size: 13px;
    font-family: inherit; background: var(--gray-50); color: var(--gray-800); outline: none;
}
.ai-chat-input:focus { border-color: #6366f1; background: var(--bg-card, #fff); }
.ai-chat-send {
    width: 38px; height: 38px; border-radius: 8px; background: #6366f1; color: #fff;
    border: none; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.ai-chat-send:disabled { background: var(--gray-300); cursor: not-allowed; }
.ai-chat-send:not(:disabled):hover { background: #4f46e5; }
.ai-chat-hint { font-size: 10px; color: var(--gray-400); margin-top: 4px; text-align: center; }

.ai-chat-pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.ai-chat-pending-chip {
    position: relative; width: 60px; height: 60px; border-radius: 6px; overflow: hidden;
    border: 1px solid var(--border-color);
}
.ai-chat-pending-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-chat-pending-chip button {
    position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%;
    background: rgba(0,0,0,.6); color: #fff; border: none; cursor: pointer; font-size: 10px;
    display: flex; align-items: center; justify-content: center;
}

[data-theme="dark"] .ai-chat-panel { background: var(--gray-100); }
[data-theme="dark"] .ai-chat-body { background: var(--gray-50); }
[data-theme="dark"] .ai-chat-input-area { background: var(--gray-100); }
[data-theme="dark"] .ai-chat-msg--assistant .ai-chat-msg-bubble { background: var(--gray-100); border-color: var(--border-color); }
[data-theme="dark"] .ai-chat-suggest { background: var(--gray-100); }

/* Links dentro de respuestas del chat IA */
.ai-chat-link {
    display: inline-block; padding: 3px 10px; margin: 2px 4px 2px 0;
    background: rgba(124, 58, 237, .12); color: #6d28d9; text-decoration: none;
    border-radius: 6px; font-size: 12px; font-weight: 500;
    transition: background .15s;
}
.ai-chat-link:hover { background: rgba(124, 58, 237, .22); text-decoration: none; }
.ai-chat-msg--user .ai-chat-link { background: rgba(255,255,255,.22); color: #fff; }
.ai-chat-msg--user .ai-chat-link:hover { background: rgba(255,255,255,.35); }
[data-theme="dark"] .ai-chat-link { background: rgba(167, 139, 250, .18); color: #c4b5fd; }
