/* Tervo — layout · Navy + Teal (v2)
   The app header is now the NAVY brand bar (white wordmark, teal active
   underline). Mark the current page with aria-current="page" on its nav
   <a>. No HTML changes required — the brand mark is injected via CSS. */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 64px;
  padding: 0 clamp(24px, 3vw, 48px);
  background: var(--color-brand);
  border-bottom: 1px solid var(--brand-hairline);
}

.app-header-panel {
  display: contents;
}

.app-mobile-controls,
.app-mobile-drawer-header,
.app-mobile-backdrop {
  display: none;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--color-on-brand);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: 0;
  text-decoration: none;
}

/* Hexagonal Tervo mark for dark surfaces: teal hexagon, navy inner cut */
.app-brand::before {
  content: "";
  width: 26px;
  height: 26px;
  flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M24 4 L40.5 13.5 V32.5 L24 42 L7.5 32.5 V13.5 Z' fill='%233f938c'/%3E%3Cpath d='M24 14.5 L31 18.5 V26.5 L24 30.5 L17 26.5 V18.5 Z' fill='%230e1c30'/%3E%3C/svg%3E") center / contain no-repeat;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: clamp(10px, 1.25vw, 18px);
  color: var(--color-on-brand-muted);
  font-size: 0.92rem;
}

.app-nav a,
.app-nav-trigger {
  color: var(--color-on-brand-muted);
  text-decoration: none;
  padding: 8px 2px;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.app-nav a:hover,
.app-nav-trigger:hover { color: var(--color-on-brand); }
.app-nav a[aria-current="page"],
.app-nav-group[data-active="true"] > .app-nav-trigger {
  color: var(--color-on-brand);
  font-weight: 600;
  border-bottom-color: var(--teal-bright);
}

.app-nav-group {
  position: relative;
}

.app-nav-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-top: 0;
  border-right: 0;
  border-left: 0;
  cursor: pointer;
  background: transparent;
  font: inherit;
}

.app-nav-caret {
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--transition);
}

.app-nav-group.is-open .app-nav-caret {
  transform: translateY(1px) rotate(225deg);
}

.app-nav-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 30;
  display: none;
  min-width: 210px;
  padding: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.app-nav-group.is-open .app-nav-menu {
  display: grid;
}

.app-nav-menu::before {
  position: absolute;
  top: -6px;
  left: 20px;
  width: 10px;
  height: 10px;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-left: 1px solid var(--color-border);
  content: "";
  transform: rotate(45deg);
}

.app-nav-menu .app-nav-link {
  display: block;
  padding: 10px 12px;
  color: var(--color-text);
  border: 0;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.app-nav-menu .app-nav-link:hover {
  color: var(--color-text);
  background: var(--color-surface-muted);
}

.app-nav-menu .app-nav-link[aria-current="page"] {
  color: var(--color-primary);
  background: var(--teal-50);
  font-weight: 700;
}

/* Logout button sits on navy — make the secondary button readable on dark */
.app-header .btn-secondary {
  color: var(--color-on-brand);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--brand-hairline);
}
.app-header .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
}

.app-user {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.app-user-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
  color: var(--color-on-brand);
  text-align: right;
}

.app-user-copy strong {
  max-width: 180px;
  overflow: hidden;
  font-size: 0.9rem;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user-copy span {
  color: var(--color-on-brand-muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.page-shell {
  width: min(1440px, calc(100% - 48px));
  margin: 28px auto;
}

.page-title { margin-bottom: 22px; }
.page-title h1 { margin: 0 0 6px; font-size: 1.75rem; font-weight: 700; letter-spacing: 0; }
.page-title p { max-width: 820px; margin: 0; color: var(--color-muted); }

.page-header {
  margin-bottom: 22px;
}

.page-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
}

.page-header-copy {
  min-width: 0;
}

.page-header h1 {
  margin: 0 0 6px;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0;
}

.page-header p {
  max-width: 820px;
  margin: 0;
  color: var(--color-muted);
}

.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex: none;
  flex-wrap: wrap;
  gap: 10px;
}

.page-header-context {
  margin-top: 16px;
}

.page-header-field {
  min-width: min(260px, 100%);
}

/* ---- Login ---- */
.login-shell {
  display: grid;
  /* Columna definida al 100%: con la pista auto, el contenido ancho (fila de
     contraseña) expandia la tarjeta mas alla del viewport en moviles. */
  grid-template-columns: 100%;
  min-height: 100vh;
  /* Viewport dinamico: en moviles 100vh incluye la zona de la barra de URL
     y genera scroll permanente; dvh mide solo el area visible. */
  min-height: 100dvh;
  padding: 24px;
  place-items: center;
}

.login-shell-modern {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(246, 247, 249, 0.94)),
    var(--color-background);
}

