/* CCE Dashboard Styles */

/* WordPress Theme Reset */
.aux-wrapper, .aux-main, .aux-page-content-wrapper,
.elementor-section, .elementor-container {
    margin: 0 !important;
    padding: 0 !important;
}

/* The theme caps every page at `.aux-container { max-width: 1270px }`, i.e. a
   1200px column. The dashboard has to be able to exceed that. */
.aux-container { max-width: none !important; }

/* Dashboard Container */
.dashboard-container {
    /* 🚨 WAS `width: 75%`, WHICH COMPOUNDED AFTER MIGRATION.
       75% was written for the standalone dashboard, where the container's
       parent is the viewport. Inside the theme the parent is already a 1200px
       column, so the page rendered at 1200 x 0.75 = 900 — a 660px chart adrift
       in the middle of a 1920 screen, which is what Chase asked about.

       The site measure is 72vw (see esgri-chrome.css). Used bare it would fix
       1920 and REGRESS the tablet: 72vw of 1024 is 737, narrower than the 878
       the old rule happened to give. So the measure carries a floor of 900 —
       the current desktop width — and is then clamped to whatever the parent
       actually offers. Every width comes out wider than before, none narrower:

         1920   900 -> 1382     chart  660 -> 1132
         1024   878 ->  900     chart  688 ->  846
          390   320 ->  320     unchanged, the parent is the limit

       `.aux-container` is unpinned below for the same reason as on the other
       pages: the theme caps it at 1270 and the measure has to be able to pass
       that. */
    width: min(max(72vw, 900px), 100%);
    max-width: none;
    font-family: 'Arial', 'Segoe UI', sans-serif;
    background: #f5f7fa;
    padding: 0;
    margin: 0 auto;
}

.dashboard-container * {
    box-sizing: border-box;
}

/* Back Link */
.cce-back-link {
    display: inline-block;
    font-size: 13px;
    font-weight: 600;
    color: #367F54;
    text-decoration: none;
    margin-bottom: 12px;
    transition: opacity 0.2s ease;
}

