/* ── Theme tokens (semantic, swap on .dark) ────────────────────────── */
:root {
    --surface: #FFFFFF;
    --elevated: #F9FAFB;
    --sunken: #F3F4F6;
    --text-primary: #2D2926;     /* sob-black */
    --text-secondary: #54585A;   /* sob-grey-1 */
    --text-muted: #939598;       /* sob-grey-4 */
    --text-inverse: #FFFFFF;
    --border-default: #E5E7EB;
    --border-strong: #A7A8AA;    /* sob-grey-2 */
    --shadow-color: 0 20 137;    /* sob-reflex as r,g,b for rgba() use */
    --accent: #00A0E6;           /* Impact Blue — unchanged in dark */
    --accent-strong: #001489;    /* Reflex Blue — unchanged in dark */
    --accent-tint: #e6f6fd;      /* Impact Blue 10% */
    --accent-tint-hover: #ccf0fb;
    --accent-border: #99d9f4;
    --tooltip-bg: #111827;
}

html.dark {
    --surface: #1A1817;
    --elevated: #2D2926;         /* sob-black for cards */
    --sunken: #0F0E0D;
    --text-primary: #FFFFFF;
    --text-secondary: #B1B3B3;   /* sob-grey-5 */
    --text-muted: #6D6E71;       /* sob-grey-3 */
    --text-inverse: #2D2926;
    --border-default: #54585A;   /* sob-grey-1 */
    --border-strong: #6D6E71;
    --shadow-color: 0 0 0;
    /* Brand accents unchanged */
    --accent-tint: rgba(0, 160, 230, 0.15);
    --accent-tint-hover: rgba(0, 160, 230, 0.25);
    --accent-border: rgba(0, 160, 230, 0.4);
    --tooltip-bg: #2D2926;
    /* Tells the browser to render native form controls in dark style.
       Chrome/Safari honor this for <select>, scrollbars, etc.; Firefox
       partially. The explicit rules below cover what color-scheme misses. */
    color-scheme: dark;
}

/* Native <select> and its dropdown items: force dark surface + light text
   in dark mode. Without this, Firefox renders <option> with OS defaults
   (often white-on-white or white-on-light, hard to read). */
html.dark select,
html.dark option {
    background-color: #2D2926;   /* sob-black */
    color: #FFFFFF;
}
html.dark select option:checked,
html.dark select option:hover {
    background-color: rgba(0, 160, 230, 0.3);
}

html, body {
    background-color: var(--surface);
    color: var(--text-primary);
}

/* ── Engineering Tool Badges — semantic, NOT brand. Stay hardcoded. ── */
.eng-badge-good {
    background: #C6EFCE;
    color: #006100;
}

.eng-badge-moderate {
    background: #FFD966;
    color: #7c6900;
}

.eng-badge-near {
    background: #FF6666;
    color: #ffffff;
}

.eng-badge-violation {
    background: #C00000;
    color: #ffffff;
}

/* Engineering cable row animation */
.eng-cable-row {
    animation: engSlideIn 0.2s ease;
}

@keyframes engSlideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Engineering size table */
.eng-size-table th {
    position: sticky;
    top: 0;
    background: var(--elevated);
}

/* Print styles for engineering */
@media print {
    #sidebar, .lg\\:pl-64, button, .btn-primary, .btn-secondary, nav, footer {
        display: none !important;
    }
    .lg\\:pl-64 {
        padding-left: 0 !important;
    }
    main {
        padding: 0 !important;
        margin: 0 !important;
    }
    .eng-cable-row select {
        display: none;
    }
    .portal-card {
        break-inside: avoid;
    }
}

/* ── Portal Cards ─────────────────────────────────────────────────── */
.portal-card {
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border-default);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    display: block;
    text-decoration: none;
}

.portal-card:hover {
    border-color: var(--accent);
    box-shadow: 0 8px 24px rgba(var(--shadow-color), 0.1);
    transform: translateY(-2px);
}

.portal-card-disabled {
    opacity: 0.6;
    cursor: default;
}

.portal-card-disabled:hover {
    border-color: var(--border-default);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transform: none;
}

/* ── File Manager Icons ───────────────────────────────────────────── */
.file-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--sunken);
    color: var(--text-muted);
}

