/* =======================================================
   Pulse Dashboard — enterprise, minimal, data-dense
   Palette: neutral slate + one accent (ember) + functional semantics
   ======================================================= */

:root {
    /* Surfaces */
    --bg:            #0b0d12;
    --bg-soft:       #0f1218;
    --surface:       #14181f;
    --surface-2:     #181d26;
    --surface-3:     #1f2530;
    --border:        #242a36;
    --border-strong: #2e3546;
    --hairline:      rgba(255,255,255,0.06);

    /* Text */
    --text:          #e7ebf2;
    --text-2:        #a3aab8;
    --text-3:        #6b7385;
    --text-4:        #4a5162;

    /* Accent (single) */
    --accent:        #ff6b4a;
    --accent-soft:   rgba(255,107,74,0.12);
    --accent-ring:   rgba(255,107,74,0.28);

    /* Semantics */
    --danger:        #f04a5e;
    --danger-soft:   rgba(240,74,94,0.10);
    --warn:          #f0a04a;
    --warn-soft:     rgba(240,160,74,0.10);
    --info:          #4a8ef0;
    --info-soft:     rgba(74,142,240,0.10);
    --ok:            #3ccf91;
    --ok-soft:       rgba(60,207,145,0.10);

    /* Radii + shadow */
    --r-sm: 6px;
    --r:    10px;
    --r-lg: 14px;
    --shadow: 0 1px 0 rgba(255,255,255,0.02) inset, 0 8px 24px rgba(0,0,0,0.25);

    /* Rhythm */
    --gap:   14px;
    --gap-lg:18px;
    --pad:   16px;
    --pad-sm:12px;
}

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

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Vazirmatn', 'Inter', -apple-system, sans-serif;
    font-size: 13.5px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    letter-spacing: 0;
}

body::before {
    content: '';
    position: fixed; inset: 0;
    background:
        radial-gradient(1200px 600px at 85% -10%, rgba(255,107,74,0.04), transparent 60%),
        radial-gradient(900px 500px at -10% 100%, rgba(74,142,240,0.03), transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.app {
    position: relative;
    z-index: 1;
    max-width: 1680px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: var(--gap-lg);
}

/* ═══════════ HEADER ═══════════ */
.hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 12px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}

.hdr-brand {
    display: flex; align-items: center; gap: 12px;
}

.logo {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-ring);
    border-radius: 9px;
}

.hdr-title { display: flex; flex-direction: column; line-height: 1.2; }
.hdr-name  { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.hdr-sub   { font-size: 12px; color: var(--text-3); margin-top: 3px; }

.hdr-meta { display: flex; align-items: center; gap: 8px; }

.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 11.5px;
    color: var(--text-2);
    font-weight: 500;
}
.chip.accent { border-color: var(--accent-ring); color: var(--accent); background: var(--accent-soft); }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.chip-dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(60,207,145,0.18); animation: blink 2.4s infinite; }

@keyframes blink { 50% { opacity: 0.55; } }

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-2);
    padding: 6px 12px;
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }

/* ═══════════ KPI ROW ═══════════ */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
}

.kpi {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    overflow: hidden;
}
.kpi::before {
    content: '';
    position: absolute; top: 0; right: 0;
    width: 3px; height: 100%;
    background: var(--text-4);
    border-radius: 0 var(--r-lg) var(--r-lg) 0;
}
.kpi.danger::before { background: var(--danger); }
.kpi.warn::before   { background: var(--warn);   }
.kpi.info::before   { background: var(--info);   }

.kpi-label {
    font-size: 11.5px;
    color: var(--text-3);
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 6px;
}
.kpi-value {
    font-size: 26px;
    font-weight: 700;
    font-family: 'Inter', 'Vazirmatn', sans-serif;
    line-height: 1.1;
    letter-spacing: -0.5px;
    color: var(--text);
}
.kpi-caption {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--text-3);
    display: flex; align-items: center; gap: 6px;
}

/* ═══════════ GRID MAIN — 12 column ═══════════ */
.grid-main {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: auto auto;
    gap: var(--gap);
}

