/* Playbook UI — design tokens */
:root {
  color-scheme: light;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --accent-border: #c7d2fe;
  --brand: var(--accent);

  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-text: #92400e;

  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #b91c1c;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --app-header-height: 60px;
  --document-anchor-offset: 88px;

  --shadow-sm: 0 1px 2px rgb(15 23 42 / 5%);
  --shadow: 0 1px 3px rgb(15 23 42 / 8%), 0 1px 2px rgb(15 23 42 / 4%);
  --shadow-lg: 0 10px 30px rgb(15 23 42 / 12%), 0 2px 8px rgb(15 23 42 / 6%);

  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #191a1c;
  --surface: #232427;
  --surface-muted: #2a2b2f;
  --border: #35363a;
  --border-strong: #4a4b50;

  --text: #f2f3f5;
  --text-secondary: #b6b8bd;
  --text-muted: #8b8d93;

  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: rgb(129 140 248 / 14%);
  --accent-border: rgb(129 140 248 / 35%);
  --brand: var(--text);

  --warn-bg: rgb(251 191 36 / 10%);
  --warn-border: rgb(251 191 36 / 35%);
  --warn-text: #fbbf24;

  --error-bg: rgb(248 113 113 / 10%);
  --error-border: rgb(248 113 113 / 35%);
  --error-text: #f87171;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-lg: 0 10px 30px rgb(0 0 0 / 50%);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #191a1c;
    --surface: #232427;
    --surface-muted: #2a2b2f;
    --border: #35363a;
    --border-strong: #4a4b50;

    --text: #f2f3f5;
    --text-secondary: #b6b8bd;
    --text-muted: #8b8d93;

    --accent: #818cf8;
    --accent-strong: #a5b4fc;
    --accent-soft: rgb(129 140 248 / 14%);
    --accent-border: rgb(129 140 248 / 35%);
    --brand: var(--text);

    --warn-bg: rgb(251 191 36 / 10%);
    --warn-border: rgb(251 191 36 / 35%);
    --warn-text: #fbbf24;

    --error-bg: rgb(248 113 113 / 10%);
    --error-border: rgb(248 113 113 / 35%);
    --error-text: #f87171;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 10px 30px rgb(0 0 0 / 50%);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

html {
  scroll-behavior: smooth;
}

::selection {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:is(button, input, select, textarea, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Inputs */
input,
select,
textarea,
.global-search input,
.section-search input,
.login-form input,
.login-form select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  padding: 8px 10px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #94a3b8;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

input[type="checkbox"] {
  accent-color: var(--accent);
  height: 15px;
  width: 15px;
}

textarea {
  min-height: 220px;
  resize: vertical;
  width: 100%;
  line-height: 1.6;
}

/* Buttons: neutral by default, primary on form submits */
button,
.actions a,
.session-actions a {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 500;
  gap: 6px;
  justify-content: center;
  padding: 7px 14px;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 60ms ease;
}

button:hover,
.actions a:hover,
.session-actions a:hover {
  background: var(--surface-muted);
  border-color: #94a3b8;
  color: var(--text);
  text-decoration: none;
}

button:active {
  transform: translateY(1px);
}

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

button[type="submit"]:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

html[data-theme="dark"] button[type="submit"] {
  background: #f2f3f5;
  border-color: #f2f3f5;
  color: #191a1c;
}

html[data-theme="dark"] button[type="submit"]:hover {
  background: #d7d8dc;
  border-color: #d7d8dc;
  color: #191a1c;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) button[type="submit"] {
    background: #f2f3f5;
    border-color: #f2f3f5;
    color: #191a1c;
  }

  html:not([data-theme="light"]) button[type="submit"]:hover {
    background: #d7d8dc;
    border-color: #d7d8dc;
    color: #191a1c;
  }
}

button:disabled {
  cursor: default;
  opacity: 0.55;
  transform: none;
}

/* Login / standalone panel pages */
.shell {
  min-height: 100vh;
  display: grid;
  place-items: start center;
  padding: 48px 24px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: min(720px, 100%);
}

/* App shell */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 20px;
  grid-template-columns: auto minmax(240px, 1fr) minmax(220px, 340px) auto;
  min-height: 60px;
  padding: 10px 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  align-items: center;
  color: var(--brand);
  display: inline-flex;
  font-size: 19px;
  font-weight: 700;
  min-height: 40px;
  text-decoration: none;
}

.brand:hover {
  color: var(--brand);
  text-decoration: none;
}

.brand.is-branding-loading {
  visibility: hidden;
}

.brand-logo {
  display: block;
  max-height: 36px;
  max-width: 180px;
  object-fit: contain;
}

/* Top navigation */
.top-nav {
  align-items: center;
  display: flex;
  gap: 4px;
  min-height: 40px;
}

.nav-item {
  display: flex;
  position: relative;
}

.nav-item > button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  padding: 7px 12px;
}

