/* =========================================
   1. GLOBAL LAYOUT & RESET
   ========================================= */
html, body {
    height: 100%;
    margin: 0;
    padding-top: 25px;
    overflow-x: hidden;
}

/* Fix scroll padding when modals are open */
body[style],
.modal-open,
.modal-open .fixed-top,
.modal-open .fixed-bottom {
    padding-right: 0 !important;
    overflow: auto !important;
}

/* Sticky Footer Wrapper */
.page-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    padding-bottom: 20px;
}

footer {
    margin-top: auto;
}

/* Footer Links */
.footer-link {
    transition: color 0.2s ease;
}

.footer-link:hover {
    color: var(--mdb-emphasis-color) !important;
}

/* =========================================
   2. CAPTCHA STYLES
   ========================================= */
/* Container */
.form-check.position-relative {
    min-height: 26px;
}

/* Checkbox & Checkmark Positioning */
#captcha-checkbox, 
#captcha-final-check {
    position: absolute;
    left: 0;
    top: 0;
    width: 26px;
    height: 26px;
    margin: 0;
    transition: opacity 0.2s;
}

#captcha-checkbox {
    opacity: 1;
    z-index: 12;
}

#captcha-final-check {
    opacity: 0;
    z-index: 11;
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Loading Spinner */
.captcha-spinner {
    position: absolute;
    left: -11px;
    top: -11px;
    width: 48px;
    height: 48px;
    border: 3px solid #ccc;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    opacity: 0;
    transition: opacity 0.2s;
    box-sizing: border-box;
    z-index: 10;
    pointer-events: none;
}

.captcha-spinner.show {
    opacity: 1;
}

@keyframes spin { 
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Label Spacing */
.form-check-label.ms-3 {
    margin-left: 2rem !important;
}

/* L1 Captcha Container (Checkbox Box) */
#captcha-checkbox-box {
    max-width: 280px;
    min-height: 78px;
    margin-left: auto !important;
    margin-right: auto !important;
    background-color: #eeeeee !important;
    border: 1px solid #d3d3d3 !important;
}

/* L2 Captcha Container (Card) */
#captcha-container .card {
    max-width: 320px;
    border: 1px solid #d3d3d3;
    justify-content: center !important;
    margin: 0 auto !important;
}

/* Digit Tiles */
.digit-tile {
    cursor: pointer;
    padding: 10px 0;
    margin: 0;
    border-radius: 4px;
    font-size: 24px;
    font-weight: bold;
    color: #fff;
    background-color: #495057;
    transition: background-color 0.1s;
    height: 60px;
    line-height: 40px;
    user-select: none;
}

.digit-tile:hover {
    background-color: #343a40;
}

.digit-tile.selected {
    background-color: #0d6efd;
    border: 2px solid #0a58ca;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.5);
}

/* Image Tiles */
.captcha-image-tile {
    width: 100px;
    height: 100px;
    object-fit: cover;
    cursor: pointer;
    border: 5px solid transparent;
    padding: 12px;
    box-sizing: border-box;
}

.captcha-image-tile.selected {
    border-color: #0d6efd;
    filter: brightness(1.1);
}

#captcha-image-grid .col-4 {
    padding: 2px;
}

/* Captcha Modal (Light Theme) */
.modal-backdrop {
    background-color: transparent !important;
}

#captchaImageModal .modal-content {
    background-color: #f6f6f6 !important;
    border: 1px solid #dee2e6 !important;
}

#captchaImageModal .modal-footer {
    background-color: #dadfe4 !important;
    border-top: 1px solid #dee2e6 !important;
}

/* --- Dark Theme Overrides for Captcha --- */
html[data-mdb-theme='dark'] #uidCaptcha #captcha-checkbox-box.card {
    background-color: #808080 !important;
    border: 1px solid #4f4f4f !important;
}

html[data-mdb-theme='dark'] #uidCaptcha #captcha-checkbox-box .form-check-label {
    color: #e9ecef !important;
}

html[data-mdb-theme='dark'] #captchaImageModal .modal-content {
    background-color: #5d5d5d !important;
    border: 1px solid #4f4f4f !important;
}

html[data-mdb-theme='dark'] #captchaImageModal .modal-footer {
    background-color: #505050 !important;
    border-top: 1px solid #4f4f4f !important;
}

/* =========================================
   3. SEARCH & RESULTS
   ========================================= */
#search-input-demo {
    background-color: var(--mdb-surface-bg);
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.2rem;
    border-width: 2px;
    caret-color: #0d6efd;
}

.result-card, 
#rawdata-container {
    opacity: 0;
    transition: opacity 0.6s ease-in-out;
}

.result-card.visible, 
#rawdata-container.visible {
    opacity: 1;
}

#rawdata-block {
    background-color: var(--mdb-surface-bg);
    border: 1px solid var(--mdb-border-color);
    padding: 1rem;
    border-radius: .5rem;
    font-family: 'Courier New', Courier, monospace;
}

.rawdata-row {
    border-bottom: 1px solid var(--mdb-border-color-translucent);
    padding: 10px 0;
}

.rawdata-row:last-child {
    border-bottom: none;
}

.rawdata-source {
    color: var(--mdb-secondary);
}

.rawdata-data code {
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--mdb-dark);
    word-break: break-all;
}

.search-card {
    margin-bottom: 10px;
}

