:root {
  color-scheme: light;
  --background: #f7f4ef;
  --surface: #fffdf9;
  --surface-muted: #f0ebe3;
  --border: #ded7cd;
  --text: #241f1a;
  --muted: #746d65;
  --burgundy: #74263a;
  --burgundy-dark: #591a2b;
  --green: #247451;
  --amber: #a96c16;
  --red: #aa3939;
  --shadow: 0 10px 28px rgba(52, 42, 33, 0.07);
  --grid: #e6e0d8;
  --table-heading: #fbf8f3;
  --tooltip: rgba(255, 253, 249, 0.98);
  --toast: #28231f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--text); }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--burgundy) 38%, transparent); outline-offset: 2px; }
.topbar {
  min-height: 74px;
  padding: 12px clamp(18px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { display: block; width: 132px; height: 48px; object-fit: contain; object-position: left center; }
.brand div { align-self: stretch; display: flex; align-items: center; }
.brand strong { display: block; font-family: Georgia, serif; font-size: 18px; line-height: 1; }
.brand span:last-child { color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.sync-state { color: var(--muted); font-size: 12px; }
#sync-button {
  height: 40px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--burgundy);
  border-radius: 6px;
  background: var(--burgundy);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
#sync-button:hover { background: var(--burgundy-dark); }
#sync-button:disabled { cursor: wait; opacity: 0.65; }
.button-icon { display: block; width: 18px; height: 18px; flex: 0 0 18px; filter: brightness(0) invert(1); }
.button-label { display: block; line-height: 1; }

main { width: min(1480px, calc(100% - 36px)); margin: 0 auto; padding: 32px 0 56px; }
.toolbar, .panel-heading, .section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}
.toolbar { margin-bottom: 22px; }
h1, h2, p { margin: 0; }
h1 { font-family: Georgia, serif; font-size: clamp(28px, 3vw, 40px); }
h2 { font-family: Georgia, serif; font-size: 22px; }
.toolbar p, .panel-heading p, .section-heading p { margin-top: 5px; color: var(--muted); font-size: 13px; }
.range-control { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; background: var(--surface); }
.range-control button {
  height: 38px;
  padding: 0 14px;
  display: grid;
  place-items: center;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
}
.range-control button:last-child { border-right: 0; }
.range-control button.active { background: var(--burgundy); color: #fff; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi, .panel, .network-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.kpi { min-height: 126px; padding: 19px; display: flex; flex-direction: column; justify-content: space-between; }
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 750; text-transform: uppercase; }
.kpi-value-row { margin-top: 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.kpi-value { font-size: clamp(28px, 3vw, 40px); line-height: 1; font-weight: 780; }
.kpi-detail { margin-top: 9px; color: var(--muted); font-size: 12px; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.neutral { color: var(--muted); }
.trend { flex: 0 0 auto; font-size: 12px; line-height: 1; font-weight: 760; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trend.unavailable { color: var(--muted); font-weight: 600; }

.panel { margin-bottom: 28px; }
.panel-heading { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.chart { min-height: 330px; padding: 18px 20px 14px; overflow: hidden; }
.chart svg { display: block; width: 100%; min-width: 0; height: 300px; overflow: visible; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-label { fill: #827a72; font-size: 11px; }
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.followers-line { stroke: var(--burgundy); stroke-width: 3; }
.followers-area { fill: var(--burgundy); opacity: .08; }
.chart-crosshair { stroke: rgba(116, 38, 58, 0.38); stroke-width: 1.5; stroke-dasharray: 4 5; opacity: 0; pointer-events: none; }
.chart-day-target { cursor: crosshair; outline: none; }
.chart-day-target rect { fill: transparent; }
.chart-day-target:hover .chart-crosshair,
.chart-day-target:focus .chart-crosshair,
.chart-day-target.active .chart-crosshair { opacity: 1; }
.chart-tooltip {
  position: fixed;
  z-index: 20;
  width: min(238px, calc(100vw - 16px));
  padding: 13px;
  border: 1px solid rgba(116, 38, 58, 0.18);
  border-radius: 7px;
  background: var(--tooltip);
  box-shadow: 0 14px 34px rgba(52, 42, 33, 0.18);
  pointer-events: none;
}
.chart-tooltip[hidden] { display: none; }
#monthly-chart .chart-tooltip,
#views-chart .chart-tooltip { width: min(310px, calc(100vw - 16px)); }
.chart-tooltip > strong { display: block; font-family: Georgia, serif; font-size: 14px; }
.tooltip-total,
.tooltip-list > div { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.tooltip-total { margin-top: 9px; padding-bottom: 8px; border-bottom: 1px solid var(--border); color: var(--burgundy); }
.tooltip-total span,
.tooltip-list span { display: inline-flex; align-items: center; gap: 7px; line-height: 18px; }
.tooltip-list { display: grid; gap: 7px; margin-top: 9px; color: var(--muted); font-size: 11px; }
.tooltip-total b,
.tooltip-list b { color: var(--text); font-variant-numeric: tabular-nums; }
.tooltip-list .follower-breakdown-numbers { flex-shrink: 0; gap: 5px; }
.tooltip-list .follower-breakdown-percent { display: inline-block; font-size: 9px; font-variant-numeric: tabular-nums; }
.tooltip-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 4px;
  line-height: 0;
  vertical-align: middle;
}
.tooltip-icon img {
  display: block;
  width: 10px;
  height: 10px;
  margin: 0;
  object-fit: contain;
  object-position: center;
}
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.legend-icon { width: 18px; height: 18px; display: grid; place-items: center; border-radius: 4px; }
.legend-icon img { width: 10px; height: 10px; }
.network-icon, .legend-icon, .tooltip-icon, .platform-icon {
  background: #fff;
  border: 1px solid rgba(45, 35, 23, .07);
  box-shadow: 0 2px 8px rgba(45, 35, 23, .06);
}
.network-icon img, .legend-icon img, .tooltip-icon img, .platform-icon img { object-fit: contain; }
.platform-tiktok img, .platform-dailymotion img { border-radius: 4px; }

.monthly-heading { align-items: center; }
.history-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px 20px; }
.history-range button { font-size: 12px; white-space: nowrap; }
.monthly-logo { pointer-events: none; }
.monthly-logo image { filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 4px rgba(255, 255, 255, .95)); }
.chart-toggle { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; user-select: none; }
.chart-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toggle-track { width: 38px; height: 22px; padding: 3px; display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-muted); transition: background .18s ease, border-color .18s ease; }
.toggle-track span { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform .18s ease, background .18s ease; }
.chart-toggle input:checked + .toggle-track { border-color: var(--burgundy); background: var(--burgundy); }
.chart-toggle input:checked + .toggle-track span { transform: translateX(16px); background: #fff; }
.chart-toggle input:focus-visible + .toggle-track { outline: 3px solid color-mix(in srgb, var(--burgundy) 38%, transparent); outline-offset: 2px; }
.monthly-legend { min-height: 0; padding: 10px 20px 0; }
.monthly-legend:empty { display: none; }
.monthly-chart { position: relative; min-height: 330px; padding: 10px 20px 14px; overflow: hidden; }
.monthly-chart svg { display: block; width: 100%; height: 300px; overflow: visible; }
.monthly-total-bar { fill: var(--burgundy); }
.monthly-segment {
  stroke: var(--surface);
  stroke-width: 1.25;
  vector-effect: non-scaling-stroke;
  transition: opacity .16s ease;
}
.monthly-value { fill: var(--text); font-size: 10px; font-weight: 760; font-variant-numeric: tabular-nums; pointer-events: none; }
.monthly-label { text-transform: capitalize; }
.monthly-target { fill: transparent; cursor: crosshair; }
.monthly-bar { outline: none; }
.monthly-bar:hover .monthly-segment,
.monthly-bar:focus .monthly-segment,
.monthly-bar.active .monthly-segment,
.monthly-bar:hover .monthly-total-bar,
.monthly-bar:focus .monthly-total-bar,
.monthly-bar.active .monthly-total-bar { opacity: .88; }

.section-heading { margin: 0 2px 13px; }
.network-grid { display: grid; gap: 14px; margin-bottom: 28px; }
.network-facebook { --network-color: #0866ff; }
.network-youtube { --network-color: #ff0000; }
.network-instagram { --network-color: #e4405f; }
.network-tiktok, .network-threads, .network-x { --network-color: #202020; }
.network-substack { --network-color: #ff6719; }
.network-podcast { --network-color: #009486; }
.network-dailymotion { --network-color: #202020; }
.network-pinterest { --network-color: #bd081c; }
.network-bluesky { --network-color: #0285ff; }
.network-mastodon { --network-color: #6364ff; }
.network-tumblr { --network-color: #35465c; }
.network-rumble { --network-color: #487819; }
.network-row { display: grid; gap: 12px; }
.network-primary { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.network-secondary { grid-template-columns: repeat(7, minmax(0, 1fr)); }
.network-card { padding: 0; min-width: 0; overflow: hidden; display: flex; flex-direction: column; box-shadow: none; }
.network-head { display: grid; grid-template-columns: 32px minmax(0, 1fr); align-items: center; gap: 14px 8px; padding: 16px 13px 15px; background: color-mix(in srgb, var(--network-color) 78%, #111); color: #fff; }
.network-instagram .network-head { background: linear-gradient(115deg, #833ab4, #b92a5a, #9f4215); }
.network-name { grid-column: 1 / -1; font-size: 17px; font-weight: 780; min-width: 0; }
.network-head .network-icon { width: 32px; height: 32px; border-radius: 8px; box-shadow: none; background: #fff; }
.network-body { padding: 12px; }
.network-summary { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.platform-podcast { display: inline-flex; align-items: center; justify-content: center; isolation: isolate; }
.network-podcast .network-head { grid-template-columns: 80px minmax(0, 1fr); background: #e5f4ef; color: #183d33; }
.network-head .platform-podcast { display: inline-flex; width: 80px; padding: 0; background: transparent; border: 0; border-radius: 0; box-shadow: none; }
.platform-podcast img { position: relative; flex: 0 0 26px; width: 26px; height: 26px; box-sizing: border-box; object-fit: contain; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.platform-podcast img + img { margin-left: -8px; }
.platform-podcast img:nth-child(1) { z-index: 1; }
.platform-podcast img:nth-child(2) { z-index: 2; border-radius: 5px; }
.platform-podcast img:nth-child(3) { z-index: 3; }
.platform-podcast img:nth-child(4) { z-index: 4; }
.network-icon { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 6px; flex: 0 0 auto; }
.network-icon img { width: 19px; height: 19px; display: block; }
.network-icon.platform-podcast img { width: 26px; height: 26px; }
.network-followers { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px; }
.network-followers strong { font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.network-followers span { color: var(--muted); font-size: 10px; }
.network-stats { display: grid; gap: 0; margin-top: 10px; margin-bottom: 8px; }
.network-stat { min-height: 52px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 5px; padding-block: 7px; border-bottom: 1px solid var(--border); }
.network-stat:last-child { border-bottom: 0; }
.network-stat > span { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; }
.metric-row { display: flex; align-items: baseline; justify-content: flex-end; gap: 7px; min-width: 0; }
.network-stat strong { display: block; min-width: 0; font-size: 18px; line-height: 1; font-variant-numeric: tabular-nums; }
.network-stat .trend { font-size: 10px; }
.network-profile {
  min-width: 0;
  display: block;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-decoration: none;
}
.network-head .network-profile { color: #fff; opacity: .9; }
.network-podcast .network-profile { color: #183d33; }
.network-profile:hover { opacity: 1; text-decoration: underline; }
.network-profile.unavailable { color: var(--muted); font-weight: 600; }
.network-info { border: 0; background: transparent; color: var(--muted); padding: 4px; width: 24px; height: 28px; flex: 0 0 24px; cursor: help; }
.network-info-symbol { display: block; width: 16px; height: 16px; background: currentColor; mask: url('/social/info.svg') center / contain no-repeat; -webkit-mask: url('/social/info.svg') center / contain no-repeat; opacity: .7; }
.network-info:hover .network-info-symbol { opacity: 1; }
.network-info-warning { color: #ba7500; }
.network-info-warning .network-info-symbol { opacity: 1; }
.network-tooltip { width: min(300px, calc(100vw - 16px)); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; white-space: pre-line; }
.network-secondary .network-stat { flex-direction: column; align-items: flex-start; justify-content: center; gap: 5px; padding-block: 7px; }

.table-panel { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; background: var(--table-heading); }
tbody tr:last-child td { border-bottom: 0; }
td.number, th.number { text-align: right; font-variant-numeric: tabular-nums; }
.post-title { display: block; max-width: 560px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--text); font-weight: 650; text-decoration: none; }
.post-title:hover { color: var(--burgundy); text-decoration: underline; }
.platform-chip { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.platform-icon { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 5px; }
.platform-icon img { width: 14px; height: 14px; display: block; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }
.source-status {
  margin-top: -10px;
  padding: 10px 3px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 11px;
}
.source-status-summary { display: inline-flex; align-items: center; gap: 7px; }
.source-status-summary strong { color: var(--text); font-weight: 750; font-variant-numeric: tabular-nums; }
.source-status-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent); }
.source-status-detail { text-align: right; }
.source-status-detail > span { display: block; line-height: 1.6; }
.source-status-dot.has-issues { background: var(--amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 14%, transparent); }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: 7px;
  background: var(--toast);
  color: #fff;
  box-shadow: 0 16px 36px rgba(0,0,0,.22);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: #171513;
    --surface: #211e1b;
    --surface-muted: #2b2723;
    --border: #3c3630;
    --text: #f3eee8;
    --muted: #aaa198;
    --burgundy: #b55770;
    --burgundy-dark: #913d55;
    --green: #68c495;
    --amber: #e0a64f;
    --red: #e87777;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
    --grid: #3a342f;
    --table-heading: #292521;
    --tooltip: rgba(33, 30, 27, 0.98);
    --toast: #f3eee8;
  }
  .toast { color: #211e1b; }
  .brand-logo { padding: 3px 7px; border-radius: 5px; background: #f7f4ef; }
  .network-icon, .legend-icon, .tooltip-icon, .platform-icon { background: #f7f3ed; }
  .network-info-warning { color: #ffbd4a; }
}

@media (max-width: 1180px) {
  .network-primary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .network-secondary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .topbar { min-height: 66px; align-items: center; padding: 10px 12px; gap: 10px; }
  .sync-state { display: none; }
  .brand { min-width: 0; gap: 8px; }
  .brand-logo { width: 94px; height: 38px; }
  .brand div { min-width: 0; }
  .brand strong { font-size: 16px; }
  .brand span:last-child { display: none; }
  #sync-button { width: 42px; height: 42px; padding: 0; }
  #sync-button .button-label { display: none; }
  main { width: calc(100% - 16px); padding: 20px 0 38px; }
  .toolbar { align-items: stretch; flex-direction: column; gap: 14px; margin-bottom: 16px; }
  h1 { font-size: 30px; }
  .range-control { width: 100%; }
  .range-control button { flex: 1; min-width: 0; padding: 0 8px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { min-height: 116px; padding: 14px; }
  .kpi-label { font-size: 10px; }
  .kpi-value-row { gap: 6px; }
  .kpi-value { font-size: clamp(24px, 8vw, 31px); }
  .kpi-value-row .trend { font-size: 10px; }
  .kpi-detail { font-size: 10px; line-height: 1.35; }
  .panel { margin-bottom: 22px; }
  .panel-heading { padding: 15px 14px 12px; }
  h2 { font-size: 20px; }
  .network-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .network-card { padding: 0; }
  .network-head { align-items: center; }
  .network-name { gap: 7px; font-size: 13px; }
  .network-icon { width: 30px; height: 30px; }
  .network-icon img { width: 17px; height: 17px; }
  .network-followers { align-items: baseline; flex-direction: row; gap: 5px; }
  .network-followers strong { font-size: 17px; }
  .network-followers span { font-size: 8px; }
  .network-stats { gap: 0; margin-top: 14px; }
  .network-stat { min-height: 42px; align-items: flex-start; flex-direction: column; justify-content: center; gap: 4px; }
  .network-stat span { font-size: 10px; }
  .network-stat strong { font-size: 18px; }
  .network-stat .trend { font-size: 9px; }
  .network-profile { font-size: 10px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .monthly-heading { gap: 12px; }
  .history-actions { width: 100%; }
  .chart-toggle { width: 100%; justify-content: space-between; }
  .legend { justify-content: flex-start; }
  .chart { min-height: 284px; padding: 12px 8px; }
  .chart svg { min-width: 0; height: 260px; }
  .monthly-legend { padding: 10px 14px 0; }
  .monthly-chart { min-height: 284px; padding: 8px 6px 12px; }
  .monthly-chart svg { height: 260px; }
  th, td { padding: 12px 13px; }
  th:nth-child(3), td:nth-child(3) { display: none; }
  .post-title { max-width: 190px; }
  .source-status { margin-top: -6px; align-items: flex-start; flex-direction: column; gap: 4px; padding-inline: 4px; }
  .source-status-detail { padding-left: 14px; text-align: left; }
  .toast { right: 8px; bottom: 8px; max-width: calc(100vw - 16px); }
}

@media (max-width: 370px) {
  .brand strong { display: none; }
  .kpi-grid { grid-template-columns: 1fr; }
}

.platform-x, .network-head .platform-x { background: #fff; border: 0; }
.platform-x img { filter: brightness(0); }

.audience-distribution { margin-bottom: 22px; }
.audience-bar { display: flex; width: 100%; height: 54px; border-radius: 8px; overflow: hidden; }
.audience-segment { position: relative; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; min-width: 0; height: 100%; padding: 0; border: 0; border-radius: 0; cursor: pointer; transition: filter .18s ease; }
.audience-segment:hover { filter: brightness(1.15); }
.audience-segment:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }
.audience-logo { display: flex; align-items: center; justify-content: center; width: min(32px, 72%); aspect-ratio: 1; border-radius: 3px; background: #fff; box-shadow: 0 0 8px 4px rgba(255,255,255,.95), 0 0 17px 7px rgba(255,255,255,.55); pointer-events: none; }
.audience-logo img { width: 76%; max-height: 76%; object-fit: contain; }
.audience-logo.platform-podcast img { width: 35%; margin-left: -12%; }
.audience-logo.platform-podcast img:first-child { margin-left: 0; }
.audience-tooltip { white-space: normal; }
.audience-tooltip-values { display: flex; align-items: baseline; gap: 5px; margin-top: 5px; font-variant-numeric: tabular-nums; }
.audience-tooltip-values small { font-size: 10px; color: var(--muted); }
@media (max-width: 600px) {
  .audience-bar { height: 44px; }
  .audience-distribution { margin-bottom: 16px; }
}
