@media (prefers-color-scheme: dark) {
    body {
        --bs-bg: #212529;
        --bs-text: #f8f9fa;
        /* Add other variable overrides as needed */
    }
}

[x-cloak] {
    display: none !important;
}

/* Django Tables2 Sort Indicators */
.table thead th.asc:after,
table.table thead th.asc:after,
.table-container th.asc:after {
    content: '\0000a0\0025b2';  /* non-breaking space + up triangle */
    float: right;
}

.table thead th.desc:after,
table.table thead th.desc:after,
.table-container th.desc:after {
    content: '\0000a0\0025bc';  /* non-breaking space + down triangle */
    float: right;
}

.shifted-dropdown {
    margin-top: 4px !important;
    right: 1px !important;
    left: auto !important;
}

.brand-name {
    font-size: 48px;
    font-weight: bold;
    /* Choose a font that fits your branding */
    font-family: 'Helvetica', sans-serif;
}

.ask {
    color: #007bff;
}

.robots {
    color: #28a745;
}

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1050;
}

.modal-content {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    padding: 20px;
    border-radius: 5px;
    max-width: 500px;
    width: 100%;
}

[data-bs-theme="light"] .modal-content {
    background-color: #ffffff;
    color: #000000;
}

[data-bs-theme="dark"] .modal-content {
    background-color: #343a40;
    color: #ffffff;
}

.btn-close {
    /* Style as needed */
}

#overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    z-index: 9999;
}

/* =============================================================================
   TABLE STYLING - GLOBAL FIXES FOR ALL PAGES
   ============================================================================= */

/* Make all tables responsive by default */
table.table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: auto !important;
}

/* Ensure tables don't overflow their containers */
.table-container,
.table-responsive,
.retro-table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    width: 100% !important;
}

/* For django-tables2 rendered tables without explicit containers */
/* Using :has() selector for modern browsers */
div:has(> table.table) {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

/* Fallback for browsers without :has() support - target common parent patterns */
.django-tables2-container,
div[class*="col"] > table.table,
main table.table,
.content table.table {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    display: block !important;
}

/* Fix table cells to prevent overflow */
table.table th,
table.table td {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: 300px !important; /* Adjust as needed */
}

/* Special handling for description/content cells that need wrapping */
table.table td.text-wrap,
table.table td[data-name="description"],
table.table td[data-name="content"],
table.table td[data-name="body"] {
    white-space: normal !important;
    word-wrap: break-word !important;
    max-width: 400px !important;
}

/* Keep django-tables2 list views as real tables (not block), so columns size correctly. */
table.note-content-table,
table.task-status-table,
table.article-content-table {
    display: table !important;
    width: 100% !important;
    table-layout: auto !important;
}

/* Notes & Articles: never hard-clip main content/title column on desktop. */
@media (min-width: 992px) {
    table.note-content-table th:first-child,
    table.note-content-table td:first-child,
    table.article-content-table th:first-child,
    table.article-content-table td:first-child {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        max-width: none !important;
        word-break: break-word !important;
    }
}

/* Keep desktop tables readable (avoid aggressive clipping on wide screens). */
@media (min-width: 992px) {
    table.table th {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        max-width: none !important;
    }

    table.table td[data-name="content"],
    table.table td[data-name="description"],
    table.table td[data-name="title"],
    .task-status-table td:first-child {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        max-width: none !important;
    }

    .task-status-table {
        table-layout: auto !important;
        width: 100% !important;
    }
}

/* Action columns should be narrower */
table.table th:last-child,
table.table td:last-child {
    width: auto !important;
    white-space: nowrap !important;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    table.table {
        font-size: 0.875rem !important;
    }
    
    table.table th,
    table.table td {
        padding: 0.5rem !important;
        max-width: 200px !important;
    }
    
    /* Hide less important columns on mobile */
    table.table th.d-none-mobile,
    table.table td.d-none-mobile {
        display: none !important;
    }
}

/* Table styling - uses earth theme colors */
.retro-table-container table.table {
    background: var(--window-bg, #f5f2ed) !important;
    border: 1px solid var(--app-border, #d4cdc4) !important;
    border-radius: 8px !important;
}

.retro-table-container table.table th {
    background: var(--bark, #6b5d4d) !important;
    color: var(--cloud, #f0ece7) !important;
    border: 1px solid var(--app-border, #d4cdc4) !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

.retro-table-container table.table td {
    border: 1px solid var(--retro-gray, #c0c0c0) !important;
}

/* Fix for inline styles that might override responsive behavior */
table[style*="width"] {
    width: 100% !important;
}

/* Ensure pagination is properly contained */
.pagination {
    flex-wrap: wrap !important;
    margin-top: 1rem !important;
}

/* Fix specific page issues */

/* Links page - ensure filter form doesn't overflow */
.form-inline {
    flex-wrap: wrap !important;
}

.form-inline .form-group {
    margin-right: 1rem !important;
    margin-bottom: 0.5rem !important;
}

/* Messages page - special handling for thread tables */
.table-hover tbody tr {
    cursor: pointer;
}

/* Tasks page - handle dynamic content */
#task-main-test,
#task-table {
    width: 100% !important;
    overflow-x: auto !important;
}

/* Direct table styling for pages without wrapper divs */
body table.table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

/* Let table wrappers handle their own horizontal scroll */
.retro-table-wrapper,
.table-responsive {
    overflow-x: auto !important;
}

/* Force horizontal scroll on smaller screens */
@media (max-width: 992px) {
    .table-responsive,
    .retro-table-container,
    table.table {
        min-width: 100% !important;
        margin-bottom: 1rem !important;
    }
    
    /* Prevent page-level horizontal scroll — tables scroll within their wrappers */
    body {
        overflow-x: hidden !important;
    }
}