.area-trend  { grid-column: span 7; }
.area-matrix { grid-column: span 5; }
.area-quotes { grid-column: span 4; max-height: 440px; }
.area-tools  { grid-column: span 4; max-height: 440px; }
.area-roles  { grid-column: span 4; max-height: 440px; }

/* ═══════════ CARD ═══════════ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color 0.2s ease;
}
.card:hover { border-color: var(--border-strong); }

.card-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--hairline);
}
.card-hdr h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.1px;
}
.card-hint {
    font-size: 11px;
    color: var(--text-3);
    font-weight: 500;
}

.card-body { padding: 14px 16px; flex: 1; min-height: 0; }

/* Chart container */
.chart-wrap { position: relative; height: 240px; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* ═══════════ CRISIS MATRIX ═══════════ */
.matrix {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    height: 100%;
}
.matrix-cell {
    position: relative;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    min-height: 104px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.18s ease;
}
.matrix-cell:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.matrix-cell[data-level="4"] { border-right: 3px solid var(--danger); }
.matrix-cell[data-level="3"] { border-right: 3px solid var(--warn); }
.matrix-cell[data-level="2"] { border-right: 3px solid var(--info); }
.matrix-cell[data-level="1"] { border-right: 3px solid var(--ok); }

.matrix-cell .mc-top {
    display: flex; align-items: baseline; justify-content: space-between;
}
.matrix-cell .mc-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.matrix-cell .mc-count { font-size: 20px; font-weight: 700; font-family: 'Inter', 'Vazirmatn', sans-serif; color: var(--text); letter-spacing: -0.3px; }
.matrix-cell .mc-bar {
    height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.matrix-cell .mc-bar-fill { height: 100%; background: currentColor; transition: width 0.6s ease; }
.matrix-cell[data-level="4"] .mc-bar-fill { background: var(--danger); }
.matrix-cell[data-level="3"] .mc-bar-fill { background: var(--warn); }
.matrix-cell[data-level="2"] .mc-bar-fill { background: var(--info); }
.matrix-cell[data-level="1"] .mc-bar-fill { background: var(--ok); }
.matrix-cell .mc-pct { font-size: 10.5px; color: var(--text-3); margin-top: 4px; }

/* ═══════════ TOP QUOTES ═══════════ */
.quotes-body {
    padding: 10px;
    overflow-y: auto;
}
.quotes {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.quote-item {
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-right: 3px solid var(--danger);
    border-radius: var(--r);
    font-size: 12.5px;
    line-height: 1.8;
    color: var(--text-2);
    flex-shrink: 0;
}
.quote-item .q-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.quote-item .q-meta {
    display: flex; align-items: center; gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--hairline);
    font-size: 11px;
    color: var(--text-3);
}
.quote-item .q-meta .role { color: var(--accent); font-weight: 600; }

/* ═══════════ TOOLS IMPACTED ═══════════ */
.tools {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.tool-row {
    display: grid;
    grid-template-columns: 90px 1fr auto;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    padding: 4px 0;
}
.tool-row .t-name { color: var(--text); font-weight: 500; font-family: 'Inter', 'Vazirmatn'; }
.tool-row .t-bar {
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}
.tool-row .t-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ff9b7a);
    border-radius: 3px;
    transition: width 0.6s ease;
}
.tool-row .t-count {
    font-size: 11.5px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: left;
}

/* ═══════════ ROLES DISTRIBUTION ═══════════ */
.roles {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.role-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px dashed var(--hairline);
    font-size: 12px;
}
.role-row:last-child { border-bottom: none; }
.role-row .r-left {
    display: flex; align-items: center; gap: 10px;
    min-width: 0;
}
.role-row .r-rank {
    width: 20px;
    font-size: 11px;
    color: var(--text-3);
    font-family: 'Inter';
    font-variant-numeric: tabular-nums;
}
.role-row .r-name {
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.role-row .r-right {
    display: flex; align-items: center; gap: 10px;
    font-variant-numeric: tabular-nums;
}
.role-row .r-bar {
    width: 70px; height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.role-row .r-bar-fill { height: 100%; background: var(--accent); border-radius: 2px; }
.role-row .r-count { font-size: 11.5px; color: var(--text-2); min-width: 30px; text-align: left; }

/* ═══════════ INSIGHTS GRID (4 col) ═══════════ */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--gap);
}
.insight {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    overflow: hidden;
}
.insight::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0;
    height: 2px;
}
.insight.eco::before { background: var(--warn); }
.insight.edu::before { background: var(--info); }
.insight.psy::before { background: var(--danger); }
.insight.rip::before { background: var(--accent); }

