/* Admin Panel Custom Styles - Premium Design */

:root {
    /* Color Palette */
    --primary-color: #3171ff;
    --primary-hover: #255edb;
    --primary-soft: #eff6ff;
    --primary-focus-shadow: 0 0 0 3px rgba(49, 113, 255, 0.16);
    --primary-action-shadow: 0 4px 6px -1px rgba(49, 113, 255, 0.3);
    --bs-primary: #3171ff;
    --bs-primary-rgb: 49, 113, 255;
    --bs-link-color: #3171ff;
    --bs-link-hover-color: #255edb;
    --success-color: #10b981;
    /* Emerald 500 */
    --danger-color: #ef4444;
    /* Red 500 */
    --warning-color: #f59e0b;
    /* Amber 500 */
    --info-color: #3b82f6;
    /* Blue 500 */

    /* Backgrounds */
    --bg-body: #f8fafc;
    /* Slate 50 */
    --bg-subtle: #f8fafc;
    --bg-surface: #ffffff;
    --bg-sidebar: #1e293b;
    /* Slate 800 */
    --bg-sidebar-hover: #334155;
    /* Slate 700 */

    /* Text */
    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */
    --text-light: #f1f5f9;
    /* Slate 100 */

    /* Borders & Shadows */
    --border-color: #e2e8f0;
    /* Slate 200 */
    --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);

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
}

/* Wrapper Layout */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
    align-items: stretch;
}

/* Sidebar */
.sidebar {
    min-width: 260px;
    max-width: 260px;
    height: 100vh;
    position: sticky;
    top: 0;
    background: var(--bg-sidebar);
    color: var(--text-light);
    transition: var(--transition-normal);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    overflow-y: auto;
}

.sidebar.active {
    margin-left: -260px;
}

.sidebar-header {
    padding: 20px 24px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
}

.sidebar-header h3 {
    color: #fff;
    font-size: 1.1rem;
    margin: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    line-height: 1.2;
}

.sidebar-logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.sidebar ul.components {
    padding: 16px 0;
    flex-grow: 1;
}

.sidebar ul li {
    padding: 4px 16px;
}

.sidebar .nav-link {
    font-size: 1.05rem;
    font-weight: 500;
    color: #94a3b8;
    /* Slate 400 */
    padding: 12px 18px;
    text-decoration: none;
    display: flex;
    align-items: center;
    border-radius: 8px;
    transition: var(--transition-fast);
}

.sidebar .nav-link:hover {
    color: #fff;
    background-color: var(--bg-sidebar-hover);
    transform: translateX(4px);
}

.sidebar .nav-link.active {
    color: #fff;
    background-color: var(--primary-color);
    box-shadow: var(--primary-action-shadow);
}

.sidebar .nav-link i {
    margin-right: 12px;
    font-size: 1.35rem;
    width: 28px;
    text-align: center;
}

.sidebar-footer {
    padding: 24px;
    background: rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    color: var(--text-light);
}

.sidebar-footer .user-info i {
    font-size: 2rem;
    color: var(--text-muted);
}

/* Content Area */
.content {
    width: 100%;
    min-height: 100vh;
    transition: var(--transition-normal);
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
    position: sticky;
    top: 0;
    z-index: 900;
}

#sidebarCollapse {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    padding: 4px;
    cursor: pointer;
    transition: var(--transition-fast);
    border-radius: 6px;
}

#sidebarCollapse:hover {
    color: var(--primary-color);
    background-color: var(--primary-soft);
}

/* Main Content */
main {
    padding: 2rem;
    flex-grow: 1;
}

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: var(--transition-fast);
}

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

