/*
 * Padrão de layout do hub da Move, v1 (docs/layout.html do MoveEnergia-Core).
 * Servido pelo Core em /assets/hub/v1/hub.css e carregado por todo módulo antes do CSS
 * dele. Aqui só o que é comum: tokens, base, a moldura (trilho + conteúdo), o cabeçalho
 * da página e os componentes da base. Nada específico de módulo.
 * Versão nova que quebre algo vira /assets/hub/v2/; a v1 só recebe correções.
 */

/* ---------- Tokens ---------- */

:root {
  /* Marca */
  --hub-navy: #10263b;
  --hub-navy-2: #0b1b2b;
  --hub-orange: #ef7d1a;
  --hub-orange-hover: #d96d12;
  --hub-orange-bg: #fff4e9;
  --hub-on-orange: #1b1004;

  /* Superfícies */
  --hub-bg: #f3f5f7;
  --hub-surface: #ffffff;
  --hub-surface-2: #f8fafb;
  --hub-surface-hover: #f5f8fb;
  --hub-border: #e6e9ed;
  --hub-border-strong: #d6dbe1;

  /* Texto */
  --hub-text: #1b2733;
  --hub-text-2: #46545f;
  --hub-muted: #6b7783;

  /* Semântica: cor e o fundo claro correspondente */
  --hub-info: #1d6fb8;
  --hub-info-bg: #eef5fc;
  --hub-ok: #24804a;
  --hub-ok-bg: #e9f7ef;
  --hub-warn: #b85a06;
  --hub-warn-bg: #fef6e7;
  --hub-error: #b91c1c;
  --hub-error-bg: #fef2f2;

  /* Tipografia */
  --hub-font: 'Lato', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --hub-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Espaço e forma */
  --hub-space-1: 4px;
  --hub-space-2: 8px;
  --hub-space-3: 12px;
  --hub-space-4: 16px;
  --hub-space-5: 24px;
  --hub-space-6: 32px;
  --hub-radius: 8px;
  --hub-radius-lg: 10px;
  --hub-shadow: 0 1px 2px rgba(16, 38, 59, 0.06), 0 1px 3px rgba(16, 38, 59, 0.05);
  --hub-shadow-lg: 0 12px 40px rgba(16, 38, 59, 0.18);
  --hub-focus: 0 0 0 3px rgba(239, 125, 26, 0.28);

  /* Moldura */
  --hub-rail-w: 56px;
  --hub-rail-w-expanded: 224px;
  --hub-page-h: 40px;
  --hub-text-max: 960px;
}

/* Tema escuro: já escrito, ligado só por data-theme="dark" (decisão L5: o padrão v1 é claro). */
:root[data-theme='dark'] {
  --hub-orange-bg: #33230f;
  --hub-bg: #0f1720;
  --hub-surface: #16212c;
  --hub-surface-2: #1b2733;
  --hub-surface-hover: #1f2d3a;
  --hub-border: #263544;
  --hub-border-strong: #33475a;
  --hub-text: #e6edf3;
  --hub-text-2: #b9c6d3;
  --hub-muted: #8b9aa8;
  --hub-info: #6cb0f0;
  --hub-info-bg: #13283d;
  --hub-ok: #5cc486;
  --hub-ok-bg: #12291c;
  --hub-warn: #f0a35a;
  --hub-warn-bg: #2f2210;
  --hub-error: #f28b8b;
  --hub-error-bg: #341617;
  color-scheme: dark;
}

/* ---------- Base ---------- */

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

body {
  margin: 0;
  font-family: var(--hub-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--hub-text);
  background: var(--hub-bg);
  -webkit-font-smoothing: antialiased;
}

.hub-muted {
  color: var(--hub-muted);
}

.hub-mono {
  font-family: var(--hub-mono);
  font-size: 0.9em;
}

/* ---------- Moldura: trilho + conteúdo ---------- */

