/* App shell layout (3-pane) + auth/onboarding scaffolding (§40). */
.app-shell {
  display: grid;
  grid-template-columns: var(--nav-w) var(--list-w) 1fr;
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden; /* page never scrolls; panes below scroll internally */
  background: var(--bg);
}

/* --- Nav rail ------------------------------------------------------------------ */
.nav-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  padding: var(--sp-3) 0;
  background: var(--surface-sunken);
  border-right: 1px solid var(--border);
}
.brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-12);
  margin-bottom: var(--sp-4);
  text-decoration: none;
  transition: background var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
  border: 1px solid transparent;
}
.brand img { width: 28px; height: 28px; display: block; }
.brand:hover { background: var(--surface-elevated); border-color: var(--border); }
.brand:focus-visible { outline: none; background: var(--surface-elevated); border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-subtle); }
.nav-rail .spacer { flex: 1; }
.nav-rail .icon-btn.active {
  background: var(--primary);
  color: var(--primary-fg);
  box-shadow: var(--shadow-2);
}

/* --- Conversation list ---------------------------------------------------------- */
.conv-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.conv-list-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.conv-list-header h1 { font-size: var(--text-xl); flex: 1; font-weight: 700; letter-spacing: -0.02em; }
.conv-search { padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); }
.conv-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: var(--sp-2); }

/* --- Chat pane ------------------------------------------------------------------ */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  height: 100dvh;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 64px;
}
/* The identity block owns the remaining width (so the call/timer/menu controls
 * sit at the trailing edge) and shrinks so long names truncate instead of
 * pushing those controls off the pane. */
.chat-header .chat-id { flex: 1 1 auto; min-width: 0; }
.chat-id-text { min-width: 0; }
.chat-title { font-weight: 700; font-size: var(--text-md); line-height: 1.3; }
.chat-sub { font-size: var(--text-xs); color: var(--text-tertiary); line-height: 1.4; }
.chat-title,
.chat-sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scroll-messages { flex: 1; min-height: 0; overflow-y: auto; background: var(--bg); }

/* --- Auth / full-screen views ---------------------------------------------------- */
.fullscreen {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow-y: auto;
  padding: var(--sp-4);
  background: var(--bg);
}
/* Auto margins centre the card when it fits and let it scroll (aligned to the
   top, not clipped) when the viewport is shorter than the content. */
.fullscreen > * { margin: auto; }
.auth-card {
  width: min(95vw, 420px);
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-24);
  padding: var(--sp-10);
  box-shadow: var(--shadow-3);
}
/* Mobile: the card is nearly the whole screen (95vw x 95vh) and scrolls
   internally so tall forms are never clipped. */
@media (max-width: 560px) {
  .fullscreen { padding: var(--sp-2); }
  .auth-card {
    width: 95vw;
    max-width: none;
    height: 95vh;
    padding: var(--sp-6);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
.auth-card h1 {
  font-size: var(--text-4xl);
  letter-spacing: -0.04em;
  margin-bottom: var(--sp-2);
  font-weight: 800;
}
.auth-card .tagline { color: var(--text-secondary); margin-bottom: var(--sp-8); font-size: var(--text-md); }

/* The SHHH mark centres the card where the old text wordmark used to sit. */
.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: var(--sp-2);
}
.auth-logo img { width: 96px; height: 96px; }
@media (max-width: 560px) {
  .auth-logo img { width: 80px; height: 80px; }
  .auth-card .tagline { margin-bottom: var(--sp-6); }
}

.recovery-phrase {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--surface-sunken);
  border-radius: var(--r-8);
  margin-bottom: var(--sp-4);
}
.recovery-phrase .word-index { color: var(--text-tertiary); font-size: var(--text-xs); margin-right: var(--sp-1); }
.recovery-phrase .word {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-12);
  padding: var(--sp-2);
  text-align: center;
}

.onboarding-step { width: 100%; max-width: 560px; }

.invite-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--text-lg);
  letter-spacing: 0.08em;
  text-align: center;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-12);
  padding: var(--sp-3);
  margin-top: var(--sp-2);
  user-select: all;
  word-break: break-all;
}

/* --- Security screen ---------------------------------------------------------------- */
.sec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
}

/* --- Settings / detail panels ---------------------------------------------------------- */
.detail-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-16);
  padding: var(--sp-4);
  margin-top: var(--sp-4);
}
.divider { border: none; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }

/* --- Responsive ------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: var(--nav-w) 1fr;
  }
  /* Only two tracks here, so the empty chat pane must not occupy a phantom
     third row; it appears full-screen only once a conversation is opened. */
  .chat-pane:not(.full) { display: none; }
  .conv-list.is-active { display: none; }
  .chat-pane.full { position: fixed; inset: 0; z-index: 30; }
  .chat-back {
    display: inline-flex !important;
  }
}

@media (max-width: 560px) {
  /* Phones: single column, and the left rail becomes a bottom nav bar pinned to
     the viewport. Reserve its height so the conversation list never hides
     behind it. */
  .app-shell {
    grid-template-columns: 1fr;
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }
  .nav-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    gap: 0;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    padding: 0 var(--sp-2) env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-right: none;
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-2);
  }
  .nav-rail .brand,
  .nav-rail .spacer {
    display: none;
  }
  .nav-rail .icon-btn { flex: 1; }
  /* Inside a conversation the chat pane is full-screen with its own back
     button, so the bottom bar steps out of the way. */
  .app-shell.chat-open .nav-rail { display: none; }
  /* Phones: back + timer + menu leave no room for the inline call buttons and
     the redundant "Encrypted" badge in the header, which would crush the
     conversation name to zero width. Drop them here; calls are still reachable
     from the chat menu, and the encryption state stays visible in the subtitle
     and on the empty state. */
  .chat-calls,
  .chat-sec { display: none !important; }
  .conv-list { display: none; }
  .conv-list.mobile-open { display: flex; height: 100%; }
  .chat-back { display: inline-flex !important; }
}
.chat-back { display: none; }