/* Estructura de la pagina: topbar, shell (sidebar + contenido), botones,
   formularios y los componentes chicos que ambas paginas comparten
   (status-pill). Nada de esto es "dato" -- son piezas de UI. */

/* El atributo [hidden] pierde contra CUALQUIER clase de autor que le
   ponga display a un elemento (ej. .field usa display:flex) -- no es un
   problema de especificidad, un display de autor le gana al [hidden] del
   navegador sin importar la especificidad. Sin esto, un campo con
   class="field" hidden se sigue viendo aunque JS ponga .hidden = true.
   Regla global para que [hidden] siempre gane, la use la clase que la use. */
[hidden] { display: none !important; }

/* Lockup "INSIGHTS" grande + "by VALION" chico debajo -- firma/tagline de
   marca, usada en login.html (encabezado del formulario) y en la pantalla
   de carga (.app-loading, mas abajo), que la comparten ambas paginas. */
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.auth-brand__insights { height: 68px; width: auto; display: block; }
.auth-brand__by {
  display: flex;
  align-items: center;
  gap: 7px;
}
.auth-brand__by span {
  font-size: 17px;
  font-weight: 600;
  font-style: italic;
  color: var(--text-muted);
}
.auth-brand__valion { height: 19px; width: auto; display: block; }

.auth-brand__insights--dark, .auth-brand__valion--dark { display: none; }
@media (prefers-color-scheme: dark) {
  .auth-brand__insights--light, .auth-brand__valion--light { display: none; }
  .auth-brand__insights--dark, .auth-brand__valion--dark { display: block; }
}

/* Pantalla de carga: tapa toda la ventana (position:fixed, por encima de
   todo) mientras se resuelve el chequeo de sesion al abrir login.html o
   app.html -- evita que se alcance a ver el formulario de login o el shell
   vacio por el instante en que tarda el refresh silencioso con el refresh
   token de localStorage (CognitoAuth.refreshSession, ver auth.js). Se
   oculta con display:none (regla [hidden] de arriba) apenas termina el
   chequeo, revelando lo que ya esta debajo -- no bloquea el render de eso,
   solo lo tapa mientras tanto. */
.app-loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: var(--page);
}
.app-loading .auth-brand { margin-bottom: 0; }
.app-loading__spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--gridline);
  border-top-color: var(--brand-primary);
  animation: app-loading-spin .7s linear infinite;
}
@keyframes app-loading-spin { to { transform: rotate(360deg); } }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
  background: var(--nav-surface);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--nav-border);
  color: var(--text-primary);
  flex-wrap: wrap;
}
/* Solo el logo de Insights en el navbar -- la marca Valion queda en el
   footer (app-footer, mas abajo). Es un link a Dashboard (patron estandar
   de "logo lleva al home"), sin el subrayado/color por defecto de <a>. */
.topbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  opacity: 1;
  transition: opacity .15s ease;
}
.topbar__brand:hover { opacity: .75; }
.topbar__product-logo { height: 26px; width: auto; display: block; }

.topbar__product-logo--dark { display: none; }
@media (prefers-color-scheme: dark) {
  .topbar__product-logo--light { display: none; }
  .topbar__product-logo--dark { display: block; }
}
.topbar__right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.topbar__nav { display: flex; gap: 4px; }
.topbar__nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
}
.topbar__nav a:hover { color: var(--text-primary); background: color-mix(in srgb, var(--gridline) 50%, transparent); }
.topbar__nav a.active { color: var(--text-primary); background: var(--gridline); }

/* Desplegables del topbar (estilo consola AWS): texto + flecha, clic abre
   un panel flotante. Patron generico -- lo usan el menu "Administracion" y
   el menu de usuario, cada uno con su propio contenido dentro del panel. */
.topbar__dropdown { position: relative; }
.topbar__dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 8px 12px;
  cursor: pointer;
}
.topbar__dropdown-trigger:hover,
.topbar__dropdown-trigger.active,
.topbar__dropdown.open .topbar__dropdown-trigger {
  background: var(--gridline);
  border-color: var(--border);
}
.topbar__dropdown-chevron {
  width: 14px;
  height: 14px;
  flex: none;
  color: var(--text-muted);
  transition: transform .15s ease;
}
.topbar__dropdown.open .topbar__dropdown-chevron { transform: rotate(180deg); }

.topbar__dropdown-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 220px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  padding: 6px;
  z-index: 20;
}
/* Items como lista de links, no como botones apilados dentro de otro
   boton: sin caja/fondo, el hover y el estado activo se marcan solo con
   color y peso de texto. */
