/* Page layout for the server-rendered documents (UI_PLAN.md §2.1, slice U9).
 *
 * What this file is: the layout of the shells the Worker renders — the app
 * shell (sidebar, bottom nav, content column, breadcrumbs), the settings
 * pages, the auth pages, the error page, and the appearance swatch grid. It
 * is loaded by all three documents (AppShell, AuthShell, and the SPA document
 * in src/views/app-shell.tsx), which is why the shell chrome here is shared
 * with src/client/app/App.vue: both draw the same classes.
 *
 * What this file is NOT: a control stylesheet. Every button, chip, field,
 * list row, card, tile and avatar on these pages is a component class from
 * src/client/ui/ui.css (`ui-*`), which ships inside public/dist/islands.css
 * and is linked by all three documents. Tokens likewise come from
 * src/client/ui/tokens.css — this file defines none, and a new control style
 * is a change to ui.css, reviewed as such (UI_PLAN.md §2.1).
 *
 * The one exception is fenced at the bottom: `.notice*`, the callout the
 * library has no component for yet, which both this file's pages and ~25
 * files in src/client render. It moves into ui.css with a `Notice` component.
 *
 * `bun run lint:css` (scripts/check-css.ts) checks all of this.
 */

/* `hidden` has to beat a component's own `display` — app.css is linked
   before islands.css, so the two elements that carry the attribute name
   themselves. */
[hidden] {
  display: none;
}
.install-card[hidden],
.install-button[hidden] {
  display: none;
}

* {
  box-sizing: border-box;
}
html {
  font-size: 16px;
}
body {
  margin: 0;
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
body.auth-body {
  background: var(--surface-2);
  min-height: 100vh;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
code,
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.icon {
  display: inline-block;
  flex: 0 0 auto;
  vertical-align: middle;
}
.muted {
  color: var(--ink-60);
}

/* Skip link — the markup carries `ui-btn ui-btn--primary`, so this is only
   where it sits (off-screen until focused). */
.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
}
.skip-link:focus {
  top: 1rem;
}

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand:hover {
  text-decoration: none;
}
.brand-mark {
  display: block;
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex: 0 0 auto;
}

/* Layout shell — the same classes src/client/app/App.vue renders. */
.app-shell {
  display: grid;
  min-height: 100vh;
}
.sidebar {
  display: none;
  flex-direction: column;
  padding: 1.75rem 1rem 1.1rem;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}
.sidebar .brand {
  padding: 0 0.65rem 2rem;
}
.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
}
.sidebar .nav-label {
  padding: 0 0.65rem;
  margin: 0 0 0.45rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink-60);
  padding: 0.62rem 0.65rem;
  border-radius: var(--r-control);
  font-size: 0.86rem;
  font-weight: 500; /* radius-ok: shell nav row, drawn by this file *and* App.vue; it becomes a library ListRow when the shell itself moves into ui/ */
}
.nav-item:hover,
.nav-item.is-current {
  text-decoration: none;
  background: var(--accent-soft);
  color: var(--accent);
}
.nav-item.is-current {
  font-weight: 600;
}
.nav-item-quiet {
  color: var(--ink-40);
  font-weight: 500;
}
.nav-item-quiet:hover {
  color: var(--ink-60);
  background: var(--line-soft);
}
.sidebar-lower {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 0.8rem;
}
.account-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 1rem;
  padding: 0.65rem;
  color: var(--ink);
  border-radius: var(
    --r-control
  ); /* radius-ok: same shell nav row as .nav-item above */
}
.account-chip:hover {
  background: var(--line-soft);
  text-decoration: none;
}
.account-chip > span:not(.ui-avatar) {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.account-chip strong {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-chip small {
  font-size: 0.68rem;
  color: var(--ink-60);
}
.main-content {
  min-width: 0;
  padding: calc(1.35rem + env(safe-area-inset-top)) 1rem 6.5rem;
}
.content-wrap {
  max-width: 960px;
  margin: 0 auto;
}
.main-wide .content-wrap {
  max-width: 1240px;
}

/* Breadcrumbs: on mobile only the parent crumb (`.crumb-parent`, tagged
   server-side in AppShell) renders, as a back link with a left caret — every
   page keeps upward navigation instead of losing the trail outright. The
   full uppercase trail with `caret-right` separators shows at desktop. */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.9rem;
  font: 600 0.84rem / 1.3 var(--font-body);
  color: var(--ink-60);
}
.breadcrumbs > * {
  display: none;
}
.breadcrumbs .crumb-parent {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.crumb-back-caret {
  display: inline-flex;
  align-items: center;
}
@media (min-width: 980px) {
  .breadcrumbs {
    flex-wrap: wrap;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--ink-40);
    font: 600 0.78rem / 1.3 var(--font-body);
  }
  .breadcrumbs > * {
    display: inline-flex;
  }
  .breadcrumbs a {
    color: var(--ink-40);
  }
  .breadcrumbs a:hover {
    text-decoration: underline;
  }
  .breadcrumbs [aria-current="page"] {
    color: var(--ink-60);
  }
  .breadcrumbs .icon {
    color: var(--ink-40);
    flex: none;
  }
  .breadcrumbs .crumb-back-caret {
    display: none;
  }
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4.15rem;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  z-index: 6;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--ink-40);
  position: relative;
}
.bottom-nav a.is-current {
  color: var(--accent);
  font-weight: 600;
}
.bottom-nav .ui-avatar {
  width: 1.75rem;
  height: 1.75rem;
  font-size: 0.58rem;
}
.bottom-nav a.is-current .ui-avatar {
  box-shadow: 0 0 0 2px var(--accent);
}
/* Bottom-nav hiding — an island that needs the full viewport (e.g. an open
   chat thread) adds `nav-hidden` to <html> on mount and removes it on
   unmount. */
