/* AVA UI Design System v1.1 — App Shell superior.
   Esta capa solo modifica presentación y conserva los contratos DOM usados por app.js. */

.app-shell {
  width: 100%;
  max-width: none;
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: var(--ava-topbar-height) 84px minmax(0, 1fr);
  grid-template-areas: "topbar" "modules" "workspace";
  overflow: hidden;
  background: var(--ava-background);
  box-shadow: none;
}

.app-shell.is-module-bar-open { grid-template-columns: minmax(0, 1fr); }

/* El control superior libera completamente el alto de la navegación cuando
   el usuario decide ocultar los módulos. La barra conserva su DOM y eventos,
   por lo que puede restaurarse sin recargar ni perder el módulo activo. */
.app-shell:not(.is-module-bar-open) {
  grid-template-rows: var(--ava-topbar-height) 0 minmax(0, 1fr);
}

.app-shell:not(.is-module-bar-open) > .module-bar {
  height: 0;
  min-height: 0;
  max-height: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.billing-focus-mode .app-shell:not(.is-module-bar-open),
body.statement-focus-mode .app-shell:not(.is-module-bar-open) {
  grid-template-rows: var(--ava-topbar-height) 0 minmax(0, 1fr);
}

.topbar {
  grid-area: topbar;
  position: relative;
  top: auto;
  min-height: var(--ava-topbar-height);
  height: var(--ava-topbar-height);
  display: grid;
  grid-template-columns: 196px minmax(170px, 260px) minmax(0, 1fr);
  grid-template-areas: "brand company account";
  align-items: center;
  gap: var(--ava-space-3);
  padding: 0 var(--ava-space-5);
  color: #fff;
  background: var(--ava-primary-dark);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  box-shadow: none;
  z-index: 80;
}

.topbar-brand {
  grid-area: brand;
  width: 176px;
  height: 56px;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.topbar-brand img {
  width: 176px;
  height: 56px;
  display: block;
  object-fit: contain;
  object-position: left center;
}

.module-bar,
.module-bar.is-open {
  grid-area: modules;
  position: relative;
  inset: auto;
  width: 100%;
  height: 84px;
  max-height: 84px;
  min-width: 0;
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0;
  color: #fff;
  background: #102E4C;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 4px 12px rgba(11, 47, 79, .12);
  transform: none;
  opacity: 1;
  z-index: 70;
  scrollbar-width: thin;
}

.module-bar .module-nav,
.module-bar.is-open .module-nav {
  width: 100%;
  min-width: max-content;
  height: 83px;
  display: flex;
  align-items: stretch;
  gap: 0;
  overflow: visible;
  padding: 0 var(--ava-space-2);
}

.module-bar .nav-button {
  position: relative;
  min-width: 92px;
  min-height: 83px;
  height: 83px;
  flex: 1 0 92px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  padding: 6px var(--ava-space-2) 7px;
  border: 0;
  border-radius: 0;
  color: rgba(255, 255, 255, .82);
  text-align: center;
  background: transparent;
  box-shadow: none;
  transform: none;
  transition: color 140ms ease, background 140ms ease;
}

.module-bar .nav-button::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 0;
  left: 8px;
  height: 3px;
  border-radius: var(--ava-radius-pill) var(--ava-radius-pill) 0 0;
  background: transparent;
}

.module-bar .nav-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, .07);
  box-shadow: none;
  transform: none;
}

.module-bar .nav-button.is-active {
  color: #fff;
  background: rgba(29, 111, 165, .34);
  box-shadow: none;
}

