/*
 * App shell: reset, sidebar, topbar, content frame, and the auth pages.
 * Components live in components.css.
 */

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

html,
body {
  margin: 0;
  padding: 0;
}

/* Keeps the page background continuous when content scrolls past the viewport. */
html {
  background: var(--hx-paper);
}

/* Author `display` rules outrank the UA stylesheet's [hidden] regardless of specificity, so any
   component given a display value would otherwise ignore the attribute. Tabs and wizard steps
   rely on it. */
[hidden] {
  display: none !important;
}

/* Applies to the console shell and the standalone auth pages alike. */
body {
  font-family: var(--hx-font);
  font-size: var(--hx-fs-base);
  color: var(--hx-text);
  background: var(--hx-paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a {
  color: var(--hx-primary-dark);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

:focus-visible {
  outline: 3px solid var(--hx-primary-ring);
  outline-offset: 2px;
  border-radius: var(--hx-r-xs);
}

/* ------------------------------------------------------------------ shell */

.hx-shell {
  display: grid;
  grid-template-columns: var(--hx-sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--hx-transition);
}

.hx-shell.is-collapsed {
  grid-template-columns: var(--hx-sidebar-w-collapsed) 1fr;
}

.hx-main {
  display: flex;
  flex-direction: column;
  min-width: 0; /* lets wide tables scroll instead of stretching the grid column */
}

.hx-content {
  flex: 1;
  width: 100%;
  max-width: var(--hx-content-max);
  margin: 0 auto;
  padding: var(--hx-s6) var(--hx-s7) var(--hx-s8);
}

.hx-footer {
  display: flex;
  justify-content: center;
  padding: var(--hx-s4) var(--hx-s7) var(--hx-s6);
  color: var(--hx-faint);
  font-size: var(--hx-fs-xs);
}

.hx-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--hx-faint);
}

.hx-footer-copyright {
  color: var(--hx-faint);
  font-size: 12px;
}

.hx-footer-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hx-footer-name .w1,
.hx-footer-name .w2,
.hx-footer-name .w3 { color: var(--hx-muted); }

/* ------------------------------------------------------------------ sidebar */

.hx-sidebar {
  position: sticky;
  top: 0;
  z-index: var(--hx-z-sidebar);
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--hx-sidebar);
  color: var(--hx-sidebar-text);
  overflow: hidden;
}

.hx-brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: var(--hx-s4) var(--hx-s5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.055), transparent 66%);
  text-decoration: none;
  color: inherit;
  flex: 0 0 auto;
}

.hx-brand::after {
  content: "";
  position: absolute;
  left: var(--hx-s5);
  right: var(--hx-s5);
  bottom: -1px;
  height: 2px;
  border-radius: var(--hx-r-pill);
  background: linear-gradient(90deg, var(--hx-primary), transparent 76%);
  opacity: 0.8;
}

.hx-brand img {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.24));
}

.hx-brand-text {
  font-weight: 800;
  font-size: 20px;
  line-height: 1;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.hx-brand-text .w1 {
  color: #ffffff;
}
.hx-brand-text .w2 {
  color: var(--hx-primary);
}
.hx-brand-text .w3 {
  color: #ffd39d;
}

.hx-tenant {
  margin: 0 var(--hx-s4) var(--hx-s4);
  padding: var(--hx-s3);
  border-radius: var(--hx-r-sm);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: var(--hx-s3);
  min-width: 0;
}

.hx-tenant-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--hx-r-sm);
  object-fit: cover;
  background: var(--hx-primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex: 0 0 auto;
  text-transform: uppercase;
}

