/* App frame (sidebar, top bar, bottom tab bar, drawer) and layout helpers.
   Phone first: below 960px there is a menu drawer and a bottom tab bar. From 960px there is a sidebar. */

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

.app__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
}

.sidebar {
  display: none;
}

/* ---------------------------------------------------------------- brand */

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: inherit;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand__logo {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand__name {
  font-size: var(--fs-xl);
  letter-spacing: 0.01em;
}

.brand__sub {
  font-size: var(--fs-xs);
  opacity: 0.8;
}

/* ---------------------------------------------------------------- navigation links */

.nav-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--c-text-2);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}

.nav-link:hover {
  background: var(--c-surface-2);
  color: var(--c-text);
  text-decoration: none;
}

.nav-link[aria-current="page"] {
  background: var(--c-primary-soft);
  color: var(--c-primary-text);
}

.nav-link__icon {
  display: grid;
  flex: none;
}

.nav-link__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.nav-link__desc {
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
  color: var(--c-text-3);
}

.sidebar .nav-link {
  color: var(--c-sidebar-dim);
}

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

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

.sidebar .nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset-inline-start: -14px;
  top: 10px;
  bottom: 10px;
  width: 5px;
  border-radius: 0 5px 5px 0;
  background: var(--brand-gold);
}

.sidebar :focus-visible {
  outline-color: #fff;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--sp-3) 0;
  background: color-mix(in srgb, var(--c-surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
}

.topbar__heading {
  flex: 1;
  min-width: 0;
}

.topbar__title {
  overflow: hidden;
  font-size: var(--fs-xl);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__subtitle {
  overflow: hidden;
  font-size: var(--fs-xs);
  color: var(--c-text-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--sp-2);
}

.topbar__tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--sp-2);
}

/* On a phone, header buttons keep only their icon (the text stays for screen readers). */
@media (max-width: 719px) {
  .topbar__actions .btn:not(.btn--icon),
  .topbar__account {
    width: var(--control-h);
    padding: 0;
  }

  .topbar__actions .btn:not(.btn--icon) .btn__label,
  .topbar__account .btn__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .topbar__account .icon--chevron-down {
    display: none;
  }

  .topbar__theme {
    display: none;
  }
}

/* ---------------------------------------------------------------- main */

.main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--sp-4) var(--gutter) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-6));
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  min-width: 0;
}

/* The sign in page fills the whole screen. */
.app[data-layout="bare"] .sidebar,
.app[data-layout="bare"] .topbar,
.app[data-layout="bare"] .tabbar {
  display: none;
}

.app[data-layout="bare"] .main {
  max-width: none;
  padding: 0;
}

/* ---------------------------------------------------------------- bottom tab bar (phone) */

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: var(--z-tabbar);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  box-shadow: 0 -6px 20px rgba(45, 20, 110, 0.07);
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--c-text-3);
  font-size: 0.75rem;
  font-weight: var(--fw-semibold);
  text-decoration: none;
}

.tab:hover {
  text-decoration: none;
}

.tab__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 30px;
  border-radius: var(--r-pill);
  transition: background var(--dur) var(--ease);
}

.tab__label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab[aria-current="page"],
.tab.is-active {
  color: var(--c-primary-text);
  font-weight: var(--fw-bold);
}

.tab[aria-current="page"] .tab__icon,
.tab.is-active .tab__icon {
  background: var(--c-primary-soft);
}

.tab[aria-current="page"]::before,
.tab.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 28px;
  height: 3px;
  margin-left: -14px;
  border-radius: 0 0 3px 3px;
  background: var(--brand-gold);
}

/* ---------------------------------------------------------------- drawer (phone menu) */

.drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: calc(var(--sp-4) + env(safe-area-inset-top)) var(--sp-4) var(--sp-4);
  background: linear-gradient(160deg, var(--c-sidebar-from), var(--c-sidebar-to));
  color: var(--c-sidebar-text);
}

.drawer__close {
  --btn-fg: var(--c-sidebar-text);
  --btn-hover: var(--c-sidebar-hover);
}

