/* Management · Dashboard (management-dashboard.js). Só esta página o
   carrega. Ordem de leitura: período (na barra de topo) → resultado do
   período (receita − custos = resultado) e operação → indicadores por
   quarto numa só grelha → por área. Cores e vidro vêm de management.css
   (tokens --mg-*). Ritmo: secções a 20px, grupos internos a 12px, linhas
   apertadas a 4–8px. */

.mgd { display: flex; flex-direction: column; gap: var(--sp-5); transition: opacity 0.2s ease; }
.mgd[hidden] { display: none; }
/* Ao mudar o período, o que já está desenhado fica a meia-luz em vez de piscar. */
.mgd.is-busy { opacity: 0.55; pointer-events: none; }

/* ---------- aviso sem relatórios ---------- */
.dashboard-no-data {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.dashboard-no-data[hidden] { display: none; }
.dashboard-no-data .icon { flex-shrink: 0; margin-top: 2px; }
.dashboard-no-data a { color: var(--mg-accent); font-weight: 650; text-underline-offset: 3px; }

/* ---------- erro ao carregar ---------- */
.mgd-error {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid rgba(255, 59, 48, 0.25);
  border-radius: 16px;
  background: var(--mg-danger-soft);
  color: var(--mg-ink-soft);
  font-size: var(--fs-md);
  line-height: 1.45;
}
.mgd-error[hidden] { display: none; }
.mgd-error .icon { flex-shrink: 0; color: var(--mg-danger); }
.mgd-error span { flex: 1; }
.mgd-error .btn { flex-shrink: 0; }

/* ---------- período (barra de topo) ---------- */
/* A barra cresce quando o período tem de passar para baixo do título (ecrãs estreitos). */
.topbar:has(.mgd-period) { height: auto; min-height: var(--topbar-h); }
.mgd-period { gap: var(--sp-2); }
@media (min-width: 1241px) {
  .mgd-period { flex-wrap: nowrap; flex-shrink: 0; }
}
.mgd-presets {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-full);
  background: var(--mg-fill);
}
.mgd-preset {
  min-height: 32px;
  padding: 0 var(--sp-3);
  border: none;
  border-radius: var(--r-full);
  background: none;
  color: var(--mg-secondary);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.mgd-preset:hover { background: rgba(255, 255, 255, 0.6); color: var(--mg-ink); }
.mgd-preset.is-active { background: #fff; color: var(--mg-ink); box-shadow: 0 1px 3px rgba(20, 30, 60, 0.14); }
.mgd-preset:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--mg-accent-soft); }

.mgd-date { display: inline-flex; align-items: center; gap: var(--sp-2); }
.mgd-date__label {
  color: var(--mg-tertiary);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.mgd-date .date-field { width: 148px; }

/* ---------- resultado + operação ---------- */
.mgd-top {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: stretch;
}
.mgd-top > .panel { display: flex; flex-direction: column; }

.mgd-result__body { display: flex; flex-direction: column; gap: var(--sp-5); flex: 1; }
/* O painel do resultado é o ponto alto da página: ganha um tom suave do sinal do resultado. */
.mgd-result.is-positive {
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(52, 199, 89, 0.14), transparent 55%),
    var(--mg-glass-bg-strong);
}
.mgd-result.is-negative {
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(255, 59, 48, 0.12), transparent 55%),
    var(--mg-glass-bg-strong);
}

/* Receita por dia (ou por mês): uma coluna por período, até 24px de largura,
   ponta arredondada; sem relatório PMS fica um toco cinzento. */
