/* Glampfire app shell. Replaces Campfire's layout.css.

   Signed in (body.app): one rounded window on a softly glowing canvas.

     ┌ window ──────────────────────────────────────────────┐
     │ sidebar   │ top bar (search, you)                     │
     │ (brand,   │ ┌ card ───────────────────┬─ panel ─────┐ │
     │  nav,     │ │ header                  │ details     │ │
     │  rooms,   │ │ content                 │             │ │
     │  you)     │ └─────────────────────────┴─────────────┘ │
     └──────────────────────────────────────────────────────┘

   Narrow screens: the card fills the screen; the sidebar slides in as a drawer. */

html {
  background:
    radial-gradient(55% 60% at 100% 0%, var(--gf-glow), transparent 70%),
    radial-gradient(45% 50% at 0% 100%, color-mix(in oklch, var(--gf-glow) 60%, transparent), transparent 70%),
    var(--gf-canvas);
  min-block-size: 100%;
  overscroll-behavior: none;
}

body {
  --footer-height: 5.5rem;
  --navbar-height: 0px;
  --sidebar-width: 0px;

  margin: 0;
}

/* Signed-out pages keep their own layout (auth.css). */
body:not(.app) {
  display: grid;
  grid-template-rows: min-content 1fr;
  max-block-size: 100dvh;

  #main-content { overflow: auto; }
  #sidebar { display: none; }
}

/* Signed in: the window */
body.app {
  --sidebar-width: 248px;
  --panel-width: 340px;
  --window-inset: 14px;
  --card-inset: 10px;

  background-color: var(--gf-window);
  block-size: calc(100dvh - var(--window-inset) * 2);
  border-radius: var(--gf-radius-window);
  box-shadow:
    0 0 0 1px oklch(0% 0 0 / 0.04),
    0 30px 80px -30px oklch(45% 0.08 45 / 0.25);
  box-sizing: border-box;
  display: grid;
  grid-template-areas:
    "sidebar topbar"
    "sidebar nav"
    "sidebar main";
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  margin: var(--window-inset);
  overflow: hidden;
  padding: 0 var(--card-inset) var(--card-inset) 0;

  &.room-panel-open {
    grid-template-areas:
      "sidebar topbar topbar"
      "sidebar nav panel"
      "sidebar main panel";
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--panel-width);
  }

  @media (prefers-color-scheme: dark) {
    box-shadow: 0 0 0 1px oklch(100% 0 0 / 0.06), 0 30px 80px -30px oklch(0% 0 0 / 0.6);
  }
}

/* One white card behind the header, the content and (when open) the details panel.
   Its radius is the window's minus the inset between them (concentric). */
.app-card {
  background-color: var(--gf-surface);
  border-radius: calc(var(--gf-radius-window) - var(--card-inset));
  box-shadow: 0 0 0 1px oklch(0% 0 0 / 0.04), 0 2px 8px -2px oklch(0% 0 0 / 0.05);
  grid-column: nav;
  grid-row: nav-start / main-end;

  .room-panel-open & { grid-column: nav-start / panel-end; }

  @media (prefers-color-scheme: dark) { box-shadow: 0 0 0 1px oklch(100% 0 0 / 0.06); }
}

body.app {
  #nav { grid-area: nav; z-index: 1; }

  #main-content {
    display: flex;
    flex-direction: column;
    grid-area: main;
    min-block-size: 0;
    overflow: auto;
    position: relative;
    z-index: 1;
  }

  &.sidebar #main-content { overflow: hidden; }
}

#footer {
  flex: none;
}

/* Top bar: search and your avatar, on the window */
.topbar {
  align-items: center;
  display: flex;
  gap: 12px;
  grid-area: topbar;
  justify-content: flex-end;
  min-block-size: 64px;
  padding-inline: 8px 4px;
}

.topbar__search {
  inline-size: min(340px, 100%);
  margin: 0;

  label {
    align-items: center;
    background-color: var(--gf-surface);
    block-size: 40px;
    border-radius: 999px;
    box-shadow: 0 0 0 1px oklch(0% 0 0 / 0.05);
    color: var(--gf-ink-faint);
    cursor: text;
    display: flex;
    gap: 8px;
    padding-inline: 14px;

    &:focus-within { box-shadow: 0 0 0 1px var(--gf-border-strong), 0 0 0 4px oklch(var(--lch-black) / 0.05); }
  }

  .icon { block-size: 17px; flex: none; inline-size: 17px; }

  input {
    background: transparent;
    border: 0;
    color: var(--gf-ink);
    flex: 1;
    font: inherit;
    font-size: 14px;
    min-inline-size: 0;
    outline: 0;
    padding: 0;

    &::placeholder { color: var(--gf-ink-faint); }
    &::-webkit-search-cancel-button { display: none; }
  }

  /* The search page has its own, larger field. */
  .searches & { visibility: hidden; }

  @media (prefers-color-scheme: dark) { label { box-shadow: 0 0 0 1px oklch(100% 0 0 / 0.08); } }
}

.topbar__avatar {
  border-radius: 50%;
  display: block;
  flex: none;

  img {
    block-size: 36px;
    border-radius: 50%;
    display: block;
    inline-size: 36px;
    object-fit: cover;
    outline: 1px solid oklch(0% 0 0 / 0.1);
    outline-offset: -1px;
  }

  &:active { scale: 0.96; }
  &:focus-visible { outline: 2px solid var(--gf-mention); outline-offset: 2px; }
}

/* Sidebar column: on the window, no card */
#sidebar {
  display: flex;
  flex-direction: column;
  grid-area: sidebar;
  min-block-size: 0;
  overflow: hidden;
  padding: 18px 12px 12px 14px;
}

/* Room details panel: inside the card, after a hairline */
.room-panel {
  border-inline-start: 1px solid var(--gf-border);
  grid-column: panel;
  grid-row: nav-start / main-end;
  min-block-size: 0;
  overflow-y: auto;
  z-index: 1;

  &[hidden] { display: none; }
}

/* Narrow screens: the card fills the screen; the sidebar is a drawer. */
.app-backdrop { display: none; }

@media (max-width: 100ch) {
  body.app,
  body.app.room-panel-open {
    block-size: 100dvh;
    border-radius: 0;
    box-shadow: none;
    grid-template-areas: "nav" "main";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    margin: 0;
    padding: 0;
  }

  .topbar { display: none; }

  .app-card,
  .room-panel-open .app-card {
    border-radius: 0;
    box-shadow: none;
    grid-column: 1;
  }

  body.app #sidebar {
    background-color: var(--gf-window);
    block-size: 100dvh;
    inline-size: min(300px, calc(100vw - 48px));
    inset-block: 0;
    inset-inline-start: 0;
    position: fixed;
    /* The drawer is occasional and spatial: it slides, once, quickly. */
    transition: translate 200ms var(--gf-ease-drawer);
    translate: calc(-100% - 24px) 0;
    z-index: 30;
  }

  body.app.sidebar-open #sidebar { translate: 0 0; }

  .app-backdrop {
    background: oklch(0% 0 0 / 0.35);
    display: block;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    transition: opacity 200ms var(--gf-ease-out);
    z-index: 25;

    .sidebar-open & { opacity: 1; pointer-events: auto; }
  }

  .room-panel {
    background-color: var(--gf-surface);
    border: 0;
    box-shadow: var(--gf-shadow-pop);
    inline-size: min(360px, 100vw);
    inset: 0 0 0 auto;
    position: fixed;
    z-index: 30;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.app #sidebar { transition: none; }
}
