/*
 * layout.css — the shell and every structural primitive. The only file that
 * sets page widths, centres containers or declares width breakpoints
 * (sm 30rem · md 48rem · lg 64rem · xl 80rem). Feature styles compose these.
 */

/* ---------- Base ---------- */

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

html {
  accent-color: var(--primary);
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: var(--tracking-snug);
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

fieldset {
  min-width: 0;
  border: 0;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
}

img,
svg {
  display: block;
  flex: none;
  max-width: 100%;
}

svg.ic {
  display: inline-block;
  vertical-align: middle;
}

a {
  color: inherit;
  text-decoration: none;
  text-underline-offset: 3px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
}

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}

:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

::selection {
  background: var(--highlight);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- App shell ----------
   Below lg the sidebar collapses to its <nav>, docked to the bottom.
   From lg it is the rail beside the conversation column. */

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

.app-shell:has(.app-nav) > .app-main {
  padding-block-end: var(--bottom-nav-height);
}

.app-sidebar {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 30;
  padding: var(--space-1) var(--space-2) calc(var(--space-1) + env(safe-area-inset-bottom));
  background: var(--surface);
  border-block-start: 1px solid var(--line);
}

.app-sidebar:not(:has(.app-nav)) {
  display: none;
}

@media (width < 64rem) {
  .app-sidebar > :not(.app-nav) {
    display: none;
  }
}

.app-nav__list {
  display: flex;
}

.app-nav__list > li {
  flex: 1 1 0;
  min-width: 0;
}

.app-nav__link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px var(--space-1);
  border-radius: var(--radius-sm);
  color: var(--ink-subtle);
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
}

.app-nav__icon {
  display: grid;
  place-items: center;
  width: 3.125rem;
  height: 1.875rem;
  border-radius: var(--radius);
  transition: background var(--duration);
}

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

.app-nav__link[aria-current] {
  color: var(--signal);
}

.app-nav__link[aria-current] > .app-nav__icon {
  background: var(--signal-tint);
}

.app-sidebar__foot {
  margin-block-start: auto;
}

@media (width >= 64rem) {
  .app-shell {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr);
  }

  .app-shell:has(.app-nav) > .app-main {
    padding-block-end: 0;
  }

  .app-sidebar,
  .app-sidebar:not(:has(.app-nav)) {
    position: sticky;
    inset-block-start: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    height: 100dvh;
    padding: var(--space-6) var(--space-4);
    overflow-y: auto;
    background: var(--surface-sunken);
    border-block-start: 0;
    border-inline-end: 1px solid var(--line-soft);
  }

  .app-nav__list {
    flex-direction: column;
    gap: 2px;
  }

  .app-nav__link {
    flex-direction: row;
    gap: var(--space-3);
    height: 2.625rem;
    padding: 0 var(--space-3);
    color: var(--ink-muted);
    font-size: var(--text-ui);
  }

  .app-nav__link:hover {
    background: var(--surface-hover);
  }

  .app-nav__icon {
    width: auto;
    height: auto;
  }

  .app-nav__link[aria-current] {
    background: var(--signal-tint);
  }

  .app-nav__link[aria-current] > .app-nav__icon {
    background: none;
  }
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 4rem;
  padding: var(--space-3) var(--gutter);
  background: color-mix(in oklch, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.2) blur(8px);
}

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

@media (width >= 64rem) {
  .topbar {
    padding-inline: var(--space-8);
  }

  .topbar > .topbar__mobile {
    display: none;
  }

  .topbar--mobile {
    display: none;
  }
}

/* ---------- Page and container ---------- */