.nav-item > button:hover {
  background: var(--surface-muted);
  border-color: transparent;
  color: var(--text);
}

.nav-item:hover > button,
.nav-item:focus-within > button {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  left: 0;
  min-width: 280px;
  padding: 10px;
  position: absolute;
  top: calc(100% + 6px);
}

/* Invisible bridge across the 6px gap so moving the cursor from the center
   tab to the menu doesn't cross a dead zone and close the dropdown. */
.nav-menu::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 0;
  right: 0;
  height: 6px;
}

.nav-item:hover .nav-menu,
.nav-item:focus-within .nav-menu {
  display: grid;
  gap: 2px;
}

.nav-menu a {
  border-radius: var(--radius-sm);
  color: var(--text);
  display: block;
  padding: 7px 10px;
}

.nav-menu a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  text-decoration: none;
}

.dropdown-group {
  position: relative;
}

.dropdown-flyout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  left: calc(100% + 4px);
  list-style: none;
  margin: 0;
  min-width: 230px;
  padding: 8px;
  position: absolute;
  top: -8px;
}

/* Bridge the 4px horizontal gap to the flyout. */
.dropdown-flyout::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  width: 4px;
}

.dropdown-group:hover .dropdown-flyout,
.dropdown-group:focus-within .dropdown-flyout {
  display: block;
}

.dropdown-flyout li {
  margin: 0;
}

.dropdown-flyout a {
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: block;
  font-size: 14px;
  padding: 6px 10px;
}

.dropdown-flyout a:hover {
  background: var(--surface-muted);
  color: var(--text);
  text-decoration: none;
}

.section-link {
  color: var(--text);
  font-weight: 600;
}

/* Header search */
.global-search {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.global-search label {
  display: grid;
  gap: 4px;
}

.global-search span {
  display: none;
}

.global-search input {
  border-radius: 999px;
  padding: 8px 16px;
}

.global-search button {
  border-radius: 999px;
}

@media (min-width: 900px) {
  .global-search button {
    display: none;
  }
}

.section-search {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(200px, 420px) auto;
  margin: 20px 0 0;
}

.section-search label {
  display: grid;
  gap: 4px;
}

.section-search span,
.login-form span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

/* Account area */
.account {
  align-items: end;
  display: grid;
  gap: 6px;
  justify-items: end;
}

.current-user {
  align-items: center;
  display: flex;
  gap: 8px;
  text-align: right;
}

.avatar {
  align-items: center;
  background: #d9f99d;
  border-radius: 999px;
  color: #1a2e05;
  display: inline-flex;
  flex: 0 0 28px;
  font-size: 11px;
  font-weight: 700;
  height: 28px;
  justify-content: center;
  line-height: 1;
  width: 28px;
}

.user-details {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.user-name {
  font-weight: 600;
  line-height: 1.25;
}

.user-meta,
.muted {
  color: var(--text-muted);
  font-size: 12px;
}

.user-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.session-actions a,
.session-actions button {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 5px 9px;
}

.session-actions a:hover,
.session-actions button:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.theme-toggle {
  min-width: 30px;
}

#theme-toggle-static {
  position: fixed;
  right: 16px;
  top: 16px;
  z-index: 20;
}

/* Main content */
.main-content {
  margin: 28px auto;
  max-width: 960px;
  padding: 0 24px 64px;
  width: 100%;
}

.main-content.has-document-layout {
  max-width: 1064px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1 {
  border-bottom: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0 0 8px;
  padding-bottom: 0;
}

h2 {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 0;
}

h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.lede {
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.6;
  margin: 10px 0 28px;
  max-width: 65ch;
}

/* Cards and lists */
.section-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  margin-top: 24px;
}

.section-card,
.document-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.section-card {
  display: grid;
  gap: 10px;
  padding: 18px;
  transition: box-shadow 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.section-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.section-card p {
  color: var(--text-secondary);
  line-height: 1.55;
  margin: 0;
}

.stack {
  display: grid;
  gap: 8px;
}

.document-list {
  display: grid;
  gap: 0;
  margin-top: 24px;
  padding: 8px 20px;
}

.document-row {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.document-row:last-child {
  border-bottom: 0;
}

.document-row p {
  color: var(--text-secondary);
  line-height: 1.55;
  margin: 6px 0 0;
}

.search-results {
  margin-top: 8px;
}

.empty-note {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
  padding: 10px 0;
}

/* Ask Playbook */
.assistant-main {
  max-width: 920px;
}

/* Ask Playbook chat */
.main-content.has-chat-layout {
  margin: 0;
  max-width: none;
  padding: 0;
  flex: 1;
  min-height: 0;
  display: flex;
}

#home-chat,
#assistant-chat {
  flex: 1;
  min-height: 0;
  display: flex;
}

.app-shell.is-pwa-mode {
  background: var(--bg);
  min-height: 100dvh;
}

.app-shell.is-pwa-mode .app-header {
  display: none;
}

.app-shell.is-pwa-mode #app-status {
  left: max(12px, env(safe-area-inset-left));
  margin: 0;
  max-width: calc(100% - 24px);
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  z-index: 90;
}

.pwa-main {
  min-height: 100dvh;
}

.pwa-chat-shell {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 100dvh;
  min-width: 0;
}

.pwa-chat-header {
  align-items: center;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  display: grid;
  gap: 8px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-height: 58px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  position: sticky;
  top: 0;
  z-index: 20;
}

.pwa-title-block {
  display: grid;
  gap: 1px;
  justify-items: center;
  min-width: 0;
  text-align: center;
}

.pwa-app-name {
  font-size: 15px;
  font-weight: 700;
}

.pwa-tenant-name {
  color: var(--text-muted);
  font-size: 12px;
}

.pwa-icon-button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: inline-flex;
  height: 40px;
  justify-content: center;
  padding: 0;
  width: 40px;
}