.hx-tenant-name {
  font-weight: 700;
  font-size: var(--hx-fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hx-tenant-sub {
  font-size: var(--hx-fs-xs);
  color: var(--hx-sidebar-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hx-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--hx-s3) var(--hx-s4);
  scrollbar-width: thin;
}

.hx-nav-label {
  margin: var(--hx-s4) var(--hx-s3) var(--hx-s2);
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--hx-sidebar-muted);
  font-weight: 700;
}

.hx-nav-item,
.hx-nav-group-toggle {
  display: flex;
  align-items: center;
  gap: var(--hx-s3);
  width: 100%;
  padding: 10px var(--hx-s3);
  margin-bottom: 2px;
  border: 0;
  border-radius: var(--hx-r-sm);
  background: transparent;
  color: var(--hx-sidebar-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  text-align: left;
  transition: background var(--hx-transition), color var(--hx-transition);
}

.hx-nav-item:hover,
.hx-nav-group-toggle:hover {
  background: var(--hx-sidebar-hover);
}

.hx-nav-item svg,
.hx-nav-group-toggle svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  stroke-width: 1.9;
}

.hx-nav-item.is-active {
  background: linear-gradient(135deg, var(--hx-primary), var(--hx-primary-dark));
  color: #fff;
  box-shadow: 0 6px 16px rgba(232, 111, 46, 0.32);
}

.hx-nav-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hx-nav-caret {
  width: 15px !important;
  height: 15px !important;
  transition: transform var(--hx-transition);
  opacity: 0.75;
}

.hx-nav-group.is-open > .hx-nav-group-toggle .hx-nav-caret {
  transform: rotate(90deg);
}

/* Collapsed by default; the open state is set server-side or by the toggle. */
.hx-nav-children {
  display: none;
  margin: 2px 0 var(--hx-s2) 0;
  padding-left: calc(19px + var(--hx-s3));
  border-left: 1px solid var(--hx-sidebar-line);
  margin-left: calc(var(--hx-s3) + 9px);
}

.hx-nav-group.is-open > .hx-nav-children {
  display: block;
}

.hx-nav-children .hx-nav-item {
  font-weight: 500;
  font-size: var(--hx-fs-sm);
  padding: 8px var(--hx-s3);
}

.hx-sidebar-foot {
  flex: 0 0 auto;
  padding: var(--hx-s3) var(--hx-s5) var(--hx-s5);
  border-top: 1px solid var(--hx-sidebar-line);
}

.hx-signout {
  display: flex;
  align-items: center;
  gap: var(--hx-s3);
  width: 100%;
  padding: 10px var(--hx-s3);
  border: 0;
  border-radius: var(--hx-r-sm);
  background: transparent;
  color: var(--hx-sidebar-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  /* Buttons centre their text by default, which would push the label away from its icon. */
  text-align: left;
  transition: background var(--hx-transition), color var(--hx-transition);
}

.hx-signout:hover {
  background: rgba(209, 67, 67, 0.16);
  color: #ffb4b4;
}

.hx-signout svg {
  width: 19px;
  height: 19px;
}

/* Collapsed rail: icons only. */
.hx-shell.is-collapsed .hx-nav-text,
.hx-shell.is-collapsed .hx-nav-caret,
.hx-shell.is-collapsed .hx-brand-text,
.hx-shell.is-collapsed .hx-nav-label,
.hx-shell.is-collapsed .hx-tenant-meta,
.hx-shell.is-collapsed .hx-sidebar-foot .hx-nav-text {
  display: none;
}

.hx-shell.is-collapsed .hx-nav-children {
  display: none !important;
}

.hx-shell.is-collapsed .hx-brand,
.hx-shell.is-collapsed .hx-tenant {
  justify-content: center;
}

.hx-shell.is-collapsed .hx-brand {
  padding-inline: 0;
}

.hx-shell.is-collapsed .hx-brand::after {
  left: 14px;
  right: 14px;
}

.hx-shell.is-collapsed .hx-nav-item,
.hx-shell.is-collapsed .hx-nav-group-toggle,
.hx-shell.is-collapsed .hx-signout {
  justify-content: center;
}

/* ------------------------------------------------------------------ topbar */

.hx-topbar {
  position: sticky;
  top: 0;
  z-index: var(--hx-z-topbar);
  display: flex;
  align-items: center;
  gap: var(--hx-s4);
  height: var(--hx-topbar-h);
  padding: 0 var(--hx-s7);
  background: rgba(255, 248, 234, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hx-border);
}

.hx-icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--hx-border);
  border-radius: var(--hx-r-sm);
  background: var(--hx-surface);
  color: var(--hx-muted);
  cursor: pointer;
  flex: 0 0 auto;
  transition: all var(--hx-transition);
}

.hx-icon-btn:hover {
  color: var(--hx-text);
  border-color: var(--hx-border-strong);
}

.hx-icon-btn svg {
  width: 18px;
  height: 18px;
}