.login-workspace {
  display: grid;
  grid-template-columns: minmax(340px, 0.9fr) minmax(360px, 430px);
  width: min(980px, 100%);
  /* Alto deseado acotado por el viewport (menos el padding del shell):
     620px fijos generan scroll en pantallas apaisadas bajas (tablets 1024x600,
     moviles landscape). */
  min-height: min(620px, calc(100vh - 48px));
  min-height: min(620px, calc(100dvh - 48px));
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(14, 28, 48, 0.14);
}

.login-context {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  padding: 34px;
  color: var(--color-on-brand);
  background:
    linear-gradient(135deg, rgba(21, 38, 63, 0.98), rgba(14, 28, 48, 1));
}

.login-context::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.055) 1px, transparent 1px);
  background-size: 42px 42px;
  content: "";
}

.login-context > * {
  position: relative;
  z-index: 1;
}

.login-context-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 1.05rem;
  font-weight: 700;
}

.login-context-copy {
  align-self: center;
  max-width: 420px;
}

.login-context-copy h2 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.login-context-copy p {
  margin: 0;
  color: var(--color-on-brand-muted);
  font-size: 1rem;
  line-height: 1.6;
}

.login-context-kicker {
  margin: 0 0 12px !important;
  color: var(--teal-bright) !important;
  font-size: 0.78rem !important;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-context-list {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 18px;
  border: 1px solid var(--brand-hairline);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.065);
  list-style: none;
}

.login-context-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--color-on-brand-muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.login-context-list-icon {
  display: grid;
  flex: none;
  width: 20px;
  height: 20px;
  place-items: center;
  margin-top: 1px;
  color: var(--navy-900);
  background: var(--teal-bright);
  border-radius: 50%;
}

.login-context-list-icon svg { width: 12px; height: 12px; stroke-width: 3; }

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  padding: clamp(24px, 4vw, 42px);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

/* App-icon lockup: teal tile, white hexagon, teal inner */
.login-logo {
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 11px;
  background: var(--color-primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M24 8 L38 16.5 V31.5 L24 40 L10 31.5 V16.5 Z' fill='%23ffffff'/%3E%3Cpath d='M24 17 L31 21 V29 L24 33 L17 29 V21 Z' fill='%231f5f5b'/%3E%3C/svg%3E") center / 30px no-repeat;
}

.login-logo-dark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background-color: var(--teal-bright);
  background-size: 23px;
}

.login-kicker {
  margin: 3px 0 0;
  color: var(--color-muted);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---- App footer ---- */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1440px, calc(100% - 48px));
  margin: 24px auto 0;
  padding: 18px 0 28px;
  color: var(--color-muted);
  border-top: 1px solid var(--color-border);
  font-size: 0.84rem;
}