.pwa-icon-button:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.is-pwa-chat .chat-layout {
  grid-template-columns: minmax(0, 1fr);
  height: calc(100dvh - 58px);
}

/* In PWA mode the sidebar becomes a ChatGPT-style drawer sliding in from
   the left; a backdrop dims the chat and closes the drawer on tap. */
.is-pwa-chat .chat-sidebar {
  bottom: 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  left: 0;
  max-width: calc(100vw - 56px);
  overflow: hidden;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  position: fixed;
  top: 0;
  transform: translateX(-105%);
  transition: transform 220ms ease, visibility 220ms;
  visibility: hidden;
  width: 320px;
  z-index: 70;
}

.is-pwa-chat .chat-sidebar.is-open {
  transform: none;
  visibility: visible;
}

.is-pwa-chat .chat-history {
  flex: 1;
}

.chat-drawer-backdrop {
  background: rgb(0 0 0 / 45%);
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  transition: opacity 220ms ease;
  z-index: 65;
}

.chat-drawer-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.chat-drawer-top {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding-left: 8px;
}

.chat-drawer-brand {
  font-size: 15px;
  font-weight: 700;
}

.chat-drawer-footer {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 2px;
  padding-top: 10px;
}

.chat-drawer-action {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex;
  font-size: 14px;
  font-weight: 500;
  justify-content: flex-start;
  padding: 9px 10px;
  text-align: left;
  width: 100%;
}

.chat-drawer-action:hover {
  background: var(--surface-muted);
  color: var(--text);
  text-decoration: none;
}

.chat-drawer-user {
  align-items: center;
  display: flex;
  gap: 10px;
  margin-top: 6px;
  padding: 8px 10px 0;
}

@media (prefers-reduced-motion: reduce) {
  .is-pwa-chat .chat-sidebar,
  .chat-drawer-backdrop {
    transition: none;
  }
}

.is-pwa-chat .chat-transcript {
  gap: 22px;
  padding: 22px 0 8px;
}

.is-pwa-chat .chat-message,
.is-pwa-chat .chat-intro {
  width: min(720px, calc(100% - 28px));
}

.is-pwa-chat .chat-composer {
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.chat-layout {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  height: calc(100vh - 61px);
}

.chat-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 16px 12px;
}

.chat-new {
  gap: 8px;
  justify-content: flex-start;
  width: 100%;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
}

.chat-history-group {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  margin: 16px 8px 4px;
  text-transform: uppercase;
}

.chat-history-row {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  min-height: 36px;
}

