/* ============================================================
   Kia WhatsApp Bot — Panel de Administración
   Estilos CSS Premium con Modo Oscuro
   ============================================================ */

/* === Variables raíz del sistema de diseño === */
:root {
    /* Fondos oscuros */
    --bg-base: #0a0a0f;
    --bg-card: #12121a;
    --bg-hover: #1a1a2e;
    --bg-input: #16162a;
    --bg-elevated: #1e1e32;

    /* Colores de acento */
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-blue-glow: rgba(59, 130, 246, 0.25);
    --accent-green: #10b981;
    --accent-green-glow: rgba(16, 185, 129, 0.25);
    --accent-amber: #f59e0b;
    --accent-amber-glow: rgba(245, 158, 11, 0.25);
    --accent-emerald: #059669;
    --accent-red: #ef4444;
    --accent-red-glow: rgba(239, 68, 68, 0.25);

    /* Texto */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    /* Bordes */
    --border-subtle: rgba(255, 255, 255, 0.05);
    --border-light: rgba(255, 255, 255, 0.08);
    --border-medium: rgba(255, 255, 255, 0.12);

    /* Sombras */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow-blue: 0 0 20px rgba(59, 130, 246, 0.15);

    /* Glassmorphism */
    --glass-bg: rgba(18, 18, 26, 0.7);
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-blur: 12px;

    /* Dimensiones */
    --sidebar-width: 260px;
    --sidebar-collapsed: 72px;
    --header-height: 64px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transiciones */
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Tipografía */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Scrollbar personalizado === */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* === Pantalla de autenticación === */
.auth-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-base);
    z-index: 9999;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), var(--shadow-glow-blue);
    animation: fadeInUp 0.6s ease;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 12px;
}

.auth-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-green));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-logo p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.825rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.auth-form input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.925rem;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.auth-form input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.btn-block {
    width: 100%;
}

/* === Contenedor de la aplicación === */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* === Barra lateral === */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base), width var(--transition-base);
}

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

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

.logo-icon {
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-blue), #6366f1);
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.logo-text h2 {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.logo-subtitle {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.sidebar-close:hover {
    background: var(--bg-hover);
}

/* Navegación de la barra lateral */
.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

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

.sidebar-nav li {
    padding: 2px 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.925rem;
    transition: all var(--transition-base);
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--accent-blue-glow), transparent);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.nav-item:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-item.active::before {
    opacity: 1;
}

.nav-item.active::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent-blue);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    font-size: 1.25rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

.nav-text {
    position: relative;
    z-index: 1;
    white-space: nowrap;
}

/* Pie de la barra lateral */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-subtle);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    font-size: 0.8rem;
    color: var(--accent-green);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-green);
    flex-shrink: 0;
}

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

.btn-logout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: none;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-top: 8px;
}

.btn-logout:hover {
    background: var(--accent-red-glow);
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* Overlay de la barra lateral (móvil) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    backdrop-filter: blur(4px);
}

/* === Contenido principal === */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition-base);
}

/* === Encabezado superior === */
.top-header {
    position: sticky;
    top: 0;
    height: var(--header-height);
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

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

.header-title {
    flex: 1;
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
}

.header-breadcrumb {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-time {
    font-size: 0.825rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-hover);
    border-radius: var(--radius-md);
    font-size: 0.85rem;
}

.user-avatar {
    font-size: 1.1rem;
}

.user-name {
    color: var(--text-secondary);
}

/* === Secciones de contenido === */
.content-section {
    display: none;
    padding: 24px;
    flex: 1;
    animation: fadeIn 0.35s ease;
}

.content-section.active {
    display: block;
}

/* Sección de chat necesita flex para llenar el espacio */
#section-chat.active {
    display: flex;
    padding: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === Tarjetas de estadísticas === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    overflow: hidden;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Borde con gradiente a la izquierda */
.stat-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.stat-card[data-accent="blue"]::before {
    background: linear-gradient(180deg, var(--accent-blue), #6366f1);
}

.stat-card[data-accent="green"]::before {
    background: linear-gradient(180deg, var(--accent-green), #34d399);
}

.stat-card[data-accent="amber"]::before {
    background: linear-gradient(180deg, var(--accent-amber), #fbbf24);
}

.stat-card[data-accent="emerald"]::before {
    background: linear-gradient(180deg, var(--accent-emerald), var(--accent-green));
}

.stat-icon {
    font-size: 2rem;
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: var(--bg-hover);
    flex-shrink: 0;
}

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

.stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.5px;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.stat-trend {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    background: var(--bg-hover);
}

.stat-trend.up {
    color: var(--accent-green);
    background: var(--accent-green-glow);
}

.stat-trend.down {
    color: var(--accent-red);
    background: var(--accent-red-glow);
}

/* === Tarjetas genéricas === */
.card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    overflow: hidden;
    transition: box-shadow var(--transition-base);
}

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

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
}

.card-full {
    grid-column: 1 / -1;
}

/* === Tablas === */
.table-wrapper {
    overflow-x: auto;
}

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

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-hover);
    white-space: nowrap;
}

