:root {
  --brand-ink: #071917;
  --brand-deep: #0b211e;
  --brand-forest: #0f2824;
  --brand-sage: #98b3a5;
  --brand-sage-hover: #86a394;
  --brand-sage-border: #738f82;
  --brand-mint: #7de3c3;
  --brand-ivory: #f3f4ec;
  --brand-white: #ffffff;
  --brand-text: #0f2824;
  --brand-muted: #52635f;
  --brand-line: #dce3d9;
  --brand-soft: #edf1e9;
  --semantic-positive: #50bdb0;
  --semantic-positive-soft: #eaf9f5;
  --semantic-neutral-soft: #fff8e5;
  --semantic-critical-soft: #fff0f3;
  --semantic-positive-dark: #126450;
  --semantic-neutral: #f2c65d;
  --semantic-neutral-dark: #725319;
  --semantic-critical: #ef8193;
  --semantic-critical-dark: #7d2932;
  --bg: var(--brand-ivory);
  --bg-alt: var(--brand-ivory);
  --panel: var(--brand-white);
  --panel-strong: var(--brand-white);
  --line: var(--brand-line);
  --text: var(--brand-text);
  --muted: var(--brand-muted);
  --accent: var(--semantic-positive);
  --accent-dark: var(--semantic-positive-dark);
  --gold: var(--semantic-neutral);
  --rose: var(--semantic-critical);
  --ink-soft: #29443f;
  --shadow: 0 6px 18px rgba(7, 25, 23, 0.07);
}

body {
  color: var(--brand-text);
  background-color: var(--brand-ivory);
  background-image: none;
}

a {
  color: var(--semantic-positive-dark);
}

.hero,
.panel,
.filters-card,
.metric-card,
.tabs-nav {
  border-color: var(--brand-line);
  background: var(--brand-white);
  box-shadow: var(--shadow);
}

.app-header {
  color: var(--brand-white);
  border: 1px solid #12342e;
  background: linear-gradient(110deg, var(--brand-ink) 0%, var(--brand-deep) 70%, #0b2924 100%);
  box-shadow: 0 14px 30px rgba(7, 25, 23, 0.16);
}

.app-header::before {
  background: var(--brand-sage);
}

.app-header::after {
  display: none;
}

.app-header .eyebrow {
  color: #b9cec3;
}

.app-header .hero-copy p,
.header-subject span,
.header-status-row {
  color: rgba(255, 255, 255, 0.75);
}

.header-automation-row {
  margin-top: 0.35rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid rgba(154, 187, 171, 0.32);
  border-radius: 0.45rem;
  background: rgba(154, 187, 171, 0.08);
  color: #d8e7df;
  font-size: 0.82rem;
  line-height: 1.35;
}

.header-automation-row[data-state="enabled"],
.header-automation-row[data-state="running"] {
  border-color: rgba(102, 201, 165, 0.46);
  background: rgba(102, 201, 165, 0.12);
  color: #e5f5ed;
}

.header-summary {
  border-color: rgba(255, 255, 255, 0.2);
}

.status-dot {
  background: var(--brand-mint);
  box-shadow: 0 0 0 4px rgba(125, 227, 195, 0.13);
}

.app-header .header-actions .button-secondary {
  color: var(--brand-white);
  border-color: rgba(255, 255, 255, 0.26);
  background: rgba(255, 255, 255, 0.06);
}

.app-header .header-actions .button-secondary:hover {
  color: var(--brand-ink);
  background: var(--brand-sage);
}

.filters-card,
.panel,
.metric-card {
  color: var(--brand-text);
  border-color: var(--brand-line);
  background: var(--brand-white);
}

.panel-caption,
.metric-card span,
.metric-card small,
label,
.comment-card-footer,
.meta-grid,
.reaction-summary-row,
.reaction-legend,
.risk-metrics-row,
.risk-card p,
.risk-card small {
  color: var(--brand-muted);
}

.eyebrow,
.quality-label {
  color: var(--semantic-positive-dark);
}

.source-context-panel,
.quality-panel .dashboard-order-quality-intro {
  border-left-color: var(--brand-sage);
  background: #fafbf7;
}

.button-primary,
.platform-chip.active {
  color: var(--brand-ink);
  border-color: var(--brand-sage);
  background: var(--brand-sage);
  box-shadow: none;
}

.button-primary:hover,
.platform-chip.active:hover {
  color: var(--brand-ink);
  background: var(--brand-sage-hover);
}

.button-secondary,
.platform-chip {
  color: var(--brand-text);
  border-color: var(--brand-line);
  background: var(--brand-white);
}

.filters-card .button-secondary,
.panel .button-secondary {
  border-color: var(--brand-line);
}

.button-secondary:hover,
.platform-chip:hover:not(.active) {
  color: var(--brand-ink);
  border-color: #b8c6b9;
  background: var(--brand-soft);
}

.platform-chip-news,
.news-breakdown-card {
  color: var(--brand-forest);
  border-color: #b8d8ca;
  background: #e9f5ef;
}

input,
select,
textarea {
  color: var(--brand-text);
  border-color: var(--brand-line);
  background: var(--brand-white);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--semantic-positive);
  box-shadow: 0 0 0 3px rgba(47, 158, 131, 0.13);
  outline: none;
}