.summary-estab-card:hover {
    transform: translateY(-2px);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.card-body {
    padding: 1.5rem;
}

.table-panel-header {
    display: block;
}

.table-panel-title {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.table-panel-title h4 {
    align-items: center;
    display: inline-flex;
    gap: 0.5rem;
    line-height: 1.25;
}

.table-filters {
    align-items: end;
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
    width: 100%;
}

.table-filter-field {
    min-width: 0;
}

.table-filter-field-wide {
    grid-column: span 2;
}

.table-filters .form-label {
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.table-filters .form-control,
.table-filters .form-select {
    min-height: 40px;
}

.table-filter-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    min-width: 0;
}

.table-filter-actions .btn {
    flex: 0 0 auto;
    justify-content: center;
    white-space: nowrap;
}

.table-filter-actions .btn-outline-secondary {
    background-color: var(--bg-surface);
    border: 1px solid #cbd5e1;
    color: var(--text-muted);
}

.table-filter-actions .btn-outline-secondary:hover,
.table-filter-actions .btn-outline-secondary:focus,
.table-filter-actions .btn-outline-secondary:active {
    background-color: var(--bg-subtle);
    border-color: #94a3b8;
    color: var(--text-main);
}

.conversation-filters {
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.conversation-filters .table-filter-field {
    grid-column: span 2;
}

.conversation-filters .table-filter-field-wide {
    grid-column: span 3;
}

.conversation-filters .table-filter-actions {
    align-self: end;
    display: grid;
    gap: 0.5rem;
    grid-column: span 3;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
}

.conversation-filters .table-filter-actions .btn {
    min-width: 0;
    width: 100%;
}

/* Tables */
.table {
    margin-bottom: 0;
    color: var(--text-main);
    vertical-align: middle;
}

.table th,
.dataTable thead th {
    background-color: var(--bg-subtle);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    vertical-align: middle;
}

.table th {
    letter-spacing: 0.05em;
    padding: 1rem;
}

.table td,
.dataTable tbody td {
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    vertical-align: middle;
}

.table td {
    padding: 1rem;
}

.table-hover tbody tr:hover,
.dataTable tbody tr:hover td {
    background-color: var(--bg-subtle);
}

/* Buttons */
.btn {
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background-color: var(--primary-hover) !important;
    border-color: var(--primary-hover) !important;
    box-shadow: var(--primary-action-shadow);
}

.btn-outline-primary {
    color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
}

.btn-outline-primary:hover,
.btn-outline-primary:focus,
.btn-outline-primary:active {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: #fff !important;
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

.text-primary {
    color: var(--primary-color) !important;
}

.border-primary {
    border-color: var(--primary-color) !important;
}

.progress-bar {
    background-color: var(--primary-color);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: var(--primary-focus-shadow);
}

.page-link {
    color: var(--primary-color);
}

.page-link:hover,
.page-link:focus {
    color: var(--primary-hover);
    box-shadow: var(--primary-focus-shadow);
}

.page-item.active .page-link {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

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

.btn-sm {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
}

/* Badges */
.badge {
    font-weight: 600;
    padding: 0.35em 0.8em;
    border-radius: 6px;
}

/* Alerts */
.floating-alerts-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    width: 350px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    /* Allow clicking through the container */
}

.alert {
    pointer-events: auto;
    /* Re-enable pointer events for the alerts themselves */
    border: none;
    border-radius: 12px;
    padding: 1rem 1.25rem;
    padding-bottom: 1rem;
    margin-bottom: 0;
    /* Container handles gap */
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border-left: 4px solid transparent;
    /* Reset default border */
    position: relative;
    overflow: visible;
    min-width: 280px;
}

/* Progress bar using ::after pseudo-element */
.alert::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    width: 100%;
    background: linear-gradient(90deg, currentColor 0%, currentColor 100%);
    opacity: 0.3;
    border-radius: 0 0 12px 12px;
    animation: alertProgressAnimation 5s linear forwards;
}

@keyframes alertProgressAnimation {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.alert-info {
    background-color: rgba(239, 246, 255, 0.95);
    /* #eff6ff with opacity */
    color: #1e40af;
    border-left-color: var(--info-color);
}

.alert-info::after {
    background: linear-gradient(90deg, var(--info-color) 0%, #60a5fa 100%);
    opacity: 0.5;
}

.alert-success {
    background-color: rgba(236, 253, 245, 0.95);
    /* #ecfdf5 with opacity */
    color: #065f46;
    border-left-color: var(--success-color);
}

.alert-success::after {
    background: linear-gradient(90deg, var(--success-color) 0%, #34d399 100%);
    opacity: 0.5;
}

.alert-danger {
    background-color: rgba(254, 242, 242, 0.95);
    /* #fef2f2 with opacity */
    color: #991b1b;
    border-left-color: var(--danger-color);
}

.alert-danger::after {
    background: linear-gradient(90deg, var(--danger-color) 0%, #f87171 100%);
    opacity: 0.5;
}

.alert-warning {
    background-color: rgba(255, 251, 235, 0.95);
    /* #fffbeb with opacity */
    color: #92400e;
    border-left-color: var(--warning-color);
}

.alert-warning::after {
    background: linear-gradient(90deg, var(--warning-color) 0%, #fbbf24 100%);
    opacity: 0.5;
}

/* Alert message content */
.alert > span,
.alert > div:first-child {
    flex: 1;
    min-width: 0;
}

/* Close button styling for alerts - Tapestry uses .close class */
.alert .close,
.alert .btn-close {
    flex-shrink: 0;
    background: transparent;
    border: none;
    font-size: 1.2rem;
    line-height: 1;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}

.alert .close:hover,
.alert .btn-close:hover {
    opacity: 1;
}

/* Conversation token usage */
.token-usage-panel {
    background: var(--bg-subtle);
    padding: 0.85rem 1rem;
}

.token-usage-metrics .badge {
    white-space: nowrap;
}

.token-internal-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 100%;
    padding: 0.35rem 0.6rem;
    color: #334155;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.78rem;
    line-height: 1.2;
}

.message-token-usage {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.65rem;
    font-size: 0.72rem;
    opacity: 0.85;
}

.message-sources {
    min-width: min(100%, 320px);
}

#detailModal .conversation-detail-dialog {
    height: calc(100dvh - 1rem);
    margin-bottom: 0.5rem;
    margin-top: 0.5rem;
    max-height: calc(100dvh - 1rem);
}

#detailModal .modal-content {
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

#detailModal .conversation-detail-zone {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    max-height: 100%;
    min-height: 0;
}

#detailModal .modal-header,
#detailModal .modal-footer,
#detailModal .conversation-detail-meta,
#detailModal .token-usage-panel,
#detailModal .conversation-detail-note {
    flex: 0 0 auto;
}

#detailModal .conversation-detail-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

#detailModal .conversation-message-thread {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

@media (min-width: 576px) {
    #detailModal .conversation-detail-dialog {
        height: calc(100dvh - 3.5rem);
        margin-bottom: 1.75rem;
        margin-top: 1.75rem;
        max-height: calc(100dvh - 3.5rem);
    }
}

/* Dashboard */
.dashboard-page {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.dashboard-header {
    align-items: flex-start;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
}

.dashboard-header h2 {
    font-weight: 700;
    letter-spacing: 0;
    margin: 0 0 0.25rem;
}

.dashboard-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: flex-end;
}

.dashboard-kpi-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.dashboard-kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    color: var(--text-main);
    display: grid;
    gap: 0.25rem;
    min-height: 156px;
    padding: 1.15rem;
    position: relative;
    text-decoration: none;
    transition: var(--transition-fast);
}

.dashboard-kpi-card:hover {
    box-shadow: var(--shadow-md);
    color: var(--text-main);
    transform: translateY(-2px);
}

.dashboard-kpi-card::before {
    border-radius: 12px 12px 0 0;
    content: '';
    height: 4px;
    left: -1px;
    position: absolute;
    right: -1px;
    top: -1px;
}

.dashboard-kpi-primary::before {
    background: var(--primary-color);
}

.dashboard-kpi-green::before {
    background: var(--success-color);
}

.dashboard-kpi-amber::before {
    background: var(--warning-color);
}

.dashboard-kpi-red::before {
    background: var(--danger-color);
}

.dashboard-kpi-icon {
    align-items: center;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--primary-color);
    display: inline-flex;
    font-size: 1.2rem;
    height: 40px;
    justify-content: center;
    margin-bottom: 0.35rem;
    width: 40px;
}

.dashboard-kpi-label {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
}

.dashboard-kpi-card strong {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.dashboard-kpi-card small {
    align-self: end;
    color: var(--text-muted);
    font-weight: 600;
}

.dashboard-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    min-height: 100%;
    overflow: hidden;
}

.dashboard-panel-header {
    align-items: flex-start;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding: 1.15rem 1.25rem;
}

.dashboard-panel-header h5 {
    align-items: center;
    display: flex;
    font-size: 1rem;
    font-weight: 700;
    gap: 0.5rem;
    margin: 0 0 0.2rem;
}

.dashboard-panel-header p {
    color: var(--text-muted);
    font-size: 0.86rem;
    margin: 0;
}

.dashboard-table th,
.dashboard-table td {
    padding: 0.85rem 1.25rem;
}

.dashboard-health-list {
    display: grid;
    gap: 0;
}

.dashboard-health-list > div,
.dashboard-sync-last {
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding: 0.9rem 1.25rem;
}

.dashboard-health-list span,
.dashboard-rag-strip span,
.dashboard-sync-last span {
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.dashboard-health-list strong,
.dashboard-sync-last strong {
    font-size: 0.92rem;
    text-align: right;
}

.dashboard-rag-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-rag-strip > div {
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    padding: 1rem;
    text-align: center;
}

.dashboard-rag-strip > div:last-child {
    border-right: 0;
}

.dashboard-rag-strip strong {
    display: block;
    font-size: 1.35rem;
    line-height: 1.2;
    margin-top: 0.2rem;
}

.dashboard-conversation-list {
    display: grid;
    gap: 0.75rem;
    padding: 1rem 1.25rem 1.25rem;
}

.dashboard-conversation-item {
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    display: grid;
    gap: 1rem;
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 82px;
    padding: 0.9rem;
    text-decoration: none;
    transition: var(--transition-fast);
}

.dashboard-conversation-item:hover {
    border-color: rgba(var(--bs-primary-rgb), 0.35);
    box-shadow: var(--shadow-sm);
    color: var(--text-main);
}

.dashboard-conversation-title {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dashboard-conversation-meta {
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.8rem;
    gap: 0.4rem 0.75rem;
    margin-top: 0.25rem;
}

.dashboard-conversation-stats {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    justify-content: flex-end;
    max-width: 520px;
}

.dashboard-conversation-stats small,
.dashboard-totals span {
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 700;
    padding: 0.28rem 0.5rem;
    white-space: nowrap;
}

.dashboard-totals {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-end;
}

.dashboard-conversation-stats .dashboard-feedback-positive {
    background: #ecfdf5;
    border-color: #bbf7d0;
    color: #047857;
}

.dashboard-conversation-stats .dashboard-feedback-negative {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.dashboard-empty {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    min-height: 180px;
    padding: 2rem;
    text-align: center;
}

.dashboard-empty i {
    color: var(--primary-color);
    font-size: 1.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        margin-left: -260px;
        position: fixed;
        height: 100%;
    }

    .sidebar.active {
        margin-left: 0;
    }

    .content {
        width: 100%;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar.active+.sidebar-overlay {
        display: block;
    }

    .dashboard-header {
        display: grid;
    }

    .dashboard-header-actions {
        justify-content: stretch;
    }

    .dashboard-header-actions .btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    .dashboard-kpi-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-panel-header,
    .dashboard-health-list > div,
    .dashboard-sync-last {
        align-items: flex-start;
        display: grid;
    }

    .dashboard-health-list strong,
    .dashboard-sync-last strong {
        text-align: left;
    }

    .dashboard-rag-strip {
        grid-template-columns: 1fr;
    }

    .dashboard-rag-strip > div {
        border-right: 0;
    }

    .dashboard-conversation-item {
        grid-template-columns: 1fr;
    }

    .dashboard-conversation-stats {
        justify-content: flex-start;
        max-width: none;
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .dashboard-kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Utilities */
.text-muted {
    color: var(--text-muted) !important;
}

.shadow-sm {
    box-shadow: var(--shadow-sm) !important;
}

.shadow {
    box-shadow: var(--shadow-md) !important;
}

.shadow-lg {
    box-shadow: var(--shadow-lg) !important;
}

/* ============================================
   DATATABLES
   ============================================ */

.dt-container {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
}

.dt-container .dt-layout-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    justify-content: space-between;
    margin: 0 0 1rem;
}

.dt-container .dt-layout-row:last-child {
    margin: 1rem 0 0;
}

.dt-container .dt-layout-cell {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.dt-container .dt-layout-cell.dt-layout-start {
    justify-content: flex-start;
}

.dt-container .dt-layout-cell.dt-layout-end {
    justify-content: flex-end;
}

.dataTable {
    border-collapse: separate !important;
    border-spacing: 0;
    width: 100% !important;
    margin: 0 !important;
}

.dataTable thead th {
    border-top: 0;
    letter-spacing: 0;
    padding: 0.875rem 1rem !important;
    white-space: nowrap;
}

.dataTable tbody td {
    padding: 0.75rem 1rem !important;
    overflow-wrap: anywhere;
}

.conversation-title-btn {
    color: var(--primary-color);
    font-weight: 600;
    line-height: 1.35;
    max-width: 100%;
    padding: 0 !important;
    text-align: left;
    text-decoration: none;
    white-space: normal;
}

.conversation-title-btn:hover,
.conversation-title-btn:focus {
    color: var(--primary-hover);
    text-decoration: underline;
}

.dataTable thead th.dt-orderable-asc,
.dataTable thead th.dt-orderable-desc {
    cursor: pointer !important;
    padding-right: 2rem !important;
    user-select: none;
}

.dataTable thead th.dt-orderable-asc span.dt-column-order:before,
.dataTable thead th.dt-orderable-desc span.dt-column-order:after {
    color: var(--text-muted);
    opacity: 0.35;
}

.dataTable thead th.dt-ordering-asc span.dt-column-order:before,
.dataTable thead th.dt-ordering-desc span.dt-column-order:after {
    color: var(--primary-color);
    opacity: 1;
}

.dt-length,
.dt-search,
.dt-buttons {
    margin-bottom: 0;
}

.dt-length label,
.dt-search label {
    align-items: center;
    color: var(--text-muted);
    display: flex;
    font-size: 0.875rem;
    font-weight: 500;
    gap: 0.5rem;
}

.dt-length select,
.dt-search input {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.875rem;
    min-height: 38px;
    transition: var(--transition-fast);
}

.dt-length select {
    cursor: pointer;
    padding: 0.375rem 2rem 0.375rem 0.75rem;
}

.dt-search input {
    margin-left: 0.5rem;
    min-width: min(260px, 100%);
    padding: 0.5rem 0.75rem;
}

.dt-length select:focus,
.dt-search input:focus {
    border-color: var(--primary-color);
    box-shadow: var(--primary-focus-shadow);
    outline: none;
}

.dt-buttons .dt-button {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    color: var(--text-main) !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    line-height: 1.25 !important;
    padding: 0.5rem 0.75rem !important;
    transition: var(--transition-fast);
}

.dt-buttons .dt-button:hover,
.dt-buttons .dt-button:focus {
    background: var(--primary-soft) !important;
    border-color: var(--primary-color) !important;
    color: var(--primary-color) !important;
    outline: none !important;
}

div.dt-button-collection {
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 0.35rem !important;
}

div.dt-button-collection .dt-button {
    background: transparent !important;
    border: 0 !important;
    border-radius: 6px !important;
    box-shadow: none !important;
    text-align: left !important;
    width: 100%;
}

.dt-info {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 0;
}

.dt-paging {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
    padding: 0.5rem 0;
}

.dt-paging .dt-paging-button {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    color: var(--text-main) !important;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    margin: 0;
    min-height: 36px;
    min-width: 36px;
    padding: 0.45rem 0.7rem;
    text-decoration: none !important;
    transition: var(--transition-fast);
}

.dt-paging .dt-paging-button:not(.disabled):hover {
    background: var(--primary-soft) !important;
    border-color: rgba(49, 113, 255, 0.22) !important;
    color: var(--primary-color) !important;
    transform: translateY(-1px);
}

.dt-paging .dt-paging-button.current,
.dt-paging .dt-paging-button.current:hover {
    background: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: #fff !important;
    box-shadow: var(--primary-action-shadow);
}

.dt-paging .dt-paging-button.first,
.dt-paging .dt-paging-button.previous,
.dt-paging .dt-paging-button.next,
.dt-paging .dt-paging-button.last {
    padding-inline: 0.85rem;
}

.dt-paging .dt-paging-button.disabled,
.dt-paging .dt-paging-button.disabled:hover {
    background: var(--bg-subtle) !important;
    border-color: var(--border-color) !important;
    color: var(--text-muted) !important;
    cursor: not-allowed;
    opacity: 0.62;
    transform: none;
}

.dt-processing {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    color: var(--text-main);
    font-size: 0.875rem;
    font-weight: 500;
    left: 50%;
    padding: 1rem 1.25rem;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.dt-empty {
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 2.5rem 1.5rem !important;
    text-align: center;
}

.dataTable .badge {
    align-items: center;
    border-radius: 6px;
    display: inline-flex;
    font-size: 0.75rem;
    font-weight: 600;
    gap: 0.25rem;
    padding: 0.35em 0.7em;
}

.dataTable .btn-group-sm .btn {
    border-radius: 6px;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
}

@media (max-width: 768px) {
    .table-panel-title {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.5rem;
    }

    .table-filters {
        grid-template-columns: 1fr;
    }

    .table-filter-field-wide {
        grid-column: auto;
    }

    .table-filter-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        min-width: 0;
        width: 100%;
    }

    .table-filter-actions .btn {
        justify-content: center;
        width: 100%;
    }

    .conversation-filters .table-filter-field,
    .conversation-filters .table-filter-field-wide,
    .conversation-filters .table-filter-actions {
        grid-column: auto;
    }

    .dt-container .dt-layout-row,
    .dt-container .dt-layout-cell {
        display: block;
        text-align: left;
    }

    .dt-length,
    .dt-search,
    .dt-buttons {
        margin-bottom: 0.75rem;
    }

    .dt-search label {
        align-items: stretch;
        flex-direction: column;
        gap: 0.35rem;
    }

    .dt-search input {
        margin-left: 0;
        min-width: 100%;
        width: 100%;
    }

    .dt-info,
    .dt-paging {
        text-align: center;
    }

    .dt-paging {
        justify-content: center;
    }

    .dt-paging .dt-paging-button {
        min-height: 34px;
        min-width: 34px;
        padding: 0.4rem 0.6rem;
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .table-filters {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
    }

    .table-filter-field-wide {
        grid-column: auto;
    }

    .table-filter-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: stretch;
    }

    .table-filter-actions .btn {
        width: 100%;
    }

    .conversation-filters {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .conversation-filters .table-filter-field,
    .conversation-filters .table-filter-field-wide {
        grid-column: span 2;
    }

    .conversation-filters .table-filter-actions {
        grid-column: span 2;
    }
}

@media (min-width: 1200px) and (max-width: 1539px) {
    .conversation-filters {
        grid-template-columns: repeat(8, minmax(0, 1fr));
    }

    .conversation-filters .table-filter-field {
        grid-column: span 2;
    }

    .conversation-filters .table-filter-field-wide {
        grid-column: span 3;
    }

    .conversation-filters .table-filter-actions {
        grid-column: span 3;
    }
}

/* Breadcrumbs */
.breadcrumb {
    background-color: var(--bg-subtle);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    margin-bottom: 0;
    display: flex;
    align-items: center;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    font-size: 1rem;
}

.breadcrumb-item a {
    color: var(--text-muted);
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
}

.breadcrumb-item a:hover {
    color: var(--primary-color);
}

.breadcrumb-item.active {
    color: var(--text-main);
    font-weight: 600;
    display: flex;
    align-items: center;
}

.breadcrumb-item+.breadcrumb-item::before {
    color: var(--text-muted);
    content: "/";
    padding-top: 1px;
}

/* Nav Icon Buttons */
.nav-icon-btn {
    color: var(--text-muted);
    font-size: 1.25rem;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon-btn:hover {
    color: var(--primary-color);
    background-color: var(--primary-soft);
}

/* RAG Sync Panel */
.rag-sync-panel {
    position: fixed;
    top: 70px;
    /* Below navbar */
    right: 20px;
    width: 320px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.rag-sync-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.rag-sync-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rag-sync-header h5 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.rag-sync-body {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.rag-sync-header .btn-close {
    font-size: 0.8rem;
}

/* RAG Sync Panel - Contenido Dinámico */

.rag-sync-content {
    font-size: 0.875rem;
}

/* Sincronización Actual */
.current-sync-section {
    background: linear-gradient(135deg, var(--primary-soft) 0%, var(--bg-subtle) 100%);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.sync-progress-card {
    background: white;
    border-radius: 6px;
    padding: 10px;
    margin-top: 8px;
}

.sync-info-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 0.8rem;
}

.sync-info-row .label {
    color: #64748b;
    font-weight: 500;
}

.sync-info-row .value {
    color: #1e293b;
    font-weight: 600;
}

/* Animación spinning para el icono de refresh */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spinning {
    display: inline-block;
    animation: spin 2s linear infinite;
}

/* No Sync Section */
.no-sync-section {
    opacity: 0.7;
}

/* Sync Action Section */
.sync-action-section .btn {
    transition: all 0.2s ease;
}

.sync-action-section .btn:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.sync-action-section .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Historial de Sincronizaciones */
.sync-history-section h6 {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sync-history-list {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 4px;
}

/* Custom scrollbar para el historial */
.sync-history-list::-webkit-scrollbar {
    width: 6px;
}

.sync-history-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.sync-history-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.sync-history-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Item de historial */
.sync-history-item {
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

.sync-history-item:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateX(2px);
}

.sync-history-item:last-child {
    margin-bottom: 0;
}

.sync-history-item .badge {
    font-size: 0.7rem;
    padding: 3px 8px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.sync-item-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.75rem;
}

.detail-row {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #475569;
}

.detail-row i {
    color: #94a3b8;
    font-size: 0.7rem;
}

/* Alert pequeño para errores */
.alert-sm {
    font-size: 0.75rem;
    padding: 6px 10px;
    margin-top: 8px;
}

/* Badges de estado */
.badge.bg-primary {
    background-color: var(--primary-color) !important;
}

.badge.bg-success {
    background-color: var(--success-color) !important;
}

.badge.bg-danger {
    background-color: var(--danger-color) !important;
}

.badge.bg-secondary {
    background-color: #6b7280 !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .rag-sync-panel {
        width: 100%;
        right: 0;
        left: 0;
        border-radius: 0;
        top: 60px;
    }

    .sync-item-details {
        grid-template-columns: 1fr;
    }
}