.app-footer strong {
  color: var(--color-text);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

@media (max-width: 760px) {
  .mobile-nav-open { overflow: hidden; }
  .app-header {
    align-items: center;
    flex-direction: row;
    min-height: 64px;
    padding: 10px 16px;
  }
  .app-brand { min-height: 44px; }
  .app-mobile-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
  }
  .app-mobile-offline {
    display: inline-flex;
  }
  .app-mobile-menu-button {
    display: inline-grid;
    width: 44px;
    height: 44px;
    place-items: center;
    padding: 0;
    color: var(--color-on-brand);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--brand-hairline);
    border-radius: var(--radius-sm);
    cursor: pointer;
  }
  .app-mobile-menu-button:hover,
  .app-mobile-menu-button:active {
    background: rgba(255, 255, 255, 0.12);
  }
  .app-mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: block;
    padding: 0;
    pointer-events: none;
    background: rgba(14, 28, 48, 0.58);
    border: 0;
    opacity: 0;
    transition: opacity 180ms ease-out;
  }
  .app-header.is-mobile-menu-open .app-mobile-backdrop {
    pointer-events: auto;
    opacity: 1;
  }
  .app-header-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    width: min(360px, calc(100vw - 28px));
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    color: var(--color-text);
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow);
    transform: translateX(102%);
    visibility: hidden;
    transition:
      transform 180ms cubic-bezier(0.2, 0, 0, 1),
      visibility 0s linear 180ms;
  }
  .app-header.is-mobile-menu-open .app-header-panel {
    transform: translateX(0);
    visibility: visible;
    transition-delay: 0s;
  }
  .app-mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 72px;
    padding: max(12px, env(safe-area-inset-top)) 16px 12px;
    color: var(--color-on-brand);
    background: var(--color-brand);
    border-bottom: 1px solid var(--brand-hairline);
  }
  .app-mobile-drawer-header h2 {
    margin: 2px 0 0;
    font-size: 1.08rem;
  }
  .app-mobile-drawer-kicker {
    color: var(--color-on-brand-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }
  .app-nav {
    align-items: stretch;
    flex: 1;
    flex-direction: column;
    width: 100%;
    gap: 4px;
    overflow-y: auto;
    padding: 12px 16px;
    color: var(--color-text);
  }
  .app-nav > .app-nav-link,
  .app-nav-trigger {
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    color: var(--color-text);
    border: 0;
    border-radius: var(--radius-sm);
  }
  .app-nav > .app-nav-link:hover,
  .app-nav-trigger:hover {
    color: var(--color-text);
    background: var(--color-surface-muted);
  }
  .app-nav > .app-nav-link[aria-current="page"],
  .app-nav-group[data-active="true"] > .app-nav-trigger {
    color: var(--color-primary);
    background: var(--teal-50);
    border: 0;
  }
  .app-nav-group { position: static; }
  .app-nav-menu {
    position: static;
    min-width: 0;
    width: 100%;
    margin: 2px 0 6px;
    padding: 4px 8px 4px 16px;
    background: var(--color-surface-muted);
    border: 0;
    border-radius: var(--radius-sm);
    box-shadow: none;
  }
  .app-nav-menu::before { display: none; }
  .app-nav-menu .app-nav-link {
    min-height: 42px;
    padding: 10px 12px;
    white-space: normal;
  }
  .app-user {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin: 0;
    padding: 14px 16px max(14px, env(safe-area-inset-bottom));
    background: var(--color-brand);
    border-top: 1px solid var(--brand-hairline);
  }
  .app-user-offline { display: none; }
  .app-user-copy { text-align: left; }
  .app-user .btn { width: 100%; }
  .page-shell { width: calc(100% - 32px); margin: 24px auto; }
  .page-header-row {
    align-items: stretch;
    flex-direction: column;
    gap: 16px;
  }
  .page-header-actions {
    justify-content: flex-start;
    width: 100%;
  }
  .page-header-actions > .btn {
    flex: 1 1 auto;
  }
  .page-header-field {
    width: 100%;
  }
  .app-footer { align-items: flex-start; flex-direction: column; }
  .login-shell { padding: 16px; }
  .login-workspace {
    display: block;
    min-height: 0;
    border-radius: var(--radius);
  }
  .login-context { display: none; }
  .login-panel { padding: 22px; }
}

/* Viewports apaisados de poca altura (tablets 1024x600, moviles landscape):
   compactar el lado decorativo para que el login quepa sin scroll. */
@media (max-height: 560px) {
  .login-shell { padding: 16px; }
  .login-workspace { min-height: min(620px, calc(100vh - 32px)); min-height: min(620px, calc(100dvh - 32px)); }
  .login-context { padding: 24px; }
  .login-context-list { display: none; }
  .login-context-copy h2 { font-size: clamp(1.5rem, 3vw, 2rem); }
  .login-panel { padding: 20px 28px; }
  .login-brand { margin-bottom: 14px; }
}