.container {
  width: 100%;
  max-width: var(--page-default);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.page {
  width: 100%;
  max-width: var(--page-default);
  margin-inline: auto;
  padding: var(--space-4) var(--gutter) var(--space-10);
}

.page--narrow,
.container--narrow {
  max-width: var(--page-narrow);
}

.page--wide,
.container--wide {
  max-width: var(--page-wide);
}

.page--full,
.container--full {
  max-width: var(--page-full);
}

@media (width >= 64rem) {
  .page {
    padding-block-start: var(--space-8);
  }
}

/* A lone card centred in the viewport: sign-in, invitations, permission errors. */
.page--centered {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
}

.measure {
  max-width: var(--measure);
}

/* ---------- Flow ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.stack--xs {
  gap: var(--space-1);
}

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

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

.stack--xl {
  gap: var(--space-10);
}

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

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

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

.actions-row--end {
  justify-content: flex-end;
}

.actions-row--stretch > * {
  flex: 1 1 auto;
}

.spacer {
  flex: 1;
}

/* ---------- Grids ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: var(--space-3);
}

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

@media (width >= 30rem) {
  .grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

@media (width >= 48rem) {
  .grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.grid--split {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (width >= 48rem) {
  .grid--split {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  }

  .grid__wide {
    grid-column: 1 / -1;
  }
}

/* Main column plus a side pane of rail width (from lg). */
.rail {
  display: grid;
  gap: var(--space-6);
}

@media (width >= 64rem) {
  .rail {
    grid-template-columns: minmax(0, 1fr) var(--rail);
    align-items: start;
  }
}

/* ---------- Panel ---------- */

.panel {
  min-width: 0;
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
}

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-block-end: var(--space-3);
}

.panel__title {
  font-size: var(--text-lg);
  font-weight: 700;
}

.panel__aside {
  color: var(--ink-subtle);
  font-size: var(--text-sm);
}

@media (width >= 48rem) {
  .panel {
    padding: var(--space-5);
  }
}

/* ---------- Data table ---------- */

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-ui);
  font-variant-numeric: tabular-nums;
}

.data-table > thead > tr > th {
  padding: 0 var(--space-3) var(--space-2) 0;
  border-block-end: 1.5px solid var(--ink);
  color: var(--ink-subtle);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-align: start;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table > tbody > tr > td {
  padding: var(--space-3) var(--space-3) var(--space-3) 0;
  border-block-end: 1px solid var(--line-soft);
}

.data-table > tfoot > tr > td {
  padding: var(--space-3) var(--space-3) 0 0;
  border-block-start: 1.5px solid var(--ink);
  font-weight: 700;
}

.data-table__num {
  text-align: end;
}

.data-table--compact > tbody > tr > td {
  padding-block: var(--space-2);
}

/* ---------- Empty state ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-5) var(--space-6);
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  text-align: center;
}

.empty-state__icon {
  color: var(--ink-subtle);
}

.empty-state__title {
  max-width: 24ch;
  font-size: var(--text-xl);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.empty-state__text {
  max-width: 40ch;
  color: var(--ink-muted);
  font-size: var(--text-md);
}

.empty-state--inline {
  align-items: flex-start;
  padding: 22px 18px 20px;
  border-width: 1px;
  background: transparent;
  text-align: start;
}

.empty-state--inline > .empty-state__title {
  max-width: none;
  font-size: var(--text-lg);
}

.empty-state > .actions-row {
  justify-content: center;
  margin-block-start: var(--space-3);
}

/* ---------- Docked composer ---------- */

.composer-dock {
  position: sticky;
  inset-block-end: 0;
  z-index: 15;
  margin-block-start: auto;
  padding-block: var(--space-3);
  background: linear-gradient(transparent, var(--bg) 30%);
}

/* ---------- Sheets (popover) ----------
   A bottom sheet on phones; a centred dialog from sm. */

.sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-height: 88dvh;
  margin: 0;
  padding: var(--space-3) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  overflow: auto;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-overlay);
}

.sheet::backdrop {
  background: color-mix(in oklch, var(--shadow-color) 35%, transparent);
}

.sheet::before {
  content: "";
  display: block;
  width: 2.5rem;
  height: 4px;
  margin: 0 auto var(--space-3);
  border-radius: 2px;
  background: var(--line);
}

@media (width >= 30rem) {
  .sheet {
    inset: 0;
    width: min(27.5rem, calc(100% - 2 * var(--gutter)));
    height: fit-content;
    margin: auto;
    padding-block-start: var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
  }

  .sheet::before {
    display: none;
  }
}