.hub-app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* A área do módulo: toda a altura da janela e é ela que rola. */
.hub-content {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.hub-rail {
  flex: 0 0 var(--hub-rail-w);
  width: var(--hub-rail-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--hub-surface);
  border-right: 1px solid var(--hub-border);
  overflow: hidden;
  z-index: 20;
  transition: width 0.16s ease, flex-basis 0.16s ease;
}

/* Expandido: escolha guardada pelo <hub-rail-toggle> e aplicada em <html>, vale em todo módulo. */
:root[data-hub-rail='expanded'] .hub-rail,
.hub-rail.is-expanded {
  flex-basis: var(--hub-rail-w-expanded);
  width: var(--hub-rail-w-expanded);
}

/* Marca Move no topo; leva ao início do hub. Expandido, mostra o nome do módulo. */
.hub-rail__brand {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 7px;
  background: var(--hub-navy);
  border-bottom: 1px solid var(--hub-navy-2);
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}

.hub-rail__brand img,
.hub-rail__brand svg {
  flex: none;
  width: 42px;
  height: 34px;
  object-fit: contain;
  display: block;
}

.hub-rail__module {
  font-weight: 900;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hub-rail__nav {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--hub-space-1);
  padding: var(--hub-space-3) 7px;
  overflow-x: hidden;
  overflow-y: auto;
}

.hub-rail-group {
  display: flex;
  flex-direction: column;
  gap: var(--hub-space-1);
}

.hub-rail-group + .hub-rail-group {
  margin-top: var(--hub-space-2);
  padding-top: var(--hub-space-2);
  border-top: 1px solid var(--hub-border);
}

.hub-rail-group__label {
  display: none;
  padding: 2px 10px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--hub-muted);
  white-space: nowrap;
}

.hub-rail-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--hub-space-3);
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--hub-radius);
  background: transparent;
  color: var(--hub-muted);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.hub-rail-item svg {
  flex: none;
  width: 22px;
  height: 22px;
}

.hub-rail-item:hover {
  background: var(--hub-surface-hover);
  color: var(--hub-text);
}

.hub-rail-item:focus-visible {
  outline: none;
  box-shadow: var(--hub-focus);
}

.hub-rail-item.is-active,
.hub-rail-item[aria-current='page'] {
  background: var(--hub-orange-bg);
  color: var(--hub-orange);
}

.hub-rail-item.is-active::before,
.hub-rail-item[aria-current='page']::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--hub-orange);
}

/* Rótulos: escondidos no trilho recolhido (a dica é o title do item, por conta do módulo). */
.hub-rail-item__label,
.hub-rail__module {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}

:root[data-hub-rail='expanded'] .hub-rail .hub-rail-item__label,
:root[data-hub-rail='expanded'] .hub-rail .hub-rail__module,
.hub-rail.is-expanded .hub-rail-item__label,
.hub-rail.is-expanded .hub-rail__module {
  opacity: 1;
  pointer-events: auto;
}

:root[data-hub-rail='expanded'] .hub-rail .hub-rail-group__label,
.hub-rail.is-expanded .hub-rail-group__label {
  display: block;
}

/* Rodapé: expandir/recolher e, por último, o usuário (<hub-menu>). */
.hub-rail__foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--hub-space-1);
  padding: var(--hub-space-2) 7px var(--hub-space-3);
  border-top: 1px solid var(--hub-border);
}

hub-menu,
hub-rail-toggle {
  display: block;
}

/* Telas estreitas: o trilho vira barra no rodapé da tela; nada vai para o topo. */
@media (max-width: 719px) {
  .hub-app {
    flex-direction: column;
  }

  .hub-rail,
  :root[data-hub-rail='expanded'] .hub-rail,
  .hub-rail.is-expanded {
    order: 2;
    flex: 0 0 56px;
    width: 100%;
    height: 56px;
    flex-direction: row;
    border-right: 0;
    border-top: 1px solid var(--hub-border);
    transition: none;
  }

  .hub-rail__brand {
    width: 56px;
    border-bottom: 0;
  }

  .hub-rail .hub-rail__module,
  .hub-rail .hub-rail-item__label,
  .hub-rail .hub-rail-group__label,
  hub-rail-toggle {
    display: none !important;
  }

  .hub-rail__nav,
  .hub-rail-group {
    flex-direction: row;
    align-items: center;
  }

  .hub-rail__nav {
    padding: 7px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .hub-rail-group + .hub-rail-group {
    margin: 0 0 0 var(--hub-space-2);
    padding: 0 0 0 var(--hub-space-2);
    border-top: 0;
    border-left: 1px solid var(--hub-border);
  }

  .hub-rail-item {
    width: 42px;
    flex: none;
  }

  .hub-rail-item.is-active::before,
  .hub-rail-item[aria-current='page']::before {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: -7px;
    width: auto;
    height: 3px;
    border-radius: 3px 3px 0 0;
  }

  .hub-rail__foot {
    flex-direction: row;
    align-items: center;
    padding: 7px;
    border-top: 0;
    border-left: 1px solid var(--hub-border);
  }
}

/* ---------- Cabeçalho da página: título e ações, rola com o conteúdo ---------- */

/* Fica dentro do recuo do conteúdo do módulo; o espaço abaixo já vem com ele. */
.hub-page {
  flex: none;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--hub-space-2) var(--hub-space-3);
  min-height: var(--hub-page-h);
  margin: 0 0 var(--hub-space-4);
}

