/* ══════════════════════════════════════════════════════════
   ANALYTICS LAYOUT
══════════════════════════════════════════════════════════ */
.analytics-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.analytics-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ══════════════════════════════════════════════════════════
   KPI CARDS — Stitch bento-card style (white + subtle tint)
══════════════════════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.kpi-card {
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,.05);
  transition: transform .2s, box-shadow .2s;
}
.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,.10);
}

/* Subtle gradient tint overlay per card — Stitch style */
.kpi-card:nth-child(1) { background: linear-gradient(135deg, rgba(37,211,102,.08) 0%, var(--card) 100%); }
.kpi-card:nth-child(2) { background: linear-gradient(135deg, rgba(72,196,255,.08) 0%, var(--card) 100%); }
.kpi-card:nth-child(3) { background: linear-gradient(135deg, rgba(233,30,99,.08) 0%, var(--card) 100%); }
.kpi-card:nth-child(4) { background: linear-gradient(135deg, rgba(186,26,26,.08) 0%, var(--card) 100%); }

/* Bottom accent bar — Stitch signature */
.kpi-card:nth-child(1)::after { content:''; position:absolute; bottom:0; left:0; right:0; height:3px; background: var(--accent); }
.kpi-card:nth-child(2)::after { content:''; position:absolute; bottom:0; left:0; right:0; height:3px; background: var(--blue); }
.kpi-card:nth-child(3)::after { content:''; position:absolute; bottom:0; left:0; right:0; height:3px; background: #e91e63; }
.kpi-card:nth-child(4)::after { content:''; position:absolute; bottom:0; left:0; right:0; height:3px; background: var(--red); }

.kpi-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.kpi-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.kpi-icon-green  { background: rgba(37,211,102,.18);  color: var(--accent-dark); }
.kpi-icon-blue   { background: rgba(52,183,241,.18);  color: #0369a1; }
.kpi-icon-purple { background: rgba(233,30,99,.15);   color: #be185d; }
.kpi-icon-red    { background: rgba(186,26,26,.12);   color: var(--red); }

.kpi-change {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: .1px;
}
.kpi-change.up-good   { background: var(--green-light); color: #15803d; }
.kpi-change.down-good { background: var(--green-light); color: #15803d; }
.kpi-change.up-bad    { background: var(--red-light);   color: #dc2626; }
.kpi-change.neutral   { background: var(--border-light); color: var(--text-muted); }

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--text-muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .9;
}
.kpi-value {
  font-size: 32px;
  font-weight: 800;
  font-family: var(--font-headline);
  color: var(--text-primary);
  letter-spacing: -.5px;
  line-height: 1;
}

/* ══════════════════════════════════════════════════════════
   CHARTS ROW
══════════════════════════════════════════════════════════ */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 18px;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  transition: box-shadow .2s;
}
.chart-card:hover { box-shadow: var(--shadow-md); }
.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}
.chart-card-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.2px;
}
.chart-card-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
}
.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}
.legend-dot-sent { background: var(--accent); }
.legend-dot-recv { background: #c7d2fe; }

.chart-canvas-wrap { position: relative; width: 100%; }

/* Donut */
.donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.donut-canvas-wrap {
  position: relative;
  width: 160px; height: 160px;
}
.donut-center-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.donut-pct { font-size: 26px; font-weight: 800; color: var(--text-primary); }
.donut-label { font-size: 8px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .8px; margin-top: 2px; }

.sla-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sla-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 8px;
}
.sla-row span:first-child { color: var(--text-secondary); font-weight: 500; }
.sla-row span:last-child { font-weight: 700; color: var(--text-primary); }

/* ══════════════════════════════════════════════════════════
   TEMPLATE PERFORMANCE TABLE
══════════════════════════════════════════════════════════ */
.template-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.template-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.template-card-header h2 { font-size: 15px; font-weight: 800; letter-spacing: -.2px; }

/* Status badges */
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.status-dot.approved  { background: var(--green-light); color: var(--green); }
.status-dot.pending   { background: var(--orange-light); color: var(--orange); }
.status-dot.rejected  { background: var(--red-light); color: var(--red); }
.status-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  display: block;
}
.status-dot.approved::before { background: var(--green); }
.status-dot.pending::before  { background: var(--orange); }
.status-dot.rejected::before { background: var(--red); }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .analytics-body { padding: 12px; gap: 12px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 16px 14px; border-radius: 14px; }
  .kpi-icon { width: 40px; height: 40px; border-radius: 11px; }
  .kpi-value { font-size: 22px; }
  .chart-card { padding: 16px; border-radius: 14px; }
  .template-card { border-radius: 14px; overflow-x: auto; }
  .template-card .data-table { min-width: 540px; }
  .template-card-header { padding: 14px 16px; flex-wrap: wrap; gap: 6px; }
  .chart-canvas-wrap { height: 180px !important; }
  .donut-wrap { flex-direction: row; gap: 20px; align-items: center; }
  .sla-legend { flex: 1; }
}

@media (max-width: 480px) {
  .kpi-grid { gap: 8px; }
  .kpi-value { font-size: 20px; }
  .kpi-label { font-size: 11px; }
  .charts-row { gap: 10px; }
  .donut-wrap { flex-direction: column; }
}