.drawer__header :focus-visible {
  outline-color: #fff;
}

.drawer__nav {
  flex: 1;
  min-height: 0;
  padding: var(--sp-3);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-link--drawer {
  align-items: center;
  padding-block: var(--sp-2);
}

.drawer__foot {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
}

.drawer__status {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: var(--fw-semibold);
  color: var(--c-success-text);
}

.drawer__version {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  text-align: center;
}

/* ---------------------------------------------------------------- desktop */

@media (min-width: 960px) {
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: var(--sp-6);
    height: 100vh;
    height: 100dvh;
    padding: var(--sp-5) var(--sp-4);
    overflow-y: auto;
    background: linear-gradient(170deg, var(--c-sidebar-from), var(--c-sidebar-to));
    color: var(--c-sidebar-text);
  }

  .sidebar__nav {
    flex: 1;
  }

  .sidebar__foot {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--sp-3);
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, 0.08);
    color: var(--c-sidebar-dim);
    font-size: var(--fs-xs);
  }

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

  .app[data-layout="bare"] {
    display: block;
  }

  .tabbar,
  .topbar__menu {
    display: none;
  }

  .topbar {
    padding-inline: var(--sp-8);
  }

  .topbar__title {
    font-size: var(--fs-2xl);
  }

  .topbar__subtitle {
    font-size: var(--fs-sm);
  }

  .main {
    padding: var(--sp-6) var(--sp-8) var(--sp-12);
  }
}

/* ---------------------------------------------------------------- layout helpers */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap, var(--sp-4));
  min-width: 0;
}

.stack--sm {
  --gap: var(--sp-2);
}

.stack--lg {
  --gap: var(--sp-6);
}

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

.cluster--between {
  justify-content: space-between;
}

.cluster--end {
  justify-content: flex-end;
}

.row {
  display: flex;
  align-items: center;
  gap: var(--gap, var(--sp-3));
  min-width: 0;
}

.spacer {
  flex: 1;
}

/* Responsive grid: columns of at least --min (default 240px). */
.grid {
  display: grid;
  gap: var(--gap, var(--sp-4));
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min, 240px)), 1fr));
}

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

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

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

@media (max-width: 719px) {
  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (min-width: 720px) and (max-width: 1099px) {
  .grid--3,
  .grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* A row of filters above a list. On a phone each filter takes the full width. */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-3);
}

.toolbar > * {
  flex: 0 1 auto;
  min-width: 0;
}

.toolbar__grow {
  flex: 1 1 260px;
}

@media (max-width: 599px) {
  .toolbar > * {
    flex: 1 1 100%;
  }
}

/* Sticky "Save / Cancel" bar for long forms. Sits above the tab bar on a phone. */
.savebar {
  position: sticky;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-3));
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--c-surface) 94%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-2);
}

.savebar__note {
  flex: 1 1 160px;
  font-size: var(--fs-sm);
  color: var(--c-text-2);
}

@media (min-width: 960px) {
  .savebar {
    bottom: var(--sp-4);
  }
}

@media (max-width: 599px) {
  .savebar .btn {
    flex: 1 1 0;
  }
}

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

.page-intro {
  max-width: 62ch;
  color: var(--c-text-2);
}

.list-reset {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ---------------------------------------------------------------- text helpers */

.muted {
  color: var(--c-text-2);
}

.subtle {
  color: var(--c-text-3);
}

.text-sm {
  font-size: var(--fs-sm);
}

.text-xs {
  font-size: var(--fs-xs);
}

.strong {
  font-weight: var(--fw-bold);
}

.mono {
  font-family: var(--font-mono);
}

.nowrap {
  white-space: nowrap;
}

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

/* Show a notification line (also use dir="auto" on the element). */
.line-text {
  font-size: var(--fs-md);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

@media (max-width: 719px) {
  .hide-sm {
    display: none !important;
  }
}

@media (min-width: 720px) {
  .show-sm {
    display: none !important;
  }
}
