/*
 * Control Hub — componentes.
 *
 * CSS semântico, sem utilitários: cada bloco visual (shell, painel, KPI,
 * tabela, gráfico) tem sua classe. Os nomes espelham os componentes em
 * assets/js/core/ui.js.
 */

/* ── Shell ──────────────────────────────────────────────────────────────── */

.shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--shell-sidebar-width);
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
}

.sidebar__brand {
  height: var(--shell-header-height);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex: none;
}

.sidebar__mark {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--primary-foreground);
  flex: none;
}

.sidebar__title {
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar__close {
  margin-left: auto;
  display: none;
  background: none;
  border: 0;
  color: var(--muted-foreground);
  cursor: pointer;
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar__group-label {
  padding: 0 0.5rem 0.375rem;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted-foreground);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  color: color-mix(in oklab, var(--sidebar-foreground) 80%, transparent);
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar__link:hover {
  background: color-mix(in oklab, var(--sidebar-accent) 60%, transparent);
  color: var(--accent-foreground);
}

.sidebar__link[aria-current="page"] {
  background: var(--sidebar-accent);
  color: var(--accent-foreground);
  font-weight: 500;
}

.sidebar__link svg {
  flex: none;
  color: var(--muted-foreground);
}

.sidebar__link[aria-current="page"] svg {
  color: var(--primary);
}

.sidebar__dot {
  margin-left: auto;
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 999px;
  background: var(--success);
  flex: none;
}

.sidebar__dot[data-state="down"] {
  background: var(--destructive);
}

.sidebar__dot[data-state="warn"] {
  background: var(--warning);
}

.sidebar__dot[data-state="unknown"] {
  background: var(--muted-foreground);
}

.sidebar__footer {
  padding: 0.75rem;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.6875rem;
  color: var(--muted-foreground);
}

.shell__main {
  padding-left: var(--shell-sidebar-width);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--shell-header-height);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--background) 95%, transparent);
  backdrop-filter: blur(8px);
}

.topbar__toggle {
  display: none;
  background: none;
  border: 0;
  color: var(--muted-foreground);
  cursor: pointer;
}

.topbar__user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: none;
}

.topbar__identity {
  text-align: right;
  line-height: 1.25;
}

.topbar__identity strong {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
}

.topbar__identity span {
  font-size: 0.6875rem;
  color: var(--muted-foreground);
}

.content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 1024px) {
  .content {
    padding: 1.5rem;
  }
}

@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar[data-open="true"] {
    transform: translateX(0);
  }

  .sidebar__close,
  .topbar__toggle {
    display: block;
  }

  .shell__main {
    padding-left: 0;
  }
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: oklch(0 0 0 / 0.5);
}

/* ── Seletor de período ─────────────────────────────────────────────────── */

.segmented {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  padding: 0.125rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
}

.segmented button {
  padding: 0.25rem 0.625rem;
  border: 0;
  border-radius: calc(var(--radius-sm) - 2px);
  background: none;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--foreground);
}

.segmented button[aria-pressed="true"] {
  background: var(--primary);
  color: var(--primary-foreground);
}

.segmented__short {
  display: none;
}

/* Telas estreitas: "Últimos 30 dias" vira "30d" para o topo não estourar. */
@media (max-width: 767px) {
  .segmented__long {
    display: none;
  }

  .segmented__short {
    display: inline;
    text-transform: uppercase;
  }

  .topbar__identity {
    display: none;
  }
}

/* ── Botões ─────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--foreground);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.btn--primary:hover:not(:disabled) {
  background: color-mix(in oklab, var(--primary) 88%, black);
  color: var(--primary-foreground);
}

.btn--danger {
  border-color: color-mix(in oklab, var(--destructive) 50%, transparent);
  color: var(--destructive);
}

.btn--danger:hover:not(:disabled) {
  background: color-mix(in oklab, var(--destructive) 15%, transparent);
  color: var(--destructive);
}

.btn--block {
  width: 100%;
  padding: 0.5625rem 0.75rem;
  font-size: 0.8125rem;
}

/* ── Cabeçalho de página e abas ─────────────────────────────────────────── */

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-header h1 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.page-header p {
  margin-top: 0.125rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.tabs a {
  padding: 0.375rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  transition: background 0.15s ease, color 0.15s ease;
}

.tabs a:hover {
  background: var(--accent);
  color: var(--foreground);
}

.tabs a[aria-current="page"] {
  background: var(--card);
  border-color: var(--border);
  color: var(--foreground);
  font-weight: 500;
}

/* ── KPIs ───────────────────────────────────────────────────────────────── */

.kpi-row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}

.kpi {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.kpi__label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
}

.kpi__value {
  margin-top: 0.5rem;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
}

.kpi__value[data-tone="positive"] {
  color: var(--success);
}

.kpi__value[data-tone="negative"] {
  color: var(--destructive);
}

.kpi__value[data-tone="warning"] {
  color: var(--warning);
}

