/*
  DASHBOARD STORYS — tema do Portal MH

  Carregar DEPOIS de todas as outras folhas de estilo.
  Dá à Storys o mesmo aspecto do Portal MH (fundo, cartões, botões,
  separadores, letra). As cores das plataformas (Instagram rosa,
  Facebook azul) mantêm-se para os gráficos.

  html.mh-embutido = aberta dentro do portal (js/portal-embed.js): o topo
  fica só com o estado dos dados, porque nome, utilizador e sessão já
  aparecem no portal.
*/

:root {
  --bg: #0b0d14;
  --bg-2: #0d1019;
  --panel: #11141e;
  --panel-2: #141824;
  --border: rgba(255, 255, 255, .07);

  --text: #e6e9f2;
  --muted: #8b93a7;
  --muted-2: #7d859a;

  /* o "dourado" da Storys passa a ser o ciano do portal */
  --gold: #67e8f9;
  --gold-soft: rgba(34, 211, 238, .12);

  --instagram: #f472b6;
  --instagram-soft: rgba(244, 114, 182, .14);
  --facebook: #60a5fa;
  --facebook-soft: rgba(96, 165, 250, .14);

  --positive: #34d399;
  --warning: #f59e0b;
  --danger: #fb7185;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .35);

  --mh-ciano: #22d3ee;
  --mh-ciano-claro: #67e8f9;
  --mh-magenta: #d946ef;
  --mh-degrade: linear-gradient(90deg, #22d3ee, #d946ef);
  --mh-degrade-botao: linear-gradient(90deg, #0891b2, #a21caf);
  --mh-linha: rgba(255, 255, 255, .06);
}

html, body {
  background: var(--bg) !important;
}

body {
  font-family: "Plus Jakarta Sans", Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid rgba(34, 211, 238, .7);
  outline-offset: 2px;
}


/* ---------------- Topo ---------------- */

.topbar {
  min-height: 68px;
  border-bottom: 1px solid var(--mh-linha);
  background: rgba(13, 16, 25, .85);
}

.brand h1 {
  font-weight: 800;
  letter-spacing: -.01em;
}

.brand-kicker {
  background: var(--mh-degrade);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.quality-badge,
.last-data {
  border: 1px solid var(--mh-linha);
  border-radius: 999px;
  background: #141824;
}

html.mh-embutido .topbar {
  position: static;
  min-height: 0;
  padding-top: 18px;
  padding-bottom: 0;
  border-bottom: 0;
  background: transparent;
  backdrop-filter: none;
}

html.mh-embutido .topbar .brand {
  display: none !important;
}

html.mh-embutido .topbar-right {
  margin-left: auto;
}


/* ---------------- Separadores (Visão geral / Diário / …) ---------------- */

.tabs {
  border: 1px solid var(--mh-linha);
  border-radius: 12px;
  background: #0d1019;
}

.tab-button {
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 600;
  transition: background .15s ease, color .15s ease;
}

.tab-button:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .04);
}

.tab-button.active {
  color: var(--mh-ciano-claro);
  background: rgba(34, 211, 238, .08);
  border-color: rgba(34, 211, 238, .28);
  box-shadow: 0 0 18px rgba(34, 211, 238, .10);
}


/* ---------------- Botões de acção (Filtros, Análise Geral, …) ---------------- */

.manage-link {
  gap: 8px;
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease;
}

.manage-link:hover {
  background: rgba(255, 255, 255, .05);
  border-color: rgba(34, 211, 238, .35);
}

.manage-link[aria-expanded="true"] {
  color: var(--mh-ciano-claro);
  border-color: rgba(34, 211, 238, .35);
  background: rgba(34, 211, 238, .08);
}

.manage-link .mh-icone {
  display: inline-flex;
  color: var(--mh-ciano-claro);
}

.manage-link .mh-icone svg {
  width: 16px;
  height: 16px;
}

/* Botões principais (ex.: guardar, tentar novamente) */
.error-card button,
.mh-botao-principal {
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--mh-degrade-botao);
  font-weight: 700;
}


/* ---------------- Cartões e painéis ---------------- */

.panel,
.filters-card,
.analysis-chart-card,
.platform-card,
.error-card {
  border: 1px solid var(--mh-linha);
  border-radius: var(--radius);
  background: #0f121b;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .02), 0 10px 40px rgba(0, 0, 0, .35);
}

.panel-header h2,
.audience-kpi-heading h2 {
  font-weight: 700;
  letter-spacing: -.01em;
}

.section-kicker {
  color: var(--mh-ciano-claro);
  letter-spacing: .09em;
}


/* ---------------- Indicadores (KPI) ---------------- */

