/* Layout Structure */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

@media screen and (min-width: 769px) {
    .app-shell {
        flex-direction: row;
    }

    .sidebar-nav {
        width: 100px;
        min-width: 80px;
        max-width: 120px;
        height: 100%;
        display: flex;
        flex-direction: column;
        padding: 15px 10px;
        border-right: 1px solid rgba(255, 255, 255, 0.08);
        background: rgba(15, 23, 42, 0.6);
        flex-shrink: 0;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: 10;
    }

    /* The main area takes up all remaining space */
    .main-content,
    .module-body {
        flex: 1;
        min-width: 0;
        /* CRITICAL: prevents flex children from overflowing */
        overflow-y: auto;
        overflow-x: hidden;
        position: relative;
        display: flex;
        flex-direction: column;
        height: 100%;
    }
}

@media screen and (max-width: 768px) {
    /* On mobile, sidebar transforms into a bottom ribbon defined below */

    .main-content,
    .module-body {
        flex: 1;
        overflow-y: hidden; /* Main container fixed */
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 0;
    }

    #main-content-area {
        padding-bottom: 20px;
    }
}


/* Nav icons - desktop sidebar */
.nav-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 10px 5px;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 5px;
    transition: background 0.2s, color 0.2s;
    color: #94a3b8;
    text-align: center;
    user-select: none;
}

.nav-icon:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

.nav-icon.active {
    background: rgba(72, 202, 228, 0.15);
    color: #48cae4;
    border-left: 3px solid #48cae4;
}

.nav-icon span:first-child {
    font-size: 1.4rem;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    line-height: 1.2;
}

.close-nav {
    color: #e74c3c;
    margin-top: auto;
}

.close-nav:hover {
    background: rgba(231, 76, 60, 0.15);
}

.org-structure-container {
    padding: 20px;
    color: #fff;
    font-family: 'Inter', sans-serif;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.chart-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    padding: 20px;
}

.chart-node {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    min-width: 250px;
    max-width: 350px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    position: relative;
    user-select: none;
}

.chart-node:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #48cae4;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.chart-node.active {
    border-color: #48cae4;
    box-shadow: 0 0 15px rgba(72, 202, 228, 0.3);
}

.node-name {
    font-weight: 700;
    font-size: 1rem;
    color: #48cae4;
    display: block;
    margin-bottom: 4px;
}

.node-role {
    font-size: 0.8rem;
    color: #aaa;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.node-depts {
    margin-top: 10px;
    font-size: 0.75rem;
    color: #ddd;
    line-height: 1.4;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    text-align: left;
}

.children-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    position: relative;
    width: 100%;
}

.chart-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    flex: 1;
}

/* Connectors (CSS lines) */
.node-connector-v {
    width: 2px;
    height: 30px;
    background: rgba(255, 255, 255, 0.2);
}

/* Sub-node styles */
.sub-node {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.85rem;
    width: 220px;
    text-align: left;
}

.sub-node-name {
    color: #facc15;
    font-weight: 600;
}

.sub-node-role {
    color: #94a3b8;
    font-size: 0.75rem;
    margin-left: 5px;
}

.sub-node-desc {
    font-size: 0.7rem;
    color: #bbb;
    margin-top: 4px;
    display: block;
}

/* Expansion logic */
.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    width: 100%;
}

.collapsible-content.expanded {
    max-height: 3000px;
    /* Large enough */
}

/* BO List */
/* --- DB VIEW STYLES (Offices, Surveyors, etc.) --- */
.db-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 350px), 1fr));
    gap: 20px;
    width: 100%;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    width: 200px;
    padding: 20px 10px;
    background: rgba(15, 23, 42, 0.95);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    transition: width 0.3s ease;
    z-index: 100;
    gap: 5px;
}

.sidebar-nav .nav-icon {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 15px;
    gap: 12px;
    height: 45px;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
}

.nav-icon span:first-child {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.nav-label {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    color: #94a3b8;
}

.nav-icon.close-nav {
    color: #ff4757;
}

.nav-icon.close-nav:hover {
    background: rgba(255, 71, 87, 0.1) !important;
}

.nav-icon:hover .nav-label,
.nav-icon.active .nav-label {
    color: #fff !important;
}

.nav-icon.active {
    background: rgba(72, 202, 228, 0.2) !important;
    border-color: rgba(72, 202, 228, 0.5) !important;
}


.db-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    backdrop-filter: blur(5px);
}

.db-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
    border-color: #48cae4;
}

