/* ── Layout: app shell, page header, grids (mobile first; breakpoints 768px and 1280px) ── */

/* ── App shell: top bar, side menu, main ── */
/* the top bar sits above the side menu: at the page end the footer pushes the sticky menu up, and it must pass under the bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: calc(var(--z-nav) + 1);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-h);
  padding: 0 var(--space-4);
  background: var(--color-topbar-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-top: 3px solid var(--color-accent);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-1);
}

/* glass only where the browser draws it and the user has not asked for less transparency (docs/standards/ux_principles.md §2) */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar {
    background: var(--color-topbar-solid);
  }
}

@media (prefers-reduced-transparency: reduce), (forced-colors: active) {
  .topbar {
    background: var(--color-topbar-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  color: var(--color-text);
  text-decoration: none;
}

/* product mark: the GPMS sign on the shell's navy */
.product-mark {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-brand-deep-2), var(--color-brand-deep));
  color: var(--color-on-primary);
  box-shadow: var(--shadow-btn);
}

.product-mark .icon {
  width: 18px;
  height: 18px;
}

/* the Authority's logo leads; a very wide one is capped so the actions keep their room */
.topbar-logo {
  flex: none;
  height: 36px;
  width: auto;
  max-width: 96px;
  object-fit: contain;
}

/* no logo uploaded: the Authority's initials on its accent */
.topbar-initials {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: var(--color-on-accent);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
}

/* the product's full name, the Authority's name under it */
.topbar-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: var(--lh-tight);
}

.topbar-product,
.topbar-tenant {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* the Authority's name leads; the product's name sits smaller under it (ux_principles §13) */
.topbar-tenant {
  order: -1;
  color: var(--color-text);
  font-size: var(--fs-base);
  font-weight: var(--fw-bold);
  letter-spacing: var(--ls-tight);
}

.topbar-product {
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-caps);
}

/* a thin rule between the larger-text button and the bell and user menu (from 768px) */
.topbar-sep {
  display: none;
  width: 1px;
  height: 24px;
  background: var(--color-border);
}

.text-size-btn {
  gap: 2px;
  min-width: var(--control-h);
  padding: 0 var(--space-2);
  font-weight: var(--fw-bold);
}

.text-size-btn[aria-pressed="true"] {
  background: var(--color-primary-soft);
  color: var(--color-link);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.btn.nav-toggle {
  display: inline-flex;
}

.app-body {
  display: block;
  min-height: calc(100vh - var(--topbar-h));
}

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  bottom: 0;
  left: 0;
  z-index: var(--z-nav);
  display: flex;
  flex-direction: column;
  width: min(85vw, var(--sidebar-w));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-nav-title) transparent;
  padding: var(--space-4) var(--space-3);
  background: var(--color-nav-bg);
  color: var(--color-nav-text);
  transform: translateX(-100%);
  transition: transform var(--motion-base) var(--ease);
}

.app-nav-open .sidebar {
  transform: translateX(0);
  box-shadow: var(--shadow-3);
}

/* phones: the open menu dims the page behind it (a click there closes it, common.js) */
.app-nav-open::after {
  content: "";
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  z-index: calc(var(--z-nav) - 1);
  background: var(--color-overlay);
}

.main {
  width: 100%;
  min-width: 0;
  max-width: var(--content-max-w);
  padding: var(--space-5) var(--space-4) var(--space-8);
}

/* the skip link moves focus here; the whole region needs no outline */
.main:focus {
  outline: none;
}

/* quiet band (ux_principles §13): Authority and year | product | secure session; stacked and centred on phones, one row from 768px */
.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-subtle);
  font-size: var(--fs-xs);
  text-align: center;
}

.footer-part {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.footer-tenant {
  color: var(--color-text-muted);
  font-weight: var(--fw-medium);
}

.footer-secure .icon {
  width: 14px;
  height: 14px;
  color: var(--color-success);
}

@media (min-width: 768px) {
  .btn.nav-toggle {
    display: none;
  }

  .topbar {
    padding: 0 var(--space-6);
  }

  .topbar-logo {
    max-width: 160px;
  }

  .app-body {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .app-body-no-nav {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h));
    width: auto;
    transform: none;
    transition: none;
  }

  .app-nav-open .sidebar {
    box-shadow: none;
  }

  .app-nav-open::after {
    content: none;
  }

  .main {
    padding: var(--space-6) var(--space-8) var(--space-10);
  }

  .footer {
    flex-direction: row;
    justify-content: space-between;
    padding: var(--space-4) var(--space-8);
    text-align: left;
  }

  .topbar-sep {
    display: block;
  }
}

/* ── Side menu ── */
.nav-group {
  margin-bottom: var(--space-3);
}

/* groups are set apart by a faint rule, so each title reads as a heading */
.nav-group + .nav-group {
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-nav-line);
}

.nav-group-title {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-3);
  color: var(--color-nav-title);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-nav-text);
  font-weight: var(--fw-medium);
  text-decoration: none;
  transition: background-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
}

.nav-link .icon {
  opacity: 0.85;
}

.nav-link:hover {
  background: var(--color-nav-hover);
  color: var(--color-nav-active-text);
}

.nav-link:focus-visible {
  outline: 2px solid var(--color-nav-indicator);
  outline-offset: -2px;
}

.nav-link[aria-current="page"] {
  background: var(--color-nav-active);
  color: var(--color-nav-active-text);
  font-weight: var(--fw-semibold);
}

.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: calc(-1 * var(--space-3));
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--color-nav-indicator);
}