.coverage-details,
.review-controls {
  border-color: var(--brand-line);
}

.review-controls label {
  color: var(--brand-muted);
}

.coverage-details summary,
.comment-expand-button {
  color: var(--semantic-positive-dark);
}

.metric-card {
  border-top-color: #c6d2c9;
}

.dashboard-order-kpis .metric-card:first-child {
  border-color: var(--brand-sage);
  background: var(--brand-white);
}

.dashboard-order-kpis .metric-card:nth-child(2) {
  border-color: var(--semantic-critical);
}

.dashboard-order-kpis .metric-card:nth-child(3) {
  border-color: var(--semantic-positive);
}

.dashboard-order-kpis .metric-card:nth-child(4) {
  border-color: var(--semantic-neutral);
}

.topic-item,
.alert-card,
.post-card,
.platform-breakdown-card,
.account-card,
.query-card,
.content-card,
.sync-run-card,
.comment-card,
.context-event-card,
.platform-risk-card,
.risk-card,
.authenticity-mini-card {
  color: var(--brand-text);
  border-color: var(--brand-line);
  background: var(--brand-white);
}

.platform-breakdown-card:hover,
.platform-breakdown-card:focus-visible,
.platform-risk-card:hover,
.platform-risk-card:focus-visible {
  border-color: var(--semantic-positive);
  box-shadow: 0 8px 20px rgba(7, 25, 23, 0.08);
}

.topic-meter,
.platform-breakdown-card .platform-bar,
.reaction-bars {
  background: #e8ede6;
}

.topic-meter span {
  background: linear-gradient(90deg, var(--semantic-positive), var(--brand-sage));
}

.platform-breakdown-card .platform-bar-fill.favorable,
.reaction-bar.favorable {
  background: var(--semantic-positive);
}

.platform-breakdown-card .platform-bar-fill.neutral,
.reaction-bar.neutral {
  background: var(--semantic-neutral);
}

.platform-breakdown-card .platform-bar-fill.critica,
.reaction-bar.critica {
  background: var(--semantic-critical);
}

.fidelity-meter {
  background: #f3dfe1;
}

.fidelity-meter-fill {
  background: linear-gradient(90deg, var(--brand-sage), var(--semantic-positive));
}

.fidelity-score-row strong,
.reaction-legend .favorable {
  color: var(--semantic-positive-dark);
}

.reaction-legend .neutral,
.noise-label {
  color: var(--semantic-neutral-dark);
}

.reaction-legend .critica {
  color: var(--semantic-critical-dark);
}

.risk-card {
  border-left-color: var(--semantic-neutral);
}

.risk-card.risk-alto,
.alert-card[data-severity="alta"] {
  border-left-color: var(--semantic-critical);
}

