/* Desktop layouts (1024px and up, the same width where the sidebar shows).

   Phones keep their single column untouched: every wrapper below is
   `display: contents` under 1024px, so its children sit in the parent
   .stack exactly as before and only wide screens get the columns.

   .dsk-top   head row: title or greeting on the left, actions on the right
   .dsk-cols  main column + side column
   .dsk-main  the wide column (what the screen is for)
   .dsk-side  the narrow column (context, shortcuts, secondary cards)
   .dsk-only  shown on desktop only
   .mob-only  shown on phones and tablets only */

.dsk-top,
.dsk-cols,
.dsk-main,
.dsk-side {
  display: contents;
}
@media (max-width: 1023px) {
  .dsk-only {
    display: none !important;
  }
}

/* A plain card with a header row, used by the desktop-only panels. */
.dsk-card {
  background: var(--surface-raised);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}
.dsk-card__h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--surface-border);
}
.dsk-card__t {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}
.dsk-empty {
  margin: 0;
  padding: 22px 18px;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

@media (min-width: 1024px) {
  .mob-only {
    display: none !important;
  }

  /* One content width for every signed-in screen on desktop. */
  .page--md,
  .page--lg {
    max-width: 1120px;
  }
  /* Forms read best narrow, even on a big screen. */
  .page--sm {
    max-width: 640px;
  }

  .dsk-top {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
  }
  .dsk-top > :first-child {
    flex: 1;
    min-width: 0;
  }
  .dsk-top > .btn {
    width: auto !important;
    flex: none;
  }
  .dsk-cols {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 24px;
    align-items: start;
  }
  .dsk-cols--even {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .dsk-main,
  .dsk-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
  }
  .dsk-main {
    gap: 24px;
  }
}

/* ---- Admin dashboard ---- */
.dsk-actions {
  display: flex;
  gap: 10px;
}
.dsk-actions .btn {
  width: auto;
}

/* ---- Super admin dashboard ---- */
.sa-tile__d--warn {
  color: var(--color-warning);
}
.sa-look__k--ok {
  background: var(--color-success-bg);
  color: var(--color-success);
}
.sa-health__bar {
  display: flex;
  gap: 2px;
  height: 8px;
  margin: 16px 18px 6px;
  border-radius: var(--radius-full);
  overflow: hidden;
}
.sa-health__seg--go {
  background: var(--color-success);
}
.sa-health__seg--warn {
  background: var(--color-warning);
}
.sa-health__seg--muted {
  background: var(--gray-300);
}
.sa-health__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--surface-border);
}
.sa-health__row:last-child {
  border-bottom: 0;
}

@media (min-width: 1024px) {
  .sa-tiles {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
}

/* ---- List screens: rows flow into two columns on desktop ---- */
@media (min-width: 1024px) {
  .pass-rows,
  .inq-list,
  #visitors-list .rd-list,
  #alerts-list > .stack,
  #orgs-list .rd-list,
  #users-list .rd-list,
  #users-list:has(> .estate-group--card),
  #events-list:has(> :nth-child(2)) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  /* Users: the invite card and pending approvals side by side. */
  #admin-extras:has(> :nth-child(2)) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
    align-items: start;
  }
}

/* ---- Profile: who you are on the left, settings on the right ---- */
.set-body {
  display: contents;
}
@media (min-width: 1024px) {
  .set-page {
    max-width: 960px;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: 32px;
    align-items: start;
  }
  .set-page > .set-head {
    grid-column: 1;
    grid-row: 1;
    padding: 28px 20px 24px;
    background: var(--surface-raised);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-xl);
  }
  .set-page > .set-footer {
    grid-column: 1;
    grid-row: 2;
    margin-top: 16px;
  }
  .set-page > .set-body {
    grid-column: 2;
    grid-row: 1 / span 2;
    display: flex;
    flex-direction: column;
    gap: 16px;
  }
}

/* ---- Single-task screens stay narrow and centred on desktop ---- */
@media (min-width: 1024px) {
  .page.dsk-narrow {
    max-width: 640px;
  }
  .sec-rep-form {
    gap: 16px;
  }
  .sec-rep-form + .dsk-side .sec-open {
    margin-top: 0;
  }
}

/* ---- Analytics: the week's number beside what needs a look ---- */
@media (min-width: 1024px) {
  .an-body {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 16px !important;
    align-items: start;
  }
  .an-body > .an-look {
    grid-column: 2;
    grid-row: 1;
  }
  .an-body > .an-hero {
    grid-column: 1;
    grid-row: 1;
  }
  .an-body:not(:has(> .an-look)) > .an-hero,
  .an-body > .an-trend {
    grid-column: 1 / -1;
  }
}

/* ---- Broadcasts: write on the left, what was sent on the right ---- */
@media (min-width: 1024px) {
  .bc-cols {
    grid-template-columns: minmax(0, 1fr) 380px;
  }
  .bc-past .bc-past-head {
    margin-top: 0;
  }
}

/* ---- Estate detail: setup checklist left, people and actions right ---- */
@media (min-width: 1024px) {
  #ed-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: 16px 24px;
    align-items: start;
  }
  #ed-body > * {
    grid-column: 2;
    margin: 0;
  }
  #ed-body > .ed-stats,
  #ed-body > .empty {
    grid-column: 1 / -1;
  }
  #ed-body > section:first-of-type {
    grid-column: 1;
    grid-row: 2 / span 6;
  }
}

@media (min-width: 1024px) {
  #events-list:has(> :nth-child(2)) > * {
    margin: 0;
  }
}
