/* ============================================================
   ORGANIGRAMA CORPORATIVO - Estilos
   ============================================================ */

:root {
    --primary: #3B82F6;
    --primary-dark: #2563EB;
    --primary-light: #DBEAFE;
    --bg-primary: #F1F5F9;
    --bg-white: #FFFFFF;
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --text-light: #94A3B8;
    --border-color: #E2E8F0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-lg: 16px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Responsive tokens — overridden in media queries */
    --header-h: 64px;
    --filters-h: 48px;
    --top-offset: 112px; /* header + filters */
    --page-pad: 24px;
}

/* ===== RESET ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    /* Prevent pull-to-refresh on mobile interfering with pan */
    overscroll-behavior: none;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }

/* ===== LOADING ===== */
#loadingOverlay {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loadingOverlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-container {
    text-align: center;
    max-width: 400px;
    padding: 40px;
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary);
}

.loader-progress {
    margin-top: 16px;
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.loader-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), #7C3AED);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ===== HEADER ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 var(--page-pad);
    box-shadow: var(--shadow-sm);
}

.header-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), #7C3AED);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
}

.logo-text {
    line-height: 1.2;
}

.logo-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    display: block;
}

.logo-sub {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ===== SEARCH ===== */
.header-search {
    flex: 1;
    max-width: 400px;
    position: relative;
}

.header-search .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 14px;
    pointer-events: none;
}

.header-search input {
    width: 100%;
    padding: 8px 40px 8px 38px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    /* Prevent iOS zoom on focus */
    -webkit-text-size-adjust: 100%;
}

.header-search input:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-white);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.header-search input::placeholder {
    color: var(--text-light);
}

.header-search .search-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px;
    display: none;
    border-radius: 50%;
    transition: var(--transition);
}

.header-search .search-clear.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-search .search-clear:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
}

/* ===== HEADER ACTIONS ===== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 14px;
    /* Touch-friendly min size */
    min-width: 36px;
    min-height: 36px;
}

.btn-icon:hover {
    background: var(--bg-white);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-primary {
    padding: 8px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-weight: 600;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-white);
    border-color: var(--primary);
    color: var(--primary);
}

/* ===== FILTERS BAR ===== */
.filters-bar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    z-index: 900;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    padding: 8px var(--page-pad);
    height: var(--filters-h);
    display: flex;
    align-items: center;
}

.filters-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.filters-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.filters-chips {
    display: flex;
    gap: 6px;
    flex: 1;
    overflow-x: auto;
    padding: 2px 0;
    /* Smooth horizontal scroll for touch */
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    /* Hide scrollbar but keep functionality */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.filters-chips::-webkit-scrollbar {
    display: none;
}

/* Fade edges on scroll */
.filters-chips {
    mask-image: linear-gradient(
        to right,
        transparent,
        black 8px,
        black calc(100% - 8px),
        transparent
    );
    -webkit-mask-image: linear-gradient(
        to right,
        transparent,
        black 8px,
        black calc(100% - 8px),
        transparent
    );
}

.chip {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: 2px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 4px;
    /* Touch-friendly */
    min-height: 32px;
    -webkit-tap-highlight-color: transparent;
}

.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.chip.active:hover {
    background: var(--primary-dark);
}

.filters-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
}

.stat-item {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-item i {
    font-size: 13px;
}

.stat-level {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    position: fixed;
    top: var(--top-offset);
    left: 0;
    right: 0;
    bottom: 0;
    padding: 16px var(--page-pad) var(--page-pad);
}

.chart-wrapper {
    width: 100%;
    height: 100%;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    /* Enable smooth pan/zoom on touch */
    touch-action: none;
}

#chartContainer {
    width: 100%;
    height: 100%;
}

#chartContainer svg {
    font-family: 'Inter', system-ui, sans-serif !important;
    /* Ensure touch events work for pan/zoom */
    touch-action: none;
}

/* ===== ORG CARD ===== */
.org-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    border: 1.5px solid var(--border-color);
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.org-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.org-card-header {
    height: 4px;
    flex-shrink: 0;
}