.module-bar .nav-button.is-active::after { background: #fff; }

.module-bar .nav-button .module-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.module-bar .nav-button .module-icon img {
  width: 28px;
  height: 28px;
  display: block;
  object-fit: contain;
  object-position: center;
  filter: none;
  opacity: .86;
}

.module-bar .nav-button:hover .module-icon img,
.module-bar .nav-button.is-active .module-icon img { opacity: 1; }

.module-bar .nav-button span:last-child {
  width: 100%;
  min-height: 30px;
  display: -webkit-box;
  overflow: hidden;
  color: inherit;
  font-family: var(--ava-font-family);
  font-size: 11px;
  font-weight: var(--ava-font-semibold);
  line-height: 14px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.header-module-switch {
  grid-area: module;
  display: none;
}

.topbar .approved-company-switch {
  grid-area: company;
  width: 100%;
  min-width: 0;
  height: 40px;
  min-height: 40px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 18px;
  align-items: center;
  gap: var(--ava-space-2);
  margin: 0;
  padding: 0 var(--ava-space-3);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--ava-radius-button);
  color: #fff;
  background: rgba(255, 255, 255, .06);
}

.topbar .approved-company-switch:hover {
  border-color: rgba(255, 255, 255, .48);
  color: #fff;
  background: rgba(255, 255, 255, .12);
}

.topbar .approved-company-switch span {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: hidden;
  clip: auto;
  color: inherit;
  font-size: var(--ava-font-sm);
  font-weight: var(--ava-font-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .approved-company-switch svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar .approved-company-switch .company-switch-chevron { display: block; }

.topbar-right {
  grid-area: account;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--ava-space-2);
}

.topbar .connection-state,
.topbar .clock { display: none; }

.notifications-button,
.topbar .profile-button,
.header-logout {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: var(--ava-radius-button);
  color: #fff;
  background: rgba(255, 255, 255, .06);
}

.notifications-button:hover,
.topbar .profile-button:hover,
.header-logout:hover {
  border-color: rgba(255, 255, 255, .48);
  color: #fff;
  background: rgba(255, 255, 255, .12);
}

.topbar .profile-button { min-width: 154px; }
.topbar .profile-copy strong { color: #fff; }
.topbar .profile-copy small { color: rgba(255, 255, 255, .68); }
.profile-avatar { color: var(--ava-primary-dark); background: #fff; }
.notifications-count { border-color: var(--ava-primary-dark); }

.workspace {
  grid-area: workspace;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--ava-background);
}

.main-content {
  width: 100%;
  max-width: none;
  min-width: 0;
  margin: 0;
  padding: var(--ava-page-padding);
}

@media (max-width: 1199px) {
  .topbar { grid-template-columns: 178px minmax(150px, 220px) minmax(0, 1fr); padding-inline: var(--ava-space-4); }
  .topbar-brand, .topbar-brand img { width: 160px; height: 52px; }
  .topbar .profile-copy, .header-logout span { display: none; }
  .topbar .profile-button { width: 40px; min-width: 40px; padding: 2px; }
  .header-logout { width: 40px; justify-content: center; padding: 0; }
  .main-content { padding: var(--ava-page-padding); }
}

@media (max-width: 760px) {
  .app-shell,
  .app-shell.is-module-bar-open {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 60px 0 minmax(0, 1fr);
  }

  .topbar {
    min-height: 60px;
    height: 60px;
    grid-template-columns: 116px minmax(0, 1fr) auto;
    grid-template-areas: "brand module account";
    gap: var(--ava-space-2);
    padding-inline: var(--ava-space-3);
  }

  .topbar-brand,
  .topbar-brand img { width: 112px; height: 44px; }

  .topbar .approved-company-switch,
  .topbar .profile-button { display: none; }

  .header-module-switch {
    width: 100%;
    min-width: 0;
    height: 40px;
    min-height: 40px;
    display: inline-grid;
    grid-template-columns: 28px minmax(0, 1fr) 16px;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: var(--ava-radius-button);
    color: #fff;
    text-align: left;
    background: rgba(255, 255, 255, .06);
  }

  .header-module-switch > .module-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
  }

  .header-module-switch > .module-icon img { width: 24px; height: 24px; object-fit: contain; filter: none; }
  .header-module-switch .module-switch-copy { min-width: 0; display: grid; }
  .header-module-switch .module-switch-copy small { display: none; }
  .header-module-switch .module-switch-copy strong { overflow: hidden; color: #fff; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .header-module-switch .module-switch-chevron { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }

  .module-bar,
  .module-bar.is-open {
    position: fixed;
    inset: 60px 0 auto;
    width: 100%;
    height: auto;
    max-height: calc(100dvh - 60px);
    display: none;
    overflow-x: hidden;
    overflow-y: auto;
    border-bottom: 1px solid rgba(255, 255, 255, .16);
    box-shadow: 0 16px 30px rgba(11, 47, 79, .24);
  }

  .module-bar.is-open { display: block; }

  .module-bar .module-nav,
  .module-bar.is-open .module-nav {
    min-width: 0;
    height: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: var(--ava-space-2);
  }

  .module-bar .nav-button {
    min-width: 0;
    min-height: 62px;
    height: 62px;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    justify-items: start;
    gap: var(--ava-space-2);
    padding: 6px var(--ava-space-2);
    border-radius: var(--ava-radius-button);
    text-align: left;
  }

  .module-bar .nav-button span:last-child {
    min-height: 0;
    display: block;
    text-align: left;
    white-space: normal;
  }

  .module-bar .nav-button::after { inset: auto 8px 0; }
  .notifications-button { width: 38px; height: 38px; flex-basis: 38px; }
  .header-logout { display: none; }
  .main-content { padding: var(--ava-space-4) var(--ava-space-3) var(--ava-space-6); }
}

@media (prefers-reduced-motion: reduce) {
  .module-bar .nav-button { transition: none; }
}