.chat-history-item {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  display: block;
  font-size: 14px;
  overflow: hidden;
  padding: 8px 4px 8px 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.chat-history-delete {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: inline-flex;
  height: 28px;
  justify-content: center;
  opacity: 0;
  padding: 0;
  width: 28px;
}

.chat-history-row:hover,
.chat-history-row:focus-within {
  background: var(--surface-muted);
  color: var(--text);
}

.chat-history-row:hover .chat-history-delete,
.chat-history-row:focus-within .chat-history-delete {
  opacity: 1;
}

.chat-history-delete:hover {
  color: var(--error-text);
}

.chat-history-row.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.chat-transcript {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 28px;
  overflow-y: auto;
  padding: 30px 0 8px;
}

.chat-layout.is-empty .chat-transcript {
  align-items: center;
  justify-content: center;
}

.chat-message,
.chat-intro {
  margin: 0 auto;
  width: min(720px, 92%);
}

.chat-intro {
  color: var(--text-secondary);
  text-align: center;
}

.chat-intro h1 {
  font-size: 26px;
  margin-bottom: 8px;
}

.chat-message.is-user {
  display: flex;
  justify-content: flex-end;
}

.chat-bubble {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 16px;
  color: var(--text);
  max-width: 80%;
  padding: 10px 16px;
}

.chat-answer {
  line-height: 1.7;
}

.chat-answer > :first-child {
  margin-top: 0;
}

.chat-answer h2 {
  font-size: 17px;
  margin: 22px 0 8px;
}

.chat-answer h3,
.chat-answer h4,
.chat-answer h5 {
  font-size: 15px;
  margin: 18px 0 6px;
}

.chat-answer p {
  margin: 0 0 12px;
}

.chat-answer .document-markdown-list {
  margin: 0 0 12px;
  padding-left: 24px;
}

.chat-answer code {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 1px 5px;
}

.chat-answer .document-blockquote {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  margin: 0 0 12px;
  padding: 8px 14px;
}

.chat-answer .document-table-wrap {
  margin: 0 0 12px;
  overflow-x: auto;
}

.chat-answer .document-table {
  border-collapse: collapse;
  width: 100%;
}

.chat-answer .document-table th,
.chat-answer .document-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.chat-refusal {
  color: var(--warn-text);
  font-size: 13px;
  margin: 8px 0 0;
}

.chat-citations {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chat-citation {
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  font-size: 13px;
  gap: 6px;
  padding: 5px 12px;
}

.chat-citation:hover {
  border-color: var(--accent-border);
  color: var(--text);
  text-decoration: none;
}

.chat-citation-icon {
  color: var(--text-muted);
  display: inline-flex;
}

.chat-citation-type {
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-citation-ref {
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  display: inline-flex;
  justify-content: center;
  margin: 0 2px;
  padding: 1px 4px;
  vertical-align: baseline;
}

.chat-citation-ref:hover {
  border-color: var(--accent-border);
  color: var(--text);
  text-decoration: none;
}

.chat-citation-ref-icon {
  display: inline-flex;
}

.chat-citation-ref-icon svg {
  height: 12px;
  width: 12px;
}

.chat-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}

.chat-thinking {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  gap: 10px;
}

.chat-thinking-label {
  font-size: 14px;
}

.chat-thinking-dots {
  display: inline-flex;
  gap: 4px;
}

.chat-thinking-dot {
  animation: chat-thinking-bounce 1.2s infinite ease-in-out;
  background: var(--text-muted);
  border-radius: 50%;
  height: 6px;
  width: 6px;
}

.chat-thinking-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-thinking-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-thinking-bounce {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-thinking-dot {
    animation: none;
  }
}

.source-viewer {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  inset: 0;
  min-height: 100dvh;
  position: fixed;
  z-index: 80;
}

.source-viewer[hidden] {
  display: none;
}

.source-viewer-header {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 12px max(14px, env(safe-area-inset-left));
}

.source-viewer-title {
  min-width: 0;
}

.source-viewer-title h2 {
  font-size: 17px;
  margin: 0;
}

.source-viewer-meta {
  color: var(--text-muted);
  font-size: 12px;
  margin: 2px 0 0;
}

.source-viewer-close {
  flex: 0 0 auto;
}

.source-viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px max(16px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.source-viewer-body .document-body,
.source-excerpt {
  margin: 0 auto;
  max-width: 760px;
}

.source-excerpt {
  background: var(--surface);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  padding: 14px 16px;
}

.source-excerpt p:last-child {
  margin-bottom: 0;
}

.offline-page {
  display: grid;
  min-height: 100dvh;
  padding: 24px;
  place-items: center;
}

.offline-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 460px;
  padding: 28px;
}

.offline-panel h1 {
  margin-top: 0;
}

.chat-action {
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
}

.chat-action:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.chat-action.is-done {
  color: var(--accent);
}

.chat-composer {
  padding: 12px 0 18px;
}

.chat-input-wrap {
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 8px;
  margin: 0 auto;
  padding: 6px 6px 6px 18px;
  width: min(720px, 92%);
}

.chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.chat-input {
  background: transparent;
  border: 0;
  box-shadow: none;
  flex: 1;
  /* 16px minimum: anything smaller makes iOS Safari auto-zoom on focus */
  font-size: 16px;
  line-height: 1.5;
  max-height: 200px;
  min-height: 0;
  outline: none;
  padding: 8px 0;
  resize: none;
}

.chat-input:hover,
.chat-input:focus {
  border: 0;
  box-shadow: none;
}

/* The wrap shows the focus ring; suppress the inner outline */
.chat-input:focus-visible {
  outline: none;
}

.chat-send {
  border-radius: 50%;
  flex: none;
  height: 34px;
  padding: 0;
  width: 34px;
}

.chat-footnote {
  color: var(--text-muted);
  font-size: 12px;
  margin: 10px 0 0;
  text-align: center;
}

@media (max-width: 820px) {
  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 61px);
  }

  .chat-sidebar {
    display: none;
  }
}

