/* ============================================================================
   Kindred — base.css
   Reset, document defaults, the app shell, layout primitives, a11y helpers.

   THE SHELL (rewritten):
     phone   (< 900px):  slim top bar · content · five-tab bottom bar
     desktop (≥ 900px):  left rail (brand, tagline, destinations, help) · content
                         content is a centred reading column (≈ 720px) so text
                         never runs edge to edge on a wide screen.
   Chat and group rooms are "full bleed": on a phone they take the whole screen
   (no bars), on desktop they keep the rail and use a two-pane layout.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: anywhere;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0 0 var(--sp-3); line-height: var(--lh-tight); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p  { margin: 0 0 var(--sp-4); }
small { font-size: var(--fs-sm); }
strong { font-weight: var(--fw-bold); }

a { color: var(--primary-strong); text-decoration: none; border-radius: var(--r-sm); }
a:hover { text-decoration: underline; }
/* Whole-row links must not underline: the decoration spreads across every line
   of a card and reads as broken text. Rows signal hover with a surface change. */
.chat-row:hover, .thought-mini:hover, .quick-tile:hover, .rail-item:hover, .tab:hover,
.chat-row:hover *, .thought-mini:hover *, .quick-tile:hover *, .rail-item:hover *, .tab:hover * { text-decoration: none; }
.thought-mini:hover, .quick-tile:hover { background: var(--surface-2); }
.thought-mini { border-radius: var(--r-md); }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm);
}
/* The router focuses each page heading for screen readers. It is not something
   anyone can type into, so it never wears a focus ring. */
h1[tabindex="-1"]:focus, h1[tabindex="-1"]:focus-visible,
[data-page-title][tabindex="-1"]:focus, [data-page-title][tabindex="-1"]:focus-visible {
  outline: none; box-shadow: none;
}

img, svg, video { max-width: 100%; display: block; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-5) 0; }
code, kbd { font-family: var(--font-mono); font-size: 0.92em; background: var(--surface-3); padding: 2px 6px; border-radius: 6px; }
::selection { background: var(--c-coral-300); color: var(--c-ink-900); }

/* Scrollbars: soft, unobtrusive */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- utilities */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 50%; transform: translate(-50%, -140%); z-index: 200;
  background: var(--primary); color: #fff; padding: 10px 18px; border-radius: 0 0 var(--r-lg) var(--r-lg);
  transition: transform var(--dur) var(--ease); font-weight: var(--fw-medium);
}
.skip-link:focus { transform: translate(-50%, 0); text-decoration: none; }
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--text-muted); }
.soft  { color: var(--text-soft); }
.small { font-size: var(--fs-sm); }
.xsmall{ font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.col { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack > * + * { margin-top: var(--sp-4); }
.grid { display: grid; gap: var(--sp-4); }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.mt-0 { margin-top: 0 } .mb-0 { margin-bottom: 0 } .mb-2 { margin-bottom: var(--sp-2) }
.mb-4 { margin-bottom: var(--sp-4) } .mb-6 { margin-bottom: var(--sp-6) } .mt-4 { margin-top: var(--sp-4) }
.mt-6 { margin-top: var(--sp-6) }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.divider { height: 1px; background: var(--border); margin: var(--sp-4) 0; }

/* The content column. Every ordinary page sits in .page-pad; on desktop that
   pad becomes a centred reading column rather than the full window width. */
.page-pad {
  padding: var(--sp-4) var(--sp-4) var(--sp-6);
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}
@media (min-width: 600px) { .page-pad { padding: var(--sp-5) var(--sp-5) var(--sp-7); } }

/* --------------------------------------------------------------- app shell */
body.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
}
.app-main { min-width: 0; padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-2)); }

/* ---- phone: top bar -------------------------------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  height: var(--header-h); padding: 0 var(--sp-2) 0 var(--sp-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header .brand { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: var(--fw-bold); font-size: var(--fs-md); color: var(--text); min-width: 0; }
.app-header .brand:hover { text-decoration: none; }
.app-header-actions { display: flex; align-items: center; gap: 0; }
.app-header .icon-btn { width: var(--tap); height: var(--tap); }
.app-header .help-btn { color: var(--primary-strong); }

/* shared icon button (used by the shell and pages) */
.icon-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); min-width: var(--tap);
  border: 0; border-radius: 50%; background: transparent; color: var(--text-soft);
  cursor: pointer; font: inherit; padding: 0;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }
.bell-dot {
  position: absolute; top: 4px; right: 2px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--danger); color: #fff; font-size: 11px; font-weight: var(--fw-bold);
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
  box-shadow: 0 0 0 2px var(--surface);
}

/* ---- phone: five-tab bottom bar ------------------------------------------- */
.tab-bar { display: none; }
@media (max-width: 899px) {
  .tab-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
  }
  .tab {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--text-muted); font-size: 12px; font-weight: var(--fw-medium); line-height: 1.1;
    min-width: 0; padding-top: 4px;
  }
  .tab:hover { text-decoration: none; color: var(--text); }
  /* Material-style active pill behind the icon. */
  .tab-ico {
    display: inline-flex; align-items: center; justify-content: center;
    width: 56px; height: 28px; border-radius: var(--r-pill);
    transition: background var(--dur) var(--ease);
  }
  .tab-ico svg { width: 22px; height: 22px; }
  .tab[aria-current="page"] { color: var(--text); font-weight: var(--fw-bold); }
  .tab[aria-current="page"] .tab-ico { background: var(--primary-soft); color: var(--primary-strong); }
  .tab .nav-badge {
    position: absolute; top: 2px; left: calc(50% + 10px);
    min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px;
  }
  .tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-3)); }
}