.insight-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.insight-icon { font-size: 18px; opacity: 0.9; }
.insight-num  {
    font-size: 22px; font-weight: 700;
    font-family: 'Inter', 'Vazirmatn', sans-serif;
    letter-spacing: -0.3px;
}
.insight h4   { font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.insight p    { font-size: 12px; color: var(--text-3); line-height: 1.75; }

/* ═══════════ STREAM ═══════════ */
.stream-wrap { display: flex; flex-direction: column; gap: var(--gap); }

.stream-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}
.search-input {
    flex: 1 1 260px;
    min-width: 200px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 12px;
    border-radius: var(--r-sm);
    font: inherit;
    font-size: 12.5px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder { color: var(--text-4); }
.search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.select {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    color: var(--text-2);
    padding: 7px 10px;
    border-radius: var(--r-sm);
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    outline: none;
    min-width: 130px;
}
.select:hover, .select:focus { color: var(--text); border-color: var(--border-strong); }
.result-count {
    margin-right: auto;
    font-size: 11.5px;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.stream-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

/* Cloud card — full width, tall */
.cloud-card {
    display: flex;
    flex-direction: column;
}
.cloud-body {
    height: 520px;
    padding: 8px 12px;
    display: grid;
    place-items: center;
    overflow: hidden;
}
#wordCloud { width: 100%; height: 100%; display: grid; place-items: center; }
#wordCloud svg { direction: rtl; max-width: 100%; height: 100%; }
#wordCloud text { cursor: pointer; transition: opacity 0.2s ease; }

.cloud-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
    padding: 12px 16px 14px;
    border-top: 1px solid var(--hairline);
}
.legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: var(--text-3);
    font-weight: 500;
}
.legend-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    display: inline-block;
}

/* Stream feed */
.stream-body {
    display: flex; flex-direction: column; gap: 10px;
    max-height: 880px;
    overflow-y: auto;
    padding: 14px 16px 4px;
}
.narrative {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 14px 16px;
    transition: border-color 0.2s ease;
}
.narrative:hover { border-color: var(--border-strong); }
.narrative .n-hdr {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 8px;
}
.narrative .n-author {
    font-size: 13px; font-weight: 600; color: var(--text);
    display: flex; align-items: center; gap: 8px;
}
.narrative .n-role {
    font-size: 11.5px;
    color: var(--text-3);
    padding: 2px 8px;
    background: var(--surface-3);
    border-radius: 999px;
    font-weight: 500;
}
.narrative .n-tags { display: flex; gap: 5px; }
.tag-sm {
    font-size: 10.5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    border: 1px solid;
    font-family: 'Inter', 'Vazirmatn';
    white-space: nowrap;
}
.tag-sm.l-4 { color: var(--danger); border-color: rgba(240,74,94,0.35); background: var(--danger-soft); }
.tag-sm.l-3 { color: var(--warn);   border-color: rgba(240,160,74,0.35); background: var(--warn-soft); }
.tag-sm.l-2 { color: var(--info);   border-color: rgba(74,142,240,0.35); background: var(--info-soft); }
.tag-sm.l-1 { color: var(--ok);     border-color: rgba(60,207,145,0.35); background: var(--ok-soft); }

.narrative .n-text {
    font-size: 13px;
    line-height: 1.95;
    color: var(--text-2);
    padding: 10px 12px;
    background: var(--bg-soft);
    border-radius: var(--r-sm);
    border-right: 2px solid var(--border-strong);
}
.narrative .n-ftr {
    display: flex; align-items: center; gap: 14px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-3);
}
.narrative .n-ftr span { display: inline-flex; align-items: center; gap: 4px; }

.load-more {
    margin: 10px 16px 16px;
    padding: 9px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-2);
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    border-radius: var(--r);
    cursor: pointer;
    transition: all 0.15s ease;
}
.load-more:hover { color: var(--accent); border-color: var(--accent-ring); background: var(--accent-soft); }