/* =========================================
   4. API & CODE BLOCKS
   ========================================= */
/* Basic Code Block */
code.code-block {
    display: block;
    padding: 1rem;
    border-radius: .25rem;
    background-color: #f8f9fa;
    color: #333;
    white-space: pre;
    overflow-x: auto;
}

/* Dark Mode for Code Block */
body.dark-theme code.code-block, 
body[data-mdb-theme="dark"] code.code-block {
    background-color: #333;
    color: #f8f9fa;
}

/* API Example (Terminal Style) */
pre code.api-example-block {
    display: block;
    padding: 1rem;
    border-radius: 5px;
    background-color: #212529;
    color: #f8f9fa;
    white-space: pre;
    overflow-x: auto;
    font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.9em;
}

.api-example-tabs .tab-content {
    padding-top: 1.5rem;
}

/* =========================================
   5. TABLES (DATATABLE & USER INDEX)
   ========================================= */
/* General Table Reset */
.table {
    background-color: transparent !important;
    margin-bottom: 0;
}

.table-responsive {
    overflow-x: auto;
}

/* Table Header Styling */
.theme-header th {
    background-color: rgba(0, 0, 0, 0.05) !important;
    color: inherit !important;
}

.dark-mode .theme-header th {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

#dataTable thead th {
    text-align: center;
}

/* API Table Header Specifics */
.table-responsive table.table-bordered.align-middle thead.table-secondary tr {
    background-color: #6c757d !important;
    color: white !important;
}

.table-responsive table.table-bordered.align-middle thead.table-secondary th {
    background-color: inherit !important;
    color: inherit !important;
    border-color: #dee2e6 !important;
}

/* --- DataTable Core --- */
div.dataTables_wrapper {
    min-width: 0 !important;
}

table.dataTable.table-bordered {
    min-width: 200px !important;
    width: 100% !important; 
}

/* Cell sizing and overflow protection */
table.dataTable thead th, 
table.dataTable tbody td {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    min-width: 10px !important;
    max-width: 160px !important;
    vertical-align: middle !important;
}

/* Specific Columns Sizing */
.buy-btn { width: 100%; padding: 5px; }
.segn-cell { min-width: 30px; max-width: 80px; text-align: center; font-size: 16px !important; }
.flag-cell { min-width: 24px; max-width: 24px; text-align: center; font-size: 16px !important; }
.ssn-cell { min-width: 90px; max-width: 90px; font-size: 16px !important; }
.lastname-cell { min-width: 60px; max-width: 130px; text-align: center; font-size: 16px !important; }
.action-cell { min-width: 110px; max-width: 110px; font-size: 18px !important; }
.action-cell_40 { min-width: 40px; max-width: 40px; font-size: 18px !important; }
.action-cell_60 { min-width: 60px; max-width: 60px; font-size: 18px !important; }

.order-cell {
    min-width: 1px;
    max-width: 1px;
    text-align: center;
    align-items: center;
    font-size: 1px !important;
}

.rawdata-cell {
    min-width: 40px;
    max-width: 170px;
    text-align: center;
    align-items: center;
    font-size: 16px !important;
    word-wrap: break-word;
    word-break: break-word;
    white-space: normal;
    overflow-wrap: break-word;
    hyphens: auto;
}

th.code-col, td.code-col {
    width: 80px;
    text-align: center;
    font-weight: 700;
}

/* Loading State */
#tableLoading {
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Table Media Queries --- */

/* Hide search filter on small screens */
@media screen and (max-width: 779px) {
    div.dataTables_filter { display: none !important; }
}

/* Show search filter on larger screens */
@media screen and (min-width: 780px) {
    div.dataTables_filter { display: block !important; }
}

/* Hide length selector on very small screens */
@media screen and (max-width: 419px) {
    .dataTables_length { display: none !important; }
    
    /* Hide headers on very small screens (mobile view) */
    table.dataTable thead,
    table.dataTable thead tr {
        display: none !important;
    }
}

/* Hide header if table has fewer than 9 rows (Modern CSS :has selector) */
table.dataTable:not(:has(tbody tr:nth-child(9))) thead {
    display: none !important;
}

/* =========================================
   6. ROW DETAILS & EXPANSION
   ========================================= */
.details-content {
    padding: 1px;
    font-size: 0.9rem;
}

.detail-title {
    color: #6c757d;
}

.detail-value {
    word-break: break-word;
}

.expand-icon {
    font-weight: bold;
    font-size: 16px;
    color: #007bff;
    cursor: pointer;
}

/* =========================================
   7. UI COMPONENTS & UTILITIES
   ========================================= */
/* Flags */
.country-flag-popover {
    cursor: pointer;
    margin-right: 5px;
    border-radius: 2px;
}

.fi.country-flag-popover {
    height: 1em;
    width: 1.33333333em;
    vertical-align: middle;
}

/* Cards */
.card {
    margin: 5px;
}

/* Status Badges */
.status-badge {
    width: 100%;
    padding: 5px;
    text-align: center;
    display: block;
}

/* Visual Effects */
.insta-gradient {
    background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285AEB 90%);
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.text-pink {
    color: #e83e8c;
}

/* Word Break Utilities */
.text-break,
.word-wrap,
.overflow-wrap,
.details-content .col-md-8,
.details-content [class*="col-"] {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
    white-space: normal !important;
    hyphens: auto;
}