.data-table td {
    padding: 14px 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

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

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

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Skeleton para carga */
.skeleton {
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-elevated) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    height: 16px;
}

.skeleton-row td {
    padding: 14px 16px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* === Badges de estado === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.725rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-new {
    background: var(--accent-blue-glow);
    color: var(--accent-blue);
}

.badge-contacted {
    background: var(--accent-amber-glow);
    color: var(--accent-amber);
}

.badge-qualified {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-green);
}

.badge-converted {
    background: rgba(5, 150, 105, 0.2);
    color: var(--accent-emerald);
}

.badge-lost {
    background: var(--accent-red-glow);
    color: var(--accent-red);
}

.badge-info {
    background: var(--accent-blue-glow);
    color: var(--accent-blue);
}

/* === Botones === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
    text-decoration: none;
}

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

.btn-primary {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 2px 8px var(--accent-blue-glow);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-blue-hover);
    box-shadow: 0 4px 16px var(--accent-blue-glow);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-medium);
}

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

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    box-shadow: 0 4px 16px var(--accent-red-glow);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.btn-send {
    padding: 10px 24px;
}

/* === Filtros y búsqueda === */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 240px;
}

.search-box-sm {
    min-width: 0;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.9rem;
    pointer-events: none;
}

.search-box input {
    width: 100%;
    padding: 10px 14px 10px 40px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.875rem;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-select {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color var(--transition-base);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394a3b8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

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

.filter-select-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
    padding-right: 28px;
}

/* Checkbox personalizado */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-blue);
    cursor: pointer;
}

/* Paginación */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* === Contenedor de Chat === */
.chat-container {
    display: flex;
    flex: 1;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

/* Panel lateral del chat */
.chat-sidebar {
    width: 320px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.chat-sidebar-header h3 {
    font-size: 1rem;
    margin-bottom: 12px;
}

.chat-contacts-list {
    flex: 1;
    overflow-y: auto;
}

.chat-contact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}

.chat-contact:hover {
    background: var(--bg-hover);
}

.chat-contact.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--accent-blue);
}

.chat-contact-avatar {
    width: 42px;
    height: 42px;
    background: var(--bg-elevated);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

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

.chat-contact-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-contact-preview {
    font-size: 0.775rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-contact-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* Panel principal del chat */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-base);
}

/* Estado vacío del chat */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.chat-empty-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.4;
}

.chat-empty h3 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.chat-empty p {
    font-size: 0.85rem;
}

/* Chat activo */
.chat-active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Encabezado del chat */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.chat-back-btn:hover {
    background: var(--bg-hover);
}

.chat-header-avatar {
    width: 38px;
    height: 38px;
    background: var(--bg-elevated);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.chat-header-info {
    flex: 1;
}

.chat-header-info h4 {
    font-size: 0.95rem;
    font-weight: 600;
}

.chat-header-info span {
    font-size: 0.775rem;
    color: var(--text-muted);
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

/* Mensajes del chat */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Fondo sutil tipo WhatsApp */
    background-image: radial-gradient(circle at 20% 50%, rgba(59, 130, 246, 0.02) 0%, transparent 50%),
                      radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.02) 0%, transparent 50%);
}

.chat-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    line-height: 1.5;
    position: relative;
    animation: bubbleIn 0.3s ease;
    word-wrap: break-word;
}

@keyframes bubbleIn {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Burbuja entrante (del cliente) */
.chat-bubble.incoming {
    align-self: flex-start;
    background: var(--bg-elevated);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

/* Burbuja saliente (del bot/agente) */
.chat-bubble.outgoing {
    align-self: flex-end;
    background: var(--accent-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-bubble-time {
    display: block;
    font-size: 0.65rem;
    margin-top: 4px;
    opacity: 0.6;
    text-align: right;
}

.chat-bubble-sender {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--accent-blue);
}

.chat-bubble.outgoing .chat-bubble-sender {
    color: rgba(255, 255, 255, 0.7);
}

/* Separador de fecha en el chat */
.chat-date-separator {
    text-align: center;
    padding: 8px 0;
}

.chat-date-separator span {
    background: var(--bg-elevated);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Barra de entrada del chat */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-input-bar input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 24px;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.875rem;
    transition: border-color var(--transition-base);
}

.chat-input-bar input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* === Mensajes Masivos - Pasos === */
.steps-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 28px;
    padding: 0 20px;
}

.step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 24px;
    font-size: 0.825rem;
    color: var(--text-muted);
    transition: all var(--transition-base);
}

.step.active {
    background: var(--accent-blue-glow);
    color: var(--accent-blue);
}

.step.completed {
    color: var(--accent-green);
}

.step-number {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--bg-hover);
    transition: all var(--transition-base);
}

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

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

.step-label {
    white-space: nowrap;
}

.step-connector {
    width: 40px;
    height: 2px;
    background: var(--border-light);
    flex-shrink: 0;
}

/* Plantillas para masivos */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 20px 24px;
}