.cce-back-link:hover {
    opacity: 0.7;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.nav-tab {
    flex: 1 1 0;
    min-width: 0;
    padding: 12px 20px;
    background: linear-gradient(135deg, #367F54 0%, #2d6342 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-align: center;
}

.nav-tab:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(54, 127, 84, 0.4);
}

.nav-tab.active {
    background: linear-gradient(135deg, #AF9731 0%, #8f7b28 100%);
    box-shadow: 0 4px 12px rgba(175, 151, 49, 0.4);
}

/* Chart Section */
.chart-section {
    display: none;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    animation: fadeIn 0.4s ease;
}

.chart-section.active {
    display: block;
}

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

.chart-title {
    font-size: 24px;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 10px;
    text-align: center;
}

.chart-description {
    font-size: 14px;
    color: #718096;
    margin-bottom: 25px;
    text-align: center;
}

.chart-insight {
    background: linear-gradient(135deg, #ebf4ff 0%, #f0f7ff 100%);
    border-left: 4px solid #3182ce;
    padding: 12px 18px;
    margin: 0 auto 20px auto;
    max-width: 900px;
    border-radius: 0 8px 8px 0;
    font-size: 13.5px;
    line-height: 1.7;
    color: #2d3748;
}

.chart-insight strong {
    color: #2b6cb0;
}

.chart-canvas {
    width: 100%;
    height: 600px;
    min-height: 400px;
}

/* Metric Buttons */
.metric-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

/* Single row buttons (e.g., Chart 4 region buttons) */
.metric-buttons.single-row {
    flex-direction: row;
    flex-wrap: wrap;
}

.metric-btn {
    padding: 10px 24px;
    background: #e2e8f0;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #4a5568;
    transition: all 0.3s ease;
}

.metric-btn:hover {
    background: #cbd5e0;
}

.metric-btn.year-btn {
    padding: 10px 12px;
    font-size: 13px;
}

.metric-btn.active {
    background: #367F54;
    color: white;
    border-color: #2d6342;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 60px;
    color: #718096;
    font-size: 16px;
}

.loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* CCE Note Box */
.cce-note {
    background: white;
    padding: 0;
    margin-top: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-left: 5px solid #367F54;
    overflow: hidden;
}

.cce-note-header {
    padding: 15px 20px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f7fafc;
    transition: background 0.3s ease;
}

.cce-note-header:hover {
    background: #edf2f7;
}

.cce-note-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: #2d3748;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.cce-note-header h3::before {
    content: none;
}

.cce-note-toggle {
    font-size: 20px;
    color: #4a5568;
    transition: transform 0.3s ease;
}

.cce-note.expanded .cce-note-toggle {
    transform: rotate(180deg);
}

.cce-note-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding: 0 30px;
}

.cce-note.expanded .cce-note-content {
    max-height: 2000px;
    padding: 20px 30px 30px 30px;
}

.cce-note p {
    font-size: 14px;
    line-height: 1.7;
    color: #4a5568;
    margin: 0 0 15px 0;
}

.cce-note h4 {
    font-size: 16px;
    font-weight: 600;
    color: #2d7a3e;
    margin: 20px 0 10px 0;
}

.cce-note ul {
    margin: 10px 0;
    padding-left: 20px;
}

.cce-note li {
    font-size: 14px;
    line-height: 1.6;
    color: #4a5568;
    margin-bottom: 8px;
}

.cce-note strong {
    color: #2d3748;
    font-weight: 600;
}

.cce-note em {
    color: #718096;
    font-style: italic;
    font-size: 13px;
}

/* CCE Dimensions Grid */
.cce-dimensions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.cce-dimension {
    background: #f7fafc;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid;
}

.cce-dimension.overall { border-left-color: #51cf66; }
.cce-dimension.opportunities { border-left-color: #ffd700; }
.cce-dimension.physical { border-left-color: #ff922b; }
.cce-dimension.regulatory { border-left-color: #37b24d; }

.cce-citation {
    font-size: 12px;
    color: #718096;
    font-style: italic;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e2e8f0;
}

/* Key Findings Section */
.cce-note.key-findings {
    border-left-color: #3182ce;
}

.cce-note.key-findings .cce-note-header h3::before {
    content: none;
}

.cce-note.key-findings .cce-note-content p {
    padding-left: 0.7em;
    text-indent: -0.7em;
}

/* Expert Section */
.expert-section {
    margin-top: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
}

.expert-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #367F54 0%, #2d6342 100%);
    margin: 0;
    padding: 12px 20px;
}

/* Author Contact */
.cce-author {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px 20px;
}

.cce-author-avatar-wrapper {
    display: block;
    width: 90px;
    height: 90px;
    min-width: 90px;
    min-height: 90px;
    border-radius: 50% !important;
    border: 3px solid #367F54;
    overflow: hidden !important;
    flex-shrink: 0;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cce-author-avatar-wrapper:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(54, 127, 84, 0.3);
}

.cce-author-avatar {
    width: 100% !important;
    height: 100% !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    object-position: center top;
    display: block;
}

.cce-author-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.cce-author-name {
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
    margin: 0;
}

.cce-author-title,
.cce-author-affiliation {
    font-size: 13px;
    color: #4a5568;
    margin: 2px 0 0 0;
}

.cce-author-contact {
    font-size: 13px;
    color: #4a5568;
    margin: 0;
}

.cce-author-contact a {
    color: #367F54;
    text-decoration: none;
}

.cce-author-contact a:hover {
    text-decoration: underline;
}

/* Mobile Ranking Card List */
.ranking-card-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 500px;
    overflow-y: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}

.ranking-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    background: #f7fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ranking-card.expanded {
    background: #fff;
    border-color: #367F54;
    box-shadow: 0 2px 8px rgba(54, 127, 84, 0.15);
}

.ranking-card-rank {
    font-size: 16px;
    font-weight: 800;
    color: #367F54;
    min-width: 32px;
    text-align: center;
    padding-top: 2px;
}

.ranking-card-body {
    flex: 1;
    min-width: 0;
}

.ranking-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.ranking-card-flag {
    width: 22px;
    height: 15px;
    border: 1px solid #ddd;
    border-radius: 2px;
    flex-shrink: 0;
}

.ranking-card-name {
    font-size: 14px;
    font-weight: 700;
    color: #2d3748;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ranking-card-industry {
    font-size: 11px;
    color: #718096;
    margin-bottom: 6px;
}

.ranking-card-bar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ranking-card-bar {
    height: 8px;
    border-radius: 4px;
    min-width: 4px;
    transition: width 0.3s ease;
}

.ranking-card-score {
    font-size: 12px;
    font-weight: 700;
    color: #4a5568;
    white-space: nowrap;
}

.ranking-card-details {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e2e8f0;
}

.ranking-card-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 12px;
    color: #4a5568;
}

.ranking-card-detail-row span:last-child {
    font-weight: 600;
    color: #2d3748;
}

/* Axis Label Tooltip (for truncated company names) */
.axis-label-tooltip {
    display: none;
    position: fixed;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    z-index: 9999;
}

/* Chart with Legend Layout */
.chart-with-legend {
    display: flex;
    align-items: stretch;
}

.chart-with-legend .chart-canvas {
    flex: 1;
}

/* Custom Legend */
.custom-legend {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
    padding: 15px;
    min-width: 180px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    padding: 5px 8px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.legend-item:hover {
    background: #f0f0f0;
}

.legend-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid #999;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.legend-checkbox-inner {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #666;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.legend-item.selected .legend-checkbox-inner {
    opacity: 1;
}

.legend-text {
    font-size: 13px;
    font-weight: 600;
}

.legend-item:not(.selected) .legend-text {
    opacity: 0.4;
}

/* Company Search */
.company-search-wrapper {
    padding: 80px 0;
    transition: padding 0.3s ease;
    text-align: center;
}

.company-search-box {
    position: relative;
    display: inline-block;
    width: 500px;
}

.company-search-wrapper.has-result {
    padding: 0 0 24px;
}

.company-search-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.company-search-input:focus {
    border-color: #367F54;
}

.company-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 280px;
    overflow-y: auto;
    z-index: 100;
    display: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.company-search-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
    font-size: 14px;
}

