/* --- BASE --- */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden; /* no page scrolling, only inner scrolls */
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #212121;
    color: #e5e7eb;
}

body {
    display: flex;
    flex-direction: column;
}

header {
    padding: 6px 16px; /* smaller header bar */
    background: #171717;
    color: #f5f5f5;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
header h1 {
    margin: 0;
    font-size: 16px;
}
header .logout-link {
    margin-left: 10px;
    color: #6366f1;
    cursor: pointer;
    text-decoration: underline;
    font-size: 12px;
}

/* header right cluster: map toggle + logout */
.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.map-toggle-btn {
    background: #27272a;
    border: 1px solid #4b5563;
    color: #e5e7eb;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    cursor: pointer;
}
.map-toggle-btn:hover {
    background: #3f3f46;
}

main {
    padding: 8px;
    flex: 1;
    min-height: 0; /* important for flex scrolling */
    display: flex;
    flex-direction: column;
}

/* --- LAYOUT --- */
.layout {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    min-height: 0;
}

.left-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* right side (tables + optional map) */
.right-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

/* row that holds Jobs + Candidates cards */
.tables-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

/* MAP CONTAINER – always within right-column */
.map-container {
    display: none;              /* only visible in map mode */
    border-radius: 12px;
    border: 1px solid #2d2d2d;
    background: #171717;
    overflow: hidden;
    flex: 1;                    /* take remaining height when shown */
}

#results-map {
    width: 100%;
    height: 100%;
    min-height: 220px;
}

/* MAP MODE: show map, shrink tables strip at top */
body.map-mode .map-container {
    display: block;
}
body.map-mode .tables-row {
    flex: 0 0 320px;            /* about two-ish visible rows for each table */
}
body.map-mode .right-column {
    min-height: 0;
}

/* keep tables scrollable inside their own cards in map mode */
body.map-mode #jobs-results-card .results-container,
body.map-mode #candidates-results-card .results-container {
    max-height: none;           /* they already flex to fill card height */
}

@media (min-width: 900px) {
    .layout {
        flex-direction: row;
        align-items: stretch;
        gap: 4px; /* global gap between columns */
        height: 100%;
    }

    .left-column {
        width: 280px;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
        height: 100%;
        margin-right: 10px; /* hard gap so jobs never sits under panels */
        overflow-y: auto;   /* scroll filters inside column */
        overflow-x: hidden;
    }

    .right-column {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 8px;
        min-height: 0;
    }

    .tables-row {
        display: flex;
        flex-direction: row;
        gap: 4px;
        flex: 1;
        min-height: 0;
    }

    #controls-card {
        width: 100%;
        flex-shrink: 0;
    }

    #jobs-filters-card {
        width: 100%;
        flex-shrink: 0;
    }

    .results-section {
        min-width: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    /* Jobs table bubble – gets a bit more width, never under filters */
    #jobs-results-card {
        flex: 1 1 520px;
        min-width: 420px;
        margin-right: 4px; /* small gap before candidates */
    }

    /* Candidates table bubble – pinned to the right but can shrink a little */
    #candidates-results-card {
        flex: 0 0 860px; /* fixed basis, no growing */
        max-width: 860px; /* keep it consistent */
        margin-left: auto; /* pushes it to the right edge */
        margin-right: 0;
    }

    .results-card .results-container {
        flex: 1;
        max-height: none;
    }

    /* RIGHT COLUMN: tables + map */
    .right-column {
        flex: 1;
        display: flex;
        flex-direction: column;
        min-width: 0;
        height: 100%;
    }  

    /* Tables row (jobs + candidates side by side) */
    .tables-row {
        display: flex;
        gap: 4px;
        flex: 1;
        min-height: 0;
    }
    
    /* Keep your existing jobs/candidates sizing working as before */
    #jobs-results-card {
        flex: 1 1 520px;
        min-width: 420px;
        margin-right: 4px;
    }
    #candidates-results-card {
        flex: 0 0 860px;
        max-width: 860px;
        margin-left: auto;
        margin-right: 0;
    } 

    /* MAP CONTAINER – always inside right column, under tables */
    .map-container {
        display: none;              /* only visible in map mode */
        margin-top: 4px;
        border-radius: 8px;
        border: 1px solid #404040;
        background: #171717;
        overflow: hidden;
    }  

    /* Leaflet map surface */
    #results-map {
        width: 100%;
        height: 100%;
        min-height: 220px;
    }

}