.kpi {
  border: 1px solid rgba(255, 255, 255, .05);
  border-radius: 14px;
  background: #131726;
  box-shadow: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.kpi:hover {
  border-color: rgba(34, 211, 238, .25);
  box-shadow: 0 0 24px rgba(34, 211, 238, .08);
}

.kpi::after {
  display: none;
}

.kpi-label {
  color: #a1a8ba;
  font-weight: 600;
}

.kpi-value {
  font-weight: 800;
  letter-spacing: -.01em;
}


/* ---------------- Tabelas e listas ---------------- */

.table-scroll {
  border-color: var(--mh-linha);
}

th {
  color: var(--muted-2);
  font-weight: 700;
}

.ranking-item {
  border-color: var(--mh-linha);
  background: #131726;
}


/* ---------------- Campos ---------------- */

input,
select,
textarea {
  border-radius: 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(34, 211, 238, .6);
  outline-offset: 1px;
}


/* Dentro do portal: Análise Geral, Planeamento, Gestão de métricas e
   Utilizadores passam para o menu lateral do portal */
html.mh-embutido #analysis-general-button,
html.mh-embutido #planning-toolbar-button,
html.mh-embutido #stories-manage-link {
  display: none !important;
}


/* Dentro do portal: sem ecrãs de carregamento próprios (o portal mostra
   uma barra fina no topo até a página avisar que está pronta) */
html.mh-embutido #loading-screen,
html.mh-embutido .analysis-spinner {
  display: none !important;
}

/* Dentro do portal: a Análise geral é uma página, não uma janela por cima */
html.mh-embutido body {
  overflow: auto !important;          /* a janela bloqueava o scroll */
}

html.mh-embutido body:has(#analysis-general-modal:not(.analysis-hidden)) #app {
  display: none !important;
}

html.mh-embutido .analysis-modal {
  /* ocupa a área toda e tem o seu próprio scroll (como uma página) */
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow-y: auto;
  padding: 24px 24px 48px;          /* igual ao .shell do Dashboard */
  background: var(--bg);
}

html.mh-embutido .analysis-backdrop,
html.mh-embutido .analysis-close {
  display: none !important;
}

html.mh-embutido .analysis-panel {
  width: auto;
  max-height: none;
  margin: 0;
  overflow: visible;
  padding: 28px;
  border: 1px solid var(--mh-linha);
  border-radius: var(--radius);
  background: #0f121b;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .02), 0 10px 40px rgba(0, 0, 0, .35);
}


/* =====================================================================
   ANÁLISE GERAL — mesmos elementos do Dashboard (css/mh-ui.css)
   ===================================================================== */

.analysis-kicker,
.analysis-section-label {
  color: var(--mh-ciano-claro);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.analysis-header {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--mh-linha);
}

.analysis-header h2 {
  margin: 4px 0 2px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
}

#analysis-period,
.analysis-chart-subtitle,
.analysis-data-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.analysis-refresh-manual,
.analysis-print {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--mh-linha-forte);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s ease, border-color .15s ease;
}

.analysis-refresh-manual:hover,
.analysis-print:hover {
  background: rgba(255, 255, 255, .05);
  border-color: rgba(34, 211, 238, .35);
}

.analysis-section,
.analysis-chart-card,
.analysis-card {
  padding: 20px;
  border: 1px solid var(--mh-linha);
  border-radius: var(--radius);
  background: #0f121b;
  box-shadow: var(--mh-sombra);
}

.analysis-chart-title,
.analysis-trend-head h3,
.analysis-retention-head h3 {
  font-size: 17px;
  font-weight: 700;
}

.analysis-card.positive .analysis-section-label { color: var(--positive); }
.analysis-card.problems .analysis-section-label { color: var(--warning); }

.analysis-retention-row,
.analysis-trend-head {
  border-color: var(--mh-linha);
}

.analysis-retention-track {
  background: #131726;
}

/* Dentro do portal a análise é uma página: o "painel" exterior deixa de ser
   um cartão e as secções ficam directamente sobre o fundo, como no Dashboard */
html.mh-embutido .analysis-panel {
  width: min(1392px, 100%);         /* .shell: 1440px menos 2 × 24px */
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

html.mh-embutido .analysis-header {
  margin-bottom: 16px;
}


/* Dentro do portal: estado dos dados e intervalo de datas estão na barra de
   cima do portal (public.portal_estado) */
html.mh-embutido .topbar {
  display: none !important;
}


/* Ícones nos botões da Análise geral (como nos da barra de ferramentas) */
.analysis-refresh-manual .mh-icone,
.analysis-print .mh-icone {
  display: inline-flex;
  color: var(--mh-ciano-claro);
}

/* Telemóvel: cabeçalho da Análise geral com os botões por baixo do título */
@media (max-width: 640px) {
  .analysis-header {
    flex-wrap: wrap;
    gap: 14px;
  }
  .analysis-header > div:first-child {
    flex: 1 1 100%;
  }
  .analysis-header-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
}