html.nav-hidden .bottom-nav {
  display: none;
}
html.nav-hidden .main-content {
  padding-bottom: 0;
}

/* Page headers */
.nav-label,
.eyebrow {
  font: 600 0.72rem / 1.3 var(--font-body);
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink-40);
  margin: 0;
}
.page-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  justify-content: space-between;
  margin: 0 0 1.3rem;
}
.page-header .header-copy {
  flex-basis: 100%;
  min-width: 0;
}
.page-header .page-actions {
  flex-basis: 100%;
  justify-content: flex-start;
}
.page-header h1 {
  font: 600 clamp(1.7rem, 6vw, 2.1rem) / 1.15 var(--font-display);
  letter-spacing: -0.025em;
  margin: 0.3rem 0 0.35rem;
}
.page-subtitle {
  color: var(--ink-60);
  margin: 0;
  max-width: 52ch;
  font-size: 0.9rem;
}
.page-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Page head — shared list-screen header (title + trailing actions),
   UI_POLISH_PLAN.md §3/§4.A, also rendered by src/client's PageHead.vue.
   Distinct from `.page-header` above (the eyebrow/subtitle form header):
   this one is a single row that never wraps. */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: nowrap;
  margin: 0 0 1.1rem;
}
.page-head-title {
  font: 600 clamp(1.5rem, 5.5vw, 1.9rem) / 1.15 var(--font-display);
  letter-spacing: -0.02em;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Utilities */
.stack-md > * + * {
  margin-top: 1rem;
}
.stack-lg > * + * {
  margin-top: 1.2rem;
}
.form-row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  align-items: center;
  margin-top: 1.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

/* Settings pages */
.settings-grid {
  display: grid;
  gap: 1.4rem;
}
.settings-grid > section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.settings-card {
  margin: 0 0 1rem;
}
.settings-grid > section > .settings-card {
  margin-bottom: 0;
}
.section-label-spaced {
  margin: 0.5rem 0 -0.5rem 4px;
}
.settings-note {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--ink-40);
}
.install-card p {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--ink-60);
  margin: 0;
}
.install-card [data-install-status]:empty {
  display: none;
}
@media (display-mode: standalone) {
  [data-install-card] {
    display: none;
  }
}

/* Avatar uploader (settings/profile) */
.avatar-uploader {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.avatar-uploader-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.avatar-uploader-button {
  position: relative;
}
.avatar-uploader-status {
  width: 100%;
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-60);
  min-height: 1.1em;
}
.avatar-uploader-status.is-error {
  color: var(--danger);
}

/* Invitations (Settings → Manage accounts) */
.invite-list {
  margin-top: 2rem;
}
.invite-list h2 {
  font: 600 1.2rem var(--font-display);
}
.invite-row {
  align-items: flex-start;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}
.invite-row-actions {
  gap: 0.5rem;
}
/* Copy field — an input and its Copy button side by side; both are library
   controls, this is only the row. */
.copy-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 22rem;
}
.copy-field .ui-input {
  width: 12rem;
  font-size: 0.72rem;
}

/* Appearance swatch picker (src/views/theme.ts is the source of truth for the
   keys/hexes; GET /theme/brand.css emits the per-key .swatch-<key> background
   rules — this is only the static layout). The circle is the one radius this
   file still sets: it is a colour sample, not a control, and the library has
   no swatch component (UI_PLAN.md §7, U7's note). */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.swatch-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  text-align: center;
}
.swatch-radio {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.swatch-circle {
  width: 3rem;
  height: 3rem;
  border-radius: var(
    --r-pill
  ); /* radius-ok: a colour sample, not a control — the allowance UI_PLAN.md §8 reserved for hue swatches */
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--line) inset;
}
.swatch-option.is-selected .swatch-circle {
  border-color: var(--ink);
  box-shadow:
    0 0 0 2px var(--surface-2),
    0 0 0 4px var(--ink);
}
.swatch-option:hover .swatch-circle {
  transform: scale(1.05);
}
.swatch-label {
  font-size: 0.75rem;
  color: var(--ink-60);
}

