* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #16297d;
    --secondary: #183190;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1f2937;
    --light: #f9fafb;
    --border: #e5e7eb;
    --bs-body-font-size: 0.9rem;
    --bs-body-line-height: 1.3;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f7fa;
    color: #1f2937;
    line-height: 1.6;
}

/* ============================================
   NAVBAR
   ============================================ */
.navbar {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-brand {
    color: white;
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-menu {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    transition: all 0.3s;
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-link:hover, 
.nav-link.active {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

/* ============================================
   CONTAINER
   ============================================ */
.container {
    max-width: 90%;
    margin: 2rem auto;
    padding: 0 2rem;
}

h1, h2, h3 {
    color: var(--dark);
    margin-bottom: 1.5rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

/* ============================================
   CARDS Y STATS
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.stat-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.stat-info {
    flex: 1;
}

.stat-label {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
    word-break: break-all;
}

.stat-value.small {
    font-size: 0.95rem;
    font-weight: 500;
}

/* ============================================
   SECTIONS
   ============================================ */
.section {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 2rem;
}

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn-primary, .btn-secondary, .btn-success, .btn-danger {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
}

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

.btn-success:hover {
    background: #059669;
}

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

.btn-danger:hover {
    background: #dc2626;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 1.5rem;
}

input[type="color"] {
    height: 50px;
    cursor: pointer;
}

/* ============================================
   TABS
   ============================================ */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
}

.tab-btn {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    color: #6b7280;
    position: relative;
    transition: color 0.3s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    font-weight: 600;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

.tab-content {
    display: none;
}

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

/* ============================================
   TABLES & LISTS
   ============================================ */
.conversations-list,
.conversations-table {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.conversation-item,
.conversation-row {
    background: #f9fafb;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.conversation-item:hover,
.conversation-row:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.conv-message {
    margin-bottom: 0.75rem;
    color: var(--dark);
    font-size: 0.95rem;
}

.conv-message strong,
.conv-msg strong,
.conv-resp strong {
    color: var(--primary);
    margin-right: 0.5rem;
}

.conv-meta {
    display: flex;
    gap: 0.25rem;
    align-items: baseline;
}

.conv-session {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: #6b7280;
}

.conv-content {
    margin: 1rem 0;
}

.conv-msg,
.conv-resp {
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

/* Stats específicos de conversaciones */
.conv-stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 0.75rem;
}

.conv-stats .stat {
    display: flex;
    gap: 0.25rem;
    align-items: baseline;
}

.conv-stats .stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
}

.conv-stats .stat-value {
    font-weight: 700;
    color: var(--dark);
    font-size: 0.8rem;
}

/* Stats del dashboard - mantener tamaño normal */
.stat-card .stat-label {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
    word-break: break-all;
}

.stat-card .stat-value.small {
    font-size: 0.95rem;
    font-weight: 500;
}

/* ============================================
   FILTERS & PAGINATION
   ============================================ */
.filters {
    margin-bottom: 2rem;
}

.conversations-summary {
    display: flex;
    gap: 2rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border-radius: 8px;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.summary-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.summary-item span {
    font-size: 0.875rem;
    color: #6b7280;
}

.summary-item strong {
    font-size: 1.25rem;
    color: var(--dark);
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    padding: 1rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    background: white;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}

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

#pageInfo {
    font-size: 0.95rem;
    color: #6b7280;
}

/* ============================================
   WIDGET CONFIG
   ============================================ */
/* .widget-config { */
    /* display: grid; */
    /* grid-template-columns: 1fr 1fr; */
    /* gap: 2rem; */
/* } */

.config-section,
.embed-section {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.color-preview {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
}

input[type="text"][id$="Hex"] {
    font-family: monospace;
    text-transform: uppercase;
}

.preview-gradient {
    height: 80px;
    border-radius: 8px;
    transition: all 0.3s;
}

#iconPreview {
    margin-top: 1rem;
    padding: 1rem;
    background: #f9fafb;
    border-radius: 8px;
    text-align: center;
}

#iconPreview img {
    max-width: 150px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.embed-code {
    display: none;
    margin-top: 1rem;
}

.embed-code.active {
    display: block;
}

.embed-code pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 1.5rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
    font-size: 0.875rem;
    line-height: 1.6;
}

.embed-code .help-text {
    padding: 1rem;
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    border-radius: 4px;
    margin-top: 1rem;
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ============================================
   TESTING AREA
   ============================================ */
.testing-area {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
}

.chat-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

.chat-messages {
    height: 500px;
    overflow-y: auto;
    padding: 1.5rem;
    background: #f9fafb;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    max-width: 70%;
    padding: 1rem 1.25rem;
    border-radius: 12px;
    animation: slideIn 0.3s ease;
}

.user-message {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message {
    align-self: flex-start;
    background: white;
    border: 1px solid var(--border);
    color: var(--dark);
    border-bottom-left-radius: 4px;
}

.message-content {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

.typing-indicator {
    display: flex;
    gap: 0.4rem;
    padding: 1rem;
    background: white;
    border-radius: 12px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

.chat-input {
    display: flex;
    gap: 1rem;
}

.chat-stats {
    display: flex;
    gap: 2rem;
    padding: 1.5rem;
    background: #f9fafb;
    border-radius: 8px;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.stat-item span {
    color: #6b7280;
}

.stat-item strong {
    color: var(--dark);
    font-size: 1.125rem;
}

/* ============================================
   CREDITS
   ============================================ */
.credit-info {
    padding: 1.5rem;
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border-radius: 8px;
    margin-bottom: 2rem;
}

.credit-info h3 {
    margin: 0 0 0.5rem 0;
    color: var(--dark);
}

.credit-info h3 span {
    color: var(--success);
    font-size: 1.75rem;
}

.credits-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.summary-card {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.summary-label {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark);
}

/* ============================================
   NOTIFICATIONS
   ============================================ */
.notification {
    position: fixed;
    top: 80px;
    right: 20px;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10000;
    max-width: 350px;
    animation: slideIn 0.3s ease;
}

.notification.success {
    background: var(--success);
    color: white;
}

.notification.error {
    background: var(--danger);
    color: white;
}

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

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

/* ============================================
   LOADING
   ============================================ */
.loading-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

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

.no-data {
    text-align: center;
    padding: 3rem;
    color: #6b7280;
    font-style: italic;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .widget-config {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }
    
    .navbar {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-menu {
        width: 100%;
        justify-content: center;
    }
    
    .header-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .chat-message {
        max-width: 85%;
    }
}

/* Botones pequeños y copiar */
.btn-copy, .btn-sm {
    padding: 0.5rem 1rem;
    border: 2px solid var(--primary);
    background: white;
    color: var(--primary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-copy:hover, .btn-sm:hover {
    background: var(--primary);
    color: white;
}

.form-group button {
    margin-top: 0.5rem;
}

/* Estilos para contenido markdown */
.markdown-content {
    margin-top: 0.5rem;
    line-height: 1.6;
}

.markdown-content ul,
.markdown-content ol {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.markdown-content li {
    margin-bottom: 0.25rem;
}

.markdown-content strong {
    font-weight: 700;
    color: var(--dark);
}

.markdown-content em {
    font-style: italic;
}

.markdown-content p {
    margin-bottom: 0.75rem;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.markdown-content code {
    background: #f3f4f6;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.markdown-content pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.markdown-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.logo {
    text-align: center;
    margin-bottom: 1.5rem;
}

.logo h4:first-of-type {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.logo h4:last-of-type {
    font-size: 1.1rem;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.logo p {
    color: #6b7280;
    font-size: 0.85rem;
}


.btn-login {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(27, 47, 204, 0.4);
}

.btn-login:active {
    transform: translateY(0);
}

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

.error-message {
    background: #fee;
    color: #c33;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    display: none;
}

.error-message.show {
    display: block;
}

.footer {
    margin-top: 1.5rem;
    text-align: center;
    color: #6b7280;
    font-size: 0.75rem;
}

.form-label {
    margin-bottom: 0.2rem;
}

.form-control {
    font-size: 0.9rem;
}

.loading {
    display: none;
    text-align: center;
    margin: 20px 0;
}

.loading.show {
    display: block;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

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