.org-card-body {
    flex: 1;
    padding: 14px 16px;
    display: flex;
    gap: 14px;
    align-items: center;
    position: relative;
}

.org-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
    border: 2.5px solid transparent;
    transition: var(--transition);
}

.org-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.org-card:hover .org-avatar {
    border-color: currentColor;
}

.org-info {
    min-width: 0;
    flex: 1;
}

.org-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.org-cargo {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.org-tags {
    margin-top: 6px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.org-tag {
    font-size: 9px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.org-email-indicator {
    position: absolute;
    top: 8px;
    right: 10px;
    color: var(--text-light);
    font-size: 11px;
}

/* ===== FLOATING COUNTER ===== */
.floating-counter {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 20px;
    box-shadow: var(--shadow-md);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.counter-number {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
}

.counter-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-overlay.visible {
    display: flex;
}

.modal-container {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    /* Prevent modal from being taller than viewport */
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-container.modal-stats {
    max-width: 560px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(241, 245, 249, 0.9);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 10;
    font-size: 14px;
    /* Keep it sticky when modal scrolls */
    position: sticky;
    float: right;
    margin: 12px 12px 0 0;
}

.modal-close:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-header-color {
    height: 6px;
    width: 100%;
}

.modal-body {
    padding: 28px 24px 24px;
    text-align: center;
}

.modal-avatar {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    font-weight: 800;
    overflow: hidden;
    border: 4px solid var(--border-color);
    transition: var(--transition);
}

.modal-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-name {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 2px;
}

.modal-cargo {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

.modal-tags {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 16px 0 20px;
    flex-wrap: wrap;
}

.modal-tag {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 14px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.modal-divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

.modal-info {
    text-align: left;
}

.modal-info-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.modal-info-row:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.modal-info-row i {
    width: 18px;
    color: var(--text-light);
    font-size: 15px;
    text-align: center;
    flex-shrink: 0;
}

.modal-info-row a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    /* Prevent long emails from overflowing */
    word-break: break-all;
}

.modal-info-row a:hover {
    text-decoration: underline;
}

.modal-info-row strong {
    color: var(--text-primary);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

/* ===== STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stats-card {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    border-top: 4px solid var(--border-color);
}

.stats-card h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.stats-number {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-primary);
}

.stats-label {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 500;
}

.stats-divider {
    height: 1px;
    background: var(--border-color);
    margin: 20px 0;
}

.stats-areas {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.stats-area {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.stats-area-name {
    min-width: 100px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: left;
}

.stats-area-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

.stats-area-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

.stats-area-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 60px;
    text-align: right;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    padding: 40px;
    text-align: center;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 8px 0 4px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-light);
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* ===== TABLET (≤1024px) ===== */
@media (max-width: 1024px) {
    :root {
        --page-pad: 16px;
    }

    .header-search {
        max-width: 280px;
    }
}

/* ===== MOBILE LANDSCAPE / SMALL TABLET (≤768px) ===== */
@media (max-width: 768px) {
    :root {
        --header-h: 56px;
        --filters-h: 44px;
        --top-offset: 100px;
        --page-pad: 12px;
    }

    /* — Header — */
    .header-container {
        gap: 10px;
    }

    .logo-icon {
        width: 32px;
        height: 32px;
        font-size: 14px;
        border-radius: 8px;
    }

    .logo-title { font-size: 15px; }
    .logo-sub { display: none; }

    /* Search takes remaining space */
    .header-search {
        max-width: none;
        flex: 1;
    }

    .header-search input {
        padding: 6px 32px 6px 34px;
        font-size: 14px; /* >=16px prevents iOS zoom, but 14px is fine with text-size-adjust */
    }

    /* — Actions — */
    .btn-icon {
        width: 34px;
        height: 34px;
        min-width: 34px;
        font-size: 13px;
        border-radius: 8px;
    }

    .btn-primary span { display: none; }
    .btn-primary {
        padding: 8px 12px;
        border-radius: 8px;
    }

    /* — Filters bar — */
    .filters-bar {
        padding: 6px var(--page-pad);
        height: var(--filters-h);
    }

    .filters-label { display: none; }

    .filters-stats .stat-level { display: none; }
    .filters-stats {
        border-left: none;
        padding-left: 0;
    }

    /* — Chart area — */
    .main-content {
        padding: var(--page-pad);
    }

    .chart-wrapper {
        border-radius: var(--radius);
    }

    /* — Counter — */
    .floating-counter {
        bottom: 12px;
        padding: 6px 14px;
        border-radius: 10px;
    }
    .counter-number { font-size: 14px; }
    .counter-label { font-size: 12px; }

    /* — Modals — */
    .modal-overlay {
        padding: 12px;
        /* On mobile, align modal to bottom for thumb reach */
        align-items: flex-end;
    }

    .modal-container {
        max-height: 85vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        animation: modalSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    @keyframes modalSlideUp {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .modal-body {
        padding: 20px 16px 24px;
    }

    .modal-avatar {
        width: 68px;
        height: 68px;
        font-size: 24px;
        border-width: 3px;
    }

    .modal-name { font-size: 19px; }
    .modal-cargo { font-size: 14px; }

    /* Stats modal */
    .modal-container.modal-stats {
        max-width: 100%;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .stats-card { padding: 12px; }
    .stats-number { font-size: 24px; }
    .stats-area-name { min-width: 80px; font-size: 12px; }
    .stats-area-count { min-width: 50px; font-size: 11px; }
}

/* ===== SMALL MOBILE (≤480px) ===== */
@media (max-width: 480px) {
    :root {
        --header-h: 52px;
        --filters-h: 40px;
        --top-offset: 92px;
        --page-pad: 8px;
    }

    /* — Header stacks search below on very small screens — */
    .header-container {
        gap: 6px;
    }

    .logo-text { display: none; }

    .logo-icon {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .header-search input {
        font-size: 13px;
        padding: 5px 28px 5px 30px;
        border-radius: 8px;
    }

    .header-search .search-icon {
        font-size: 12px;
        left: 10px;
    }

    /* Hide stats & expand/collapse on tiny screens, keep fit + export + add */
    #btnStats,
    #btnExpand,
    #btnCollapse {
        display: none;
    }

    /* Style export button green on mobile for visibility */
    #btnExport {
        border-color: #16A34A;
        color: #16A34A;
        background: #F0FDF4;
    }

    .btn-icon {
        width: 30px;
        height: 30px;
        min-width: 30px;
        font-size: 12px;
    }

    .btn-primary {
        padding: 6px 10px;
        font-size: 12px;
    }

    /* — Filters — */
    .filters-bar {
        padding: 4px var(--page-pad);
    }

    .chip {
        font-size: 11px;
        padding: 3px 10px;
        min-height: 28px;
    }

    .filters-stats { display: none; }

    /* — Chart — */
    .main-content {
        padding: var(--page-pad);
    }

    .chart-wrapper {
        border-radius: 10px;
    }

    /* — Counter: smaller, bottom-left to not overlap zoom controls — */
    .floating-counter {
        bottom: 8px;
        left: 8px;
        transform: none;
        padding: 4px 10px;
        border-radius: 8px;
    }
    .counter-number { font-size: 12px; }
    .counter-label { font-size: 11px; }

    /* — Modal takes full width — */
    .modal-overlay {
        padding: 0;
    }

    .modal-container {
        max-height: 90vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .modal-body {
        padding: 16px 14px 20px;
    }

    .modal-avatar {
        width: 60px;
        height: 60px;
        font-size: 22px;
    }

    .modal-name { font-size: 17px; }
    .modal-cargo { font-size: 13px; }

    .modal-info-row {
        font-size: 13px;
        gap: 10px;
        padding: 8px 0;
    }

    .modal-tag {
        font-size: 10px;
        padding: 3px 10px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .stats-card { padding: 10px; }
    .stats-number { font-size: 20px; }
}

/* ===== LANDSCAPE PHONES (short height) ===== */
@media (max-height: 500px) {
    :root {
        --header-h: 48px;
        --filters-h: 36px;
        --top-offset: 84px;
    }

    .logo-sub { display: none; }
    .filters-stats { display: none; }

    .floating-counter { display: none; }

    .modal-overlay { align-items: center; }
    .modal-container {
        max-height: 95vh;
        border-radius: var(--radius);
    }
    .modal-avatar { width: 50px; height: 50px; font-size: 18px; }
    .modal-body { padding: 12px; }
    .modal-name { font-size: 16px; }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== D3 ORG CHART OVERRIDES ===== */
#chartContainer .node-clickable {
    cursor: pointer;
}

#chartContainer .node-clickable:hover .org-card {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ============================================================
   DARK MODE
   ============================================================ */
body.dark-mode {
    --bg-primary: #0F172A;
    --bg-white: #1E293B;
    --text-primary: #F1F5F9;
    --text-secondary: #94A3B8;
    --text-light: #64748B;
    --border-color: #334155;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.5);
}

body.dark-mode .header {
    background: #1E293B;
    border-bottom-color: #334155;
}

body.dark-mode .header-search input {
    background: #0F172A;
    border-color: #334155;
    color: #F1F5F9;
}

body.dark-mode .header-search input:focus {
    background: #1E293B;
    border-color: var(--primary);
}

body.dark-mode .header-search input::placeholder {
    color: #475569;
}

body.dark-mode .filters-bar {
    background: #1E293B;
    border-bottom-color: #334155;
}

body.dark-mode .chip {
    border-color: #334155;
    color: #94A3B8;
}

body.dark-mode .chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(59, 130, 246, 0.15);
}

body.dark-mode .chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

body.dark-mode .chart-wrapper {
    background: #1E293B;
    border-color: #334155;
}

body.dark-mode .btn-icon {
    background: #0F172A;
    border-color: #334155;
    color: #94A3B8;
}

body.dark-mode .btn-icon:hover {
    background: #334155;
    border-color: var(--primary);
    color: var(--primary);
}

/* Dark mode button highlighted */
body.dark-mode #btnDarkMode {
    background: #FEF3C7;
    border-color: #F59E0B;
    color: #D97706;
}

body.dark-mode .floating-counter {
    background: rgba(30, 41, 59, 0.9);
    border-color: #334155;
}

body.dark-mode .counter-number {
    color: #F1F5F9;
}

body.dark-mode .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
}

body.dark-mode .modal-container {
    background: #1E293B;
}

body.dark-mode .modal-close {
    background: rgba(15, 23, 42, 0.9);
    color: #94A3B8;
}

body.dark-mode .modal-close:hover {
    background: #334155;
    color: #F1F5F9;
}

body.dark-mode .modal-name {
    color: #F1F5F9;
}

body.dark-mode .modal-info-row {
    color: #94A3B8;
    border-bottom-color: #334155;
}

body.dark-mode .modal-info-row strong {
    color: #F1F5F9;
}

body.dark-mode .modal-divider {
    background: #334155;
}

body.dark-mode .stats-card {
    background: #0F172A;
}

body.dark-mode .stats-number {
    color: #F1F5F9;
}

body.dark-mode .stats-area-bar {
    background: #334155;
}

body.dark-mode .loader-container {
    color: #F1F5F9;
}

body.dark-mode #loadingOverlay {
    background: #0F172A;
}

body.dark-mode .loader-spinner {
    border-color: #334155;
    border-top-color: var(--primary);
}

/* Dark mode cards — need inline override in JS too */
body.dark-mode .org-card {
    background: #1E293B;
    border-color: #334155;
}

body.dark-mode .org-card:hover {
    border-color: var(--primary);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

body.dark-mode .org-name {
    color: #F1F5F9;
}

body.dark-mode .org-cargo {
    color: #94A3B8;
}

/* Links in chart lines */
body.dark-mode #chartContainer path {
    stroke: #475569 !important;
}