.template-card {
    padding: 16px;
    background: var(--bg-hover);
    border: 2px solid var(--border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
}

.template-card:hover {
    border-color: var(--accent-blue);
    background: var(--bg-elevated);
}

.template-card.selected {
    border-color: var(--accent-blue);
    background: var(--accent-blue-glow);
}

.template-card h4 {
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.template-card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Previsualización del mensaje */
.preview-container {
    display: flex;
    gap: 24px;
    padding: 24px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.preview-phone {
    width: 300px;
    background: var(--bg-base);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-light);
    flex-shrink: 0;
}

.preview-phone-header {
    padding: 12px 16px;
    background: var(--accent-blue);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

.preview-bubble {
    padding: 16px;
    min-height: 100px;
}

.preview-bubble .chat-bubble {
    max-width: 100%;
}

.preview-info {
    flex: 1;
    min-width: 200px;
}

.preview-detail {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.875rem;
}

.preview-detail strong {
    color: var(--text-secondary);
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

/* Resultados del envío masivo */
.bulk-results {
    padding: 24px;
    text-align: center;
}

.bulk-results-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.bulk-results h4 {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.bulk-results p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.bulk-results-stats {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin-top: 20px;
}

.bulk-result-stat {
    text-align: center;
}

.bulk-result-stat .value {
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
}

.bulk-result-stat .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* === Catálogos === */
.upload-zone {
    padding: 40px;
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-base);
    margin: 20px 24px;
}

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

.upload-zone.dragover {
    transform: scale(1.01);
}

.upload-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.6;
}

.upload-zone h4 {
    font-size: 1rem;
    margin-bottom: 4px;
}

.upload-zone p {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.upload-hint {
    display: block;
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Barra de progreso */
.upload-progress {
    padding: 12px 24px 20px;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
    border-radius: 3px;
    width: 0%;
    transition: width var(--transition-base);
}

.progress-text {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 6px;
    text-align: center;
}

/* Grid de catálogos */
.catalogs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    padding: 20px 24px;
}

.catalog-card {
    padding: 20px;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: all var(--transition-base);
}

.catalog-card:hover {
    border-color: var(--accent-blue);
    background: var(--bg-elevated);
}

.catalog-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

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

.catalog-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
    word-break: break-word;
}

.catalog-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.catalog-actions {
    flex-shrink: 0;
}

/* === Configuración === */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

.form-group {
    margin-bottom: 20px;
}

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

.form-textarea {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.85rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.form-textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

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

/* Estado de conexión en settings */
.connection-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.connection-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-subtle);
}

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

.connection-label {
    font-size: 0.875rem;
    font-weight: 500;
}

.connection-value {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Estado vacío */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

.modal {
    width: 90%;
    max-width: 520px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.3s ease;
    overflow: hidden;
}

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

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-subtle);
}

/* === Notificaciones Toast === */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    min-width: 300px;
    max-width: 420px;
    animation: toastIn 0.4s ease;
    position: relative;
    overflow: hidden;
}

.toast::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}

.toast.success::before { background: var(--accent-green); }
.toast.error::before { background: var(--accent-red); }
.toast.warning::before { background: var(--accent-amber); }
.toast.info::before { background: var(--accent-blue); }

.toast-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
}

.toast-close:hover {
    color: var(--text-primary);
}

.toast-exit {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* === Animación Pulse === */
.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 var(--accent-green-glow); }
    70% { box-shadow: 0 0 0 6px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* === Responsivo === */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .chat-sidebar {
        width: 260px;
    }
}

@media (max-width: 768px) {
    /* Sidebar oculto en móvil */
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open + .sidebar-overlay,
    .sidebar-overlay.show {
        display: block;
    }

    .sidebar-close {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Chat en móvil: solo un panel visible */
    .chat-container {
        position: relative;
    }

    .chat-sidebar {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 10;
    }

    .chat-main {
        width: 100%;
    }

    .chat-sidebar.hidden-mobile {
        display: none;
    }

    .chat-back-btn {
        display: block;
    }

    /* Tabla: scroll horizontal */
    .data-table {
        min-width: 600px;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-box {
        min-width: 0;
    }

    .filter-group {
        width: 100%;
    }

    .filter-select {
        flex: 1;
    }

    /* Pasos de envío masivo */
    .steps-indicator {
        flex-wrap: wrap;
        gap: 4px;
    }

    .step-label {
        display: none;
    }

    .step-connector {
        width: 20px;
    }

    /* Preview */
    .preview-container {
        flex-direction: column;
    }

    .preview-phone {
        width: 100%;
    }

    /* Settings */
    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* Header acciones */
    .header-time {
        display: none;
    }

    .user-name {
        display: none;
    }
}

@media (max-width: 480px) {
    .content-section {
        padding: 16px;
    }

    .top-header {
        padding: 0 16px;
    }

    .header-title h1 {
        font-size: 1.05rem;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .catalogs-grid,
    .templates-grid {
        grid-template-columns: 1fr;
    }

    .toast {
        min-width: 0;
        max-width: calc(100vw - 40px);
    }

    .toast-container {
        right: 10px;
        left: 10px;
    }
}
