/* ════════════════════════════════════════════════════════════════════════════
   telegram-insights.css — أنماط لوحة Insights (Health + Conversations + Crises)
   ────────────────────────────────────────────────────────────────────────────
   ⚠️ ملف مستقل قابل للحذف.
   ⚠️ كل classes تبدأ بـ ti-*
   ⚠️ يدعم dark + light. الخط: inherit. الأرقام: tnum.
   ════════════════════════════════════════════════════════════════════════════ */

:root {
  --ti-champion:    #ec4899;
  --ti-active:      #10b981;
  --ti-at-risk:     #f59e0b;
  --ti-inactive:    #6b7280;
  --ti-lost:        #ef4444;
  --ti-urgent:      #dc2626;
}


/* ════════════════════════════════════════════════════════════════════════════
   (1) Page wrapper + tabs
   ════════════════════════════════════════════════════════════════════════════ */

.ti-page { padding-top: 4px; }

.ti-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border, #1e2a3a);
  overflow-x: auto;
  scrollbar-width: thin;
}

.ti-tab {
  background: transparent;
  border: none;
  color: var(--muted, #8b95a5);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 11px 18px;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.ti-tab:hover { color: var(--text, #e8eaed); }
.ti-tab.active { color: #229ED9; }
.ti-tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, #229ED9, #0088CC);
  border-radius: 2px;
}

.ti-tab-badge {
  font-size: 0.72rem;
  background: rgba(239,68,68,0.15);
  color: #ef4444;
  padding: 1px 7px;
  border-radius: 10px;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}


/* ════════════════════════════════════════════════════════════════════════════
   (2) Health level cards (5 cards: champion/active/at_risk/inactive/lost)
   ════════════════════════════════════════════════════════════════════════════ */

.ti-levels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.ti-level-card {
  background: var(--bg-card, #111a27);
  border: 1px solid var(--border, #1e2a3a);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.ti-level-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.ti-level-card.active {
  border-color: var(--ti-color, #229ED9);
  background: linear-gradient(135deg, var(--bg-card, #111a27), color-mix(in srgb, var(--ti-color, #229ED9) 8%, transparent));
}

.ti-level-card[data-level="champion"] { --ti-color: var(--ti-champion); }
.ti-level-card[data-level="active"]   { --ti-color: var(--ti-active); }
.ti-level-card[data-level="at_risk"]  { --ti-color: var(--ti-at-risk); }
.ti-level-card[data-level="inactive"] { --ti-color: var(--ti-inactive); }
.ti-level-card[data-level="lost"]     { --ti-color: var(--ti-lost); }

.ti-level-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ti-color) 18%, transparent);
  color: var(--ti-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 10px;
}

.ti-level-label {
  font-size: 0.84rem;
  color: var(--muted, #8b95a5);
  margin-bottom: 4px;
}
.ti-level-count {
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--text, #e8eaed);
  line-height: 1;
  margin-bottom: 4px;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.ti-level-meta {
  font-size: 0.72rem;
  color: var(--muted, #8b95a5);
  display: flex;
  gap: 10px;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.ti-level-meta .ti-improving { color: var(--ti-active); }
.ti-level-meta .ti-declining { color: var(--ti-lost); }


/* ════════════════════════════════════════════════════════════════════════════
   (3) Student row (in lists)
   ════════════════════════════════════════════════════════════════════════════ */

.ti-section {
  background: var(--bg-card, #111a27);
  border: 1px solid var(--border, #1e2a3a);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}

.ti-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
  flex-wrap: wrap;
}

.ti-section-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text, #e8eaed);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ti-students-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ti-student-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border, #1e2a3a);
  border-radius: 10px;
  transition: all 0.15s;
}
.ti-student-row:hover {
  background: rgba(34,158,217,0.05);
  border-color: rgba(34,158,217,0.25);
}

.ti-student-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #229ED9, #0088CC);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.92rem;
  flex-shrink: 0;
}

.ti-student-info { min-width: 0; }

.ti-student-name {
  font-weight: 600;
  color: var(--text, #e8eaed);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ti-student-meta {
  font-size: 0.76rem;
  color: var(--muted, #8b95a5);
  margin-top: 2px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

.ti-score-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: color-mix(in srgb, var(--ti-color, #229ED9) 14%, transparent);
  color: var(--ti-color, #229ED9);
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.85rem;
  font-feature-settings: "tnum";
  flex-shrink: 0;
}
.ti-score-badge.champion { --ti-color: var(--ti-champion); }
.ti-score-badge.active   { --ti-color: var(--ti-active); }
.ti-score-badge.at_risk  { --ti-color: var(--ti-at-risk); }
.ti-score-badge.inactive { --ti-color: var(--ti-inactive); }
.ti-score-badge.lost     { --ti-color: var(--ti-lost); }


/* ════════════════════════════════════════════════════════════════════════════
   (4) Conversation log row
   ════════════════════════════════════════════════════════════════════════════ */

.ti-convo-row {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border, #1e2a3a);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  border-left: 3px solid var(--ti-sentiment-color, var(--muted, #8b95a5));
}

.ti-convo-row[data-sentiment="urgent"]   { --ti-sentiment-color: var(--ti-urgent); }
.ti-convo-row[data-sentiment="negative"] { --ti-sentiment-color: var(--ti-at-risk); }
.ti-convo-row[data-sentiment="positive"] { --ti-sentiment-color: var(--ti-active); }

.ti-convo-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  gap: 8px;
  flex-wrap: wrap;
}

.ti-convo-student {
  font-weight: 600;
  color: var(--text, #e8eaed);
  font-size: 0.88rem;
}

.ti-convo-time {
  font-size: 0.74rem;
  color: var(--muted, #8b95a5);
  font-feature-settings: "tnum";
}

.ti-convo-msg {
  background: rgba(0,0,0,0.15);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.86rem;
  color: var(--text, #e8eaed);
  margin-bottom: 6px;
  white-space: pre-wrap;
  line-height: 1.55;
  max-height: 100px;
  overflow-y: auto;
}

.ti-convo-meta {
  display: flex;
  gap: 10px;
  font-size: 0.74rem;
  color: var(--muted, #8b95a5);
  flex-wrap: wrap;
}

.ti-sentiment-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 10px;
  font-weight: 600;
  background: color-mix(in srgb, var(--ti-sentiment-color, #8b95a5) 14%, transparent);
  color: var(--ti-sentiment-color, #8b95a5);
}


/* ════════════════════════════════════════════════════════════════════════════
   (5) Crisis alert row
   ════════════════════════════════════════════════════════════════════════════ */

.ti-crisis-row {
  background: linear-gradient(135deg, rgba(220,38,38,0.04), rgba(220,38,38,0.01));
  border: 1px solid rgba(220,38,38,0.25);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
}

.ti-crisis-row[data-severity="critical"] {
  border-color: rgba(220,38,38,0.5);
  box-shadow: 0 0 0 1px rgba(220,38,38,0.15);
  animation: ti-pulse-critical 2s ease-in-out infinite;
}

@keyframes ti-pulse-critical {
  0%, 100% { box-shadow: 0 0 0 1px rgba(220,38,38,0.15); }
  50%      { box-shadow: 0 0 0 4px rgba(220,38,38,0.08); }
}

.ti-crisis-severity {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.74rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.ti-crisis-severity.low      { background: rgba(245,158,11,0.14); color: var(--ti-at-risk); }
.ti-crisis-severity.moderate { background: rgba(234,88,12,0.15); color: #ea580c; }
.ti-crisis-severity.high     { background: rgba(220,38,38,0.16); color: var(--ti-urgent); }
.ti-crisis-severity.critical { background: var(--ti-urgent); color: #fff; }


/* ════════════════════════════════════════════════════════════════════════════
   (6) Buttons (reuse pattern from ta-* / tt-*)
   ════════════════════════════════════════════════════════════════════════════ */

.ti-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
  background: linear-gradient(135deg, #229ED9, #0088CC);
  color: #fff;
  box-shadow: 0 2px 8px rgba(34,158,217,0.25);
}
.ti-btn:hover {
  box-shadow: 0 4px 14px rgba(34,158,217,0.4);
  transform: translateY(-1px);
}
.ti-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.ti-btn.ghost {
  background: transparent;
  color: var(--muted, #8b95a5);
  border: 1px solid var(--border, #1e2a3a);
  box-shadow: none;
}
.ti-btn.ghost:hover { color: var(--text, #e8eaed); border-color: #229ED9; }

.ti-btn.bulk {
  background: linear-gradient(135deg, var(--ti-color, #229ED9), color-mix(in srgb, var(--ti-color, #229ED9) 70%, #000));
}
.ti-btn[data-level="champion"] { --ti-color: var(--ti-champion); }
.ti-btn[data-level="at_risk"]  { --ti-color: var(--ti-at-risk); }
.ti-btn[data-level="lost"]     { --ti-color: var(--ti-lost); }


/* ════════════════════════════════════════════════════════════════════════════
   (7) Empty + skeleton
   ════════════════════════════════════════════════════════════════════════════ */

.ti-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted, #8b95a5);
}
.ti-empty-icon {
  font-size: 2.4rem;
  margin-bottom: 12px;
  opacity: 0.45;
}
.ti-empty-title {
  font-size: 0.98rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text, #e8eaed);
}

.ti-skeleton {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border, #1e2a3a);
  border-radius: 10px;
  height: 60px;
  position: relative;
  overflow: hidden;
  margin-bottom: 10px;
}
.ti-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  animation: ti-shimmer 1.4s infinite;
}
@keyframes ti-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}


/* ════════════════════════════════════════════════════════════════════════════
   (8) Mobile + light theme
   ════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 540px) {
  .ti-student-row { grid-template-columns: auto 1fr; }
  .ti-score-badge { grid-column: 1 / -1; justify-self: end; }
  .ti-section-head { flex-direction: column; align-items: stretch; }
}

[data-theme="light"] .ti-level-card,
[data-theme="light"] .ti-section,
[data-theme="light"] .ti-student-row {
  background: #ffffff;
  border-color: #e2e8f0;
}
[data-theme="light"] .ti-convo-msg {
  background: #f8fafc;
}


/* ASCII digits enforcement */
.ti-level-count, .ti-score-badge, .ti-convo-time, .ti-student-meta {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