/* ══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE — ANALYTICS (enhanced)
══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .analytics-layout { overflow-y: auto; }
  .analytics-kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }
  .analytics-charts-row { flex-direction: column; padding: 12px; gap: 12px; }
  .analytics-chart-card { width: 100% !important; }
  .analytics-table-wrap { overflow-x: auto; }
  .analytics-table { min-width: 480px; }
  .analytics-filter-bar { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .analytics-filter-bar select, .analytics-filter-bar input { flex: 1; min-width: 120px; }
}

@media (max-width: 480px) {
  .analytics-kpi-grid { grid-template-columns: 1fr; }
  .kpi-card { padding: 14px; }
}

/* ══════════════════════════════════════════════════════════
   ANALYTICS — STITCH TOP BAR
══════════════════════════════════════════════════════════ */
.an-top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  padding: 0 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow: visible;
  position: relative;
  z-index: 50;
}

.an-top-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 4px;
}
.an-title-text {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
  font-family: var(--font-heading, 'Plus Jakarta Sans', var(--font));
}
.an-title-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.an-header-tabs {
  display: flex;
  align-self: stretch;
}

.an-period-toggle {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}
.an-period-btn {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  transition: all .12s;
  white-space: nowrap;
}
.an-period-btn.active {
  background: var(--card);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}

.an-top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.an-export-btn {
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
}

.an-export-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  min-width: 190px;
  z-index: 200;
  padding: 4px 0;
}
.an-export-section {
  padding: 6px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.an-export-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font);
  transition: background .1s;
}
.an-export-item:hover { background: var(--bg-secondary); }
.an-export-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Template teaser card ─────────────────────────────── */
.an-template-teaser {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-card);
}

.an-template-teaser-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.an-template-teaser-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}
.an-template-teaser-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.an-template-teaser-link {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  padding: 6px 0;
  white-space: nowrap;
  font-family: var(--font);
  transition: opacity .15s;
}
.an-template-teaser-link:hover { opacity: .75; }

/* ── Bottom grid ──────────────────────────────────────── */
.an-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.an-card-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Lead funnel bars ─────────────────────────────────── */
.an-funnel-body {
  padding: 12px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.an-funnel-row { display: flex; flex-direction: column; gap: 4px; }

.an-funnel-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.an-funnel-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  color: var(--text-secondary);
}
.an-funnel-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.an-funnel-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.an-funnel-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .4s ease;
  min-width: 4px;
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 900px) {
  .an-bottom-grid { grid-template-columns: 1fr; }
  .an-header-tabs { display: none; }
}
@media (max-width: 768px) {
  .an-top-bar { padding: 0 14px; gap: 6px; }
  .an-period-toggle { display: none; }
}

/* ══════════════════════════════════════════════════════════
   DARK MODE OVERRIDES
══════════════════════════════════════════════════════════ */
[data-theme="dark"] .kpi-card { border-color: var(--border); }
[data-theme="dark"] .kpi-card:nth-child(1) { background: linear-gradient(135deg, rgba(37,211,102,.12) 0%, var(--card) 100%); }
[data-theme="dark"] .kpi-card:nth-child(2) { background: linear-gradient(135deg, rgba(72,196,255,.12) 0%, var(--card) 100%); }
[data-theme="dark"] .kpi-card:nth-child(3) { background: linear-gradient(135deg, rgba(233,30,99,.12) 0%, var(--card) 100%); }
[data-theme="dark"] .kpi-card:nth-child(4) { background: linear-gradient(135deg, rgba(186,26,26,.12) 0%, var(--card) 100%); }
[data-theme="dark"] .kpi-label { color: var(--text-muted); }
[data-theme="dark"] .kpi-value { color: var(--text-primary); }
[data-theme="dark"] .kpi-icon-green  { background: rgba(37,211,102,.18); color: #4ade80; }
[data-theme="dark"] .kpi-icon-blue   { background: rgba(52,183,241,.18); color: #38bdf8; }
[data-theme="dark"] .kpi-icon-purple { background: rgba(233,30,99,.15);  color: #f472b6; }
[data-theme="dark"] .kpi-icon-red    { background: rgba(186,26,26,.15);  color: #f87171; }
[data-theme="dark"] .chart-card { background: var(--card); border-color: var(--border); }
[data-theme="dark"] .chart-card-title { color: var(--text-primary); }
[data-theme="dark"] .chart-legend-dot { border-color: var(--card); }
[data-theme="dark"] .sla-legend-label { color: var(--text-secondary); }
[data-theme="dark"] .sla-legend-bar { background: var(--surface-container); }
[data-theme="dark"] .sla-row { background: var(--surface-container); }
[data-theme="dark"] .sla-pct { color: var(--text-primary); }
[data-theme="dark"] .an-perf-table th { background: var(--bg-secondary); color: var(--text-muted); border-color: var(--border); }
[data-theme="dark"] .an-perf-table td { border-color: var(--border); color: var(--text-primary); }
[data-theme="dark"] .an-perf-table tr:hover td { background: var(--surface-container); }
[data-theme="dark"] .analytics-filter-bar select,
[data-theme="dark"] .analytics-filter-bar input { background: var(--surface-container); color: var(--text-primary); border-color: var(--border); }
[data-theme="dark"] .an-top-bar { background: var(--card); border-color: var(--border); }
[data-theme="dark"] .an-period-toggle { background: var(--surface-container); border-color: var(--border); }
[data-theme="dark"] .an-period-btn.active { background: var(--card); color: var(--text-primary); }
[data-theme="dark"] .an-export-menu { background: var(--card); border-color: var(--border); }
[data-theme="dark"] .an-export-item { color: var(--text-primary); }
[data-theme="dark"] .an-export-item:hover { background: var(--surface-container); }
[data-theme="dark"] .an-template-teaser { background: var(--card); border-color: var(--border); }
[data-theme="dark"] .an-funnel-bar-wrap { background: var(--border); }