/* Error page */
.error-page {
  max-width: 38rem;
  margin: 8vh auto;
  text-align: center;
}
.error-code {
  font: 500 0.8rem var(--font-mono);
  color: var(--accent);
}
.error-page h1 {
  font: 600 clamp(1.9rem, 6vw, 2.8rem) / 1.15 var(--font-display);
  margin: 0.4rem 0;
  letter-spacing: -0.02em;
}
.error-page p {
  color: var(--ink-60);
  margin: 0 auto 1.3rem;
}
.error-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.55rem;
}

/* Auth pages — the panel is a `ui-card`; these are its page placement and
   the copy inside it. */
.auth-page {
  width: min(100% - 2rem, 430px);
  margin: auto;
  padding: 2.5rem 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.auth-brand {
  margin-bottom: 2rem;
  align-self: center;
  font-size: 1.3rem;
}
.auth-panel {
  box-shadow: var(--shadow-1);
}
.auth-panel .ui-card__body {
  padding: 1.5rem;
}
.auth-panel h1 {
  font: 600 clamp(1.8rem, 9vw, 2.3rem) / 1.15 var(--font-display);
  letter-spacing: -0.025em;
  margin: 0.6rem 0 0.5rem;
}
.auth-intro {
  color: var(--ink-60);
  margin: 0 0 1.4rem;
}
.auth-note {
  font-size: 0.75rem;
  color: var(--ink-60);
  margin: 1.25rem 0 0;
  line-height: 1.5;
}
.auth-foot {
  text-align: center;
  color: var(--ink-40);
  font-size: 0.72rem;
  margin: 1.2rem 0 0;
}
/* The auth forms are one column of full-width controls. */
.auth-panel form .ui-btn {
  width: 100%;
}

@media (min-width: 700px) {
  .main-content {
    padding: 2.2rem 2rem 3rem;
  }
  .page-header .header-copy {
    flex-basis: auto;
  }
  .page-header .page-actions {
    flex-basis: auto;
  }
  .content-wrap {
    max-width: 1000px;
  }
  .settings-grid {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
  .auth-panel .ui-card__body {
    padding: 2.2rem;
  }
  .auth-page {
    width: min(100% - 2rem, 480px);
  }
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: 230px minmax(0, 1fr);
  }
  .sidebar {
    display: flex;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .bottom-nav {
    display: none;
  }
  .main-content {
    padding: 2.5rem 2.75rem;
  }
  .orb-layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }
}

@media (max-width: 979px) {
  .app-shell {
    grid-template-rows: 1fr auto;
  }
}

/* ------------------------------------------------------------------------
   SHARED WITH src/client — two blocks that public/app.css still owns because
   the Vue app renders the same classes and the library has no component for
   them yet. Everything else that used to live down here (.button*, .card,
   .list-*, .field*, .pill*, .empty-state, .hue-tile*, .search-bar,
   .radio-card, .plus-button, .modal*, .avatar*, the bare element resets) went
   with its last caller in U9.
   ------------------------------------------------------------------------ */

/* The one callout. ui.css has no Notice/Callout component (UI_PLAN.md §3
   names none), and 25 files in src/client plus Notice() in
   src/views/components.tsx render these classes. Hand-off: add `Notice` to
   src/client/ui and both sides move onto it together. */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  border-radius: var(--r-control);
  font-size: 0.88rem;
  margin-bottom: 1rem; /* radius-ok: the Notice the library still lacks — it uses the control token, and moves into ui.css with the component */
}
.notice strong {
  display: block;
  color: var(--ink);
}
.notice-info {
  background: var(--hue-1-soft);
  color: var(--hue-1);
}
.notice-success {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.notice-warning {
  background: var(--hue-3-soft);
  color: var(--hue-3);
}
.notice-error {
  background: var(--danger-soft);
  color: var(--danger);
}
.notice span {
  min-width: 0;
}

/* Database layout leftovers (layout only). Callers: db/components/DbLayout.vue
   (.orb-layout, with its desktop grid in the 980px block above),
   db/views/TypeView.vue and db/views/ViewPage.vue (.orb-count). */
.orb-layout {
  display: grid;
  gap: 1.5rem;
}
.orb-count {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: 500 0.78rem var(--font-mono);
  color: var(--ink-60);
}
.orb-count b {
  font: 600 0.72rem var(--font-body);
  color: var(--ink-40);
  font-weight: 600;
}
