/* Switch Space.

   The same shape ALYSSIUN CRM uses, deliberately: switching Space is one idea
   and should not look like a different feature in every application. Titled
   panel, search, a count of what you have, the list with roles, and New Space
   at the end where a list's "add" belongs.

   Opaque surfaces throughout — see aly-theme.css for why that is stated rather
   than assumed. */

.space-backdrop {
  position: fixed; inset: 0; z-index: 75;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}

.space-modal {
  width: min(420px, 100%); max-height: min(78dvh, 680px);
  display: flex; flex-direction: column; gap: 12px; padding: 20px;
  border: 1px solid var(--surface-line); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .40);
}

.space-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.space-title { margin: 2px 0 0; font-size: 20px; font-weight: 300; }
.space-close { flex: none; min-height: 34px; min-width: 34px; }

.space-search {
  width: 100%; padding: 10px 12px; min-height: 0;
  border: 1px solid var(--surface-line); border-radius: 9px;
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 13px;
}
.space-search:focus { outline: none; border-color: var(--text); background: var(--surface-2); }

.space-count { margin: 0; }

.space-list {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
}
.space-empty { margin: 8px 0; font-size: 13px; }

/* A row is a FRAME around two controls: the body switches Space, the gear opens
   that Space's settings. The frame is not itself a button — a button inside a
   button is invalid, and it would make opening settings a way to switch by
   accident. */
.space-row {
  display: flex; align-items: center; width: 100%;
  min-height: 54px; overflow: hidden;
  border: 1px solid var(--surface-line); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
.space-row:hover, .space-row:focus-within { border-color: var(--text); }
/* Where you already are, said with a border rather than a tick — the row you
   are in should look settled, not selected. */
.space-row.is-active { border-color: var(--text); background: var(--surface); }

.space-row-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px 9px 11px; cursor: pointer; text-align: left;
  border: none; background: none; color: inherit; font: inherit;
}
.space-row-main:focus-visible { outline: none; }

/* One small number, no bar — how much this Space uses. Muted: it is a fact to
   glance at, not a warning, so it never competes with the row's own name. */
.space-row-usage {
  flex: none; margin-right: 6px; color: var(--muted); font-size: 11px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* The gear is quiet until the row is under the pointer: settings are available
   on every Space, but they are not what the list is FOR. */
.space-row-settings {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; margin-right: 7px; padding: 0; cursor: pointer;
  border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--muted);
}
.space-row-settings svg { width: 17px; height: 17px; }
.space-row:hover .space-row-settings { color: var(--text); }
.space-row-settings:hover, .space-row-settings:focus-visible {
  color: var(--text); border-color: var(--surface-line); background: var(--surface);
}

.space-avatar {
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--surface-line);
  font-size: 13px; font-weight: 700;
}
.space-row-text { flex: 1; min-width: 0; display: grid; }
.space-row-name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.space-row-role { font-size: 11px; color: var(--muted); }

/* --- Space settings ------------------------------------------------------ */

/* Facts first — what your role is, what the Space holds, when it was made —
   because they are what makes the delete decision an informed one. */
.space-settings-facts {
  display: grid; grid-template-columns: auto 1fr; gap: 6px 14px;
  margin: 4px 0 0; font-size: 12.5px;
}
.space-settings-facts dt { color: var(--muted); }
.space-settings-facts dd { margin: 0; color: var(--text); }

/* Delete sits below the fields with its reason under it, never beside Save:
   a destructive control in the same row as the ordinary one is how somebody
   deletes a Space they meant to rename. */
.space-settings-danger {
  display: grid; gap: 7px; justify-items: start;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--surface-line);
}
.space-settings-danger .btn[disabled] { opacity: .5; cursor: not-allowed; }
.space-settings-danger .aly-dialog-hint { margin: 0; font-size: 12px; }

.space-new {
  width: 100%; padding: 11px; min-height: 46px; cursor: pointer;
  border: 1px dashed var(--surface-line); border-radius: 10px;
  background: none; color: var(--text); font: inherit; font-size: 13px; font-weight: 600;
}
.space-new:hover, .space-new:focus-visible { border-style: solid; border-color: var(--text); }

/* On a phone it is a sheet, where a thumb reaches. */
@media (max-width: 560px) {
  .space-backdrop { align-items: flex-end; padding: 0; }
  /* The ALYSSIUN OS launcher floats over the bottom of every page it decorates.
     ALY reserves room for it rather than fighting it for a z-index — the same
     clearance the composer already uses, and 0 when no launcher is there. */
  .space-modal {
    width: 100%; max-height: 88dvh;
    border-radius: var(--radius) var(--radius) 0 0; border-bottom: none;
    padding-bottom: calc(20px + max(env(safe-area-inset-bottom, 0px), var(--alyssiun-safe-bottom, 0px)));
  }
}

/* --- waiting for an answer -------------------------------------------------

   An invitation and a transfer are both an ASK, and neither is access until
   the person presses Accept. They sit above the Space list because that is
   what they are about to become — and they read as cards rather than rows so
   nobody taps one thinking they are switching Space. */

.space-inbox { display: grid; gap: 8px; margin-bottom: 4px; }
.space-inbox[hidden] { display: none; }
.space-inbox-head { margin: 0; }
.space-inbox-card {
  display: grid; gap: 6px;
  padding: 12px 13px; border: 1px solid var(--hair-2); border-radius: 10px; background: var(--glass);
}
.space-inbox-title { margin: 0; font-size: 13px; color: var(--text); }
.space-inbox-note { margin: 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.space-inbox-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.space-inbox-actions .btn { font-size: 11px; padding: 6px 12px; min-height: 32px; }
