:root {
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bs-primary: #E95349;
    --bs-primary-rgb: 233, 83, 73;
    --bs-link-color: #E95349;
    --bs-link-hover-color: #D64D4D;
    --bg-body: #F9FAFB;
    --bg-card: #FFFFFF;
    --text-color: #1F2937;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --bs-body-bg: #F9FAFB;
    --bs-body-color: #1F2937;
    --bs-card-bg: #FFFFFF;
    --bs-card-border-color: #E5E7EB;
    --bs-card-cap-bg: #F9FAFB;
}
* { font-family: var(--font-family); }
body {
    background: var(--bg-body);
    color: var(--text-color);
}
a { color: var(--bs-link-color); }
a:hover { color: var(--bs-link-hover-color); }

.navbar.bg-dark {
    background: #1E1E1E !important;
    border-bottom: 2px solid #E95349;
}
.navbar-brand {
    font-weight: 700;
    letter-spacing: 0.5px;
    font-size: 1.2rem;
}
.navbar .nav-link {
    color: rgba(255,255,255,0.75) !important;
    transition: color 0.15s ease;
}
.navbar .nav-link:hover,
.navbar .nav-link:focus {
    color: #E95349 !important;
}
.navbar .nav-link.active {
    color: #E95349 !important;
    font-weight: 600;
}

.card {
    background: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-color);
    border-radius: 12px;
}
.text-muted {
    color: var(--text-muted) !important;
}
.bg-light {
    background: var(--bg-card) !important;
}

.btn-primary {
    --bs-btn-bg: #E95349;
    --bs-btn-border-color: #E95349;
    --bs-btn-color: #FFFFFF;
    --bs-btn-hover-bg: #D64D4D;
    --bs-btn-hover-border-color: #D64D4D;
    --bs-btn-hover-color: #FFFFFF;
    --bs-btn-active-bg: #C6443F;
    --bs-btn-active-border-color: #C6443F;
    --bs-btn-active-color: #FFFFFF;
}
.btn-outline-primary {
    --bs-btn-color: #E95349;
    --bs-btn-border-color: #E95349;
    --bs-btn-hover-bg: #E95349;
    --bs-btn-hover-border-color: #E95349;
    --bs-btn-hover-color: #FFFFFF;
    --bs-btn-active-bg: #D64D4D;
    --bs-btn-active-border-color: #D64D4D;
    --bs-btn-active-color: #FFFFFF;
}
.btn-success {
    --bs-btn-bg: #E95349;
    --bs-btn-border-color: #E95349;
    --bs-btn-color: #FFFFFF;
    --bs-btn-hover-bg: #D64D4D;
    --bs-btn-hover-border-color: #D64D4D;
    --bs-btn-hover-color: #FFFFFF;
    --bs-btn-active-bg: #C6443F;
    --bs-btn-active-border-color: #C6443F;
}
.btn-danger {
    --bs-btn-bg: #C6443F;
    --bs-btn-border-color: #C6443F;
    --bs-btn-color: #FFFFFF;
    --bs-btn-hover-bg: #B33A36;
    --bs-btn-hover-border-color: #B33A36;
    --bs-btn-hover-color: #FFFFFF;
}
.btn-warning {
    --bs-btn-bg: #F59E0B;
    --bs-btn-border-color: #F59E0B;
    --bs-btn-color: #1F2937;
    --bs-btn-hover-bg: #D97706;
    --bs-btn-hover-border-color: #D97706;
    --bs-btn-hover-color: #1F2937;
    --bs-btn-active-bg: #B45309;
    --bs-btn-active-border-color: #B45309;
    --bs-btn-active-color: #FFFFFF;
}
.btn-outline-warning {
    --bs-btn-color: #F59E0B;
    --bs-btn-border-color: #F59E0B;
}
.btn-outline-success {
    --bs-btn-color: #10B981;
    --bs-btn-border-color: #10B981;
}
.btn-outline-danger {
    --bs-btn-color: #EF4444;
    --bs-btn-border-color: #EF4444;
}

.form-control, .form-select {
    background: #FFFFFF;
    border: 1px solid #D1D5DB;
    color: #1F2937;
    border-radius: 8px;
}
.form-control:focus, .form-select:focus {
    background: #FFFFFF;
    border-color: #E95349;
    color: #1F2937;
    box-shadow: 0 0 0 2px rgba(233, 83, 73, 0.25);
}
.form-control::placeholder {
    color: #9CA3AF;
}
.form-label {
    color: var(--text-muted);
    font-weight: 500;
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-color);
    --bs-table-striped-color: var(--text-color);
    --bs-table-striped-bg: rgba(0,0,0,0.02);
    --bs-table-hover-color: var(--text-color);
    --bs-table-hover-bg: rgba(0,0,0,0.04);
    --bs-table-th-color: var(--text-color);
}
.table > :not(caption) > * > * {
    color: var(--text-color);
    border-color: var(--border-color);
}
.table > thead {
    border-bottom-color: var(--border-color);
}
.table a {
    color: var(--bs-link-color);
}