.nav-link[aria-current="page"] .icon {
  opacity: 1;
}

.nav-link .badge {
  margin-left: auto;
}

/* ── Page header: breadcrumb, title, subtitle, actions ── */
/* a rule under the title block separates the page's identity from its content */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--color-border);
}

.page-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
}

.page-subtitle {
  width: 100%;
  margin: 0;
  color: var(--color-text-muted);
}

/* phones: the page's buttons under the title, the primary one full width */
.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  width: 100%;
}

.page-actions .btn-primary {
  flex: 1 1 auto;
  justify-content: center;
}

/* a form page: one readable column; its section index is placed from 1440px */
.main-form > * {
  max-width: var(--form-max-w);
}

.form-index {
  display: none;
}

/* ── Content blocks and grids ── */
.card {
  margin-bottom: var(--space-5);
  padding: var(--card-p);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.card-title {
  margin: 0 0 var(--space-4);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}

/* a sub-heading inside a card */
.card-subtitle {
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--fs-base);
  font-weight: var(--fw-semibold);
}

/* a single short form (change password, preferences) */
.card-narrow {
  max-width: var(--card-narrow-w);
}

.stack > * + * {
  margin-top: var(--space-4);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4) var(--space-5);
}

.form-grid-full {
  grid-column: 1 / -1;
}

/* a long form keeps its buttons in view: sticky to the bottom edge, only while the form runs past the screen */
.form-actions {
  position: sticky;
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  padding-bottom: var(--space-2);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* the filter panel is short and tinted: its buttons stay in place */
.list-filter-panel .form-actions {
  position: static;
  background: transparent;
}

@media (min-width: 768px) {
  /* one step roomier than phones; compact density lowers it with --card-p */
  .card {
    padding: calc(var(--card-p) + var(--space-1));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-actions {
    width: auto;
  }

  .page-actions .btn-primary {
    flex: none;
  }
}

@media (min-width: 1280px) {
  .form-grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* the section index of a long form: fixed beside the form column, under the top bar */
@media (min-width: 1440px) {
  .form-index {
    position: fixed;
    top: calc(var(--topbar-h) + var(--space-6));
    left: calc(var(--sidebar-w) + var(--space-8) + var(--form-max-w) + var(--space-8));
    display: block;
    width: var(--form-index-w);
    max-height: calc(100vh - var(--topbar-h) - var(--space-12));
    overflow-y: auto;
  }

  .form-index-title {
    margin: 0 0 var(--space-2);
    color: var(--color-text-subtle);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    letter-spacing: var(--ls-caps);
    text-transform: uppercase;
  }

  .form-index-list {
    margin: 0;
    padding: 0;
    border-left: 1px solid var(--color-border);
    list-style: none;
  }

  .form-index-link {
    display: block;
    margin-left: -1px;
    padding: var(--space-1) var(--space-3);
    border-left: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: var(--fs-sm);
    text-decoration: none;
  }

  .form-index-link:hover {
    color: var(--color-text);
  }

  .form-index-link[aria-current="true"] {
    border-left-color: var(--color-link);
    color: var(--color-link);
    font-weight: var(--fw-medium);
  }
}

/* ── Sign-in and other pages without the shell ── */
.auth-card {
  width: 100%;
  max-width: var(--auth-card-w);
}

/* ── Landing page (spec m02 CR-1): brand half + sign-in half; narrow screens: brand head, form, brand details ── */
.landing {
  display: grid;
  grid-template-areas: "brand-head" "auth" "brand-details";
  min-height: 100vh;
}

/* the brand half: deep navy in both themes, a faint dot grid and soft light from the corners */
.landing-brand-head,
.landing-brand-details {
  padding: var(--space-6) var(--space-5);
  background-color: var(--color-brand-deep);
  background-image:
    radial-gradient(circle, var(--color-brand-dot) 1px, transparent 1.5px),
    radial-gradient(circle at 15% 10%, var(--color-brand-glow), transparent 45%),
    radial-gradient(circle at 90% 95%, var(--color-brand-glow), transparent 40%),
    linear-gradient(160deg, var(--color-brand-deep-2), var(--color-brand-deep) 70%);
  background-size: 22px 22px, auto, auto, auto;
  background-attachment: fixed;
  color: var(--color-on-primary);
}

.landing-brand-head {
  grid-area: brand-head;
}

.landing-brand-details {
  grid-area: brand-details;
}

.landing-auth {
  display: flex;
  flex-direction: column;
  grid-area: auth;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-4);
  background: var(--color-bg);
}

/* the form sits on a raised card */
.landing-auth .auth-card {
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: var(--shadow-3);
}

.landing-auth-top {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  max-width: var(--auth-card-w);
}

@media (min-width: 1024px) {
  .landing {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: 1fr 1fr;
    grid-template-areas: "brand-head auth" "brand-details auth";
  }

  /* the brand content sits around the middle of its half */
  .landing-brand-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-end;
    padding: var(--space-12) var(--space-12) var(--space-5);
  }

  .landing-brand-details {
    padding: var(--space-5) var(--space-12) var(--space-12);
  }

  .landing-auth {
    position: relative;
    padding: var(--space-10) var(--space-12);
  }

  .landing-auth .auth-card {
    padding: var(--space-8);
  }

  .landing-auth-top {
    position: absolute;
    top: var(--space-6);
    right: var(--space-8);
    width: auto;
  }
}

/* a wide form page ($page_form_wide): the form uses the full page width and has no section index */
.main-form-wide > * {
  max-width: none;
}

.main-form-wide > .form-index {
  display: none;
}
