/* dashboard.css - Dashboard-specific styles */

/* =============================================
   Stats Grid
   ============================================= */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 12px;
    margin-bottom: 30px;
}

.stat-card {
    background-color: var(--bg-card);
    border-radius: 8px;
    padding: 12px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    min-width: 0;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.stat-card-sent {
    border-top: 3px solid var(--primary-green);
}

.stat-card-users {
    border-top: 3px solid #4fc3f7;
}

.stat-card-active24h {
    border-top: 3px solid #26a69a;
}

.stat-card-delivered {
    border-top: 3px solid var(--primary-gold);
}

.stat-card-tokens-in {
    border-top: 3px solid #7c3aed;
}

.stat-card-tokens-out {
    border-top: 3px solid #ec4899;
}

.stat-card-cost {
    border-top: 3px solid #f59e0b;
}

.stat-card-waba-cost {
    border-top: 3px solid #25d366;
}

.stat-loading {
    color: var(--text-muted);
    font-size: 1.2rem;
}

.stat-info h3 {
    font-size: 1.5rem;
    color: var(--primary-green);
    margin-bottom: 3px;
}

.stat-info p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.stat-subtitle {
    font-size: 0.65rem;
    color: var(--text-muted);
    opacity: 0.6;
    margin-top: 1px;
}

.stat-icon {
    font-size: 1.5rem;
    color: var(--primary-gold);
    opacity: 0.7;
}

/* =============================================
   Charts
   ============================================= */
.charts-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-container {
    background-color: var(--bg-card);
    border-radius: 8px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.chart-header {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-green);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-gold);
}

.chart-body {
    display: flex;
    gap: 15px;
    align-items: center;
}

.custom-legend {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* =============================================
   AI Search Insights Grid
   ============================================= */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.insight-card {
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    height: 380px;
    display: flex;
    flex-direction: column;
}

.insight-card__header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
}
.insight-card__header i {
    font-size: 1rem;
}

.insight-card__body {
    padding: 10px 16px 16px;
    flex: 1;
    display: flex;
    flex-direction: row-reverse;
    min-height: 0;
    overflow: hidden;
    align-items: center;
    gap: 0;
}

/* Chart takes ~50%, legend takes ~50% — side by side */
.insight-card__body canvas {
    width: 50% !important;
    max-width: 50%;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    min-height: 0;
}

.insight-card--total .insight-card__body {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px 18px;
}

.insight-card--wide {
    grid-column: span 3;
    height: 320px;
}

.insight-card__body--full {
    flex-direction: row;
    width: 100%;
}
.insight-card__body--full canvas {
    width: 100% !important;
    max-width: 100% !important;
    aspect-ratio: auto;
    height: 100%;
}

/* Country world map (Google GeoChart) */
.country-map-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
    height: 100%;
    min-height: 280px;
}
.country-map-container {
    flex: 1 1 0;
    width: 100%;
    min-height: 190px;
    max-height: 320px;
}
.country-legend {
    margin-top: 15px;
}
.country-legend {
    flex: 0 0 auto;
    padding: 6px 10px 4px;
    direction: rtl;
    font-family: Cairo, Tajawal, sans-serif;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--text-main, #e2e8f0);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1px 12px;
    border-top: 1px solid var(--border, #334155);
}
.country-legend__row {
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
    padding: 1px 0;
}
.country-legend__name {
    flex: 0 1 auto;
}
.country-legend__pct {
    color: var(--text-muted, #94a3b8);
    font-size: 0.68rem;
    flex: 0 0 auto;
}

.insight-card__big-number {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.1;
}

.insight-card__sub {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}

.insight-role-chip {
    background: var(--hover-color);
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Avg message length gadget */
.avg-msg-gadget {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
    padding: 0;
}

.avg-msg-columns {
    display: flex;
    direction: rtl;
    gap: 0;
    height: 100%;
}

.avg-msg-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 16px;
    gap: 14px;
}

.avg-msg-col + .avg-msg-col {
    border-right: 1px solid var(--border-color);
}

.avg-msg-col-title {
    font-family: Cairo, Tajawal, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 4px;
}

.avg-msg-col-title i {
    margin-inline-end: 6px;
}

.avg-msg-row {
    display: flex;
    align-items: center;
    gap: 12px;
    direction: rtl;
}

.avg-msg-icon {
    font-size: 1.3rem;
    width: 32px;
    text-align: center;
    flex-shrink: 0;
}

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

.avg-msg-label {
    font-family: Cairo, Tajawal, sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.avg-msg-bar-track {
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    overflow: hidden;
}

.avg-msg-bar {
    height: 100%;
    border-radius: 5px;
    transition: width 0.8s ease-out;
}

.avg-msg-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    min-width: 70px;
    text-align: start;
}

.avg-msg-value small {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-muted);
}

/* NPS Gauge */
.nps-gauge {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 10px 12px;
    width: 100%;
    box-sizing: border-box;
}

.nps-gauge__arc-wrap {
    position: relative;
    width: 400px;
    height: 220px;
    overflow: hidden;
}

.nps-gauge__arc-svg {
    width: 100%;
    height: 100%;
}

.nps-gauge__label-ring {
    font-size: 0.75rem;
    fill: var(--text-muted);
    font-family: Cairo, Tajawal, sans-serif;
    font-weight: 600;
}

.nps-gauge__needle {
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: 120px 120px;
}

.nps-gauge__score {
    font-family: Cairo, Tajawal, sans-serif;
    font-size: 3.2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-top: 6px;
    line-height: 1;
}

.nps-gauge__breakdown {
    display: flex;
    gap: 18px;
    margin-top: 10px;
    font-family: Cairo, Tajawal, sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    direction: rtl;
}

.nps-gauge__stat {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-secondary);
}

