/* ==================== VARIABLES ==================== */
:root {
    --primary: #4F46E5;
    --primary-light: #6366F1;
    --primary-dark: #4338CA;
    --success: #10B981;
    --success-light: #34D399;
    --warning: #F59E0B;
    --danger: #EF4444;
    --info: #3B82F6;

    --bg-dark: #0F172A;
    --bg-card: #1E293B;
    --bg-card-hover: #334155;
    --bg-input: #374151;

    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;

    --border: #334155;
    --border-light: #475569;

    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    --transition: all 0.3s ease;
}

/* ==================== RESET & BASE ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ==================== LAYOUT ==================== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ==================== HEADER ==================== */
.header {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-dark) 100%);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    font-size: 2rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.whatsapp-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.status-dot.disconnected {
    background: var(--danger);
    box-shadow: 0 0 10px var(--danger);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.status-text {
    font-size: 0.875rem;
    font-weight: 500;
}

.btn-qr {
    background: linear-gradient(135deg, #25D366, #128C7E);
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-qr:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.3);
}

.btn-qr.hidden {
    display: none;
}

.datetime {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ==================== STATS BAR ==================== */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-light);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.pending {
    background: rgba(245, 158, 11, 0.2);
}

.stat-icon.attention {
    background: rgba(99, 102, 241, 0.2);
}

.stat-icon.completed {
    background: rgba(16, 185, 129, 0.2);
}

.stat-icon.total {
    background: rgba(59, 130, 246, 0.2);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ==================== MAIN CONTENT ==================== */
.main-content {
    display: grid;
    grid-template-columns: 1fr 480px;
    gap: 1.5rem;
    padding: 0 2rem 2rem;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
    flex: 1;
}

.main-content.chat-active {
    grid-template-columns: 340px 480px 1fr;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-refresh,
.btn-close {
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    transition: var(--transition);
}

.btn-refresh:hover,
.btn-close:hover {
    background: var(--primary);
    border-color: var(--primary);
}

/* ==================== QUEUE SECTION ==================== */
.queue-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-height: calc(100vh - 280px);
    display: flex;
    flex-direction: column;
}

.queue-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Turno Card */
.turno-card {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: var(--transition);
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    align-items: center;
}

.turno-card:hover {
    border-color: var(--primary);
    transform: translateX(4px);
}

.turno-card.active {
    border-color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
}

.turno-card.en-atencion {
    border-left: 4px solid var(--warning);
}

.turno-codigo {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-light);
    background: rgba(99, 102, 241, 0.15);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
}

.turno-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.turno-nombre {
    font-weight: 600;
    font-size: 0.95rem;
}

.turno-servicio {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.turno-tipo {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.turno-tipo.agendamiento {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.turno-tipo.cancelacion {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.turno-tipo.cambio_horario {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.turno-tipo.historia_clinica {
    background: rgba(59, 130, 246, 0.2);
    color: var(--info);
}

.turno-tipo.asesor {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-light);
}

.turno-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
}

/* ==================== DETAIL SECTION ==================== */
.detail-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    max-height: calc(100vh - 280px);
    display: flex;
    flex-direction: column;
}

.detail-content {
    flex: 1;
    overflow-y: auto;
}

/* ==================== CHAT PANEL (separate column) ==================== */
.chat-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-height: calc(100vh - 280px);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.chat-panel.visible {
    display: flex;
}

.chat-panel-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(79, 70, 229, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.chat-panel-header .chat-patient-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-panel-header .chat-patient-name .chat-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    font-weight: 600;
}

.chat-panel-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-dark);
}

.chat-panel-input {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: var(--bg-card);
}

.chat-panel-input textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    resize: none;
    box-sizing: border-box;
    font-family: inherit;
    background: var(--bg-dark);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.chat-panel-input textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-panel-input .btn-send {
    padding: 10px 18px;
    background: linear-gradient(135deg, #25D366, #128C7E);
    border: none;
    color: white;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    white-space: nowrap;
}

.chat-panel-input .btn-send:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* Chat bubble styles */
.chat-bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.4;
    word-break: break-word;
}

.chat-bubble.incoming {
    align-self: flex-start;
    background: rgba(45, 106, 79, 0.3);
    border: 1px solid rgba(45, 106, 79, 0.5);
    border-bottom-left-radius: 4px;
}

.chat-bubble.outgoing {
    align-self: flex-end;
    background: rgba(45, 74, 111, 0.3);
    border: 1px solid rgba(45, 74, 111, 0.5);
    border-bottom-right-radius: 4px;
}

.chat-bubble .bubble-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.chat-bubble .bubble-text {
    color: var(--text-primary);
}

.detail-card {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.detail-header {
    text-align: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.detail-codigo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-light);
    margin-bottom: 0.5rem;
}

.detail-estado {
    display: inline-block;
    padding: 0.35rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.detail-estado.pendiente {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.detail-estado.en_atencion {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary-light);
}

.detail-estado.completado {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
}

.detail-estado.cancelado {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.detail-group {
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.detail-group-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.detail-value {
    font-weight: 500;
    font-size: 0.85rem;
    text-align: right;
}

.detail-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

.btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #DC2626;
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-input);
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ==================== MODAL ==================== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.qr-container {
    background: white;
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}

.qr-container canvas {
    display: block;
    margin: 0 auto;
}

.qr-placeholder {
    padding: 2rem;
    color: var(--bg-dark);
}

/* ==================== TOAST ==================== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.info {
    border-left: 4px solid var(--info);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 1024px) {

    .main-content,
    .main-content.chat-active {
        grid-template-columns: 1fr;
    }

    .detail-section {
        max-height: 400px;
    }

    .chat-panel {
        max-height: 500px;
    }

    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .header {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
    }

    .stats-bar {
        grid-template-columns: 1fr;
        padding: 1rem;
    }

    .main-content {
        padding: 0 1rem 1rem;
    }
}