.topbar__dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  text-decoration: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  padding: 8px 10px;
  cursor: pointer;
}
.topbar__dropdown-item:hover { color: var(--text-primary); }
.topbar__dropdown-item.active { color: var(--text-primary); font-weight: 600; }
.topbar__dropdown-item--danger { color: var(--status-critical); }
.topbar__dropdown-item--danger:hover { color: var(--status-critical); opacity: .8; }
.topbar__dropdown-divider { height: 1px; background: var(--border); margin: 4px 2px 6px; }

/* Especifico del menu de usuario: el correo puede ser largo, se recorta con
   ellipsis en vez de empujar el resto del topbar. */
.topbar__user-trigger { max-width: 220px; }
.topbar__user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__user-info { padding: 8px 10px 10px; }
.topbar__user-info-email {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar__user-info-role { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 56px);
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 16px;
  background: var(--surface-1);
}
.sidebar h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin: 4px 0 12px;
}

.main { padding: 24px; max-width: 880px; }
.page-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.page-sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 20px; }

/* Footer de marca -- discreto, misma linea en dashboard/onboarding/login. */
.app-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 20px 24px;
}
.app-footer a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.app-footer a:hover { color: var(--text-secondary); }

/* Botones */
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease;
}
.btn--primary:hover { transform: translateY(-1px); }
.btn--sm { padding: 6px 10px; font-size: 12px; }
.btn--primary { background: var(--brand-primary); color: var(--brand-on-primary); }
.btn--primary:hover { background: var(--brand-primary-hover); }
.btn--primary:disabled { opacity: .6; cursor: default; }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.btn--ghost:hover { background: var(--gridline); }
.btn--ghost-danger { color: var(--status-critical); }
.btn--ghost-danger:hover { background: color-mix(in srgb, var(--status-critical) 12%, transparent); border-color: var(--status-critical); }

/* Formularios */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--text-muted); }
.field input, .field select {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.field input:focus, .field select:focus { outline: 2px solid var(--text-primary); outline-offset: 1px; }
.form-error { color: var(--delta-bad); font-size: 13px; min-height: 18px; }

/* Combobox: input de texto + panel de opciones filtrables, reemplaza un
   <select> nativo cuando conviene poder buscar en la lista (ej. empresas
   en Onboarding). El input visible es decorativo -- el valor real que se
   manda vive en un <input type="hidden"> aparte, ver onboarding.js. */
.combo { position: relative; }
.combo input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}
.combo input:focus { outline: 2px solid var(--text-primary); outline-offset: 1px; }
.combo__panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  padding: 6px;
  z-index: 20;
}
.combo__item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
}
.combo__item:hover { background: var(--gridline); }
.combo__item--new {
  color: var(--brand-primary);
  font-weight: 600;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 10px;
}
.combo__empty { padding: 8px 10px; font-size: 13px; color: var(--text-muted); }

/* Status pill (estado de un tenant) */
.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--gridline);
  color: var(--text-secondary);
}
.status-pill--connected { background: color-mix(in srgb, var(--status-good) 18%, var(--gridline)); color: var(--text-primary); }
.status-pill--pending { background: color-mix(in srgb, var(--status-warning) 20%, var(--gridline)); color: var(--text-primary); }
.status-pill--error { background: color-mix(in srgb, var(--status-critical) 18%, var(--gridline)); color: var(--text-primary); }

/* Card base (reusado por dashboard y onboarding) */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin: 0 0 16px;
  font-weight: 600;
}
.card h2 .client-group__count { text-transform: none; letter-spacing: normal; font-weight: 500; }

.empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }
.error { color: var(--delta-bad); text-align: center; padding: 48px 16px; }
.loading { color: var(--text-muted); text-align: center; padding: 48px 16px; }

/* Secciones del reporte: agrupan varias cards bajo un titulo y un fondo
   propio. El espaciado entre todo lo de adentro (kpi-row, card, lo que sea)
   lo da el gap del body -- por eso se anula el margin-bottom que .card trae
   por defecto, para no sumar los dos y dejar huecos desiguales. */
.report-section {
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}
.report-section:last-child { margin-bottom: 0; }
.report-section__title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-secondary);
  font-weight: 800;
  margin: 0 0 16px;
}
.report-section__desc {
  margin: -8px 0 16px;
  max-width: 640px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.report-section__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.report-section__body > .card { margin-bottom: 0; }

.report-section--finops    { background: var(--section-finops-bg); }
.report-section--security  { background: var(--section-security-bg); }
.report-section--anomalies { background: var(--section-anomalies-bg); }