.hx-topbar-title {
  font-size: var(--hx-fs-md);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hx-topbar-spacer {
  flex: 1;
}

.hx-userchip {
  display: flex;
  align-items: center;
  gap: var(--hx-s3);
  padding: var(--hx-s1) var(--hx-s3) var(--hx-s1) var(--hx-s1);
  border: 1px solid var(--hx-border);
  border-radius: var(--hx-r-pill);
  background: var(--hx-surface);
  min-width: 0;
}

.hx-userchip-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--hx-primary), var(--hx-primary-dark));
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: var(--hx-fs-sm);
  text-transform: uppercase;
  flex: 0 0 auto;
}

.hx-userchip-name {
  font-weight: 600;
  font-size: var(--hx-fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

/* ------------------------------------------------------------------ off-canvas */

.hx-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--hx-z-scrim);
  background: rgba(43, 33, 24, 0.45);
}

@media (max-width: 1024px) {
  .hx-shell,
  .hx-shell.is-collapsed {
    grid-template-columns: 1fr;
  }

  .hx-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--hx-sidebar-w);
    transform: translateX(-100%);
    transition: transform var(--hx-transition);
    z-index: var(--hx-z-modal);
  }

  .hx-shell.is-nav-open .hx-sidebar {
    transform: none;
    box-shadow: var(--hx-shadow-xl);
  }

  .hx-shell.is-nav-open .hx-scrim {
    display: block;
  }

  /* The rail collapse is meaningless once the sidebar is off-canvas. */
  .hx-shell.is-collapsed .hx-nav-text,
  .hx-shell.is-collapsed .hx-nav-caret,
  .hx-shell.is-collapsed .hx-brand-text,
  .hx-shell.is-collapsed .hx-nav-label,
  .hx-shell.is-collapsed .hx-tenant-meta {
    display: revert;
  }

  .hx-content,
  .hx-topbar {
    padding-left: var(--hx-s5);
    padding-right: var(--hx-s5);
  }
}

@media (min-width: 1025px) {
  .hx-nav-mobile-only {
    display: none;
  }
}

/* ------------------------------------------------------------------ auth pages */

body.hx-auth {
  display: grid;
  justify-items: center;
  /* `safe` centres when the card fits and falls back to the top when it doesn't, so a tall
     form (registration) never has its first fields scrolled off above the viewport. */
  align-content: safe center;
  min-height: 100vh;
  padding: var(--hx-s7) var(--hx-s6);
  background: radial-gradient(circle at 15% 10%, #fff2dc 0%, var(--hx-paper) 45%),
    radial-gradient(circle at 90% 90%, #ffe7d3 0%, transparent 55%);
  background-attachment: fixed;
}

.hx-auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--hx-surface);
  border: 1px solid var(--hx-border);
  border-radius: var(--hx-r-lg);
  box-shadow: var(--hx-shadow-lg);
  padding: var(--hx-s7);
}

.hx-auth-card.is-wide {
  max-width: 640px;
}

.hx-auth-brand {
  display: flex;
  align-items: center;
  gap: var(--hx-s3);
  text-decoration: none;
  margin-bottom: var(--hx-s6);
}

.hx-auth-brand img {
  width: 38px;
  height: 38px;
}

.hx-auth-brand .hx-brand-text .w1 {
  color: var(--hx-text);
}
.hx-auth-brand .hx-brand-text .w3 {
  color: var(--hx-muted);
}

.hx-auth-card h1 {
  font-size: var(--hx-fs-xl);
  font-weight: 800;
}

.hx-auth-sub {
  margin: var(--hx-s2) 0 var(--hx-s6);
  color: var(--hx-muted);
}

.hx-auth-alt {
  margin: var(--hx-s6) 0 0;
  padding-top: var(--hx-s5);
  border-top: 1px solid var(--hx-border);
  text-align: center;
  color: var(--hx-muted);
  font-size: var(--hx-fs-sm);
}

/* ------------------------------------------------------------------ error pages */

.hx-error-page {
  max-width: 560px;
  margin: var(--hx-s8) auto;
  text-align: center;
  padding: var(--hx-s7);
  background: var(--hx-surface);
  border: 1px solid var(--hx-border);
  border-radius: var(--hx-r-lg);
  box-shadow: var(--hx-shadow-md);
}

.hx-error-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto var(--hx-s5);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--hx-warning-soft);
  color: var(--hx-primary-dark);
}

.hx-error-icon svg {
  width: 30px;
  height: 30px;
}

.hx-error-page h1 {
  font-size: var(--hx-fs-lg);
  margin-bottom: var(--hx-s3);
}

.hx-error-page p {
  color: var(--hx-muted);
  margin: 0 0 var(--hx-s6);
}
