/* Application shell, navigation rail, mobile drawer, authentication layout. */

.app-root {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ------------------------------------------------------------------ Shell */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  /* The rail is sticky and one viewport tall: paint its column behind it so
     the colour continues on pages taller than the viewport. */
  background: linear-gradient(
    90deg,
    var(--rail-bg) calc(var(--sidebar-width) - 1px),
    var(--rail-border) calc(var(--sidebar-width) - 1px),
    var(--rail-border) var(--sidebar-width),
    transparent var(--sidebar-width)
  );
}

.main {
  min-width: 0;
  background: var(--bg) var(--glow) no-repeat;
}

.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-8) var(--space-10) 4rem;
  animation: page-in var(--duration) var(--ease);
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.page--narrow {
  max-width: 46rem;
}

/* ------------------------------------------------------------------- Rail */

.rail {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  height: 100vh;
  height: 100dvh;
  padding: var(--space-5) var(--space-4) var(--space-4);
  overflow-y: auto;
  background: var(--rail-bg);
  border-right: 1px solid var(--rail-border);
  color: var(--rail-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--rail-text);
}

.brand:hover {
  color: var(--rail-text);
  text-decoration: none;
}

.brand__logo {
  flex: none;
  width: 40px;
  height: 40px;
  filter: drop-shadow(0 4px 10px rgba(20, 90, 230, 0.45));
}

.brand__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand__name {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand__tag {
  font-size: var(--text-xs);
  color: var(--rail-muted);
}

.rail__nav {
  flex: 1 1 auto;
}

.rail__nav ul {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail__label {
  padding: 0 var(--space-3) var(--space-2);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--rail-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 2.625rem;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  color: var(--rail-muted);
  font-size: 0.9063rem;
  font-weight: 500;
  transition:
    background-color var(--duration-fast) var(--ease),
    color var(--duration-fast) var(--ease);
}

.nav-item:hover {
  background: var(--rail-hover);
  color: var(--rail-text);
  text-decoration: none;
}

.nav-item[aria-current="page"] {
  background: var(--rail-active);
  color: var(--rail-active-text);
}

.nav-item[aria-current="page"] .icon {
  color: #7fb0ff;
}

.nav-item:focus-visible,
.brand:focus-visible,
.rail :focus-visible {
  outline-color: #8ab4ff;
}

.rail__footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--rail-control-border);
}

/* Theme switch (radio group rendered as a segmented control) */
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: var(--radius-md);
  background: var(--rail-control);
  border: 1px solid var(--rail-control-border);
}

.theme-switch__option {
  position: relative;
}

.theme-switch__option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.theme-switch__option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 1.875rem;
  padding: 0 var(--space-2);
  border-radius: 6px;
  color: var(--rail-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  transition:
    background-color var(--duration-fast) var(--ease),
    color var(--duration-fast) var(--ease);
}

.theme-switch__option input:hover + span {
  color: var(--rail-text);
}

.theme-switch__option input:checked + span {
  background: rgba(96, 150, 255, 0.24);
  color: #ffffff;
}

.theme-switch__option input:focus-visible + span {
  outline: 2px solid #8ab4ff;
  outline-offset: 1px;
}

/* Variant used on light surfaces (authentication page, preferences) */
.theme-switch--surface {
  background: var(--control);
  border-color: var(--border);
}

.theme-switch--surface .theme-switch__option span {
  color: var(--text-muted);
}

.theme-switch--surface .theme-switch__option input:hover + span {
  color: var(--text);
}

.theme-switch--surface .theme-switch__option input:checked + span {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

:root:not([data-theme="light"]) .theme-switch--surface .theme-switch__option input:checked + span {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  box-shadow: none;
}

.theme-switch--surface .theme-switch__option input:focus-visible + span {
  outline-color: var(--focus);
}

/* Account disclosure */
.account {
  position: relative;
}

.account__button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 3rem;
  padding: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--rail-text);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease);
}

.account__button:hover,
.account__button[aria-expanded="true"] {
  background: var(--rail-hover);
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: linear-gradient(145deg, #3b82f6, #1d4ed8);
  color: #ffffff;
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
}

.account__identity {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1 1 auto;
  line-height: 1.3;
}

.account__role {
  font-size: var(--text-xs);
  color: var(--rail-muted);
}

.account__email {
  overflow: hidden;
  font-size: var(--text-sm);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account__chevron {
  color: var(--rail-muted);
  transition: transform var(--duration-fast) var(--ease);
}

.account__button[aria-expanded="true"] .account__chevron {
  transform: rotate(180deg);
}

.account__menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + var(--space-2));
  left: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-1);
  border: 1px solid var(--rail-control-border);
  border-radius: var(--radius-md);
  background: var(--rail-control);
  box-shadow: var(--shadow-md);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 2.375rem;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--rail-text);
  font-size: var(--text-sm);
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--rail-hover);
  color: var(--rail-text);
  text-decoration: none;
}

.menu-item--danger {
  color: #fca5a5;
}

.menu-item--danger:hover {
  color: #fecaca;
}

/* ----------------------------------------------------------------- Topbar */

.topbar {
  display: none;
}

.rail-backdrop {
  display: none;
}