/* --- MAP MODE LAYOUT --- */
/* In map mode, tables get ~65% of the right column height, map gets the rest */
body.map-mode .right-column {
    display: flex;
    flex-direction: column;
}

body.map-mode .tables-row {
    flex: 0 0 55%;
    max-height: 55%;
}

body.map-mode .map-container {
    display: block;
    flex: 1;
}

/* constrain inner scroll area so the shrink actually shows fewer rows */
body.map-mode #jobs-results-card .results-container,
body.map-mode #candidates-results-card .results-container {
    max-height: 100%;
}


/* --- JOBS TABLE SIZING --- */
#jobs-table {
    width: 100%;
    min-width: 0; /* allow full flex shrinking */
}

/* Use percentages so jobs table always fits its bubble */
#jobs-table th:nth-child(1) { width: 28%; } /* Title */
#jobs-table th:nth-child(2) { width: 22%; } /* Company */
#jobs-table th:nth-child(3) { width: 10%; } /* Role */
#jobs-table th:nth-child(4) { width: 10%; } /* Dist */
#jobs-table th:nth-child(5) { width: 18%; } /* Location*/
#jobs-table th:nth-child(6) { width: 7%; }  /* Status */
#jobs-table th:nth-child(7) { width: 5%; }  /* Action */

/* --- CARDS --- */
.card {
    box-sizing: border-box; /* stops filter panels from poking out */
    background: #171717;
    border-radius: 12px;
    padding: 8px 10px 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.6);
    border: 1px solid #2d2d2d;
}
.card h2 {
    font-size: 15px;
    margin: 0 0 6px;
}
.card h3 {
    font-size: 13px;
    margin: 4px 0 4px;
    color: #818cf8;
}

/* --- COMPACT FILTER PANELS --- */
#controls-card,
#jobs-filters-card {
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 12px;
    line-height: 1.2;
}
#controls-card h3,
#jobs-filters-card h3 {
    margin: 4px 0 2px;
}
#controls-card .loc-finder,
#jobs-filters-card .loc-finder {
    margin-bottom: 0;
}
#controls-card .loc-found-text,
#jobs-filters-card .loc-found-text {
    margin-bottom: 4px;
}
#controls-card .double-slider-box {
    height: 22px;
    margin-top: 0;
    margin-bottom: 4px;
}
#controls-card .pill-group,
#jobs-filters-card .pill-group {
    gap: 3px;
    margin-bottom: 2px;
}
#controls-card #open-form-filters {
    padding: 6px;
    margin: 4px 0;
}
#controls-card .secondary-row {
    margin-top: 4px;
}
#controls-card .status-text,
#jobs-filters-card .status-text {
    margin-top: 4px;
}

/* --- INPUTS --- */
label {
    font-size: 11px;
    color: #9ca3af;
    display: block;
    margin-bottom: 2px;
}
input, select, button {
    font-family: inherit;
}
.loc-finder {
    display: flex;
    gap: 4px;
    margin-bottom: 2px;
}
.loc-finder input {
    flex: 1;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #4b5563;
    background: #262626;
    color: white;
    font-size: 12px;
}
.loc-finder button {
    background: #374151;
    color: white;
    border: 1px solid #4b5563;
    border-radius: 6px;
    cursor: pointer;
    padding: 0 12px;
    font-size: 11px;
}
.loc-finder button:hover {
    background: #4b5563;
}
.loc-found-text {
    font-size:11px;
    color:#34d399;
    margin-bottom:8px;
    display: block;
    height: 16px;
}

/* --- PILLS --- */
.pill-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}
.pill-toggle {
    font-size: 11px;
    border-radius: 999px;
    border: 1px solid #404040;
    padding: 5px 12px;
    background: #262626;
    cursor: pointer;
    color: #d1d5db;
    transition: all 0.2s;
}
.pill-toggle:hover { background: #333; }
.pill-toggle.active {
    background: #4f46e5;
    color: white;
    border-color: #4f46e5;
}

/* --- SLIDERS --- */
.double-slider-box {
    position: relative;
    width: 100%;
    height: 28px;
    margin-bottom: 6px;
    margin-top: 2px;
}
.double-slider-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 4px;
    background: #4b5563;
    border-radius: 2px;
    transform: translateY(-50%);
    z-index: 1;
}
.double-slider-range {
    position: absolute;
    top: 50%;
    height: 4px;
    background: #6366f1;
    transform: translateY(-50%);
    z-index: 2;
}
.double-slider-input {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    width: 100%;
    height: 20px;
    pointer-events: none;
    -webkit-appearance: none;
    background: none;
    z-index: 3;
    margin: 0;
}
.double-slider-input::-webkit-slider-thumb {
    pointer-events: auto;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: #e5e7eb;
    border-radius: 50%;
    border: 2px solid #6366f1;
    cursor: pointer;
}

