/**
 * BarrioRadar - Research Embed Widget Stylesheet
 * Self-contained, isolated responsive styles for embedded city research widgets.
 * Zero external font requests - utilizes system font stack.
 */

:root {
  --br-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --br-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  /* Theme tokens - Light (default) */
  --br-bg-page: transparent;
  --br-bg-card: #ffffff;
  --br-bg-subtle: #f8fafc;
  --br-bg-muted: #f1f5f9;
  --br-border: #e2e8f0;
  --br-border-subtle: #f1f5f9;
  --br-text-main: #0f172a;
  --br-text-secondary: #475569;
  --br-text-muted: #64748b;
  --br-brand-accent: #2563eb;
  --br-brand-accent-hover: #1d4ed8;
  --br-brand-accent-subtle: #eff6ff;
  --br-brand-dark: #0f172a;

  /* Score Tier Colors */
  --br-tier-excellent: #059669;
  --br-tier-good: #0284c7;
  --br-tier-moderate: #d97706;
  --br-tier-poor: #dc2626;

  --br-card-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* Explicit Dark Theme */
[data-theme="dark"] {
  --br-bg-card: #0f172a;
  --br-bg-subtle: #1e293b;
  --br-bg-muted: #334155;
  --br-border: #334155;
  --br-border-subtle: #1e293b;
  --br-text-main: #f8fafc;
  --br-text-secondary: #cbd5e1;
  --br-text-muted: #94a3b8;
  --br-brand-accent: #3b82f6;
  --br-brand-accent-hover: #60a5fa;
  --br-brand-accent-subtle: rgba(59, 130, 246, 0.14);
  --br-brand-dark: #f8fafc;
  --br-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* Auto Theme: Prefers Dark */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --br-bg-card: #0f172a;
    --br-bg-subtle: #1e293b;
    --br-bg-muted: #334155;
    --br-border: #334155;
    --br-border-subtle: #1e293b;
    --br-text-main: #f8fafc;
    --br-text-secondary: #cbd5e1;
    --br-text-muted: #94a3b8;
    --br-brand-accent: #3b82f6;
    --br-brand-accent-hover: #60a5fa;
    --br-brand-accent-subtle: rgba(59, 130, 246, 0.14);
    --br-brand-dark: #f8fafc;
    --br-card-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  }
}

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

html, body {
  width: 100%;
  background: var(--br-bg-page);
  font-family: var(--br-font-sans);
  color: var(--br-text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  padding: 8px;
  display: flex;
  justify-content: center;
}

.mono {
  font-family: var(--br-font-mono);
}

/* Main Embed Card Container */
.research-embed-card {
  width: 100%;
  max-width: 680px;
  background: var(--br-bg-card);
  border: 1px solid var(--br-border);
  border-radius: var(--br-radius-md, 8px);
  padding: 16px 18px;
  box-shadow: var(--br-card-shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

/* Header */
.embed-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-bottom: 1px solid var(--br-border);
  padding-bottom: 10px;
}

.embed-eyebrow {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--br-brand-accent);
  line-height: 1.2;
}

.embed-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--br-text-main);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.embed-subtitle {
  font-size: 0.775rem;
  font-weight: 500;
  color: var(--br-text-secondary);
  line-height: 1.4;
}

/* Key Insights KPI Grid */
.embed-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.embed-kpi-card {
  background: var(--br-bg-subtle);
  border: 1px solid var(--br-border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.embed-kpi-val {
  font-family: var(--br-font-mono);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--br-text-main);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.embed-kpi-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--br-text-main);
  line-height: 1.2;
}

.embed-kpi-sub {
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--br-text-muted);
  line-height: 1.25;
}

/* Editorial Statistics Strip (Unboxed) */
.embed-stats-strip {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--br-border);
  border-bottom: 1px solid var(--br-border);
  background: transparent;
}

.embed-stat-item {
  flex: 1;
  text-align: center;
  padding: 2px 6px;
  position: relative;
}

.embed-stat-item:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 15%;
  height: 70%;
  width: 1px;
  background: var(--br-border);
}

.embed-stat-num {
  font-family: var(--br-font-mono);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--br-text-main);
  line-height: 1.15;
  margin-bottom: 2px;
}

.embed-stat-lbl {
  font-size: 0.6875rem;
  font-weight: 700;
  color: var(--br-text-main);
  line-height: 1.2;
}

.embed-stat-desc {
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--br-text-muted);
  line-height: 1.2;
  margin-top: 1px;
}