.risk-card.risk-medio,
.alert-card {
  border-left-color: var(--semantic-neutral);
}

.risk-card.risk-bajo {
  border-left-color: var(--semantic-positive);
}

.risk-pill,
.tag,
.stance-pill.favorable {
  color: var(--semantic-positive-dark);
  background: var(--semantic-positive-soft);
}

.risk-pill.alto,
.severity-pill.alta,
.stance-pill.critica {
  color: var(--semantic-critical-dark);
  background: var(--semantic-critical-soft);
}

.risk-pill.medio,
.severity-pill,
.tag-subset,
.stance-pill.neutral {
  color: var(--semantic-neutral-dark);
  background: var(--semantic-neutral-soft);
}

.status-banner {
  color: var(--brand-forest);
  border-color: #b8d8ca;
  background: #e8f4ef;
}

.status-banner.error {
  color: var(--semantic-critical-dark);
  border-color: #dfb5ba;
  background: #f7e8e9;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline-color: var(--brand-sage);
}

@media (min-width: 761px) {
  .tabs-nav {
    color: var(--brand-ink);
    border-color: var(--brand-sage-border);
    background: var(--brand-sage);
    box-shadow: 0 10px 24px rgba(7, 25, 23, 0.16);
  }

  .tab-button,
  .tab-button-admin {
    color: var(--brand-ink);
    background: transparent;
  }

  .tab-button small {
    color: #29413c;
  }

  .tab-button:hover:not(.active) {
    color: var(--brand-ink);
    background: var(--brand-sage-hover);
  }

  .tab-button.active {
    color: var(--brand-white);
    background: var(--brand-ink);
    box-shadow: inset 0 -3px 0 var(--brand-mint);
  }

  .tab-button.active small {
    color: rgba(255, 255, 255, 0.76);
  }
}

@media (max-width: 760px) {
  .tabs-nav {
    border-color: var(--brand-sage-border);
    background: var(--brand-sage);
    box-shadow: 0 12px 32px rgba(7, 25, 23, 0.2);
  }

  .tab-button span,
  .tab-button span::after {
    color: var(--brand-ink);
  }

  .tab-button.active {
    color: var(--brand-white);
    background: var(--brand-ink);
    box-shadow: inset 0 -3px 0 var(--brand-mint);
  }

  .tab-button.active span,
  .tab-button.active span::after {
    color: var(--brand-white);
  }
}

/* Panorama ejecutivo: magnitud, lectura y visualizaciones explicativas. */
.dashboard-order-intro { order: 10; }
.dashboard-order-magnitude { order: 15; }
.dashboard-order-kpis { order: 20; }
.dashboard-order-conclusions { order: 25; }
.dashboard-order-social-charts { order: 30; }
.dashboard-order-context { order: 40; }
.dashboard-order-events { order: 50; }
.dashboard-order-platform { order: 60; }
.dashboard-order-image { order: 70; }
.dashboard-order-news { order: 80; }
.dashboard-order-top-posts { order: 90; }
.dashboard-order-method { order: 100; }

.source-context-panel .section-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 0.32fr);
  align-items: stretch;
  gap: 24px;
}

.executive-balance-card {
  display: grid;
  align-content: center;
  gap: 5px;
  min-height: 118px;
  padding: 18px 20px;
  color: var(--brand-white);
  border-radius: 6px;
  background: var(--brand-forest);
}

.executive-balance-card span,
.executive-balance-card small {
  color: rgba(255, 255, 255, 0.72);
}