.file-icon-pdf { background: #fef2f2; color: #dc2626; }
.file-icon-doc, .file-icon-docx { background: #eff6ff; color: #2563eb; }
.file-icon-xls, .file-icon-xlsx, .file-icon-csv { background: #ecfdf5; color: #059669; }
.file-icon-ppt, .file-icon-pptx { background: #fff7ed; color: #ea580c; }
.file-icon-png, .file-icon-jpg, .file-icon-jpeg, .file-icon-gif { background: #faf5ff; color: #7c3aed; }
.file-icon-zip { background: #fefce8; color: #ca8a04; }

html.dark .file-icon-pdf { background: rgba(220, 38, 38, 0.18); color: #fca5a5; }
html.dark .file-icon-doc, html.dark .file-icon-docx { background: rgba(37, 99, 235, 0.18); color: #93c5fd; }
html.dark .file-icon-xls, html.dark .file-icon-xlsx, html.dark .file-icon-csv { background: rgba(5, 150, 105, 0.18); color: #6ee7b7; }
html.dark .file-icon-ppt, html.dark .file-icon-pptx { background: rgba(234, 88, 12, 0.18); color: #fdba74; }
html.dark .file-icon-png, html.dark .file-icon-jpg, html.dark .file-icon-jpeg, html.dark .file-icon-gif { background: rgba(124, 58, 237, 0.18); color: #c4b5fd; }
html.dark .file-icon-zip { background: rgba(202, 138, 4, 0.18); color: #fde047; }

/* ── Sidebar section transitions ─────────────────────────────────── */
.sidebar-section {
    transition: max-height 0.2s ease;
}

#sidebar {
    transition: transform 0.2s ease-in-out;
}

/* Table row hover effect */
tbody tr {
    transition: background-color 0.1s ease;
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Flash message animation */
.flash-message {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Initials Avatar - Reflex Blue (brand, unchanged in dark) */
.initials-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #001489;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.initials-avatar-lg {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #001489;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Skill badge - Impact Blue family */
.skill-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 9999px;
    background: var(--accent-tint);
    color: var(--accent-strong);
    border: 1px solid var(--accent-border);
    cursor: pointer;
    transition: all 0.15s ease;
}

html.dark .skill-badge { color: var(--accent); }

.skill-badge:hover {
    background: var(--accent-tint-hover);
    border-color: var(--accent);
    transform: translateY(-1px);
}

/* Drawer overlay & panel */
.drawer-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(45, 41, 38, 0.3);
    transition: opacity 0.2s ease;
}

html.dark .drawer-overlay {
    background: rgba(0, 0, 0, 0.55);
}

.drawer-overlay.hidden {
    display: none;
}

.drawer-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 90vw;
    background: var(--surface);
    box-shadow: -4px 0 24px rgba(var(--shadow-color), 0.12);
    overflow-y: auto;
    transform: translateX(0);
    transition: transform 0.25s ease;
}

/* Line clamp */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Heatmap */
.heatmap-grid {
    display: grid;
    gap: 2px;
}

.heatmap-cell {
    width: 100%;
    height: 100%;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
    position: relative;
}

.heatmap-cell:hover {
    transform: scale(1.5);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 10;
    border-radius: 5px;
}

.heatmap-col-label {
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-height: 130px;
    padding: 0 2px;
    line-height: 1.2;
}

.heatmap-row-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    padding-right: 10px;
    display: flex;
    align-items: center;
    height: 100%;
}

/* Tooltip */
.heatmap-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--tooltip-bg);
    color: white;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.4;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
    z-index: 30;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.heatmap-tooltip strong {
    font-weight: 600;
}

.heatmap-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--tooltip-bg);
}

.heatmap-cell:hover .heatmap-tooltip {
    display: block;
}

/* Brand accent line — 45° rising left→right per brand spec */
.brand-accent-line {
    width: 60px;
    height: 3px;
    background: var(--accent);
    transform: rotate(-45deg);
    transform-origin: left center;
}

/* Brand button styles */
.btn-primary {
    background-color: var(--accent);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: filter 0.15s ease;
}

.btn-primary:hover {
    filter: brightness(0.9);
}

.btn-secondary {
    background-color: var(--accent-strong);
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: filter 0.15s ease;
}

.btn-secondary:hover {
    filter: brightness(0.85);
}

/* Tag badge - base */
.tag-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 9999px;
    line-height: 1.4;
}

.tag-badge button {
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
}

/* Amber (certifications) */
.tag-badge-amber {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}
html.dark .tag-badge-amber {
    background: rgba(252, 211, 77, 0.15);
    color: #fcd34d;
    border-color: rgba(252, 211, 77, 0.35);
}

/* Emerald (specialties) */
.tag-badge-emerald {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}
html.dark .tag-badge-emerald {
    background: rgba(110, 231, 183, 0.15);
    color: #6ee7b7;
    border-color: rgba(110, 231, 183, 0.35);
}

/* Sky (markets) */
.tag-badge-sky {
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #7dd3fc;
}
html.dark .tag-badge-sky {
    background: rgba(125, 211, 252, 0.15);
    color: #7dd3fc;
    border-color: rgba(125, 211, 252, 0.35);
}

/* Tag dropdown */
.tag-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 50;
    max-height: 200px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    margin-top: 4px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.tag-dropdown.hidden {
    display: none;
}

.tag-dropdown-item {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.1s;
    color: var(--text-primary);
}

.tag-dropdown-item:hover {
    background: var(--sunken);
}

/* ── Insights Drill-Down Panel ─────────────────────────────────── */
.drill-down-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 45vh;
    background: var(--surface);
    border-top: 2px solid var(--accent);
    box-shadow: 0 -8px 30px rgba(var(--shadow-color), 0.15);
    z-index: 50;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.drill-down-panel.open {
    transform: translateY(0);
}

/* Heatmap clickable cells */
.heatmap-cell.clickable {
    cursor: pointer;
}

.heatmap-cell.clickable:hover {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

/* Bench item — expandable */
.bench-item {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.bench-item:hover {
    filter: brightness(0.97);
}

.bench-item .bench-chevron {
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.bench-item.expanded .bench-chevron {
    transform: rotate(180deg);
}

/* Skill pair clickable */
.skill-pair-row {
    cursor: pointer;
    border-radius: 6px;
    padding: 4px 6px;
    margin: -4px -6px;
    transition: background-color 0.15s ease;
}

.skill-pair-row:hover {
    background: var(--accent-tint);
}

/* Location treemap boxes */
.location-box {
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    cursor: default;
}

.location-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Gap badge */
.gap-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 9999px;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    cursor: pointer;
    transition: all 0.15s ease;
}
html.dark .gap-badge {
    background: rgba(248, 113, 113, 0.15);
    color: #fca5a5;
    border-color: rgba(248, 113, 113, 0.35);
}

.gap-badge:hover {
    background: #fee2e2;
    border-color: #f87171;
    transform: translateY(-1px);
}

/* Cert-skill correlation bar */
.cert-skill-bar {
    height: 20px;
    border-radius: 4px;
    transition: width 0.3s ease;
    min-width: 4px;
}

/* ── Team Map ──────────────────────────────────────────────────── */
#team-map {
    height: 520px;
    border-radius: 12px;
    z-index: 1;
}

/* Custom map marker — uses currentColor (set inline) */
.map-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: white;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), 0 0 0 3px rgba(255, 255, 255, 0.5);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    position: relative;
}

html.dark .map-marker {
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6), 0 0 0 3px rgba(45, 41, 38, 0.6);
}

.map-marker::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid currentColor;
}

.map-marker:hover {
    transform: scale(1.2);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4), 0 0 0 4px rgba(255, 255, 255, 0.7);
    z-index: 1000 !important;
}

.map-marker.dimmed {
    opacity: 0.3;
    filter: grayscale(0.7);
}

.map-marker.dimmed:hover {
    opacity: 0.7;
    filter: grayscale(0.3);
}

/* Pulse ring for large offices */
.map-marker.pulse-ring::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid currentColor;
    opacity: 0.4;
    animation: marker-pulse 2s ease-out infinite;
}