/* ---- desktop: left rail ---------------------------------------------------- */
.side-nav { display: none; }
@media (min-width: 900px) {
  body.shell { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-rows: 1fr; }
  .app-header { display: none; }
  .side-nav {
    display: flex; flex-direction: column; gap: 2px;
    grid-column: 1; grid-row: 1;
    position: sticky; top: 0; height: 100dvh; overflow-y: auto;
    padding: var(--sp-5) var(--sp-3) var(--sp-4);
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .app-main { grid-column: 2; grid-row: 1; padding-bottom: var(--sp-7); }
  .tab-bar { display: none !important; }
}

.rail-brand { display: inline-flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-2); color: var(--text); font-weight: var(--fw-bold); font-size: var(--fs-md); }
.rail-brand:hover { text-decoration: none; }
.rail-tagline { margin: 6px var(--sp-2) var(--sp-5); font-size: var(--fs-sm); line-height: 1.45; color: var(--text-muted); }
.rail-group { display: flex; flex-direction: column; gap: 2px; }
.rail-secondary { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.rail-item {
  position: relative;
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 44px; padding: 0 var(--sp-3); border-radius: var(--r-md);
  color: var(--text-soft); font-weight: var(--fw-medium);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.rail-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.rail-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary-strong); font-weight: var(--fw-bold); }
.rail-ico { display: inline-flex; flex: 0 0 auto; }
.rail-ico svg { width: 22px; height: 22px; }
.rail-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item .nav-badge { margin-left: auto; }
.rail-foot { margin-top: auto; padding-top: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); }
.rail-help {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-2); white-space: nowrap;
  min-height: 44px; border: 0; border-radius: var(--r-pill); cursor: pointer; font: inherit; font-weight: var(--fw-bold);
  background: var(--primary-soft); color: var(--primary-strong);
}
.rail-help:hover { background: var(--surface-3); }
.rail-help svg { width: 20px; height: 20px; }
.rail-foot-row { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 0 var(--sp-2); }
.rail-link { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 6px 0; font: inherit; font-size: var(--fs-sm); color: var(--text-muted); cursor: pointer; position: relative; }
.rail-link svg { width: 18px; height: 18px; }
.rail-link:hover { color: var(--text); text-decoration: underline; }
.rail-link .bell-dot { position: static; box-shadow: none; margin-left: 2px; }
.rail-note { margin: var(--sp-2) var(--sp-2) 0; font-size: var(--fs-xs); color: var(--text-muted); }

/* ---- phone menu sheet ------------------------------------------------------ */
.menu-me { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-4); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-2); }
.menu-handle { font-weight: var(--fw-bold); }
.menu-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.menu-list a {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 48px; padding: 0 var(--sp-2); border-radius: var(--r-md);
  color: var(--text); font-weight: var(--fw-medium);
}
.menu-list a:hover { background: var(--surface-3); text-decoration: none; }
.menu-list a span:first-child { display: inline-flex; color: var(--text-soft); }
.menu-list svg { width: 22px; height: 22px; }
.help-options { display: flex; flex-direction: column; gap: var(--sp-2); }

/* ------------------------------------------------------- global busy states */
#offline-banner, #socket-banner {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 120;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-3));
  max-width: min(560px, 92vw); box-shadow: var(--shadow-md);
}
@media (min-width: 900px) { #offline-banner, #socket-banner { bottom: var(--sp-5); } }

/* page transition — a gentle fade, never a whoosh */
.page-enter { animation: pageIn var(--dur-slow) var(--ease-out); }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* skeleton shimmer */
.sk { position: relative; overflow: hidden; background: var(--surface-3); border-radius: var(--r-md); }
.sk::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
  animation: sk 1.4s infinite;
}
[data-theme="dark"] .sk::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.07), transparent); }
@keyframes sk { 100% { transform: translateX(100%); } }

/* --------------------------------------------------------------------------
   "Bare" mode: public documents (landing, legal, auth, onboarding) render in
   their own full page without the app chrome. Full-bleed rooms (a single chat
   or group) hide the chrome on a phone only; on desktop they keep the rail.
   -------------------------------------------------------------------------- */
body.bare .app-header,
body.bare .side-nav,
body.bare .tab-bar { display: none !important; }
body.bare { grid-template-columns: 1fr !important; grid-template-rows: 1fr !important; }
body.bare .app-main { padding-bottom: 0; grid-column: 1 !important; }

body.bare[data-full-bleed="1"] .app-main { padding-bottom: 0; }
@media (min-width: 900px) {
  body.bare[data-full-bleed="1"] { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) !important; }
  body.bare[data-full-bleed="1"] .side-nav { display: flex !important; }
  body.bare[data-full-bleed="1"] .app-main { grid-column: 2 !important; grid-row: 1 !important; }
  body.bare[data-full-bleed="1"] .page-pad { max-width: none; }
}

/* printing: keep it plain */
@media print { .tab-bar, .side-nav, .app-header, .fab { display: none !important; } }

/* ---------------------------------------------------------------- app feel
   Browsers flash a blue box when you tap, and show a long-press menu on
   buttons. Apps don't. Turn both off. Keyboard focus rings are kept (see above)
   so keyboard users can still see where they are. */
*, *::before, *::after { -webkit-tap-highlight-color: transparent; }
a, button, [role="button"], .btn, .icon-btn, .tab, .chip, .bell-btn {
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
