:root { color-scheme: light dark; --side: 220px; --topbar: 52px; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
/* Kill accidental horizontal scroll on every page — prevents layouts with
   long codes, URLs, or wide tables from forcing the viewport wider than
   the screen on mobile. */
html, body { max-width: 100vw; overflow-x: hidden; }
img, video, iframe { max-width: 100%; height: auto; }
pre, code { overflow-wrap: anywhere; word-break: break-word; }
/* Tables inside .pane scroll horizontally inside their own container, not
   blow out the whole page layout. */
.pane .body { overflow-x: auto; }
@media (max-width: 860px) {
  /* Stop long tokens, urls, event codes from pushing the viewport wider. */
  .pane { max-width: 100vw; }
  .pane h1 { word-break: break-word; }
  table { max-width: 100%; }
  .topbar { flex-wrap: wrap; row-gap: 6px; }
}
body {
  font: 14.5px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f5f6f8; color: #1a1a1a;
}
@media (prefers-color-scheme: dark) {
  body { background: #121214; color: #e8e8ea; }
  .pane, .card, .msg, .cell, .tbar, .topbar { background: #1b1b1e !important; border-color: #2a2a2e !important; }
  .row:hover, .ch.active, .nav a.active, .nav a:hover { background: #232327 !important; }
  .muted { color: #8a8a8f !important; }
  input, textarea, select { background: #1b1b1e; color: inherit; border-color: #2a2a2e; }
  a { color: #7eb7ff; }
}
a { color: inherit; text-decoration: none; }

.app {
  display: grid;
  grid-template-columns: var(--side) 1fr;
  grid-template-rows: var(--topbar) 1fr;
  grid-template-areas: "side top" "side main";
  height: 100vh;
}
.hamburger {
  display: none;
  background: transparent; border: none; color: inherit;
  font-size: 22px; line-height: 1; padding: 4px 10px; cursor: pointer; border-radius: 6px;
}
.hamburger:hover { background: rgba(127,127,127,0.12); }

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar) 1fr;
    grid-template-areas: "top" "main";
  }
  .hamburger { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: var(--topbar);
    left: 0;
    height: calc(100vh - var(--topbar));
    width: min(280px, 80vw);
    transform: translateX(-100%);
    transition: transform 160ms ease;
    z-index: 30;
    background: #fff !important;
    box-shadow: 0 0 24px rgba(0,0,0,0.25);
  }
  @media (prefers-color-scheme: dark) { .sidebar { background: #1b1b1e !important; } }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: ""; position: fixed; inset: var(--topbar) 0 0 0; background: rgba(0,0,0,0.55); z-index: 29;
  }
  .topbar { padding: 0 10px; }
  .topbar .crumb { font-size: 14px; }
  .main { padding: 14px; }
  .pane { border-radius: 8px; }
  .pane h1 { padding: 14px; font-size: 17px; }
  .pane .body { padding: 14px; }
  table.sheet th, table.sheet td { min-width: 70px; width: 70px; }
  /* tables shrink gracefully */
  table.list { font-size: 12px; }
  table.list th, table.list td { padding: 6px 6px; }
  .summary .stat { flex: 1; min-width: 0; }
  /* people layout stacks */
  .people-layout, .chat-layout, .info-grid { grid-template-columns: 1fr !important; }
}
.sidebar {
  grid-area: side;
  border-right: 1px solid rgba(127,127,127,0.2);
  background: rgba(255,255,255,0.6);
  overflow-y: auto;
  padding: 14px 10px;
}
@media (prefers-color-scheme: dark) {
  .sidebar { background: rgba(0,0,0,0.25); }
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; padding: 4px 8px 16px;
}
.brand .logo {
  width: 24px; height: 24px; border-radius: 6px; background: linear-gradient(135deg,#6366f1,#ec4899);
  display: inline-flex; align-items: center; justify-content: center; color: white; font-size: 12px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: #888; padding: 14px 8px 6px; }
.nav .group-header {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 10px 8px 4px; margin-top: 6px;
  background: transparent; border: 0; color: inherit; font: inherit;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #888;
  cursor: pointer; text-align: left;
  border-top: 1px solid rgba(127,127,127,0.1);
}
.nav .group-header:first-of-type { border-top: none; margin-top: 0; }
.nav .group-header:hover { color: inherit; }
.nav .group-header.collapsed .group-caret { transform: rotate(0deg); }
.nav .group-caret { display: inline-block; width: 10px; opacity: 0.6; font-size: 10px; }
.nav .group-name { flex: 1; font-weight: 600; }
.nav .group-meta {
  font-size: 10px; opacity: 0.7; padding: 1px 6px;
  border-radius: 10px; background: rgba(127,127,127,0.12);
  letter-spacing: 0; text-transform: none;
}
.nav .group-body.hidden { display: none; }
.nav a {
  padding: 7px 10px; border-radius: 6px; display: flex; align-items: center; gap: 10px;
  color: inherit;
}
.nav a:hover { background: rgba(127,127,127,0.12); }
.nav a.active { background: rgba(99,102,241,0.14); color: #6366f1; font-weight: 600; }
.nav a .ico {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.85;
}
.nav a .badge {
  margin-left: auto; font-size: 10px; color: #888; padding: 1px 6px; border-radius: 8px;
  background: rgba(127,127,127,0.15);
}

.topbar {
  grid-area: top;
  border-bottom: 1px solid rgba(127,127,127,0.2);
  background: rgba(255,255,255,0.6);
  display: flex; align-items: center; gap: 14px; padding: 0 20px;
}
@media (prefers-color-scheme: dark) {
  .topbar { background: rgba(0,0,0,0.25); }
}
.topbar .crumb { font-weight: 600; flex: 1; }

.tenant-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 6px;
  border: 1px solid rgba(127,127,127,0.3); border-radius: 20px;
  background: transparent; color: inherit; font: inherit; cursor: pointer;
  font-size: 13px; line-height: 1.2;
}
.tenant-chip:hover { background: rgba(127,127,127,0.08); }
.tenant-chip .tc-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tenant-chip .tc-label { font-weight: 600; }
.tenant-chip .tc-kind { color: #888; font-size: 11px; margin-left: 4px; }
.tenant-chip .tc-caret { color: #888; margin-left: 2px; font-size: 10px; }

.role-sel, .person-sel {
  background: transparent; padding: 5px 8px; border-radius: 6px;
  border: 1px solid rgba(127,127,127,0.3); font: inherit; font-size: 13px;
}

/* -------- Command palette (⌘K / /) -------- */
.cmdk-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 16px 16px; z-index: 200;
}
.cmdk-panel {
  width: min(640px, 100%); background: #fff; color: #1a1a1a;
  border-radius: 10px; overflow: hidden; box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  display: flex; flex-direction: column; max-height: 70vh;
}
@media (prefers-color-scheme: dark) { .cmdk-panel { background: #1b1b1e; color: #e8e8ea; } }
.cmdk-input {
  padding: 16px; font: inherit; font-size: 16px; border: 0; outline: 0;
  background: transparent; color: inherit; width: 100%;
  border-bottom: 1px solid rgba(127,127,127,0.15);
}
.cmdk-list { overflow-y: auto; padding: 6px 0; }
.cmdk-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; color: inherit; font: inherit;
  padding: 8px 14px; cursor: pointer; text-align: left;
}
.cmdk-row.sel { background: rgba(99,102,241,0.12); }
.cmdk-row.ph .cmdk-label { opacity: 0.65; }
.cmdk-ico { width: 20px; text-align: center; }
.cmdk-label { flex: 1; font-size: 14px; }
.cmdk-href { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.cmdk-badge { font-size: 10px; padding: 1px 6px; border-radius: 10px; background: rgba(127,127,127,0.15); }
.cmdk-empty { padding: 20px; text-align: center; font-size: 13px; }

/* ⌘K hint chip in the topbar */
.cmdk-hint {
  background: transparent; color: #888; border: 1px solid rgba(127,127,127,0.2);
  border-radius: 6px; padding: 3px 8px; font-size: 11.5px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.cmdk-hint kbd {
  background: rgba(127,127,127,0.12); border-radius: 3px; padding: 0 4px;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cmdk-hint:hover { background: rgba(127,127,127,0.08); color: inherit; }

.tp-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex;
  align-items: flex-start; justify-content: center; z-index: 100;
  padding: 40px 20px; overflow-y: auto;
}
.tp-dialog {
  background: #fff; color: #1a1a1a; border-radius: 12px; padding: 20px;
  max-width: 1080px; width: 100%;
}
@media (prefers-color-scheme: dark) {
  .tp-dialog { background: #1b1b1e; color: #e8e8ea; }
}
.tp-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px;
}
.tp-card {
  border: 2px solid rgba(127,127,127,0.25); border-radius: 10px; background: transparent;
  color: inherit; font: inherit; text-align: left; cursor: pointer; padding: 0;
  overflow: hidden; transition: transform 0.1s;
}
.tp-card:hover { transform: translateY(-2px); }
.tp-card.active { outline: 3px solid var(--brand-accent, #6366f1); outline-offset: 2px; }
.tp-card .tp-head { padding: 10px 12px; font-weight: 700; font-size: 15px; }
.tp-card .tp-kind  { padding: 8px 12px 2px; font-size: 12px; font-weight: 600; color: #444; }
@media (prefers-color-scheme: dark) { .tp-card .tp-kind { color: #ddd; } }
.tp-card .tp-focus { padding: 0 12px 8px; font-size: 11.5px; }
.tp-card .tp-stats { padding: 8px 12px; border-top: 1px solid rgba(127,127,127,0.15); display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; }
.tp-card .tp-stat { display: flex; justify-content: space-between; gap: 10px; }
.tp-card .tp-stat .k { color: #888; text-transform: capitalize; }
.tp-card .tp-stat .v { text-align: right; }
.tp-card .tp-seeded   { padding: 6px 12px; color: #16a34a; font-size: 11px; font-weight: 600; border-top: 1px solid rgba(22,163,74,0.18); background: rgba(22,163,74,0.06); }
.tp-card .tp-unseeded { padding: 6px 12px; font-size: 11px; font-style: italic; border-top: 1px solid rgba(127,127,127,0.12); }
/* Global search */
.global-search-wrap { position: relative; flex: 1; max-width: 400px; margin: 0 8px; }
.global-search {
  width: 100%; padding: 6px 12px; border-radius: 8px;
  border: 1px solid rgba(127,127,127,0.3); background: rgba(255,255,255,0.4);
  font: inherit; color: inherit;
}
@media (prefers-color-scheme: dark) { .global-search { background: rgba(0,0,0,0.3); } }
.global-search:focus { outline: 2px solid #6366f1; outline-offset: 1px; }
.global-search-panel {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: #fff; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  max-height: 65vh; overflow-y: auto; z-index: 50; padding: 6px;
}
@media (prefers-color-scheme: dark) { .global-search-panel { background: #1b1b1e; } }
.gs-group { padding: 4px 0; }
.gs-head { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: #888; padding: 6px 10px 4px; font-weight: 700; border-top: 1px solid rgba(127,127,127,0.08); }
.gs-head:first-child, .gs-group:first-child .gs-head { border-top: 0; }
.gs-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 12px; border-radius: 6px; text-decoration: none; color: inherit; font-size: 13px; }
.gs-row:hover { background: rgba(99,102,241,0.12); }
.gs-name { font-weight: 500; }
.gs-sub { color: #888; font-size: 12px; }
.gs-empty { padding: 16px; text-align: center; color: #888; font-size: 13px; }
@media (max-width: 860px) { .global-search-wrap { display: none; } }

.topbar select {
  background: transparent; padding: 5px 8px; border-radius: 6px;
  border: 1px solid rgba(127,127,127,0.3); font: inherit;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%; color: white;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12px; flex-shrink: 0;
}
.avatar.small { width: 22px; height: 22px; font-size: 10px; }
.avatar.big { width: 48px; height: 48px; font-size: 18px; }

.main {
  grid-area: main; overflow: auto; padding: 24px;
}
.pane {
  max-width: 1100px; margin: 0 auto;
  background: #fff; border: 1px solid rgba(0,0,0,0.06); border-radius: 10px;
  overflow: hidden;
}
.pane h1 { margin: 0; padding: 18px 22px; font-size: 19px; border-bottom: 1px solid rgba(127,127,127,0.15); }
.pane .body { padding: 22px; }
.muted { color: #6b7280; font-size: 13px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.tile {
  padding: 18px; border: 1px solid rgba(127,127,127,0.18); border-radius: 10px;
  background: rgba(255,255,255,0.6); color: inherit; display: block;
  transition: transform 0.12s, box-shadow 0.12s;
}
@media (prefers-color-scheme: dark) { .tile { background: rgba(255,255,255,0.03); } }
.tile:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.tile .tile-ico { font-size: 22px; margin-bottom: 8px; }
.tile .tile-title { font-weight: 600; font-size: 15px; }
.tile .tile-sub { color: #888; font-size: 12px; margin-top: 4px; }
.tile.placeholder { opacity: 0.6; }
.tile.placeholder .tile-sub::after { content: " · coming soon"; }

.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid rgba(127,127,127,0.1); }
.row:last-child { border-bottom: none; }
.row:hover { background: rgba(127,127,127,0.06); cursor: pointer; }
.btn {
  background: #6366f1; color: white; border: none; padding: 7px 14px;
  border-radius: 6px; cursor: pointer; font: inherit; font-weight: 500; font-size: 13px;
}
.btn:hover { background: #4f46e5; }
.btn.secondary { background: transparent; color: inherit; border: 1px solid rgba(127,127,127,0.3); }
.btn.danger { background: transparent; color: #dc2626; border: 1px solid #dc2626; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* --- entity band (live-page footer) + Events panel --- */
.entity-band {
  margin-top: 24px; padding: 10px 14px; border-top: 1px dashed rgba(127,127,127,0.25);
  font-size: 11.5px; color: #888; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}
.entity-band .ent-sec { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.entity-band .ent-k { color: #6b7280; font-weight: 600; margin-right: 3px; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; }
.entity-band .ent-link { margin-left: auto; color: #6366f1; text-decoration: none; }
.entity-band .ent-link:hover { text-decoration: underline; }
.ent-chip {
  display: inline-block; font-size: 10.5px; padding: 1px 6px; margin: 1px 2px;
  border-radius: 10px; background: rgba(99,102,241,0.12); color: #6366f1;
}
.ent-chip.ent-read  { background: rgba(99,102,241,0.12); color: #6366f1; }
.ent-chip.ent-write { background: rgba(22,163,74,0.15);  color: #16a34a; }
.ent-chip.ent-event { background: rgba(217,119,6,0.15);  color: #d97706; }
.ent-chip.ent-link-chip { background: rgba(168,85,247,0.12); color: #a855f7; }

.entity-timeline {
  border: 1px solid rgba(127,127,127,0.18); border-radius: 8px; padding: 12px 14px;
  margin-top: 14px; font-size: 13px;
}
.entity-timeline .tl-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.entity-timeline .tl-title { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: #888; }
.entity-timeline .tl-empty {
  padding: 16px; text-align: center; border: 1px dashed rgba(127,127,127,0.25);
  border-radius: 6px; background: rgba(127,127,127,0.04);
}
.entity-timeline .tl-empty .tl-empty-icon { font-size: 24px; margin-bottom: 6px; }
.entity-timeline .tl-empty .tl-empty-msg { font-size: 13px; }
.entity-timeline .tl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.entity-timeline .tl-row { display: grid; grid-template-columns: 28px 1fr; gap: 8px; padding: 6px 2px; border-bottom: 1px solid rgba(127,127,127,0.07); }
.entity-timeline .tl-row:last-child { border-bottom: none; }
.entity-timeline .tl-verb { font-size: 16px; text-align: center; }
.entity-timeline .tl-summary { font-size: 13px; }
.entity-timeline .tl-meta { font-size: 11px; margin-top: 2px; }
.entity-timeline code.tl-vcode { background: rgba(127,127,127,0.1); padding: 0 4px; border-radius: 3px; }