/* Document page */
/* Document pages break out of the centered container: the TOC rail sits at
   the far left, separated from the content by a border and its own surface. */
.app-shell:has(.doc-layout) .main-content {
  margin: 0;
  max-width: none;
  padding: 0 0 64px;
}

.doc-layout {
  align-items: stretch;
  display: grid;
  gap: 0;
  grid-template-columns: 260px minmax(0, 1fr);
  justify-content: start;
  min-height: calc(100vh - var(--app-header-height));
}

.document-column {
  min-width: 0;
  max-width: 820px;
  padding: 28px 40px 0;
  scroll-behavior: smooth;
}

.toc {
  align-self: start;
  background: var(--surface);
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  height: calc(100vh - var(--app-header-height));
  overflow-y: auto;
  padding: 28px 20px 28px 24px;
  position: sticky;
  top: var(--app-header-height);
}

.toc-inner {
  position: static;
}

.toc-eyebrow {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
}

.toc nav {
  display: grid;
  gap: 2px;
}

.toc a {
  border-left: 2px solid transparent;
  color: var(--text-muted);
  display: block;
  font-size: 13px;
  line-height: 1.35;
  padding: 5px 0 5px 10px;
}

.toc a:hover {
  color: var(--text);
  text-decoration: none;
}

.toc a.is-active {
  border-left-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.toc a.toc-level-3 {
  padding-left: 22px;
}

.breadcrumbs {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 6px;
  margin: 0 0 12px;
}

.breadcrumbs a {
  color: var(--text-muted);
}

.breadcrumbs a:hover {
  color: var(--accent);
}

.document-title-row {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.document-title-row h1 {
  margin-bottom: 0;
  min-width: 0;
}

.document-meta {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 6px 14px;
  margin: 10px 0 18px;
}

.document-meta span {
  border-right: 0;
  padding-right: 0;
}

.document-meta .content-type-badge {
  flex: 0 0 auto;
  margin: 0;
}

.document-meta-item,
.meta-separator {
  color: var(--text-muted);
}

.content-type-badge {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  color: var(--accent-strong);
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 4px 0 6px;
  padding: 3px 10px;
  text-transform: uppercase;
}

.document-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin: 0;
}

.document-actions a {
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
}

.button-icon {
  color: var(--accent-strong);
  font-weight: 700;
  line-height: 1;
}

.doc-tabs {
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 18px;
  margin: 0 0 18px;
  overflow-x: auto;
}

.doc-tabs button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: -1px;
  padding: 0 0 10px;
}

.doc-tabs button:hover {
  background: transparent;
  border-bottom-color: var(--accent-border);
  color: var(--text);
}

.doc-tabs button.is-active {
  border-bottom-color: var(--accent);
  color: var(--text);
}

.tab-chip {
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  min-width: 20px;
  padding: 3px 6px;
  text-align: center;
}

.doc-tab-panels {
  min-width: 0;
}

.tab-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.tab-row {
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 14px;
  padding: 13px 16px;
}

.tab-row:last-child {
  border-bottom: 0;
}