.mgd-trend { display: flex; flex-direction: column; gap: var(--sp-2); margin: 0; }
.mgd-trend__head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--sp-1) var(--sp-3);
  color: var(--mg-secondary);
  font-size: var(--fs-sm);
}
.mgd-trend__title { color: var(--mg-ink); font-size: var(--fs-md); font-weight: 700; }
.mgd-trend__max { font-variant-numeric: tabular-nums; }
.mgd-trend__key { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; }
.mgd-trend__swatch { width: 10px; height: 4px; border-radius: 2px; background: rgba(120, 120, 128, 0.28); }
.mgd-trend__plot,
.mgd-trend__axis {
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  column-gap: 3px;
}
.mgd-trend__plot {
  height: 132px;
  padding-top: var(--sp-2);
  border-bottom: 1px solid var(--mg-hairline);
  background: repeating-linear-gradient(to top, transparent 0, transparent 32px, rgba(60, 60, 67, 0.06) 32px, rgba(60, 60, 67, 0.06) 33px);
}
.mgd-trend__col { display: flex; align-items: flex-end; justify-content: center; min-width: 0; }
.mgd-trend__bar {
  width: 100%;
  max-width: 24px;
  height: var(--h, 0%);
  min-height: 3px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #3d9bff, var(--mg-accent));
  cursor: default;
  transition: filter 0.15s ease;
}
.mgd-trend__bar:hover { filter: brightness(0.88); }
.mgd-trend__bar.is-missing { height: 4px; min-height: 4px; background: rgba(120, 120, 128, 0.28); }
.mgd-trend__axis span {
  overflow: hidden;
  color: var(--mg-tertiary);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

/* A conta do período: receita − custos = resultado. */
.mgd-equation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1.15fr);
  align-items: end;
  column-gap: var(--sp-3);
}
.mgd-figure { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mgd-figure__label {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-1);
  color: var(--mg-secondary);
  font-size: var(--fs-md);
  font-weight: 650;
}
/* Quadrado de ícone (o mesmo dos indicadores do Manu e do People). Azul = receita,
   laranja = custos, verde = resultado: as mesmas cores da barra e do gráfico. */
.mgd-tile {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--tile-bg);
  color: var(--tile-color);
}
.mgd-tile--revenue { --tile-bg: var(--mg-accent-soft); --tile-color: var(--mg-accent); }
.mgd-tile--costs { --tile-bg: var(--mg-warning-soft); --tile-color: var(--mg-warning); }
.mgd-tile--result { --tile-bg: var(--mg-success-soft); --tile-color: var(--mg-success); }
.mgd-figure--result.is-negative .mgd-tile--result { --tile-bg: var(--mg-danger-soft); --tile-color: var(--mg-danger); }
.mgd-figure__label abbr { margin-left: 4px; color: var(--mg-tertiary); font-weight: 600; text-decoration: none; cursor: help; }
.mgd-figure__value {
  color: var(--mg-ink);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  white-space: nowrap;
}
.mgd-figure__hint { color: var(--mg-secondary); font-size: var(--fs-sm); }
.mgd-figure--result .mgd-figure__value { font-size: 1.75rem; }
.mgd-figure--result.is-positive .mgd-figure__value { color: var(--mg-success); }
.mgd-figure--result.is-negative .mgd-figure__value { color: var(--mg-danger); }
/* O sinal fica na linha dos valores (por baixo do rótulo, por cima da nota). */
.mgd-op {
  align-self: center;
  padding-top: var(--sp-3);
  color: var(--mg-tertiary);
  font-size: 1.5rem;
  font-weight: 300;
  line-height: 1;
}