.nps-gauge__dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Category bubbles */
.category-bubbles {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 100%;
    padding: 10px;
}

.cat-bubble {
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    cursor: default;
    transition: transform 0.2s;
    padding: 6px;
}
.cat-bubble:hover {
    transform: scale(1.08);
    z-index: 10;
}

.cat-bubble__label {
    color: #fff;
    font-weight: 600;
    font-family: Cairo, Tajawal, sans-serif;
    line-height: 1.2;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.cat-bubble__count {
    color: #fff;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* Role circles gadget */
#insightRoleSummary {
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: center;
}

.role-circles-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding-bottom: 6px;
}

.role-circle-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.role-circle {
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    cursor: default;
    transition: transform 0.2s;
}
.role-circle:hover {
    transform: scale(1.1);
}

.role-circle__icon {
    font-size: 1.2rem;
    margin-bottom: 2px;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

.role-circle__count {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    line-height: 1;
}

.role-circle__pct {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(255,255,255,0.9);
    text-shadow: 0 1px 2px rgba(0,0,0,0.4);
    line-height: 1;
    margin-top: 4px;
}

.role-circles-legend {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
    padding-top: 10px;
}

.role-circle-legend {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.role-circle-legend__dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Legend — side by side with chart */
.insight-legend {
    width: 50%;
    max-height: 100%;
    overflow-y: auto;
    padding: 0 8px;
}

.insight-legend__item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    padding: 5px 4px;
    border-radius: 4px;
    cursor: default;
    transition: background 0.2s;
}
.insight-legend__item:hover {
    background: var(--hover-color);
}

.insight-legend__dot {
    width: 12px;
    height: 12px;
    min-width: 12px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}
.insight-legend__dot:has(span) {
    background: none !important;
    width: auto;
    min-width: 20px;
}

.insight-legend__label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main);
    font-weight: 600;
}

.insight-legend__value {
    font-weight: 600;
    font-size: 0.82rem;
    white-space: nowrap;
    color: var(--text-muted);
    margin-inline-start: 8px;
}

/* Scrollbar for legend */
.insight-legend::-webkit-scrollbar { width: 4px; }
.insight-legend::-webkit-scrollbar-track { background: transparent; }
.insight-legend::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }

/* Responsive */
@media (max-width: 1200px) {
    .insights-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .insights-grid { grid-template-columns: 1fr; }
    .insight-card { height: 340px; }
}

/* Chat Messages */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chat-bubble.agent {
    background: linear-gradient(135deg, var(--primary-green), #006b54);
    color: white;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-bubble.user {
    background: var(--hover-color);
    color: var(--text-main);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Summary Section */
.summary-section {
    padding: 10px 0;
}

.summary-box {
    background: var(--hover-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 10px;
}

.summary-box h4 {
    color: var(--primary-green);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.summary-box p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-main);
}

/* =============================================
   Responsive
   ============================================= */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .charts-row {
        grid-template-columns: 1fr;
    }
}