.suggestion-row {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.suggestion-row > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.suggestion-row strong {
  color: var(--text);
}

.document-raw {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  margin: 0;
  overflow-x: auto;
  padding: 18px;
}

.document-content {
  line-height: 1.7;
  padding: 4px 0 0;
}

.document-content h2,
.document-content h3,
.document-content h4 {
  border-bottom: 1px solid var(--border);
  margin: 26px 0 10px;
  padding-bottom: 6px;
  scroll-margin-top: var(--document-anchor-offset);
}

.document-content h2:first-child,
.document-content h3:first-child,
.document-content h4:first-child {
  margin-top: 0;
}

.document-content p {
  margin: 0 0 14px;
}

.document-image {
  display: block;
  height: auto;
  margin: 16px 0;
  max-width: 100%;
}

.document-markdown-list {
  margin: 0 0 14px;
  padding-left: 26px;
}

.document-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.document-content code {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 1px 5px;
}

.document-code-block {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0 0 16px;
  overflow-x: auto;
  padding: 12px 14px;
}

.document-code-block code {
  background: transparent;
  border: 0;
  border-radius: 0;
  display: block;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 0;
  white-space: pre;
}

.document-blockquote {
  border-left: 3px solid var(--accent-border);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  margin: 0 0 14px;
  padding: 10px 16px;
}

.document-blockquote p {
  margin: 0 0 6px;
}

.document-blockquote p:last-child {
  margin-bottom: 0;
}

.document-table-wrap {
  margin: 0 0 16px;
  overflow-x: auto;
}

.document-table {
  border-collapse: collapse;
  width: 100%;
}

.document-table th,
.document-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.document-table th {
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 650;
}

/* Document authoring */
.document-editor-form {
  margin: 0;
}

.document-editor-sidebar-inner {
  display: grid;
  gap: 12px;
}

.document-editor-sidebar label,
.document-title-field,
.document-body-field {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.document-editor-sidebar label > span,
.document-title-field > span,
.document-body-field > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.document-editor-sidebar input,
.document-editor-sidebar select,
.document-editor-sidebar textarea {
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.document-editor-sidebar textarea {
  min-height: 100px;
}

.document-editor-sidebar .checkbox-field {
  align-items: center;
  display: flex;
  gap: 8px;
}

.document-editor-sidebar .checkbox-field input {
  flex: 0 0 auto;
  width: 15px;
}

.document-editor-sidebar .checkbox-field span {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.document-editor-title-row {
  align-items: end;
  margin-bottom: 0;
}

.document-title-field {
  flex: 1 1 auto;
}

.document-title-field input {
  background: transparent;
  border-color: transparent transparent var(--border-strong);
  border-radius: 0;
  box-shadow: none;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.2;
  min-width: 0;
  padding: 2px 0 7px;
  width: 100%;
}

.document-title-field input:hover,
.document-title-field input:focus {
  background: transparent;
  border-color: transparent transparent var(--accent);
  box-shadow: none;
}

.document-body-field {
  margin-top: 14px;
}

.document-body-field textarea {
  min-height: 420px;
}

.document-body-field .playbook-editor {
  margin-top: 3px;
}

.document-body-field .editor-surface,
.document-body-field .editor-surface .ProseMirror {
  min-height: 420px;
}

/* Generic action rows */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Login */
.auth-panel {
  display: grid;
  gap: 16px;
  padding: 36px;
}

.auth-panel h1 {
  letter-spacing: 0;
  line-height: 1.16;
  margin: 0;
}

.auth-panel .lede {
  margin: 0;
  max-width: 620px;
}

.auth-primary-actions {
  margin-top: 8px;
}

.auth-footer-actions {
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 18px;
}

.auth-footer-actions button {
  color: var(--text-secondary);
}

.login-form {
  display: grid;
  gap: 18px;
  margin-top: 24px;
}

.login-form label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.login-form input,
.login-form select {
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.tenant-picker {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.tenant-option {
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 3px;
  justify-items: start;
  padding: 14px 16px;
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
  width: 100%;
}

.tenant-option:hover {
  background: var(--surface);
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.tenant-option-label {
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
}

.tenant-option-meta {
  color: var(--text-muted);
  font-size: 13px;
}

/* Notices and findings */
.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  color: var(--warn-text);
  line-height: 1.5;
  margin: 16px auto;
  max-width: 960px;
  padding: 10px 14px;
}

.notice.is-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

.notice[hidden] {
  display: none;
}

.validation-findings {
  margin-left: 0;
  margin-right: 0;
}

.validation-findings h3 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin: 0 0 6px;
  text-transform: uppercase;
}

.validation-findings ul {
  margin: 0;
  padding-left: 20px;
}

.validation-finding {
  margin: 4px 0;
}

/* Admin lists */
.admin-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.admin-row {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 16px;
}

.admin-row-info {
  display: grid;
  gap: 2px;
}

.admin-row-label {
  font-weight: 600;
}

.admin-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-row-actions button {
  font-size: 13px;
  padding: 5px 11px;
}

.admin-detail {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 4px 0 4px 20px;
  padding: 14px 16px;
  width: 100%;
}

.admin-form {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.admin-form label {
  display: grid;
  gap: 4px;
}

.admin-form label > span,
.admin-form-stacked label > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.admin-form-stacked {
  align-items: stretch;
  flex-direction: column;
}

/* Markdown-serializing editor */
.playbook-editor {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  display: grid;
  gap: 0;
  overflow: hidden;
}

.playbook-editor [hidden],
.editor-dialog [hidden] {
  display: none !important;
}

.editor-modebar,
.editor-toolbar {
  align-items: center;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
}

.editor-modebar {
  justify-content: flex-end;
}

.editor-toolbar-group {
  align-items: center;
  border-right: 1px solid var(--border);
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding-right: 6px;
}

.editor-toolbar-group:last-child {
  border-right: 0;
  padding-right: 0;
}

.editor-toolbar-button,
.editor-dialog-tabs button {
  font-size: 13px;
  min-height: 32px;
  padding: 5px 9px;
}

.editor-toolbar-button.is-active,
.editor-dialog-tabs button.is-active,
.editor-modebar button.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-strong);
}

.editor-block-select {
  display: inline-flex;
}

.editor-block-select select {
  font-size: 13px;
  min-height: 32px;
  padding: 5px 30px 5px 9px;
}

.editor-surface {
  min-height: 300px;
}

.editor-surface .ProseMirror {
  min-height: 300px;
  outline: none;
  padding: 16px;
}

.editor-surface .ProseMirror > *:first-child {
  margin-top: 0;
}

.editor-surface .ProseMirror > *:last-child {
  margin-bottom: 0;
}

.editor-surface .ProseMirror h2,
.editor-surface .ProseMirror h3,
.editor-surface .ProseMirror h4 {
  line-height: 1.25;
  margin: 20px 0 8px;
}

.editor-surface .ProseMirror h2 {
  font-size: 24px;
}

.editor-surface .ProseMirror h3 {
  font-size: 20px;
}

.editor-surface .ProseMirror h4 {
  font-size: 17px;
}

.editor-surface .ProseMirror p {
  margin: 0 0 12px;
}

.editor-surface .ProseMirror img {
  display: block;
  height: auto;
  margin: 14px 0;
  max-width: 100%;
}

.editor-surface .ProseMirror ul,
.editor-surface .ProseMirror ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.editor-surface .ProseMirror blockquote {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  margin: 0 0 12px;
  padding: 10px 14px;
}

.editor-surface .ProseMirror code {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 1px 5px;
}

.editor-surface .ProseMirror pre {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0 0 14px;
  overflow-x: auto;
  padding: 12px 14px;
}

.editor-surface .ProseMirror pre code {
  background: transparent;
  border: 0;
  display: block;
  padding: 0;
  white-space: pre;
}

.editor-surface .ProseMirror table {
  border-collapse: collapse;
  margin: 0 0 14px;
  width: 100%;
}

.editor-surface .ProseMirror th,
.editor-surface .ProseMirror td {
  border: 1px solid var(--border);
  min-width: 80px;
  padding: 8px 10px;
  vertical-align: top;
}

.editor-surface .ProseMirror th {
  background: var(--surface-muted);
  color: var(--text-secondary);
  font-weight: 650;
}

.editor-lossy-notice,
.editor-upload-notice {
  align-items: center;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  display: flex;
  justify-content: space-between;
  margin: 0;
  max-width: none;
}

.editor-dialog-backdrop {
  align-items: center;
  background: rgb(15 23 42 / 45%);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 100;
}

.editor-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 12px;
  max-width: 520px;
  padding: 18px;
  width: min(520px, 100%);
}

.editor-dialog h2 {
  font-size: 18px;
  margin: 0;
}

.editor-dialog label {
  display: grid;
  gap: 4px;
}

.editor-dialog label > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.editor-dialog-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-dialog-notice {
  color: var(--error-text);
  margin: 0;
}

.editor-document-results {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: grid;
  gap: 0;
  max-height: 220px;
  overflow: auto;
}

.editor-document-result {
  align-items: start;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  display: grid;
  justify-items: start;
  padding: 9px 10px;
  text-align: left;
}

.editor-document-result:last-child {
  border-bottom: 0;
}

.editor-document-result-title {
  font-weight: 600;
}

.editor-document-result-path {
  color: var(--text-muted);
  font-size: 12px;
}

.color-field {
  max-width: 360px;
}

.color-control {
  align-items: center;
  display: flex;
  gap: 10px;
}

.color-control input[type="color"] {
  height: 40px;
  padding: 3px;
  width: 48px;
}

.logo-preview {
  align-items: flex-start;
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.logo-preview img {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 72px;
  max-width: 240px;
  object-fit: contain;
  padding: 8px;
}

.permission-set {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.permission-set legend {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0 6px;
  text-transform: uppercase;
}

.permission-option {
  display: block;
  margin: 6px 0;
}

/* Suggestion review */
.suggestion-meta {
  display: grid;
  gap: 4px;
  margin: 0 0 14px;
}

.suggestion-meta-line {
  align-items: center;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 6px;
}

.suggestion-channel-chip {
  background: var(--surface-muted);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  color: var(--text-secondary);
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
}

.bulk-action-bar {
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding: 10px 14px;
}

.bulk-select-all,
.bulk-select-item {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.bulk-comment {
  min-width: 220px;
}

.suggestion-review-form {
  display: grid;
  gap: 14px;
  margin: 14px 0;
}

.suggestion-review-fields {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.suggestion-review-fields label {
  display: grid;
  gap: 4px;
}

.suggestion-review-fields label > span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.suggestion-review-fields textarea {
  min-height: 64px;
  resize: vertical;
}

.suggestion-review-fields .checkbox-label {
  align-items: center;
  align-self: end;
  display: inline-flex;
  gap: 8px;
  min-height: 38px;
}

.suggestion-review-editor-heading {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0;
  text-transform: uppercase;
}

.suggestion-review-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 520px;
  min-height: 360px;
  overflow: hidden;
}

.suggestion-review-editor .diff-columns {
  height: 100%;
  margin: 0;
}

.suggestion-review-editor textarea {
  background: var(--surface);
  border: 0;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  min-height: 360px;
  padding: 14px;
  resize: vertical;
  width: 100%;
}

.diff-columns {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin: 14px 0;
}

.diff-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.diff-pane h4 {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0;
  text-transform: uppercase;
}

.diff-pane pre {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Modal */
.modal-backdrop {
  align-items: center;
  backdrop-filter: blur(2px);
  background: rgb(15 23 42 / 45%);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 48px);
  max-width: 680px;
  overflow: auto;
  padding: 24px;
  width: 100%;
}

.modal .notice {
  margin: 0;
}

.email-preview-body {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  margin: 0;
  overflow-wrap: anywhere;
  padding: 14px;
  white-space: pre-wrap;
}

/* API tokens */
.token-reveal {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  display: grid;
  gap: 10px;
  margin: 18px 0;
  padding: 16px 18px;
}

.token-secret,
.token-snippet {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  margin: 0;
  overflow-wrap: anywhere;
  padding: 12px;
  white-space: pre-wrap;
}

.api-token-table {
  border-collapse: collapse;
  margin-top: 12px;
  width: 100%;
}

.api-token-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-top: 14px;
  overflow-x: auto;
  padding: 4px 16px 8px;
}

.api-token-table th,
.api-token-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

.api-token-table tr:last-child td {
  border-bottom: 0;
}

.api-token-table th {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.api-token-name {
  font-weight: 600;
}

.api-token-table tr.is-muted {
  color: var(--text-muted);
  opacity: 0.6;
}

/* Motion preferences */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  * {
    transition: none !important;
  }
}

/* Responsive */
@media (max-width: 999px) {
  .doc-layout {
    display: block;
  }

  .toc {
    display: none;
  }

  .document-edit-layout .document-editor-sidebar {
    border-bottom: 1px solid var(--border);
    border-right: 0;
    display: block;
    padding: 18px 20px;
  }

  .document-edit-layout .document-editor-sidebar-inner {
    position: static;
  }

  .document-column {
    margin: 0 auto;
    max-width: 760px;
  }
}

@media (max-width: 900px) {
  .app-header {
    align-items: stretch;
    grid-template-columns: 1fr;
    padding: 12px 16px;
    position: static;
  }

  .top-nav {
    min-height: auto;
    overflow-x: auto;
  }

  .nav-item {
    position: static;
  }

  .nav-menu {
    left: 12px;
    right: 12px;
    top: auto;
  }

  .account {
    justify-items: start;
  }

  .current-user {
    text-align: left;
  }

  .main-content {
    margin-top: 16px;
    padding: 0 16px 48px;
  }

  .document-content {
    padding: 20px;
  }

  .document-title-row {
    display: grid;
    gap: 10px;
  }

  .document-actions {
    justify-content: flex-start;
  }

  .suggestion-row {
    align-items: start;
    display: grid;
  }
}

.app-shell.is-pwa-mode .main-content {
  margin-top: 0;
  padding: 0;
}

.app-shell.is-pwa-mode .chat-layout {
  height: calc(100dvh - 58px);
  min-height: 0;
}
