/* Shell for signed-in pages: a topbar across the full width, the sidebar and
   the page beneath it. Same palette as the landing page but completely still —
   this is a work surface, not a poster. */

body.app {
  display: grid;
  grid-template-rows: var(--top-h, 52px) 1fr;
  grid-template-columns: var(--nav-w, 224px) 1fr;
  grid-template-areas:
    "top top"
    "nav main";
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(1100px 700px at 82% -12%, rgba(143, 131, 255, 0.10), transparent 62%),
    radial-gradient(900px 620px at -8% 108%, rgba(111, 216, 230, 0.08), transparent 62%),
    var(--void);
  /* Animating the grid track keeps the sidebar and the page edge in step;
     transitioning the sidebar's own width would tear them apart mid-slide. */
  transition: grid-template-columns 0.2s ease;
}
body.app.collapsed { --nav-w: 60px; }

/* Held back until /api/auth/me answers, so a signed-out visitor never sees a
   flash of the shell before being redirected. */
body.booting { visibility: hidden; }

/* --- topbar --------------------------------------------------------------- */

.topbar {
  grid-area: top;
  z-index: 25;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 16px 0 12px;
  background: rgba(11, 15, 21, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.topbar-spacer { flex: 1; }

.topbar-toggle {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.topbar-toggle:hover { color: var(--ink); border-color: var(--line); }

.brand {
  display: flex;
  gap: 9px;
  align-items: center;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand .dot {
  flex: none;
  width: 7px;
  height: 7px;
  background: var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 9px var(--cyan);
}

/* --- sidebar -------------------------------------------------------------- */

.nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 10px;
  overflow-x: hidden;
  overflow-y: auto;
  background: rgba(11, 15, 21, 0.5);
  border-right: 1px solid var(--line);
}

.nav-section { margin: 12px 0 6px; padding: 0 10px; }
.nav-section:first-child { margin-top: 2px; }

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-item {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 9px 10px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border-radius: 8px;
  transition: color 0.2s ease, background-color 0.2s ease;
}
.nav-item svg { flex: none; }
.nav-item:hover { color: var(--ink); background: rgba(120, 145, 175, 0.08); }
.nav-item.active {
  color: var(--ink);
  background: rgba(111, 216, 230, 0.10);
  box-shadow: inset 2px 0 0 var(--cyan);
}

/* Collapsed: icons only. Labels are hidden rather than removed so the DOM and
   the accessibility tree stay intact; each item's title carries its name. */
.collapsed .nav { padding: 12px 8px; }
.collapsed .nav-label,
.collapsed .nav-section { display: none; }
.collapsed .nav-item { justify-content: center; padding: 10px 0; }

/* --- content -------------------------------------------------------------- */

.content {
  grid-area: main;
  min-width: 0;
  overflow-y: auto;
  padding: 34px clamp(20px, 4vw, 56px) 64px;
}
/* Long-form content stops before it becomes hard to scan on a wide monitor, and
   sits in the middle of what is left rather than hugging the sidebar. */
.content > * { max-width: 1040px; margin-inline: auto; }

.content-head { margin-bottom: 30px; }
.content h1 {
  margin: 6px 0 0;
  font-size: 26px;
  font-weight: 300;
  letter-spacing: 0.01em;
}
.content .lede { margin: 10px 0 0; color: var(--muted); }

.panel {
  padding: 22px;
  background: rgba(17, 23, 33, 0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
}

/* --- narrow screens: the sidebar becomes a drawer ------------------------- */

.nav-scrim { display: none; }

@media (max-width: 760px) {
  body.app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "main";
  }
  .nav {
    position: fixed;
    z-index: 20;
    top: var(--top-h, 52px);
    bottom: 0;
    left: 0;
    width: 236px;
    background: rgba(11, 15, 21, 0.97);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  body.app.nav-shown .nav { transform: none; }

  /* Collapsing means nothing off-canvas: the drawer is open or it is not. */
  .collapsed .nav { padding: 12px 10px; }
  .collapsed .nav-label,
  .collapsed .nav-section { display: revert; }
  .collapsed .nav-item { justify-content: flex-start; padding: 9px 10px; }

  .nav-scrim {
    position: fixed;
    z-index: 19;
    inset: var(--top-h, 52px) 0 0;
    display: block;
    background: rgba(3, 5, 8, 0.6);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  body.app.nav-shown .nav-scrim { opacity: 1; pointer-events: auto; }

  .content { padding: 22px 18px 48px; }
  .brand-name { display: none; }
}

/* --- passkey list ---------------------------------------------------------- */

.rowbar {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.keys { margin: 0; padding: 0; list-style: none; }

.key-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}
.key-row:first-child { border-top: 0; padding-top: 4px; }

.key-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; margin-right: auto; }
.key-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-meta { font-family: var(--mono); font-size: 11px; color: var(--dim); }

.ghost-sm {
  flex: none;
  padding: 5px 11px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
.ghost-sm:hover:not(:disabled) { color: var(--ink); border-color: var(--line-strong); }
.ghost-sm.danger:hover:not(:disabled) { color: var(--danger); border-color: rgba(255, 122, 107, 0.5); }
.ghost-sm:disabled { opacity: 0.4; cursor: default; }

.content .msg { min-height: 1.4em; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.content .msg.error { color: var(--danger); }

@media (max-width: 560px) {
  .key-row { flex-wrap: wrap; }
  .key-main { width: 100%; margin-right: 0; }
}

/* --- account menu ---------------------------------------------------------- */

/* Sits in the topbar, so it scrolls with nothing and covers nothing. */
.account { position: relative; flex: none; }

/* Placeholder avatar: the initial on a tinted disc. Swap for an image later. */
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--cyan);
  text-transform: uppercase;
  background: rgba(111, 216, 230, 0.12);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}
.avatar:hover, .account.open .avatar {
  background: rgba(111, 216, 230, 0.2);
  border-color: rgba(111, 216, 230, 0.6);
}

.account-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 10px);
  right: 0;
  width: 208px;
  padding: 6px;
  background: rgba(14, 19, 27, 0.97);
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.account.open .account-menu { opacity: 1; transform: none; pointer-events: auto; }
/* A gap between the avatar and the menu would drop the hover mid-travel. */
.account-menu::before {
  content: "";
  position: absolute;
  top: -10px;
  right: 0;
  left: 0;
  height: 10px;
}

.account-head {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 9px 10px 11px;
  border-bottom: 1px solid var(--line);
}
.account-name {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.role-badge {
  flex: none;
  margin-left: auto;
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
}
/* One scale, read at a glance: gold is the account that can open everything,
   cyan is a registered one, and the plain outline is whoever has not signed in.
   The bare `.role-badge` above is the visitor's, which is why it is the quiet
   one. */
.role-badge.user {
  color: var(--cyan);
  border-color: rgba(111, 216, 230, 0.45);
}
.role-badge.admin {
  color: var(--gold);
  border-color: rgba(227, 179, 95, 0.45);
}

/* The visitor's corner is a badge and a door, side by side. */
.account-guest {
  display: flex;
  gap: 9px;
  align-items: center;
}
.account-guest .role-badge { margin-left: 0; }

.account-item {
  display: flex;
  gap: 9px;
  align-items: center;
  width: 100%;
  margin-top: 2px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}
.account-item:hover { color: var(--ink); background: rgba(120, 145, 175, 0.1); }
.account-item.danger:hover { color: var(--danger); background: rgba(255, 122, 107, 0.1); }

/* --- modal ----------------------------------------------------------------- */

.modal {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 5, 8, 0.72);
}
/* For a panel that stands in for a whole page. */
.modal.dim { background: rgba(2, 3, 5, 0.92); }
.modal-card {
  width: 100%;
  max-width: 380px;
  padding: 24px;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: 13px;
}
.code-out {
  margin: 0;
  padding: 16px 12px;
  font-family: var(--mono);
  font-size: clamp(16px, 4.4vw, 21px);
  letter-spacing: 0.08em;
  color: var(--cyan);
  text-align: center;
  overflow-wrap: anywhere;
  background: rgba(5, 7, 10, 0.6);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.modal-note { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* Signing in without leaving the page. The card inside is the same element
   /login.html uses, styles and all — this only positions it and puts the way
   back at its top-left corner. */
.login-panel { width: 100%; max-width: 348px; }
/* Opaque, unlike the same card on the login page: there it floats over a
   gradient of its own, here it covers a working page that should not show
   through the form someone is typing into. */
.login-slot .card {
  max-width: none;
  background: var(--raised);
  border-color: var(--line-strong);
}
.login-back {
  display: block;
  margin: -6px 0 14px -4px;
  padding: 4px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.login-back:hover { color: var(--ink); }

/* --- sidebar: sections and the tool manager -------------------------------- */

.nav-section-row {
  display: flex;
  align-items: center;
  margin: 12px 0 6px;
  padding: 0 4px 0 10px;
}
.nav-section-row .nav-section { flex: 1; margin: 0; padding: 0; }

.nav-add {
  display: grid;
  flex: none;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.nav-add:hover { color: var(--cyan); border-color: var(--line); }

.nav-empty { margin: 4px 10px; font-size: 12px; color: var(--dim); }

/* Way back up a level, so account settings never feel like a dead end. */
.nav-back {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 9px 10px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border-radius: 8px;
}
.nav-back:hover { color: var(--ink); background: rgba(120, 145, 175, 0.08); }

.topbar-where {
  padding-left: 10px;
  font-size: 13px;
  color: var(--dim);
  border-left: 1px solid var(--line);
}

.collapsed .nav-section-row { justify-content: center; padding: 0; }
.collapsed .nav-section-row .nav-section { display: none; }
.collapsed .nav-empty { display: none; }
.collapsed .nav-back { justify-content: center; padding: 10px 0; }

.tool-manage { margin: 0; padding: 0; list-style: none; }
.tool-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}
.tool-row:first-child { border-top: 0; }
.tool-toggle {
  display: flex;
  flex: 1;
  gap: 9px;
  align-items: center;
  min-width: 0;
  font-size: 14px;
  cursor: pointer;
}
.tool-toggle input { accent-color: var(--cyan); }
.tool-row .ghost-sm { display: grid; place-items: center; width: 28px; padding: 5px 0; }

@media (max-width: 760px) {
  .collapsed .nav-section-row { justify-content: flex-start; padding: 0 4px 0 10px; }
  .collapsed .nav-section-row .nav-section { display: revert; }
  .collapsed .nav-back { justify-content: flex-start; padding: 9px 10px; }
  .topbar-where { display: none; }
}

/* A swap is fast enough that a spinner would only flicker; the content just
   dims while it is in flight. */
body.app.loading .content { opacity: 0.55; transition: opacity 0.12s ease; }

/* Signed in or not: two spellings of the same page rather than two pages. The
   shell puts `guest` on <body> once it knows which. */
.guest-only { display: none; }
body.guest .guest-only { display: revert; }
body.guest .signed-only { display: none; }

/* Where the avatar menu would be. A visitor has no account to show, so the
   corner holds the way in instead. */
.guest-in {
  padding: 6px 15px;
  font-size: 13px;
  white-space: nowrap;
}

/* Level badge. Levels 0 (internal), 1 (beta) and 3 (public) carry one — a
   released tool is the unremarkable case and says nothing. */
.tier {
  flex: none;
  margin-left: auto;
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  border: 1px solid currentColor;
  border-radius: 999px;
  opacity: 0.8;
}
.tier-0 { color: #d98b7a; }
.tier-1 { color: var(--violet); }
.tier-3 { color: var(--green); }
.collapsed .nav-item .tier { display: none; }
.tool-toggle .tier { margin-left: 8px; }

@media (max-width: 760px) {
  .collapsed .nav-item .tier { display: revert; }
}

.banner {
  margin: 18px 0 0;
  padding: 11px 14px;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 122, 107, 0.10);
  border: 1px solid rgba(255, 122, 107, 0.35);
  border-radius: 9px;
}