/* --- ACTION BUTTONS --- */
#open-form-filters {
    width: 100%;
    background: #262626;
    border: 1px dashed #6366f1;
    color: #818cf8;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    margin: 6px 0;
}
#open-form-filters:hover { background: #333; }

#run-search,
#run-jobs-search {
    background: #4f46e5;
    border-radius: 6px;
    border: none;
    color: white;
    padding: 10px;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    font-weight: 600;
    margin-top: 8px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
#run-search:hover:not(:disabled),
#run-jobs-search:hover:not(:disabled) {
    background: #4338ca;
}
#run-search:disabled,
#run-jobs-search:disabled {
    background: #3730a3;
    cursor: not-allowed;
    opacity: 0.8;
}

.loader-spin {
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: none;
    animation: rotation 1s linear infinite;
}
@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.secondary-row {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}
.secondary {
    background: #374151;
    border-radius: 6px;
    border: none;
    color: #e5e7eb;
    padding: 6px 10px;
    font-size: 11px;
    cursor: pointer;
    flex: 1;
}
.secondary:hover { background: #4b5563; }

.status-text {
    display: block;
    text-align: center;
    margin-top: 8px;
    font-size: 11px;
    color: #6b7280;
}

/* --- RESULTS TABLES --- */
.results-container {
    overflow-y: auto;
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #404040;
    background: #171717;
}

table.results {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    table-layout: fixed;
}

.results th {
    position: sticky;
    top: 0;
    background: #1f1f1f;
    z-index: 2;
    padding: 8px;
    border-bottom: 1px solid #404040;
    border-right: 1px solid #333;
    text-align: left;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    color: #ffffff;
}
.results th:hover { background: #2d2d2d; }
.results td {
    padding: 12px 8px;
    border-bottom: 1px solid #2d2d2d;
    border-right: 1px solid #222;
    text-align: left;
    vertical-align: top;
    overflow: hidden;
}

/* --- RESIZER HANDLES --- */
.col-resizer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}
.col-resizer::after {
    content: "";
    display: block;
    width: 2px;
    height: 50%;
    border-left: 1px solid #666;
    border-right: 1px solid #666;
}
.col-resizer:hover { background: rgba(255,255,255,0.1); }

.sort-indicator {
    margin-left: 2px;
    font-size: 9px;
    color: #6366f1;
    opacity: 0.7;
}
.sort-idx {
    font-size: 8px;
    vertical-align: super;
    opacity: 0.8;
    margin-left: 1px;
}

.results tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}
.results tbody tr:hover { background: #262626; }

/* Column formatting */
.name-cell {
    white-space: normal;
    word-wrap: break-word;
    font-weight: 500;
    color: #fff;
}
.loc-cell {
    white-space: normal;
    word-wrap: break-word;
}
.qual-cell { white-space: normal; }

/* --- PILLS (Main Table) --- */
.qual-pill,
.role-pill {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    margin: 1px 2px 1px 0;
    font-size: 10px;
    font-weight: 500;
    white-space: nowrap;
}
/* Qual Colors */
.pill-l5  { background: #4c1d95; color: #c4b5fd; border: 1px solid #5b21b6; }
.pill-l4  { background: #1e3a8a; color: #bfdbfe; border: 1px solid #1e40af; }
.pill-l3  { background: #14532d; color: #bbf7d0; border: 1px solid #166534; }
.pill-other { background: #374151; color: #9ca3af; border: 1px solid #4b5563; }

/* Role Colors */
.role-rm { background: #7f1d1d; color: #fecaca; border: 1px solid #991b1b; }
.role-dm { background: #7c2d12; color: #fed7aa; border: 1px solid #9a3412; }
.role-tl { background: #713f12; color: #fef08a; border: 1px solid #854d0e; }
.role-srsw { background: #14532d; color: #bbf7d0; border: 1px solid #166534; }
.role-rsw { background: #1e3a8a; color: #bfdbfe; border: 1px solid #1e40af; }
.role-other { background: #374151; color: #9ca3af; border: 1px solid #4b5563; }

.wt-badge {
    display: inline-block;
    background: #fbbf24;
    color: #78350f;
    font-size: 9px;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 4px;
    margin-right: 4px;
    vertical-align: middle;
}

.form-yes { color: #34d399; font-weight: bold; }
.form-no  { color: #4b5563; }
.checkbox-cell { text-align: center; }
.checkbox-cell input {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.ja-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #374151;
    color: #e5e7eb;
    border: 1px solid #4b5563;
    padding: 4px 8px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 10px;
    font-weight: 600;
}
.ja-btn:hover { background: #4b5563; }

/* Leaflet emoji markers */
.candidate-marker,
.job-marker {
    font-size: 20px;
    line-height: 20px;
    text-shadow: 0 0 4px rgba(0,0,0,0.9);
}

.candidate-marker {
    filter: drop-shadow(0 0 4px rgba(96,165,250,0.9));    /* blue-ish glow */
}

.job-marker {
    filter: drop-shadow(0 0 4px rgba(251,191,36,0.9));    /* amber-ish glow */
}


/* map markers */
.candidate-marker .marker-inner,
.job-marker .marker-inner {
    width: 22px;
    height: 22px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #f9fafb;
    box-shadow: 0 0 4px rgba(0,0,0,0.8);
}

/* individual marker colours */
.candidate-marker .marker-inner {
    background: #4f46e5;  /* purple */
    border: 2px solid #a5b4fc;
}

.job-marker .marker-inner {
    background: #10b981;  /* green */
    border: 2px solid #6ee7b7;
}

/* cluster icons */
.candidate-cluster-icon,
.job-cluster-icon {
    border-radius: 999px;
    box-shadow: 0 0 6px rgba(0,0,0,0.9);
}

.candidate-cluster-icon .cluster-inner,
.job-cluster-icon .cluster-inner {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #f9fafb;
}

/* distinct colours for clusters so you can tell them apart */
.candidate-cluster-icon .cluster-inner {
    background: #4338ca;
    border: 2px solid #a5b4fc;
}

.job-cluster-icon .cluster-inner {
    background: #047857;
    border: 2px solid #6ee7b7;
}


/* --- MODALS (Window-like) --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: none;
}

.modal {
    background: #171717;
    color: #e5e7eb;
    border-radius: 12px;
    border: 1px solid #404040;
    width: 900px;
    height: 700px;
    min-width: 400px;
    min-height: 300px;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 50%;
    left: 50%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.9);
    pointer-events: auto;
}

.modal-header {
    padding: 10px 16px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1f1f1f;
    flex-shrink: 0;
    cursor: move;
    user-select: none;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    position: relative;
}

.resizer {
    width: 15px;
    height: 15px;
    background: linear-gradient(135deg, transparent 50%, #6366f1 50%);
    position: absolute;
    bottom: 0;
    right: 0;
    cursor: se-resize;
    z-index: 10;
    border-bottom-right-radius: 12px;
}

#close-detail {
    color: #ef4444;
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    padding: 0 8px;
}
#close-detail:hover {
    color: #dc2626;
    transform: scale(1.1);
}

.login-box {
    width: 300px;
    padding: 30px;
    text-align: center;
    background: #171717;
    border: 1px solid #333;
    border-radius: 12px;
    position:relative;
    z-index:200;
    pointer-events: auto;
}
#login-overlay {
    background: rgba(0,0,0,0.85);
    pointer-events: auto;
}

.filter-section {
    margin-bottom: 12px;
    border-bottom: 1px solid #333;
    padding-bottom: 8px;
}
.filter-section h4 {
    margin: 0 0 8px;
    font-size: 14px;
    color: #818cf8;
}

.hidden { display: none !important; }

/* Inner Modal Tables */
.mini-table-container {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid #333;
    border-radius: 6px;
    margin-bottom: 16px;
}
.mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}
.mini-table th {
    background: #222;
    text-align: left;
    padding: 8px;
    border-bottom: 1px solid #333;
    position: sticky;
    top: 0;
}
.mini-table td {
    padding: 8px;
    border-bottom: 1px solid #2a2a2a;
}
.mini-table tbody tr:hover {
    background: #262626;
    cursor: pointer;
}

.detail-section { margin-bottom: 24px; }
.detail-grid {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 8px 16px;
    font-size: 13px;
    margin-bottom: 12px;
}
.label {
    color: #888;
    text-align: right;
    word-break: break-all;
}
.val {
    word-break: break-word;
}