.hub-page__title {
  margin: 0;
  min-width: 0;
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1.2;
}

.hub-page__sub {
  color: var(--hub-muted);
  font-size: 0.9rem;
}

.hub-page__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--hub-space-2);
}

/* ---------- Componentes da base ---------- */

.hub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--hub-border-strong);
  border-radius: var(--hub-radius);
  background: var(--hub-surface);
  color: var(--hub-text);
  font: inherit;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.hub-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.hub-btn:hover {
  background: var(--hub-surface-hover);
  border-color: var(--hub-muted);
}

.hub-btn:focus-visible {
  outline: none;
  box-shadow: var(--hub-focus);
}

.hub-btn:disabled,
.hub-btn[aria-disabled='true'] {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.hub-btn--primary {
  background: var(--hub-orange);
  border-color: var(--hub-orange);
  color: var(--hub-on-orange);
}

.hub-btn--primary:hover {
  background: var(--hub-orange-hover);
  border-color: var(--hub-orange-hover);
}

.hub-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--hub-text-2);
}

.hub-btn--ghost:hover {
  background: var(--hub-surface-hover);
  border-color: transparent;
  color: var(--hub-text);
}

/* Atenção: ação reversível mas com efeito (pausar, arquivar). */
.hub-btn--warn {
  background: var(--hub-warn);
  border-color: var(--hub-warn);
  color: #fff;
}

.hub-btn--warn:hover {
  background: #9a4a05;
  border-color: #9a4a05;
}

.hub-btn--danger {
  background: var(--hub-error);
  border-color: var(--hub-error);
  color: #fff;
}

.hub-btn--danger:hover {
  background: #991b1b;
  border-color: #991b1b;
}

.hub-btn--sm {
  height: 30px;
  padding: 0 10px;
  font-size: 0.875rem;
}

.hub-btn--lg {
  height: 44px;
  padding: 0 20px;
  font-size: 1.05rem;
}

.hub-field {
  display: flex;
  flex-direction: column;
  gap: var(--hub-space-1);
}

.hub-field > label,
.hub-label {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--hub-text-2);
}

.hub-input,
.hub-select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--hub-border-strong);
  border-radius: var(--hub-radius);
  background: var(--hub-surface);
  color: var(--hub-text);
  font: inherit;
}

textarea.hub-input {
  height: auto;
  min-height: 80px;
  padding: 8px 10px;
  resize: vertical;
}

.hub-input:focus,
.hub-select:focus {
  outline: none;
  border-color: var(--hub-orange);
  box-shadow: var(--hub-focus);
}

.hub-input[aria-invalid='true'] {
  border-color: var(--hub-error);
}

.hub-input:disabled,
.hub-select:disabled {
  background: var(--hub-surface-2);
  color: var(--hub-muted);
}

/* Tabela: cabeçalho fixo, linha de 40 px, ordenação por aria-sort. */
.hub-table-wrap {
  overflow: auto;
  background: var(--hub-surface);
  border: 1px solid var(--hub-border);
  border-radius: var(--hub-radius-lg);
}

.hub-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.hub-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 40px;
  padding: 0 12px;
  background: var(--hub-surface-2);
  border-bottom: 1px solid var(--hub-border);
  color: var(--hub-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.hub-table td {
  height: 40px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--hub-border);
  vertical-align: middle;
}