@media (max-width: 480px) {
  .embed-stats-strip {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 8px 0;
  }
  .embed-stat-item:not(:last-child)::after {
    display: none;
  }
}

/* Chart Container Section */
.embed-chart-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.embed-chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.embed-chart-title {
  font-size: 0.775rem;
  font-weight: 700;
  color: var(--br-text-main);
  line-height: 1.2;
}

.embed-chart-sub {
  font-size: 0.625rem;
  color: var(--br-text-muted);
  font-family: var(--br-font-mono);
}

.embed-chart-wrap {
  width: 100%;
  background: var(--br-bg-subtle);
  border: 1px solid var(--br-border);
  border-radius: 8px;
  padding: 10px 8px 8px 8px;
  position: relative;
}

.embed-chart-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* SVG Chart Typography & Elements - Light & Dark Theme Contrast */
.embed-cat-label {
  fill: var(--br-text-secondary);
}

.embed-cat-label.is-highlight {
  fill: var(--br-text-main);
  font-weight: 700;
}

.embed-val-label {
  fill: var(--br-text-muted);
}

.embed-val-label.is-highlight {
  fill: var(--br-brand-accent);
  font-weight: 700;
}

.embed-bar {
  fill: var(--br-text-muted);
  transition: fill 0.2s ease;
}

.embed-bar.is-highlight {
  fill: var(--br-brand-accent);
}

/* Dark Theme Specific Overrides for Maximum Readability */
[data-theme="dark"] .embed-cat-label {
  fill: #cbd5e1 !important;
}

[data-theme="dark"] .embed-cat-label.is-highlight {
  fill: #f8fafc !important;
  font-weight: 700;
}

[data-theme="dark"] .embed-val-label {
  fill: #cbd5e1 !important;
}

[data-theme="dark"] .embed-val-label.is-highlight {
  fill: #60a5fa !important;
  font-weight: 700;
}

[data-theme="dark"] .embed-bar {
  fill: #475569 !important;
}

[data-theme="dark"] .embed-bar.is-highlight {
  fill: #3b82f6 !important;
}

[data-theme="dark"] .embed-chart-wrap {
  background: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .embed-secondary-cta {
  color: #cbd5e1;
}

[data-theme="dark"] .embed-secondary-cta:hover {
  color: #60a5fa;
}

/* CTAs Row */
.embed-cta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}

.embed-primary-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #ffffff;
  background: var(--br-brand-accent);
  padding: 7px 14px;
  border-radius: 6px;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.1s ease;
  line-height: 1.2;
}

.embed-primary-cta:hover {
  background: var(--br-brand-accent-hover);
}

.embed-secondary-cta {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--br-text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
  white-space: nowrap;
}

.embed-secondary-cta:hover {
  color: var(--br-brand-accent);
  text-decoration: underline;
}

/* Attribution Footer */
.embed-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--br-border);
  gap: 8px;
  font-size: 0.6875rem;
}

.embed-attribution {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--br-text-muted);
  text-decoration: none;
}

.embed-attribution:hover .embed-brand-name {
  color: var(--br-brand-accent);
}

.embed-brand-name {
  font-weight: 800;
  color: var(--br-text-main);
  letter-spacing: -0.02em;
  transition: color 0.15s ease;
}

.embed-brand-name span {
  color: var(--br-brand-accent);
}

.embed-brand-icon {
  width: 14px;
  height: 14px;
  display: block;
}

/* Compact Mode */
.research-embed-card.is-compact {
  padding: 12px 14px;
  gap: 10px;
}

.research-embed-card.is-compact .embed-subtitle {
  display: none;
}

.research-embed-card.is-compact .embed-kpi-sub {
  display: none;
}

.research-embed-card.is-compact .embed-kpi-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.research-embed-card.is-compact .embed-kpi-card {
  padding: 6px 8px;
}

/* Responsive Rules: 480px and narrower */
@media (max-width: 480px) {
  body {
    padding: 4px;
  }
  .research-embed-card {
    padding: 12px 12px;
    gap: 10px;
    border-radius: var(--br-radius-md, 8px);
  }
  .embed-title {
    font-size: 1.02rem;
  }
  .embed-cta-row {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    gap: 8px;
  }
  .embed-primary-cta {
    justify-content: center;
    padding: 8px 12px;
  }
  .embed-secondary-cta {
    text-align: center;
  }
}

/* Narrow Mobile: 340px and narrower */
@media (max-width: 340px) {
  .embed-kpi-grid {
    grid-template-columns: 1fr;
  }
  .embed-chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
}