.db-card-header {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.db-code {
    font-size: 0.8rem;
    color: #facc15;
    background: rgba(250, 204, 21, 0.1);
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 600;
}

.db-title {
    font-weight: 600;
    color: #fff;
    font-size: 1rem;
    text-align: right;
    flex: 1;
    margin-left: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.db-card-body {
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.db-row {
    font-size: 0.85rem;
    color: #cbd5e1;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.db-row span {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
}

.db-row.highlight {
    color: #48cae4;
    font-weight: 500;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

/* DB Actions */
.db-actions {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.db-global-actions {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-small {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-small:hover {
    background: rgba(72, 202, 228, 0.3);
    color: #48cae4;
}

.btn-xs {
    background: rgba(250, 204, 21, 0.1);
    border: 1px solid rgba(250, 204, 21, 0.2);
    color: #facc15;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
}

.btn-xs:hover {
    background: rgba(250, 204, 21, 0.2);
}

/* Modal Overlay (Generic) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #1e293b;
    padding: 25px;
    border-radius: 12px;
    width: 95%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid #334155;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.bo-toggle {
    font-size: 0.75rem;
    color: #48cae4;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.bo-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    font-size: 0.65rem;
    color: #aaa;
    margin-top: 5px;
}

.bo-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 5px;
    border-radius: 2px;
}

/* RO Selector Styles */
#ro-selector option {
    background: #1e293b;
    color: #fff;
}

#ro-selector:hover {
    border-color: #48cae4;
    background: rgba(0, 0, 0, 0.5);
}

.note-section ol {
    padding-left: 20px;
    margin: 10px 0;
}

.note-section li {
    margin-bottom: 5px;
}

/* Improved Star Rating System */
.star-rating-v2 {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    color: #f1c40f !important;
    line-height: 1;
}

.star-half-v2 {
    position: relative;
    display: inline-block;
    color: rgba(255,255,255,0.12) !important; /* Dim/Empty background star */
    font-style: normal;
}

.star-half-v2::after {
    content: '★';
    position: absolute;
    top: 0;
    left: 0;
    width: 53%; /* Visually compensates for star glyph asymmetry */
    overflow: hidden;
    color: #f1c40f !important;
    font-style: normal;
}

.agent-details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 15px;
}

@media screen and (min-width: 769px) {
    .agent-details-grid {
        grid-template-columns: 1.3fr 1fr 1.2fr 1.3fr !important;
        align-items: stretch !important;
    }
}





/* ============================================================ 
   MOBILE AUTHORITATIVE RESPONSIVENESS (CONSOLIDATED 7.4)
   ============================================================ */
@media screen and (max-width: 768px) {
    .sidebar-nav { width: 100% !important; min-width: 100% !important; padding: 4px !important; position: fixed !important; left: 0 !important; top: auto !important; bottom: 0 !important; height: auto !important; z-index: 100 !important; flex-direction: row !important; overflow-x: auto !important; overflow-y: hidden !important; border-right: none !important; border-top: 1px solid rgba(255, 255, 255, 0.05) !important; border-radius: 12px 12px 0 0 !important; gap: 6px !important; -ms-overflow-style: none; scrollbar-width: none; box-shadow: 0 -4px 15px rgba(0,0,0,0.4) !important; }
    .sidebar-nav::-webkit-scrollbar { display: none; }
    .sidebar-nav .nav-icon { height: auto !important; padding: 4px 6px !important; flex-direction: column !important; justify-content: center !important; gap: 2px !important; min-width: 50px !important; flex-shrink: 0 !important; margin: 0 !important; border-radius: 8px !important; }
    .sidebar-nav .nav-icon span:first-child { font-size: 1.1rem !important; }
    .nav-label { display: block !important; font-size: 0.6rem !important; white-space: normal !important; text-align: center !important; line-height: 1.1 !important; }
    .close-nav { margin-top: 0 !important; margin-left: auto !important; }
    .module-body { margin-left: 0 !important; width: 100% !important; overflow-x: hidden !important; padding-bottom: 70px !important; }
    .module-header { padding: 10px 15px !important; flex-direction: column !important; align-items: flex-start !important; gap: 8px !important; }
    #main-content-area-scroll { padding: 10px !important; }
    #broadcast-section { padding: 15px 10px !important; margin-bottom: 20px !important; border-radius: 8px !important; }
    .broadcast-layout-engine { flex-direction: column !important; gap: 15px !important; }
    /* --- FULL-CARD HORIZONTAL SLIDER --- */
    .agent-card { flex-direction: row !important; align-items: stretch !important; padding: 0 !important; min-height: 120px !important; gap: 0 !important; border-width: 1px 1px 1px 6px !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch !important; scroll-snap-type: x mandatory; }
    /* Sticky Sidebar for persistence */
    .agent-sidebar { width: 95px !important; min-width: 95px !important; display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important; padding: 15px 5px !important; background: rgba(0,0,0,0.3) !important; flex-shrink: 0 !important; position: sticky !important; left: 0 !important; z-index: 5 !important; border-right: 1px solid rgba(255,255,255,0.1) !important; box-shadow: 10px 0 20px rgba(0,0,0,0.3) !important; }
    .agent-card img { width: 65px !important; height: 65px !important; margin-bottom: 6px !important; }
    .broadcast-chk-wrapper { top: -8px !important; left: -8px !important; scale: 0.8 !important; }
    /* Detail Area (First Slide) */
    .agent-card > div:nth-child(2) { flex-shrink: 0 !important; width: 300px !important; padding: 12px 15px !important; border-right: 1px solid rgba(255,255,255,0.05) !important; scroll-snap-align: start !important; }
    /* Letterhead/Verify Area (Second Slide) */
    .agent-card > div:nth-child(3) { flex-shrink: 0 !important; width: 260px !important; background: rgba(255,255,255,0.02) !important; padding: 15px !important; scroll-snap-align: center !important; }
    .agent-card h3 { font-size: 1.1rem !important; white-space: nowrap !important; margin-top: 2px !important; opacity: 1 !important; }
    .agent-card [style*='display: grid; grid-template-columns: 1.5fr 1fr'] { grid-template-columns: 1fr !important; gap: 4px !important; margin-top: 8px !important; white-space: nowrap !important; }
    .db-grid { grid-template-columns: 1fr !important; padding: 10px !important; }
    /* Styled Scrollbar Thumb */
    .agent-card::-webkit-scrollbar { height: 6px; }
    .agent-card::-webkit-scrollbar-thumb { background: #48cae4 !important; border-radius: 10px; border: 1px solid #fff; }
    .agent-card::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
}

/* ============================================================
   ORG STRUCTURE - LIGHT MODE OVERRIDES
   ============================================================ */
body.light-mode .org-structure-container { color: var(--text-main) !important; }

body.light-mode .chart-node {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.15) !important;
    color: var(--text-main) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
}
body.light-mode .chart-node:hover { border-color: var(--primary) !important; box-shadow: 0 5px 15px rgba(0,0,0,0.15) !important; }
body.light-mode .chart-node.active { border-color: var(--primary) !important; box-shadow: 0 0 15px rgba(139,92,246,0.2) !important; }
body.light-mode .node-name { color: var(--primary) !important; }
body.light-mode .node-role { color: var(--text-muted) !important; }
body.light-mode .node-depts { background: rgba(0,0,0,0.04) !important; color: var(--text-main) !important; }
body.light-mode .node-connector-v { background: rgba(0,0,0,0.2) !important; }

body.light-mode .sub-node {
    background: #f8fafc !important;
    border-color: rgba(0,0,0,0.08) !important;
    color: var(--text-main) !important;
}
body.light-mode .sub-node-name { color: #b45309 !important; }
body.light-mode .sub-node-role { color: var(--text-muted) !important; }
body.light-mode .sub-node-desc { color: var(--text-muted) !important; }

body.light-mode .db-card {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.1) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
}
body.light-mode .db-card:hover { border-color: var(--primary) !important; box-shadow: 0 5px 20px rgba(0,0,0,0.1) !important; }
body.light-mode .db-card-header { background: #f1f5f9 !important; border-color: rgba(0,0,0,0.08) !important; }
body.light-mode .db-title { color: var(--text-main) !important; }
body.light-mode .db-row { color: var(--text-main) !important; }
body.light-mode .db-row.highlight { color: var(--primary) !important; border-top-color: rgba(0,0,0,0.1) !important; }
body.light-mode .db-code { color: #92400e !important; background: rgba(234,179,8,0.12) !important; }

body.light-mode .btn-small {
    background: rgba(0,0,0,0.06) !important;
    color: var(--text-main) !important;
    border: 1px solid rgba(0,0,0,0.12) !important;
}
body.light-mode .btn-small:hover { background: rgba(139,92,246,0.1) !important; color: var(--primary) !important; }
body.light-mode .btn-xs { color: #92400e !important; border-color: rgba(234,179,8,0.3) !important; background: rgba(234,179,8,0.08) !important; }

body.light-mode .bo-toggle { color: var(--primary) !important; }
body.light-mode .bo-item { background: rgba(0,0,0,0.04) !important; color: var(--text-muted) !important; }

body.light-mode .sidebar-nav { background: #f1f5f9 !important; border-right-color: rgba(0,0,0,0.1) !important; }
body.light-mode .nav-icon { color: #475569 !important; }
body.light-mode .nav-icon:hover { background: rgba(0,0,0,0.06) !important; color: var(--text-main) !important; }
body.light-mode .nav-icon.active { background: rgba(139,92,246,0.1) !important; border-left-color: var(--primary) !important; color: var(--primary) !important; }
body.light-mode .nav-label { color: inherit !important; }

body.light-mode .db-global-actions { border-top-color: rgba(0,0,0,0.1) !important; }
body.light-mode .modal-content { background: #ffffff !important; border-color: rgba(0,0,0,0.15) !important; }

/* ============================================================
   AGENT PROFILE CARD - LIGHT MODE (counters inline styles)
   ============================================================ */
/* Card wrapper */
body.light-mode .db-card[style*="rgba(30,39,46"] {
    background: #ffffff !important;
    border-color: rgba(0,0,0,0.12) !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08) !important;
}

/* Left sidebar panel */
body.light-mode .agent-sidebar {
    background: #f1f5f9 !important;
    border-right-color: rgba(0,0,0,0.08) !important;
}

/* All direct text inside cards - make dark */
body.light-mode .db-card h3 { color: #0f172a !important; }
body.light-mode .db-card h3 * { color: inherit !important; }

/* Code chip */
body.light-mode .db-card span[style*="rgba(72, 202, 228, 0.15)"] {
    background: rgba(139,92,246,0.12) !important;
    color: var(--primary) !important;
}

/* "Type / Role" muted row */
body.light-mode .db-card div[style*="color: #aaa"],
body.light-mode .db-card span[style*="color: #aaa"],
body.light-mode .db-card div[style*="color: #888"],
body.light-mode .db-card span[style*="color: #888"] {
    color: #475569 !important;
}

/* White text (names, values) → dark */
body.light-mode .db-card span[style*="color:#fff"],
body.light-mode .db-card div[style*="color: #fff"],
body.light-mode .db-card div[style*="color:#fff"] {
    color: #1e293b !important;
}

/* Muted slate text */
body.light-mode .db-card div[style*="color: #cbd5e1"],
body.light-mode .db-card div[style*="color:#cbd5e1"] {
    color: #334155 !important;
}

/* Light #eee text */
body.light-mode .db-card div[style*="color: #eee"],
body.light-mode .db-card div[style*="color:#eee"] {
    color: #1e293b !important;
}

/* Office code yellow → dark amber for contrast */
body.light-mode .db-card div[style*="color: #facc15"],
body.light-mode .db-card div[style*="color:#facc15"] {
    color: #92400e !important;
}

/* "ATTACHED OFFICE" / "MY OFFICE" label */
body.light-mode .db-card div[style*="letter-spacing: 1px"][style*="color: #888"],
body.light-mode .db-card span[style*="letter-spacing: 1px"] {
    color: #475569 !important;
}

/* Email & phone field backgrounds */
body.light-mode .db-card div[style*="background: rgba(0,0,0,0.15)"] {
    background: #f1f5f9 !important;
    border: 1px solid rgba(0,0,0,0.08) !important;
}

/* Office/location value box */
body.light-mode .db-card div[style*="rgba(255,255,255,0.03)"] {
    background: #f8fafc !important;
    border-color: rgba(0,0,0,0.1) !important;
    color: #1e293b !important;
}

/* Right panel (letterhead area) */
body.light-mode .db-card > div[style*="rgba(255,255,255,0.02)"] {
    background: #f8fafc !important;
    border-left-color: rgba(0,0,0,0.08) !important;
}

/* "LETTERHEAD ASSET" teal label */
body.light-mode .db-card span[style*="color: #48cae4"],
body.light-mode .db-card span[style*="color:#48cae4"] {
    color: var(--primary) !important;
}

/* Recent messages section */
body.light-mode .db-card div[style*="border-top: 1px solid rgba(255,255,255,0.05)"] {
    border-top-color: rgba(0,0,0,0.1) !important;
}
body.light-mode .db-card button[style*="color:#48cae4"],
body.light-mode .db-card button[style*="color: #48cae4"] {
    color: var(--primary) !important;
}
body.light-mode .db-card div[style*="background:rgba(0,0,0,0.2)"][style*="border-radius:8px"] {
    background: #f1f5f9 !important;
    border-left-color: rgba(0,0,0,0.2) !important;
}
body.light-mode .db-card div[style*="font-size:0.85rem"][style*="color:#eee"] {
    color: #1e293b !important;
}
body.light-mode .db-card span[style*="color:#aaa"] { color: #64748b !important; }
body.light-mode .db-card span[style*="color:#48cae4"] { color: var(--primary) !important; }

/* Broadcast checkbox wrapper */
body.light-mode .broadcast-chk-wrapper { background: #fff !important; border-color: var(--primary) !important; }