/* Barra da receita: parte que foi para custos e parte que ficou como resultado. */
.mgd-split { display: flex; flex-direction: column; gap: var(--sp-2); }
.mgd-split[hidden] { display: none; }
.mgd-split__bar {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: var(--r-full);
  background: var(--mg-fill);
  overflow: hidden;
}
.mgd-split__part { display: block; height: 100%; }
.mgd-split__part--costs { background: #ff9f0a; }
.mgd-split__part--result { background: #30d158; }
.mgd-split.is-loss .mgd-split__part--costs { background: #ff453a; }
.mgd-split__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-5);
  margin: 0;
  color: var(--mg-secondary);
  font-size: var(--fs-sm);
}
.mgd-split__legend strong { color: var(--mg-ink); font-weight: 700; }
.mgd-dot { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 999px; vertical-align: 0.05em; }
.mgd-dot--costs { background: #ff9f0a; }
.mgd-dot--result { background: #30d158; }
.mgd-split.is-loss .mgd-dot--costs { background: #ff453a; }

.mgd-coverage {
  margin: auto 0 0;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--mg-hairline);
  color: var(--mg-secondary);
  font-size: var(--fs-sm);
}
.mgd-coverage.is-partial { color: var(--mg-warning); font-weight: 600; }

/* Operação: ocupação num anel (o mesmo donut das presenças do People) e
   três caixas de cor suave ao lado. */
.mgd-ops__body { display: flex; align-items: center; gap: var(--sp-5); flex: 1; }
.mgd-donut { position: relative; width: 132px; height: 132px; flex-shrink: 0; }
.mgd-donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.mgd-donut__track { fill: none; stroke: var(--mg-fill); stroke-width: 12; }
.mgd-donut__value {
  fill: none;
  stroke: var(--mg-accent);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.mgd-donut__label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.mgd-donut__label strong { color: var(--mg-ink); font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -0.02em; }
.mgd-donut__label span { color: var(--mg-secondary); font-size: var(--fs-sm); }

.mgd-chips { display: flex; flex-direction: column; gap: var(--sp-2); flex: 1; min-width: 0; margin: 0; }
/* Rótulo em cima, valor por baixo: cabe ao lado do anel sem partir o rótulo. */
.mgd-chip {
  --chip-color: var(--mg-accent);
  --chip-bg: var(--mg-accent-soft);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: 12px;
  background: var(--chip-bg);
}
.mgd-chip dt { color: var(--mg-ink-soft); font-size: var(--fs-md); font-weight: 600; }
.mgd-chip dt abbr { margin-left: 4px; color: var(--mg-tertiary); font-size: var(--fs-sm); font-weight: 600; text-decoration: none; cursor: help; }
.mgd-chip dd { margin: 0; color: var(--chip-color); font-size: var(--fs-lg); font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mgd-chip--rooms { --chip-color: #0060df; --chip-bg: var(--mg-accent-soft); }
.mgd-chip--guests { --chip-color: #8944ab; --chip-bg: rgba(191, 90, 242, 0.12); }
/* Verde mais escuro que o do sistema: o texto sobre o fundo verde suave precisa de 4,5:1. */
.mgd-chip--revpac { --chip-color: #1a6e30; --chip-bg: var(--mg-success-soft); }

/* ---------- indicadores por quarto ---------- */
.mgd-matrices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-8);
}
.mgd-matrix { width: 100%; border-collapse: collapse; table-layout: fixed; }
.mgd-matrix__caption {
  caption-side: top;
  padding-bottom: var(--sp-2);
  color: var(--mg-ink);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: left;
}
.mgd-matrix thead th {
  padding: 0 var(--sp-2) var(--sp-2);
  border-bottom: 1px solid var(--mg-hairline);
  color: var(--mg-tertiary);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-align: right;
  text-transform: uppercase;
}
.mgd-matrix thead td { width: 32%; border-bottom: 1px solid var(--mg-hairline); }
.mgd-matrix tbody th {
  padding: var(--sp-3) var(--sp-2) var(--sp-3) 0;
  color: var(--mg-ink-soft);
  font-size: var(--fs-md);
  font-weight: 600;
  text-align: left;
  vertical-align: top;
}
.mgd-matrix tbody td { padding: var(--sp-3) var(--sp-2); text-align: right; vertical-align: top; }
.mgd-matrix tbody tr + tr > * { border-top: 1px solid var(--mg-hairline); }

.mgd-cell__value {
  display: block;
  color: var(--mg-ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mgd-matrix tbody tr:first-child .mgd-cell__value { font-size: var(--fs-lg); }
.mgd-cell__value.is-positive { color: var(--mg-success); }
.mgd-cell__value.is-negative { color: var(--mg-danger); }
.mgd-cell__code {
  display: block;
  margin-top: 2px;
  color: var(--mg-tertiary);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-decoration: none;
  cursor: help;
}

/* ---------- por área ---------- */
.mgd-areas-panel__action { flex-shrink: 0; }
.mgd-areas { min-width: 600px; }
/* O nome da área é o cabeçalho da linha: mesmo espaçamento e linha divisória das outras células. */
.mgd-areas tbody th {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--mg-hairline);
  color: var(--mg-ink);
  font-weight: 600;
  text-align: left;
  vertical-align: middle;
}
.mgd-areas tbody tr:last-child th { border-bottom: none; }
.mgd-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mgd-areas thead th.mgd-num { text-align: right; }
.mgd-areas td.is-positive { color: var(--mg-success); font-weight: 650; }
.mgd-areas td.is-negative { color: var(--mg-danger); font-weight: 650; }
.mgd-share-col { width: 26%; }
.mgd-share { display: flex; align-items: center; gap: var(--sp-2); }
.mgd-share__track { flex: 1; height: 8px; border-radius: 0 4px 4px 0; background: var(--mg-fill); }
.mgd-share__fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--mg-accent); }
.mgd-share__pct { min-width: 48px; color: var(--mg-secondary); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; text-align: right; }
.mgd-areas-empty { margin: 0; padding: var(--sp-6) var(--sp-5); color: var(--mg-secondary); text-align: center; }
.mgd-areas-empty[hidden] { display: none; }

/* ---------- adaptação ---------- */
@media (max-width: 1440px) {
  .mgd-top { grid-template-columns: minmax(0, 1fr); }
  /* Painel em largura total: o anel e as três caixas ficam lado a lado. */
  .mgd-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mgd-chip { gap: var(--sp-1); padding: var(--sp-3); }
}

@media (max-width: 1100px) {
  .mgd-matrices { grid-template-columns: minmax(0, 1fr); gap: var(--sp-6); }
}

@media (max-width: 760px) {
  .mgd-equation { grid-template-columns: minmax(0, 1fr); row-gap: var(--sp-3); }
  .mgd-op { display: none; }
  .mgd-figure { flex-direction: row; flex-wrap: wrap; align-items: baseline; column-gap: var(--sp-2); }
  .mgd-figure__label { flex: 1 0 auto; }
  .mgd-figure__hint { flex-basis: 100%; }
  .mgd-figure__value,
  .mgd-figure--result .mgd-figure__value { font-size: var(--fs-2xl); }
  .mgd-ops__body { flex-direction: column; align-items: stretch; }
  .mgd-donut { align-self: center; }
  .mgd-chips { grid-template-columns: minmax(0, 1fr); }
  .mgd-chip { flex-direction: row; align-items: center; padding: var(--sp-2) var(--sp-3); }
  .mgd-trend__plot { height: 110px; }
  .mgd-trend__key { margin-left: 0; }
  .mgd-presets { order: 3; width: 100%; overflow-x: auto; }
  /* Grelha estreita: o rótulo de cada linha passa para cima e os três valores ficam por baixo,
     alinhados com as colunas Receita / Custos / Resultado. */
  .mgd-matrix,
  .mgd-matrix thead,
  .mgd-matrix tbody { display: block; }
  .mgd-matrix thead tr,
  .mgd-matrix tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mgd-matrix thead td { display: none; }
  .mgd-matrix__caption { display: block; }
  .mgd-matrix tbody th { grid-column: 1 / -1; padding: var(--sp-3) 0 var(--sp-1); }
  .mgd-matrix tbody td { padding: 0 var(--sp-2) var(--sp-3); }
  .mgd-matrix tbody tr + tr > * { border-top: none; }
  .mgd-matrix tbody tr + tr { border-top: 1px solid var(--mg-hairline); }
  .mgd-matrix tbody tr:first-child .mgd-cell__value { font-size: var(--fs-md); }
}

@media (prefers-reduced-motion: reduce) {
  .mgd,
  .mgd-donut__value,
  .mgd-trend__bar { transition: none; }
}