.alert {
    background: var(--bg-card);
    color: var(--text-color);
    border-color: var(--border-color);
    border-radius: 12px;
}
.alert-success {
    border-left: 4px solid #10B981;
}
.alert-danger {
    border-left: 4px solid #EF4444;
}
.alert-warning {
    border-left: 4px solid #F59E0B;
}
.alert-info {
    border-left: 4px solid #3B82F6;
}

.modal-content {
    background: var(--bg-card);
    color: var(--text-color);
    border-color: var(--border-color);
    border-radius: 12px;
}
.modal-header {
    border-bottom-color: var(--border-color);
}
.modal-footer {
    border-top-color: var(--border-color);
}

.dropdown-menu {
    background: #FFFFFF;
    border-color: #E5E7EB;
    border-radius: 12px;
}
.dropdown-item {
    color: #1F2937;
}
.dropdown-item:hover {
    background: rgba(233, 83, 73, 0.1);
    color: #E95349;
}
.dropdown-divider {
    border-top-color: #E5E7EB;
}

.list-group-item {
    background: var(--bg-card);
    color: var(--text-color);
    border-color: var(--border-color);
}

hr {
    color: var(--border-color);
    opacity: 1;
}

.navbar {
    position: relative;
    z-index: 1030;
}
.navbar .dropdown-menu {
    z-index: 9999;
}

.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #E95349;
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(233, 83, 73, 0.4);
    cursor: pointer;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}
.chat-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(233, 83, 73, 0.5);
}
.chat-fab:active {
    transform: scale(0.95);
}
.chat-widget {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    height: 550px;
    background: #FFFFFF;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.15);
    z-index: 1051;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.25s ease, opacity 0.25s ease;
}
.chat-widget.closed {
    transform: scale(0.8);
    opacity: 0;
    pointer-events: none;
}
.chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #1E1E1E;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}
.chat-widget-header button {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.chat-widget-header button:hover {
    color: white;
}
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.chat-widget-message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    overflow-wrap: break-word;
    word-break: break-word;
}
.chat-widget-message p {
    margin-bottom: 0;
}
.chat-widget-message p:not(:last-child) {
    margin-bottom: 0.3rem;
}
.chat-widget-message ul,
.chat-widget-message ol {
    padding-left: 1.2em;
    margin: 0.2rem 0;
}
.chat-widget-message h1,
.chat-widget-message h2,
.chat-widget-message h3,
.chat-widget-message h4,
.chat-widget-message h5,
.chat-widget-message h6 {
    font-size: 14px;
    font-weight: 700;
    margin: 0.5rem 0 0.2rem;
    color: #E95349;
}
.chat-widget-message h1:first-child,
.chat-widget-message h2:first-child,
.chat-widget-message h3:first-child {
    margin-top: 0;
}
.chat-widget-message strong {
    color: #E95349;
}
.chat-widget-message.user {
    background: #E95349;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.chat-widget-message.assistant {
    background: #F3F4F6;
    color: #1F2937;
    border: 1px solid #E5E7EB;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.chat-widget-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #E5E7EB;
    flex-shrink: 0;
}
.chat-widget-input textarea {
    flex: 1;
    border: 1px solid #D1D5DB;
    border-radius: 20px;
    padding: 7px 12px;
    font-size: 13px;
    resize: none;
    outline: none;
    background: #F9FAFB;
    max-height: 60px;
}
.chat-widget-input textarea:focus {
    border-color: #E95349;
    box-shadow: 0 0 0 2px rgba(233, 83, 73, 0.25);
}
.chat-widget-input button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #E95349;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}
.chat-widget-input button:hover {
    background: #D64D4D;
}
.chat-widget-input button:disabled {
    opacity: 0.5;
    cursor: default;
}
.chat-widget-input button i {
    font-size: 16px;
}
.chat-widget-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9CA3AF;
    text-align: center;
    padding: 20px;
}
.chat-widget-empty i {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}
.chat-widget-empty p {
    font-size: 13px;
    margin: 0;
}
.chat-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 1049;
}
.chat-overlay.active {
    display: block;
}
.widget-typing {
    display: none;
    align-self: flex-start;
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    padding: 10px 16px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.widget-typing.active {
    display: flex;
}
.widget-typing span {
    width: 7px;
    height: 7px;
    background: #9CA3AF;
    border-radius: 50%;
    animation: widget-typing 1.4s infinite ease-in-out;
    margin: 0 2px;
}
.widget-typing span:nth-child(2) { animation-delay: 0.2s; }
.widget-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes widget-typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}
.chat-widget-message .btn-success {
    --bs-btn-bg: #10B981;
    --bs-btn-border-color: #10B981;
    --bs-btn-color: #FFFFFF;
    --bs-btn-hover-bg: #059669;
    --bs-btn-hover-border-color: #059669;
    --bs-btn-hover-color: #FFFFFF;
}
@media (max-width: 480px) {
    .chat-widget {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
    }
    .chat-widget.closed {
        transform: translateY(100%);
        opacity: 0;
    }
}