.company-search-item:hover {
    background: #f0faf4;
}

.company-search-item-name {
    font-weight: 600;
    color: #2d3748;
}

.company-search-item-meta {
    font-size: 12px;
    color: #718096;
}

/* Company Profile Card */
.company-profile {
    animation: fadeIn 0.3s ease;
}

.company-profile-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 20px;
}

.company-profile-name {
    font-size: 22px;
    font-weight: 700;
    color: #2d3748;
    margin: 0 0 8px 0;
}

.company-profile-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.company-profile-tag {
    font-size: 12px;
    padding: 3px 10px;
    background: #edf2f7;
    color: #4a5568;
    border-radius: 4px;
    font-weight: 500;
}

.company-profile-latest {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    min-width: 360px;
}

.company-profile-metric {
    text-align: center;
    padding: 10px 8px;
    background: #f7fafc;
    border-radius: 8px;
    border-top: 3px solid;
}

.company-profile-metric.overall { border-top-color: #51cf66; }
.company-profile-metric.opportunities { border-top-color: #ffd700; }
.company-profile-metric.physical { border-top-color: #ff922b; }
.company-profile-metric.regulatory { border-top-color: #94d82d; }

.company-profile-metric-label {
    font-size: 11px;
    color: #718096;
    margin-bottom: 4px;
}

.company-profile-metric-value {
    font-size: 18px;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 4px;
}

.metric-badge {
    display: inline-block;
    background: #367F54;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 4px;
}

.metric-zscore {
    display: block;
    font-size: 11px;
    color: #4a5568;
}

.metric-spread {
    display: block;
    font-size: 10px;
    color: #a0aec0;
}

/* Metric hover tooltip */
.company-profile-metric.has-tooltip {
    position: relative;
    cursor: default;
}

.metric-tooltip {
    display: none;
    position: absolute;
    top: 50%;
    left: 105%;
    transform: translateY(-50%);
    background: #2d3748;
    color: #fff;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    min-width: 160px;
}

.metric-tooltip::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #2d3748;
}

.company-profile-metric.has-tooltip:hover .metric-tooltip {
    display: block;
}

.metric-tooltip-title {
    font-weight: 700;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

.metric-tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 2px 0;
}

.metric-tooltip-row span:first-child {
    color: #a0aec0;
}

.metric-tooltip-row span:last-child {
    font-weight: 600;
}

/* Responsive — iPad / Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .dashboard-container { width: 92%; }
    .chart-canvas { height: 500px; }
    .chart-section { padding: 20px; }
    .nav-tab { min-width: 0; font-size: 12px; padding: 10px 8px; }
    .metric-btn { padding: 5px 8px; font-size: 11px; }
    .metric-btn.year-btn { padding: 4px 5px; font-size: 11px; }
    .custom-legend { min-width: 150px; padding: 10px; gap: 8px; }
    .legend-text { font-size: 12px; }
    .cce-author-avatar-wrapper { width: 70px; height: 70px; min-width: 70px; min-height: 70px; }
}

/* Responsive — Mobile (< 768px) */
@media (max-width: 768px) {
    .dashboard-container { width: 100%; padding: 0 12px; }

    /* Back link — bigger touch target */
    .cce-back-link { font-size: 14px; padding: 8px 0; margin-bottom: 8px; }

    /* Nav tabs — full width stack */
    .nav-tabs { gap: 6px; padding: 10px; margin-bottom: 15px; }
    .nav-tab { min-width: 100%; font-size: 13px; padding: 10px 12px; }

    /* Chart sections */
    .chart-section { padding: 15px 12px; }
    .chart-title { font-size: 18px; margin-bottom: 6px; }
    .chart-description { font-size: 12px; margin-bottom: 15px; }
    .chart-canvas { height: 350px; min-height: 280px; }
    .chart-canvas:has(.ranking-card-list) { height: auto; min-height: 0; }

    /* Legend — horizontal wrap */
    .chart-with-legend { flex-direction: column; }
    .custom-legend { flex-direction: row; flex-wrap: wrap; justify-content: center; min-width: auto; padding: 8px; gap: 6px; }
    .legend-text { font-size: 11px; }
    .legend-checkbox { width: 14px; height: 14px; }
    .legend-checkbox-inner { width: 8px; height: 8px; }

    /* Metric buttons — horizontal scroll */
    .metric-buttons { gap: 4px; flex-direction: row; flex-wrap: wrap; }
    .metric-btn { padding: 6px 10px; font-size: 12px; white-space: nowrap; }

    /* Notes */
    .cce-note { margin-top: 12px; }
    .cce-note-header { padding: 12px 15px; }
    .cce-note-header h3 { font-size: 14px; gap: 6px; }
    .cce-note-header h3::before { font-size: 16px; }
    .cce-note-toggle { font-size: 16px; }
    .cce-note.expanded .cce-note-content { padding: 12px 15px 18px 15px; }
    .cce-note p { font-size: 13px; margin: 0 0 10px 0; }
    .cce-note li { font-size: 13px; }
    .cce-dimensions { grid-template-columns: 1fr; gap: 10px; }
    .cce-dimension { padding: 12px; }
    .cce-dimension h4 { font-size: 14px; }

    /* Expert */
    .expert-section { margin-top: 12px; }
    .expert-title { font-size: 14px; padding: 10px 15px; }
    .cce-author { flex-direction: column; text-align: center; padding: 12px 15px; }
    .cce-author-avatar-wrapper { width: 70px; height: 70px; min-width: 70px; min-height: 70px; }
    .cce-author-name { font-size: 14px; }
    .cce-author-title, .cce-author-affiliation, .cce-author-contact { font-size: 12px; }
    .cce-author-info { align-items: center; }

    /* Company search — less padding, wider box */
    .company-search-wrapper { padding: 40px 0; }
    .company-search-box { width: 90%; }
    .company-search-input { font-size: 14px; padding: 10px 14px; }

    /* Company profile */
    .company-profile-header { flex-direction: column; }
    .company-profile-latest { min-width: auto; grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .company-profile-name { font-size: 18px; }
    .company-profile-metric-value { font-size: 16px; }
    .company-profile-metric-label { font-size: 10px; }

    /* Metric tooltip — show below on mobile instead of right */
    .metric-tooltip {
        left: 50% !important;
        top: 105% !important;
        transform: translateX(-50%) !important;
    }
    .metric-tooltip::before {
        right: auto !important;
        left: 50% !important;
        top: auto !important;
        bottom: 100% !important;
        transform: translateX(-50%) !important;
        border: 6px solid transparent !important;
        border-bottom-color: #2d3748 !important;
        border-right-color: transparent !important;
    }
}

/* Responsive — Small phones (< 400px) */
@media (max-width: 400px) {
    .chart-canvas { height: 280px; min-height: 240px; }
    .chart-title { font-size: 16px; }
    .nav-tab { font-size: 12px; padding: 8px 10px; }
    .metric-btn { padding: 6px 10px; font-size: 11px; }
    .company-search-box { width: 95%; }
    .company-search-wrapper { padding: 24px 0; }
    .company-profile-latest { grid-template-columns: 1fr 1fr; }
}