@media (max-width: 1023.98px) {
  .shell {
    display: block;
    background: none;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--topbar-height);
    padding: 0 var(--space-3);
    background: var(--rail-bg);
    border-bottom: 1px solid var(--rail-border);
    color: var(--rail-text);
  }

  .topbar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    color: var(--rail-text);
    font-weight: 600;
    letter-spacing: -0.01em;
  }

  .topbar__brand:hover {
    color: var(--rail-text);
    text-decoration: none;
  }

  .topbar__brand img {
    flex: none;
    width: 30px;
    height: 30px;
  }

  .topbar__brand span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar .icon-btn {
    color: var(--rail-text);
  }

  .topbar .icon-btn:hover {
    background: var(--rail-hover);
  }

  .topbar :focus-visible {
    outline-color: #8ab4ff;
  }

  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(86vw, 304px);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    visibility: hidden;
    transition:
      transform var(--duration) var(--ease),
      visibility 0s linear var(--duration);
  }

  .shell[data-drawer="open"] .rail {
    transform: none;
    visibility: visible;
    transition:
      transform var(--duration) var(--ease),
      visibility 0s;
  }

  .rail-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: block;
    background: var(--backdrop);
    opacity: 0;
    visibility: hidden;
    transition:
      opacity var(--duration) var(--ease),
      visibility 0s linear var(--duration);
  }

  .shell[data-drawer="open"] .rail-backdrop {
    opacity: 1;
    visibility: visible;
    transition:
      opacity var(--duration) var(--ease),
      visibility 0s;
  }

  .rail__close {
    display: inline-flex !important;
  }

  .page {
    padding: var(--space-6) var(--space-5) var(--space-12);
  }
}

@media (max-width: 599.98px) {
  .page {
    padding: var(--space-5) var(--space-4) var(--space-12);
  }
}

.rail__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.rail__close {
  display: none;
  color: var(--rail-muted);
}

.rail__close:hover {
  background: var(--rail-hover);
  color: var(--rail-text);
}

/* ------------------------------------------------------------ Page header */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4) var(--space-6);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}

.page-header__text {
  min-width: 0;
  flex: 1 1 18rem;
}

.page-header__lead {
  margin-top: var(--space-1);
  max-width: 44rem;
  color: var(--text-muted);
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.backlink {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

.backlink:hover {
  color: var(--text);
  text-decoration: none;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.section-title h2 {
  font-size: var(--text-lg);
}

/* ------------------------------------------------------- Authentication */

.auth {
  display: grid;
  grid-template-columns: minmax(22rem, 5fr) minmax(0, 7fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.auth__brand {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-8);
  padding: var(--space-10);
  overflow: hidden;
  background:
    radial-gradient(42rem 26rem at 12% 0%, rgba(37, 99, 235, 0.32), transparent 62%),
    radial-gradient(30rem 22rem at 100% 100%, rgba(14, 116, 204, 0.18), transparent 60%),
    linear-gradient(165deg, #101b33 0%, #0a101c 70%);
  color: #eef2f8;
}

.auth__identity {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.auth__logo {
  flex: none;
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 8px 20px rgba(20, 90, 230, 0.55));
}

.auth__name {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.auth__tag {
  margin-top: 2px;
  color: #a9b6ca;
  font-size: var(--text-sm);
}

.auth__pitch {
  position: relative;
  max-width: 24rem;
}

.auth__pitch p:first-child {
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-wrap: balance;
}

.auth__pitch p + p {
  margin-top: var(--space-3);
  color: #a9b6ca;
}

/* Decorative echo of the application's device cards. */
.auth__art {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  max-width: 26rem;
}

.ghost-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border: 1px solid rgba(148, 170, 205, 0.16);
  border-radius: var(--radius-lg);
  background: rgba(26, 35, 52, 0.62);
}

.ghost-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #7fb0ff;
}

.ghost-card--off .ghost-card__top {
  color: #64748b;
}

.ghost-card__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.ghost-card--off .ghost-card__dot {
  background: #64748b;
}

.ghost-card__name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: #eef2f8;
}

.ghost-card__meta {
  font-size: var(--text-xs);
  color: #9aa7bb;
}

.ghost-card__state {
  font-size: var(--text-xs);
  color: #4ade80;
}

.ghost-card--off .ghost-card__state {
  color: #9aa7bb;
}

.ghost-card--add {
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-style: dashed;
  background: transparent;
  color: #9aa7bb;
  font-size: var(--text-xs);
}

.auth__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--space-5) var(--space-6) var(--space-6);
  background: var(--bg) var(--glow) no-repeat;
}

.auth__top {
  display: flex;
  justify-content: flex-end;
}

.auth__top .theme-switch {
  width: 15.5rem;
  max-width: 100%;
}

.auth__outlet {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 27.5rem;
  margin: 0 auto;
  padding: var(--space-8) 0;
}

.auth__outlet--wide {
  max-width: 34rem;
}

.auth__footer {
  color: var(--text-subtle);
  font-size: var(--text-xs);
  text-align: center;
}

.auth-card {
  animation: page-in var(--duration) var(--ease);
}

.auth-card__title {
  font-size: var(--text-2xl);
}

.auth-card__lead {
  margin-top: var(--space-2);
  color: var(--text-muted);
}

.auth-card__body {
  margin-top: var(--space-6);
}

.auth-card__foot {
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--divider);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

@media (max-width: 899.98px) {
  .auth {
    display: flex;
    flex-direction: column;
  }

  .auth__brand {
    flex: none;
    flex-direction: row;
    align-items: center;
    padding: var(--space-4) var(--space-5);
  }

  .auth__logo {
    width: 40px;
    height: 40px;
  }

  .auth__name {
    font-size: var(--text-lg);
  }

  .auth__pitch,
  .auth__art {
    display: none;
  }

  .auth__main {
    flex: 1 1 auto;
    padding: var(--space-4) var(--space-4) var(--space-5);
  }

  .auth__outlet {
    justify-content: flex-start;
    padding: var(--space-6) 0 var(--space-8);
  }
}

/* Full-page states (boot failure) */
.fullpage {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-6);
}