/* ==== Modo oscuro (rojo/negro) ==== */
html.dark {
    --bg-body: #0b0a09;
    --bg-card: #1c1917;
    --text-color: #f5f5f4;
    --text-muted: #a8a29e;
    --border-color: #2a2825;
    --bs-body-bg: #0b0a09;
    --bs-body-color: #f5f5f4;
    --bs-card-bg: #1c1917;
    --bs-card-border-color: #2a2825;
    --bs-card-cap-bg: #24211e;
}
html.dark body {
    background:
        radial-gradient(circle at 85% -10%, rgba(233, 83, 73, 0.22), transparent 55%),
        radial-gradient(circle at -10% 110%, rgba(120, 53, 15, 0.3), transparent 55%),
        #0b0a09;
    background-attachment: fixed;
}
html.dark .card {
    border-color: #2a2825;
}
html.dark .form-control,
html.dark .form-select {
    background: #151312;
    border-color: #3a3632;
    color: #fff;
}
html.dark .form-control:focus,
html.dark .form-select:focus {
    background: #151312;
    color: #fff;
}
html.dark .form-control::placeholder {
    color: #6B7280;
}
html.dark .dropdown-menu {
    background: #1c1917;
    border-color: #2a2825;
}
html.dark .dropdown-item {
    color: #e7e5e4;
}
html.dark .table {
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
}
html.dark .chat-widget {
    background: #1c1917;
}
html.dark .chat-widget-message.assistant {
    background: #2a2825;
    color: #e7e5e4;
    border-color: #3a3632;
}
html.dark .chat-widget-input {
    border-top-color: #2a2825;
}
html.dark .chat-widget-input textarea {
    background: #151312;
    border-color: #3a3632;
    color: #fff;
}
html.dark .widget-typing {
    background: #2a2825;
    border-color: #3a3632;
}

/* ==== Modo oscuro: chat de página completa ==== */
html.dark .chat-layout {
    border-top-color: #2a2825;
}
html.dark .message-assistant {
    background: #2a2825;
    color: #e7e5e4;
    border-color: #3a3632;
}
html.dark .chat-sidebar {
    background: #1c1917;
    border-right-color: #2a2825;
}
html.dark .sidebar-header {
    border-bottom-color: #2a2825;
}
html.dark .sidebar-item {
    color: #e7e5e4;
}
html.dark .sidebar-item:hover {
    background: #2a2825;
    color: #f5f5f4;
}
html.dark .sidebar-item.active {
    background: rgba(233, 83, 73, 0.18);
    color: #E95349;
}
html.dark .chat-input-area {
    border-top-color: #2a2825;
}
html.dark .chat-input-area textarea {
    background: #151312;
    color: #fff;
    border-color: #3a3632;
}
html.dark .typing-indicator {
    background: #2a2825;
    border-color: #3a3632;
}
html.dark .file-preview .chip {
    background: rgba(255, 255, 255, 0.08);
}
html.dark .msg-attachment {
    background: rgba(255, 255, 255, 0.08);
}
html.dark .msg-attachment:hover {
    background: rgba(255, 255, 255, 0.16);
}

/* ==== Modo oscuro: previsualización de publicaciones ==== */
html.dark .text-dark:not(.badge) {
    color: var(--text-color) !important;
}
html.dark .badge.bg-light.text-dark {
    color: #e7e5e4 !important;
}
html.dark .fb-post,
html.dark .fb-header,
html.dark .fb-actions {
    background: #1c1917;
    border-color: #3a3632;
}
html.dark .fb-page-name,
html.dark .fb-content {
    color: #e7e5e4;
}
html.dark .fb-image-placeholder,
html.dark .li-image-placeholder,
html.dark .tw-image {
    background: linear-gradient(135deg, #2a2825, #3a3632) !important;
}
html.dark .li-post,
html.dark .li-header,
html.dark .li-actions {
    background: #1c1917;
    border-color: #3a3632;
}
html.dark .li-page-name {
    color: #e7e5e4;
}
html.dark .li-content {
    color: #e7e5e4 !important;
}
html.dark .tw-post,
html.dark .tw-header {
    background: #1c1917;
    border-color: #3a3632;
}
html.dark .tw-name,
html.dark .tw-content {
    color: #e7e5e4;
}
html.dark .th-post,
html.dark .th-header,
html.dark .th-thread {
    background: #1c1917;
    border-color: #3a3632;
}
html.dark .th-name {
    color: #e7e5e4;
}
html.dark .th-dot {
    background: #a8a29e !important;
}
html.dark .th-line {
    background: #3a3632 !important;
}
html.dark .yt-post,
html.dark .yt-info,
html.dark .yt-actions {
    background: #1c1917;
    border-color: #3a3632;
}
html.dark .yt-info p {
    color: #e7e5e4 !important;
}
html.dark .nl-post {
    background: #1c1917 !important;
    color: #e7e5e4 !important;
    border-color: #3a3632 !important;
}
html.dark .nl-post h2 {
    color: #e7e5e4 !important;
}
html.dark .nl-post > div {
    color: #e7e5e4 !important;
}
html.dark .an-post {
    background: #1c1917 !important;
    border-color: #3a3632 !important;
}
html.dark .analytics-preview div[style*="Consolas"] {
    background: #151312 !important;
    color: #e7e5e4 !important;
    border-color: #2a2825 !important;
}