.executive-balance-card span {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.executive-balance-card strong {
  font-family: Cambria, Georgia, serif;
  font-size: clamp(2.15rem, 4vw, 3.35rem);
  line-height: 0.95;
}

.magnitude-panel {
  color: var(--brand-white);
  border-color: var(--brand-forest);
  background: var(--brand-forest);
}

.magnitude-panel h2,
.magnitude-panel .eyebrow {
  color: var(--brand-white);
}

.magnitude-panel .eyebrow {
  color: #b9cec3;
}

.magnitude-panel .panel-caption,
.magnitude-period {
  color: rgba(255, 255, 255, 0.7);
}

.magnitude-period {
  align-self: start;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.magnitude-grid {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.magnitude-item {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 122px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.045);
}

.magnitude-item-primary {
  border-left: 4px solid var(--brand-sage);
  background: rgba(255, 255, 255, 0.08);
}

.magnitude-item span,
.magnitude-item small {
  color: rgba(255, 255, 255, 0.68);
}

.magnitude-item span {
  font-size: 0.74rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.055em;
}

.magnitude-item strong {
  color: var(--brand-white);
  font-family: Cambria, Georgia, serif;
  font-size: clamp(1.75rem, 2.8vw, 2.7rem);
  line-height: 1;
}

.dashboard-order-kpis {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.executive-conclusions-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.executive-conclusion-card {
  display: grid;
  align-content: start;
  gap: 9px;
  min-height: 178px;
  padding: 17px;
  border: 1px solid var(--brand-line);
  border-top: 4px solid var(--brand-sage);
  border-radius: 6px;
  background: #fafbf8;
}

.executive-conclusion-card[data-tone="critical"] { border-top-color: var(--semantic-critical); }
.executive-conclusion-card[data-tone="positive"] { border-top-color: var(--semantic-positive); }
.executive-conclusion-card[data-tone="context"] { border-top-color: var(--brand-forest); }

.executive-conclusion-card .conclusion-label {
  color: var(--brand-muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.executive-conclusion-card strong {
  color: var(--brand-forest);
  font-size: 1.03rem;
  line-height: 1.35;
}

.executive-conclusion-card p {
  margin: 0;
  color: var(--brand-muted);
  font-size: 0.88rem;
  line-height: 1.48;
}

.dashboard-order-social-charts {
  grid-template-columns: minmax(0, 1.75fr) minmax(300px, 0.75fr);
  align-items: stretch;
}

.dashboard-order-social-charts > .panel {
  height: 100%;
}

.dashboard-order-social-charts .chart-shell-compact {
  height: 250px;
}

.dashboard-order-image {
  grid-template-columns: minmax(280px, 0.75fr) minmax(0, 1.25fr);
  align-items: start;
}

.chart-shell-image {
  height: 420px;
}

.topic-sentiment-item {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--brand-line);
}

.topic-sentiment-item:last-child {
  border-bottom: 0;
}

.topic-sentiment-heading,
.topic-sentiment-legend {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.topic-sentiment-heading span,
.topic-sentiment-legend {
  color: var(--brand-muted);
  font-size: 0.78rem;
}

.topic-sentiment-bar {
  display: flex;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8ede6;
}

.topic-sentiment-bar span { min-width: 0; }
.topic-sentiment-bar .favorable { background: var(--semantic-positive); }
.topic-sentiment-bar .neutral { background: var(--semantic-neutral); }
.topic-sentiment-bar .critica { background: var(--semantic-critical); }

.topic-sentiment-legend .favorable { color: var(--semantic-positive-dark); }
.topic-sentiment-legend .critica { color: var(--semantic-critical-dark); }

.context-event-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-order-top-posts .top-posts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.dashboard-order-top-posts .post-card {
  margin: 0;
}

@media (max-width: 1100px) {
  .magnitude-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .magnitude-item-primary {
    grid-column: span 2;
  }

  .executive-conclusions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .filters-card:not(.filters-open) .filters-grid,
  .filters-card:not(.filters-open) .coverage-details {
    display: none;
  }

  .filters-card:not(.filters-open) .platform-shortcuts {
    margin-bottom: 0;
  }

  .source-context-panel .section-heading,
  .dashboard-order-social-charts,
  .dashboard-order-image {
    grid-template-columns: 1fr;
  }

  .magnitude-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .magnitude-item-primary {
    grid-column: 1 / -1;
  }

  .magnitude-item {
    min-height: 112px;
  }

  .dashboard-order-kpis,
  .executive-conclusions-grid,
  .context-event-grid,
  .dashboard-order-top-posts .top-posts {
    grid-template-columns: 1fr;
  }

  .executive-conclusion-card {
    min-height: 0;
  }

  .chart-shell-image {
    height: 360px;
  }
}

/* La publicación web es de consulta: la operación y revisión quedan privadas. */
.public-deployment .tab-button-admin,
.public-deployment #sources-panel,
.public-deployment .admin-only,
.public-deployment .dashboard-order-review {
  display: none !important;
}

/* Navegación persistente: el usuario siempre sabe si la vista está filtrada. */
.public-deployment .tabs-nav {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.persistent-filter-tools {
  position: sticky;
  top: 86px;
  z-index: 38;
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 50px;
  margin: -6px 0 14px;
  padding: 7px 9px;
  color: var(--brand-white);
  border: 1px solid #28443e;
  border-left: 4px solid var(--brand-sage);
  border-radius: 6px;
  background: rgba(11, 33, 30, 0.97);
  box-shadow: 0 10px 24px rgba(7, 25, 23, 0.16);
  backdrop-filter: blur(14px);
}

.has-active-filters .persistent-filter-tools {
  border-left-color: var(--semantic-neutral);
}

.persistent-tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 12px;
  color: var(--brand-white);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  font: inherit;
  font-size: 0.79rem;
  font-weight: 750;
  cursor: pointer;
}

.persistent-tool-button:hover:not(:disabled),
.persistent-tool-button:focus-visible {
  color: var(--brand-ink);
  border-color: var(--brand-sage);
  background: var(--brand-sage);
}

.persistent-tool-button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.active-filter-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  color: var(--brand-ink);
  border-radius: 999px;
  background: var(--semantic-neutral);
  font-size: 0.72rem;
  font-weight: 850;
}

.active-filter-count[hidden] {
  display: none;
}

.active-filter-summary {
  min-width: 0;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.77rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.has-active-filters .active-filter-summary {
  color: #f4e4bf;
}

.filters-card {
  scroll-margin-top: 148px;
}

.chart-toggle-button {
  display: none;
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 11px;
  color: var(--brand-forest);
  border: 1px solid var(--brand-line);
  border-radius: 4px;
  background: var(--brand-soft);
  font: inherit;
  font-size: 0.77rem;
  font-weight: 750;
  cursor: pointer;
}

.chart-panel.chart-collapsed .chart-shell {
  display: none;
}

.charts-compact .chart-shell,
.charts-compact .chart-shell-large,
.charts-compact .chart-shell-compact,
.charts-compact .chart-shell-image {
  height: 220px !important;
  min-height: 220px !important;
}

@media (min-width: 761px) {
  .persistent-filter-tools {
    top: 88px;
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: calc(146px + env(safe-area-inset-bottom));
  }

  .persistent-filter-tools {
    position: fixed;
    inset: auto 7px calc(80px + env(safe-area-inset-bottom));
    z-index: 99;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 5px;
    min-height: 52px;
    margin: 0;
    padding: 6px;
    border-left-width: 1px;
    border-radius: 10px;
    box-shadow: 0 10px 26px rgba(7, 25, 23, 0.28);
  }

  .persistent-tool-button {
    min-width: 0;
    min-height: 38px;
    padding: 0 6px;
    font-size: 0.68rem;
    line-height: 1.05;
  }

  .persistent-reset-button {
    color: #fff4dc;
    border-color: rgba(214, 169, 79, 0.44);
  }

  .active-filter-summary {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .active-filter-count {
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    font-size: 0.65rem;
  }

  .filters-card {
    scroll-margin-top: 8px;
  }

  .chart-toggle-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  .chart-panel > .section-heading {
    gap: 10px;
  }

  .charts-compact .chart-shell,
  .charts-compact .chart-shell-large,
  .charts-compact .chart-shell-compact,
  .charts-compact .chart-shell-image {
    height: 205px !important;
    min-height: 205px !important;
  }
}