@keyframes marker-pulse {
    0% { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(1.8); opacity: 0; }
}

/* Map popup */
.map-popup .leaflet-popup-content-wrapper {
    border-radius: 12px;
    padding: 0;
    overflow: hidden;
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: 0 8px 30px rgba(var(--shadow-color), 0.2);
}

.map-popup .leaflet-popup-content {
    margin: 0;
    min-width: 260px;
    max-width: 320px;
}

.map-popup .leaflet-popup-tip {
    background: var(--surface);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.map-popup-header {
    padding: 12px 16px;
    color: white;
    font-weight: 600;
    font-size: 14px;
}

.map-popup-body {
    padding: 12px 16px;
    max-height: 220px;
    overflow-y: auto;
}

.map-popup-person {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-default);
    cursor: pointer;
    transition: background-color 0.1s;
}

.map-popup-person:last-child {
    border-bottom: none;
}

.map-popup-person:hover {
    background: var(--accent-tint);
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
}

/* Map stats chip */
.map-stats-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--accent-tint);
    color: var(--accent-strong);
}

html.dark .map-stats-chip { color: var(--accent); }

/* ── Brand wordmark (text-only for now; logo SVG drops in later) ──── */
.brand-wordmark {
    display: inline-flex;
    align-items: baseline;
    gap: 0.05em;
    text-decoration: none;
    color: inherit;
}

.brand-wordmark .reg {
    font-size: 0.5em;
    line-height: 1;
    vertical-align: baseline;
    padding-left: 0.05em;
}

/* ── Theme toggle (sidebar footer) ──────────────────────────────── */
.theme-toggle {
    display: inline-flex;
    gap: 0;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 9999px;
    padding: 2px;
}

.theme-toggle button {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.55);
    border-radius: 9999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.theme-toggle button:hover {
    color: white;
}

.theme-toggle button[aria-pressed="true"] {
    background: var(--accent);
    color: white;
}

/* ── Respect reduced-motion preference ──────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── Visible keyboard focus ring for custom/interactive elements ──── */
/* Components built from raw CSS (.btn-*, .skill-badge, .tag-badge button,
   .theme-toggle button, clickable cards/rows) had no focus style; this
   restores a consistent ring for keyboard users without affecting mouse. */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Global HTMX request progress bar (see app.js listeners) ──────── */
#htmx-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--accent);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: width 0.2s ease, opacity 0.3s ease;
}
#htmx-progress.active { opacity: 1; }

/* Tag-picker dropdown: keyboard-highlighted option */
.tag-dropdown-item.tp-active {
    background: var(--sunken);
}