.kpi__meta {
  margin-top: 0.375rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.kpi__delta {
  display: inline-flex;
  align-items: center;
  gap: 0.125rem;
  font-weight: 500;
  color: var(--success);
}

.kpi__delta[data-direction="down"] {
  color: var(--destructive);
}

/* ── Painéis ────────────────────────────────────────────────────────────── */

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 1279px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 767px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.panel[data-span="2"] {
  grid-column: span 2;
}

.panel[data-span="3"] {
  grid-column: span 3;
}

@media (max-width: 1279px) {
  .panel[data-span="3"] {
    grid-column: span 2;
  }
}

@media (max-width: 767px) {
  .panel[data-span="2"],
  .panel[data-span="3"] {
    grid-column: span 1;
  }
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.panel__head h2 {
  font-size: 0.875rem;
  font-weight: 600;
}

.panel__head p {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.panel__body {
  padding: 1rem;
  flex: 1;
  min-width: 0;
}

/* ── Tabelas ────────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

table.data th {
  padding: 0.5rem;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data td {
  padding: 0.5rem;
  border-bottom: 1px solid color-mix(in oklab, var(--border) 60%, transparent);
  vertical-align: middle;
}

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

table.data tbody tr:hover {
  background: color-mix(in oklab, var(--accent) 40%, transparent);
}

table.data [data-align="right"] {
  text-align: right;
}

table.data code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.cell-actions {
  display: flex;
  gap: 0.375rem;
  justify-content: flex-end;
}

/* ── Selos e listas ─────────────────────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
  background: var(--muted);
  color: var(--muted-foreground);
}

.pill[data-tone="positive"] {
  background: color-mix(in oklab, var(--success) 15%, transparent);
  color: var(--success);
}

.pill[data-tone="negative"] {
  background: color-mix(in oklab, var(--destructive) 15%, transparent);
  color: var(--destructive);
}

.pill[data-tone="warning"] {
  background: color-mix(in oklab, var(--warning) 15%, transparent);
  color: var(--warning);
}

.pill[data-tone="accent"] {
  background: color-mix(in oklab, var(--primary) 18%, transparent);
  color: color-mix(in oklab, var(--primary) 70%, white);
}

.status-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.status-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.status-list span {
  color: var(--muted-foreground);
  min-width: 0;
}

.status-list small {
  display: block;
  font-size: 0.6875rem;
  color: color-mix(in oklab, var(--muted-foreground) 75%, transparent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Avisos, vazio e carregamento ───────────────────────────────────────── */

.note {
  display: flex;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

.note[data-tone="warning"] {
  border-left-color: var(--warning);
}

.note[data-tone="danger"] {
  border-left-color: var(--destructive);
  color: color-mix(in oklab, var(--destructive) 70%, white);
}

.note[data-tone="info"] {
  border-left-color: var(--primary);
}

.empty {
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--muted) 25%,
    color-mix(in oklab, var(--muted) 60%, var(--accent)) 37%,
    var(--muted) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ── Gráficos ───────────────────────────────────────────────────────────── */

.chart {
  position: relative;
  width: 100%;
}

.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.chart__grid line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart__axis {
  fill: var(--muted-foreground);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.chart__hover {
  stroke: color-mix(in oklab, var(--foreground) 40%, transparent);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart__tooltip {
  position: absolute;
  z-index: 5;
  min-width: 9rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.45);
  font-size: 0.75rem;
  pointer-events: none;
  transform: translate(-50%, -100%);
  white-space: nowrap;
}

.chart__tooltip strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.6875rem;
  color: var(--muted-foreground);
  font-weight: 500;
}

.chart__tooltip-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  justify-content: space-between;
}

.chart__swatch {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 2px;
  flex: none;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.625rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.donut {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.donut__legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-size: 0.75rem;
  min-width: 0;
  flex: 1;
}

.donut__legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.donut__legend span:first-child {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 2px;
  flex: none;
}

.donut__legend span:nth-child(2) {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted-foreground);
}

/* ── Autenticação ───────────────────────────────────────────────────────── */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth__card {
  width: 100%;
  max-width: 23rem;
  padding: 1.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
}

.auth__brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 1.25rem;
}

.auth__brand h1 {
  font-size: 1rem;
  font-weight: 600;
}

.auth__brand p {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

/* ── Formulários ────────────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3125rem;
  margin-bottom: 0.875rem;
  min-width: 0;
}

.field label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--input);
  border-radius: var(--radius-sm);
  background: var(--background);
  font-size: 0.8125rem;
  transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--ring);
  outline: none;
}

.field small {
  font-size: 0.6875rem;
  color: color-mix(in oklab, var(--muted-foreground) 80%, transparent);
}

.field--inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field--inline input {
  width: auto;
}

.form-grid {
  display: grid;
  gap: 0 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.form-error {
  margin-bottom: 0.875rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid color-mix(in oklab, var(--destructive) 40%, transparent);
  border-radius: var(--radius-sm);
  background: color-mix(in oklab, var(--destructive) 12%, transparent);
  color: color-mix(in oklab, var(--destructive) 75%, white);
  font-size: 0.75rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ── Toasts ─────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 22rem;
}

.toast {
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 0.8125rem;
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.4);
  animation: toast-in 0.18s ease;
}

.toast[data-tone="success"] {
  border-left-color: var(--success);
}

.toast[data-tone="error"] {
  border-left-color: var(--destructive);
}

.toast[data-tone="info"] {
  border-left-color: var(--primary);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