/* ═══════════ EMPTY ═══════════ */
.empty {
    padding: 50px 20px;
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
}

/* Scrollbars */
.stream-body::-webkit-scrollbar, .quotes-body::-webkit-scrollbar {
    width: 6px;
}
.stream-body::-webkit-scrollbar-thumb, .quotes-body::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}
.stream-body::-webkit-scrollbar-thumb:hover, .quotes-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-4);
}

/* ═══════════ FOOTER ═══════════ */
.ftr {
    display: flex; justify-content: center; align-items: center;
    gap: 8px;
    padding: 18px 0 6px;
    color: var(--text-4);
    font-size: 11.5px;
}
.ftr .dot { opacity: 0.5; }

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 1400px) {
    .area-trend  { grid-column: span 12; }
    .area-matrix { grid-column: span 12; }
    .area-quotes { grid-column: span 6; }
    .area-tools  { grid-column: span 6; }
    .area-roles  { grid-column: span 12; }
}

@media (max-width: 1100px) {
    .kpi-row        { grid-template-columns: repeat(2, 1fr); }
    .insights-grid  { grid-template-columns: repeat(2, 1fr); }
    .cloud-body     { height: 420px; }
    .area-quotes    { grid-column: span 12; }
    .area-tools     { grid-column: span 12; }
}

@media (max-width: 680px) {
    .app { padding: 12px; gap: 12px; }
    .hdr { flex-direction: column; align-items: stretch; gap: 10px; }
    .hdr-meta { flex-wrap: wrap; }
    .kpi-row       { grid-template-columns: 1fr 1fr; }
    .insights-grid { grid-template-columns: 1fr; }
    .kpi-value     { font-size: 22px; }
    .matrix        { grid-template-columns: 1fr 1fr; }
    .chart-wrap    { height: 200px; }
    .cloud-body    { height: 360px; }
}

/* ═══════════ CONCEPT TOOLTIP ═══════════ */
.concept-tip {
    position: fixed;
    top: 0; left: 0;
    min-width: 240px;
    max-width: 300px;
    padding: 12px 14px;
    background: rgba(20, 24, 31, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255,255,255,0.02) inset;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
    z-index: 9999;
    font-family: 'Vazirmatn', 'Inter', sans-serif;
    direction: rtl;
    will-change: transform, opacity;
}

.tip-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding-bottom: 9px;
    border-bottom: 1px solid var(--hairline);
}
.tip-dot {
    width: 7px; height: 7px; border-radius: 50%;
    flex-shrink: 0;
}
.tip-title {
    flex: 1;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tip-cat {
    font-size: 10.5px;
    font-weight: 600;
    opacity: 0.9;
    white-space: nowrap;
}

.tip-primary {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 8px;
}
.tip-big {
    font-size: 24px;
    font-weight: 800;
    font-family: 'Inter', 'Vazirmatn', sans-serif;
    letter-spacing: -0.5px;
    color: var(--text);
    line-height: 1;
}
.tip-unit {
    font-size: 11.5px;
    color: var(--text-3);
    font-weight: 500;
}
.tip-pct {
    margin-right: auto;
    font-size: 11.5px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
    font-family: 'Inter', 'Vazirmatn';
}

.tip-row { margin: 8px 0 10px; }
.tip-bar {
    width: 100%;
    height: 4px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.tip-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.tip-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 8px 0;
    border-top: 1px solid var(--hairline);
    border-bottom: 1px solid var(--hairline);
    margin-bottom: 8px;
}
.tip-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}
.tip-meta-item strong {
    color: var(--text);
    font-weight: 700;
    font-family: 'Inter', 'Vazirmatn';
}
.tip-dot-sm {
    width: 5px; height: 5px; border-radius: 50%;
    flex-shrink: 0;
}

.tip-foot {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    padding: 4px 0 2px;
}
.tip-foot-label { color: var(--text-3); }
.tip-foot-value {
    color: var(--text);
    font-weight: 600;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tip-foot-count {
    color: var(--accent);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-family: 'Inter', 'Vazirmatn';
}

.tip-hint {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--hairline);
    font-size: 10.5px;
    color: var(--text-4);
    text-align: center;
}