.hub-table tbody tr:last-child td {
  border-bottom: 0;
}

.hub-table tbody tr:hover td {
  background: var(--hub-surface-hover);
}

.hub-table th[aria-sort] {
  cursor: pointer;
}

.hub-table th[aria-sort='ascending']::after {
  content: ' ↑';
}

.hub-table th[aria-sort='descending']::after {
  content: ' ↓';
}

.hub-card {
  background: var(--hub-surface);
  border: 1px solid var(--hub-border);
  border-radius: var(--hub-radius-lg);
  box-shadow: var(--hub-shadow);
  padding: var(--hub-space-4) var(--hub-space-5);
}

/* Aviso: info, ok, atenção, erro. Texto corrido (com <strong>, <code>…) fica num bloco só.
   Com botão ("Tentar de novo" em .hub-notice__action), a mensagem vai num elemento próprio
   antes dele: <div class="hub-notice"><span>…</span><button class="… hub-notice__action"> */
.hub-notice {
  display: block;
  padding: var(--hub-space-3) var(--hub-space-4);
  border-left: 4px solid var(--hub-info);
  border-radius: var(--hub-radius);
  background: var(--hub-info-bg);
  color: var(--hub-text);
}

.hub-notice--ok {
  border-left-color: var(--hub-ok);
  background: var(--hub-ok-bg);
}

.hub-notice--warn {
  border-left-color: var(--hub-warn);
  background: var(--hub-warn-bg);
}

.hub-notice--error {
  border-left-color: var(--hub-error);
  background: var(--hub-error-bg);
  color: var(--hub-error);
}

.hub-notice:has(> .hub-notice__action) {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--hub-space-2) var(--hub-space-3);
}

.hub-notice__action {
  margin-left: auto;
}

/* Vazio: card tracejado com o passo seguinte. */
.hub-empty {
  padding: var(--hub-space-6) var(--hub-space-5);
  border: 1px dashed var(--hub-border-strong);
  border-radius: var(--hub-radius-lg);
  background: var(--hub-surface);
  color: var(--hub-text-2);
  text-align: center;
}

.hub-empty strong {
  display: block;
  margin-bottom: var(--hub-space-1);
  color: var(--hub-text);
}

/* Carregando: texto discreto, só depois de 300 ms (nada pisca em resposta rápida). */
.hub-loading {
  padding: var(--hub-space-5);
  color: var(--hub-muted);
  animation: hub-appear 0.2s ease 0.3s both;
}

@keyframes hub-appear {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Diálogo de confirmação (<dialog class="hub-dialog">). */
.hub-dialog {
  width: min(480px, calc(100vw - 32px));
  padding: var(--hub-space-5);
  border: 0;
  border-radius: var(--hub-radius-lg);
  background: var(--hub-surface);
  color: var(--hub-text);
  box-shadow: var(--hub-shadow-lg);
}

.hub-dialog::backdrop {
  background: rgba(16, 38, 59, 0.45);
}

.hub-dialog__title {
  margin: 0 0 var(--hub-space-2);
  font-size: 1.15rem;
  font-weight: 900;
}

.hub-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--hub-space-2);
  margin-top: var(--hub-space-5);
}

/* Toast: confirmação breve, canto inferior direito (acima da barra no celular). */
.hub-toast {
  position: fixed;
  right: var(--hub-space-5);
  bottom: var(--hub-space-5);
  z-index: 1000;
  max-width: min(420px, calc(100vw - 32px));
  padding: var(--hub-space-3) var(--hub-space-4);
  border-left: 4px solid var(--hub-orange);
  border-radius: var(--hub-radius);
  background: var(--hub-navy);
  color: #fff;
  box-shadow: var(--hub-shadow-lg);
}

.hub-toast--ok {
  border-left-color: #5cc486;
}

.hub-toast--error {
  border-left-color: #f28b8b;
}

@media (max-width: 719px) {
  .hub-toast {
    right: var(--hub-space-4);
    bottom: calc(56px + var(--hub-space-4));
  }
}

@media (prefers-reduced-motion: reduce) {
  .hub-rail,
  .hub-rail-item,
  .hub-rail-item__label,
  .hub-rail__module,
  .hub-loading {
    transition: none;
    animation: none;
  }
}
