/*
 * My Digital Space - reusable UI primitives
 * Opt-in ui-* classes let existing pages adopt the system incrementally.
 */

html {
  background: var(--color-bg-page);
  color: var(--color-text-primary);
  font-family: var(--font-body);
}

body,
button,
input,
select,
textarea {
  font-family: var(--font-body);
}

/* Page headers */
.ui-page-header {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) minmax(0, auto);
  align-items: end;
  gap: var(--space-6);
}

.ui-page-header--no-back {
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
}

.ui-page-header--no-actions {
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
}

.ui-page-header--no-back.ui-page-header--no-actions {
  display: block;
}

.ui-page-header__back {
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
}

.ui-page-header__back:hover {
  color: var(--color-primary);
}

.ui-page-header__eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.16em;
}

.ui-page-header__title {
  margin: 0;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: var(--font-size-page-title);
  font-weight: 400;
  line-height: var(--line-height-tight);
}

.ui-page-header__subtitle {
  max-width: 68ch;
  margin: var(--space-2) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
}

.ui-page-header__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.ui-page-header__meta {
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--shadow-focus);
}

:where(button, input, select, textarea):disabled,
:where(.ui-button, .ui-icon-button)[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.52;
}

/* Buttons */
.ui-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control);
  background: transparent;
  padding: 0 var(--space-4);
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}

.ui-button:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary-hover);
}

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

.ui-button--primary {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.ui-button--primary:hover {
  border-color: var(--color-primary-hover);
  background: var(--color-primary-hover);
  color: var(--color-text-inverse);
}

.ui-button--quiet {
  border-color: transparent;
  color: var(--color-text-secondary);
}

.ui-button--quiet:hover {
  border-color: transparent;
  background: var(--color-bg-subtle);
  color: var(--color-primary-hover);
}

.ui-button--danger {
  border-color: rgba(150, 84, 76, 0.3);
  color: var(--color-error);
}

.ui-button--danger:hover {
  border-color: var(--color-error);
  background: var(--color-error-soft);
  color: var(--color-error);
}

/* Icon buttons should include aria-label; data-tooltip is optional. */
.ui-icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-control-sm);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);
}

.ui-icon-button:hover {
  border-color: var(--color-border);
  background: var(--color-bg-subtle);
  color: var(--color-primary);
}

.ui-icon-button:active {
  transform: translateY(1px);
}

/* Form controls */
.ui-input,
.ui-select,
.ui-search {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  outline: 0;
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  font-size: var(--font-size-body);
  line-height: var(--line-height-compact);
  transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}

.ui-input,
.ui-search {
  padding: var(--space-2) var(--space-3);
}

textarea.ui-input {
  min-height: 112px;
  resize: vertical;
  line-height: var(--line-height-body);
}

.ui-input::placeholder,
.ui-search::placeholder {
  color: var(--color-text-muted);
}

.ui-input:hover,
.ui-select:hover,
.ui-search:hover {
  border-color: var(--color-border-strong);
}

.ui-input:focus,
.ui-select:focus,
.ui-search:focus {
  border-color: var(--color-primary);
}

.ui-search {
  padding-left: 38px;
  background-image: radial-gradient(circle, transparent 54%, currentColor 56%, currentColor 65%, transparent 67%), linear-gradient(currentColor, currentColor);
  background-position: 13px 50%, 25px calc(50% + 7px);
  background-size: 15px 15px, 7px 1px;
  background-repeat: no-repeat;
  color: var(--color-text-secondary);
}

.ui-search:focus,
.ui-search:not(:placeholder-shown) {
  color: var(--color-text-primary);
}

.ui-select {
  appearance: none;
  padding: 0 38px 0 var(--space-3);
  background-image: linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%), linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.ui-field-error {
  margin: var(--space-2) 0 0;
  color: var(--color-error);
  font-size: var(--font-size-meta);
  line-height: var(--line-height-compact);
}

/* Tags and statuses */
.ui-tag,
.ui-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  gap: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-bg-muted);
  padding: 2px var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
}

.ui-status--success {
  border-color: rgba(79, 117, 95, 0.2);
  background: var(--color-success-soft);
  color: var(--color-success);
}

.ui-status--warning {
  border-color: rgba(139, 106, 54, 0.2);
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.ui-status--error {
  border-color: rgba(150, 84, 76, 0.2);
  background: var(--color-error-soft);
  color: var(--color-error);
}

.ui-status--danger {
  border-color: rgba(150, 84, 76, 0.2);
  background: var(--color-error-soft);
  color: var(--color-error);
}

.ui-status--muted,
.ui-status--private {
  border-color: var(--color-divider);
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
}

.ui-status--public {
  border-color: rgba(79, 117, 95, 0.2);
  background: var(--color-success-soft);
  color: var(--color-success);
}

.ui-status--pending {
  border-color: rgba(139, 106, 54, 0.2);
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.ui-status__icon {
  font-size: 0.9em;
  line-height: 1;
}

/* Surfaces */
.ui-surface {
  background: var(--color-surface);
  color: var(--color-text-primary);
}

.ui-surface--contained {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  padding: var(--space-6);
}

.ui-surface--quiet {
  border-radius: var(--radius-container);
  background: var(--color-bg-subtle);
  padding: var(--space-6);
}

/* Dialogs */
.ui-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-dialog);
  background: var(--color-surface);
  box-shadow: var(--shadow-dialog);
  color: var(--color-text-primary);
}

.ui-dialog::backdrop {
  background: rgba(24, 36, 30, 0.42);
}

.ui-dialog__header,
.ui-dialog__body,
.ui-dialog__footer {
  padding: var(--space-5) var(--space-6);
}

.ui-dialog__header {
  border-bottom: 1px solid var(--color-divider);
}

.ui-dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  border-top: 1px solid var(--color-divider);
}

.ui-dialog__header--embedded {
  padding: 0;
  border-bottom: 0;
}

.ui-dialog__header--danger h2 {
  color: var(--color-error);
}

.ui-dialog__eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.16em;
}

.ui-dialog__description {
  max-width: 52ch;
  margin: var(--space-2) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
}

/* Empty, loading and error states */
.ui-empty-state,
.ui-loading-state,
.ui-error-state {
  display: grid;
  min-height: 180px;
  place-items: center;
  align-content: center;
  gap: var(--space-2);
  padding: var(--space-8);
  color: var(--color-text-secondary);
  text-align: center;
}

.ui-empty-state__title,
.ui-error-state__title {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
  font-weight: 650;
}

.ui-empty-state__copy,
.ui-error-state__copy {
  max-width: 42ch;
  margin: 0;
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
}

.ui-empty-state__icon {
  color: var(--color-text-muted);
  font-size: 1.25rem;
  line-height: 1;
}

.ui-empty-state__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.ui-empty-state--compact {
  min-height: 120px;
  padding: var(--space-6);
}

.ui-error-state {
  border-radius: var(--radius-container);
  background: var(--color-error-soft);
  color: var(--color-error);
}

.ui-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: ui-spin 800ms linear infinite;
}

@keyframes ui-spin {
  to { transform: rotate(360deg); }
}

/* Tables */
.ui-table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
}

.ui-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
  text-align: left;
}

.ui-table th,
.ui-table td {
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-4);
  vertical-align: middle;
}

.ui-table th {
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
  font-weight: 650;
  letter-spacing: 0.02em;
}

.ui-table tbody tr {
  transition: background-color var(--duration-fast) var(--ease-standard);
}

.ui-table tbody tr:hover {
  background: var(--color-bg-subtle);
}

.ui-table tbody tr:last-child td {
  border-bottom: 0;
}

/* Dividers and tooltips */
.ui-divider {
  height: 1px;
  margin: var(--space-4) 0;
  border: 0;
  background: var(--color-divider);
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  right: 50%;
  bottom: calc(100% + 8px);
  z-index: 100;
  width: max-content;
  max-width: 220px;
  transform: translate(50%, 3px);
  border-radius: var(--radius-control-sm);
  background: var(--color-surface-inverse);
  box-shadow: var(--shadow-popover);
  padding: 6px 8px;
  color: var(--color-text-inverse);
  font-size: var(--font-size-micro);
  font-weight: 500;
  line-height: 1.4;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard), visibility var(--duration-fast) var(--ease-standard);
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  transform: translate(50%, 0);
  opacity: 1;
  visibility: visible;
}

/* Authenticated application shell */
body.app-page {
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--color-bg-page);
  color: var(--color-text-primary);
}

.app-shell {
  --app-sidebar-width: 232px;
  --app-topbar-height: 70px;
  display: grid;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  grid-template-columns: var(--app-sidebar-width) minmax(0, 1fr);
  overflow: hidden;
  background: var(--color-bg-page);
}

.app-global-sidebar {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--color-divider);
  background: var(--color-bg-subtle);
  padding: var(--space-6) var(--space-4) var(--space-4);
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

.app-shell > .app-global-sidebar.side-panel {
  position: relative;
  inset: auto;
  width: auto;
  min-width: 0;
  height: auto;
  padding: var(--space-6) var(--space-4) var(--space-4);
  background: var(--color-bg-subtle);
  box-shadow: none;
}

.app-global-sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 var(--space-2) var(--space-8);
  color: var(--color-text-primary);
}

.app-global-sidebar__brand > span {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border-radius: var(--radius-control);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-display);
  font-size: 1rem;
}

.app-global-sidebar__brand strong,
.app-global-sidebar__brand small,
.app-global-sidebar__identity strong,
.app-global-sidebar__identity small {
  display: block;
}

.app-global-sidebar__brand strong {
  font-size: var(--font-size-supporting);
}

.app-global-sidebar__brand small {
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: 0.625rem;
  letter-spacing: 0.14em;
}

.app-global-nav {
  display: grid;
  gap: var(--space-1);
}

.app-global-nav__link {
  display: grid;
  min-height: 42px;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  border-radius: var(--radius-control-sm);
  padding: 0 var(--space-3);
  color: var(--color-text-secondary);
  transition: color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard);
}

.app-global-nav__link b {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 500;
}

.app-global-nav__link span {
  overflow: hidden;
  font-size: var(--font-size-supporting);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-global-nav__link:hover {
  background: color-mix(in srgb, var(--color-surface), transparent 35%);
  color: var(--color-primary);
}

.app-global-nav__link.is-active {
  background: var(--color-surface);
  color: var(--color-primary);
}

.app-global-nav__link.is-active b {
  color: var(--color-accent-warm);
}

.app-global-sidebar__workspace-actions {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.app-global-sidebar__workspace-actions button {
  min-height: 36px;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-control-sm);
  background: transparent;
  padding: 0 var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
  text-align: left;
  cursor: pointer;
}

.app-global-sidebar__workspace-actions button:hover {
  border-style: solid;
  background: color-mix(in srgb, var(--color-surface), transparent 25%);
  color: var(--color-primary);
}

.app-global-sidebar__account {
  display: grid;
  gap: var(--space-3);
  margin-top: auto;
  border-top: 1px solid var(--color-divider);
  padding: var(--space-4) var(--space-2) 0;
}

.app-global-sidebar__identity {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2);
}

.app-global-sidebar__avatar {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-display);
  font-size: var(--font-size-supporting);
}

.app-global-sidebar__identity strong {
  overflow: hidden;
  font-size: var(--font-size-supporting);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-global-sidebar__identity small {
  margin-top: 2px;
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.app-global-sidebar__account-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-1);
}

.app-global-sidebar__account-links a,
.app-global-sidebar__account-links button {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-control-sm);
  background: transparent;
  padding: 0 var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
  text-align: left;
  cursor: pointer;
}

.app-global-sidebar__account-links a {
  display: flex;
  align-items: center;
}

.app-global-sidebar__account-links form {
  grid-column: 1 / -1;
  margin: 0;
}

.app-global-sidebar__account-links a:hover,
.app-global-sidebar__account-links button:hover,
.app-global-sidebar__account-links [aria-current="page"] {
  background: color-mix(in srgb, var(--color-surface), transparent 30%);
  color: var(--color-primary);
}

.app-shell__surface {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: var(--app-topbar-height) minmax(0, 1fr);
  overflow: hidden;
}

.app-topbar {
  position: relative;
  z-index: var(--z-sticky);
  display: flex;
  min-width: 0;
  height: var(--app-topbar-height);
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  border-bottom: 1px solid var(--color-divider);
  background: color-mix(in srgb, var(--color-surface), transparent 5%);
  padding: 0 var(--space-6);
}

.app-topbar__context {
  min-width: 0;
}

.app-topbar__eyebrow,
.app-topbar__title,
.app-topbar__subtitle {
  display: block;
}

.app-topbar__eyebrow {
  margin-bottom: 2px;
  color: var(--color-text-muted);
  font-size: 0.625rem;
  font-weight: 650;
  letter-spacing: 0.12em;
}

.app-topbar__title {
  overflow: hidden;
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-body);
  font-weight: 650;
  line-height: var(--line-height-tight);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-topbar__subtitle {
  margin-top: 2px;
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
}

.app-topbar__actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

.app-topbar .model-pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-primary-soft);
  padding: 0 var(--space-3);
  color: var(--color-primary);
  font-size: var(--font-size-micro);
}

.app-topbar .model-pill i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-success);
}

.app-shell__content {
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.app-secondary-sidebar,
.app-right-panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.app-secondary-sidebar {
  flex: 0 0 292px;
  border-right: 1px solid var(--color-divider);
  background: var(--color-bg-muted);
}

.app-right-panel {
  flex: 0 0 320px;
  border-left: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.app-shell__main {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  background: var(--color-bg-page);
}

/* Existing page compatibility inside the new shell */
body.app-page.ai-page,
body.app-page.workspace-page {
  min-width: 0;
  overflow: hidden;
}

.app-shell .home-agent-main > .ai-main {
  width: 100%;
  min-height: 100%;
  padding: var(--space-6);
}

.app-shell .home-agent-main .agent-shell {
  width: min(940px, 100%);
}

.app-shell .app-topbar.workspace-top {
  display: flex;
  height: var(--app-topbar-height);
  grid-template-columns: none;
  padding: 0 var(--space-6);
}

.app-shell .app-topbar.workspace-top .app-topbar__context {
  flex: 0 1 180px;
}

.app-shell .app-topbar.workspace-top .app-topbar__actions {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: var(--space-4);
}

.workspace-module-sidebar {
  padding: var(--space-4);
}

.app-shell .workspace-module-sidebar .tree-card {
  min-height: 100%;
}

.app-shell .workspace-editor-main {
  padding: var(--space-5);
}

.app-shell .workspace-editor-main > .note-card {
  width: 100%;
  min-height: 100%;
  margin: 0 auto;
}

.app-shell .account-main {
  min-height: 0;
  background: var(--color-bg-page);
}

.app-shell .account-main .account-shell {
  min-height: 0;
  padding: var(--space-8) clamp(var(--space-5), 4vw, var(--space-12));
}

@media (max-width: 1180px) {
  .app-shell {
    --app-sidebar-width: 208px;
  }

  .app-secondary-sidebar {
    flex-basis: 260px;
  }

  .app-shell .app-topbar.workspace-top .app-topbar__actions {
    grid-template-columns: minmax(210px, 1fr) auto;
    gap: var(--space-2);
  }

  .app-shell .workspace-editor-main {
    padding: var(--space-3);
  }
}

@media (max-width: 900px) {
  .app-shell {
    --app-sidebar-width: 184px;
  }

  .app-global-sidebar {
    padding-right: var(--space-3);
    padding-left: var(--space-3);
  }

  .app-shell > .app-global-sidebar.side-panel {
    padding-right: var(--space-3);
    padding-left: var(--space-3);
  }

  .app-topbar {
    padding: 0 var(--space-4);
  }

  .app-topbar__subtitle {
    display: none;
  }

  .app-secondary-sidebar {
    flex-basis: 232px;
  }

  .app-shell .app-topbar.workspace-top .app-topbar__context {
    flex-basis: 130px;
  }

  .app-shell .app-topbar.workspace-top .app-topbar__actions {
    grid-template-columns: minmax(180px, 1fr) auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ui-spinner {
    animation: none;
    border-top-color: var(--color-border-strong);
  }
}

/* Stage 17: explicit Wiki links and the quiet, collapsible knowledge network. */
.knowledge-wiki-link {
  color: var(--color-primary, #254c3d);
  text-decoration-color: color-mix(in srgb, currentColor 42%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

button.knowledge-wiki-link {
  appearance: none;
  border: 0;
  border-bottom: 1px dashed currentColor;
  background: transparent;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

.knowledge-wiki-link.is-unresolved,
.knowledge-wiki-link.is-ambiguous {
  color: var(--color-text-secondary, #68736e);
  text-decoration-style: dashed;
}

.knowledge-wiki-link.is-unavailable,
.knowledge-wiki-link.is-broken {
  color: var(--color-text-muted, #929b96);
  text-decoration: line-through;
}

.knowledge-wiki-link.is-anchor_changed {
  text-decoration-style: wavy;
}

.knowledge-links-panel {
  margin-block: var(--space-6, 24px);
  border-top: 1px solid var(--color-divider, #e3e5df);
  border-bottom: 1px solid var(--color-divider, #e3e5df);
}

.knowledge-links-panel > summary {
  display: flex;
  align-items: baseline;
  gap: var(--space-3, 12px);
  padding: var(--space-4, 16px) var(--space-1, 4px);
  color: var(--color-text-primary, #26332e);
  cursor: pointer;
  list-style: none;
}

.knowledge-links-panel > summary::-webkit-details-marker { display: none; }
.knowledge-links-panel > summary::after {
  content: "⌄";
  margin-left: auto;
  color: var(--color-text-muted, #929b96);
  transition: transform var(--duration-fast, 150ms) ease;
}
.knowledge-links-panel[open] > summary::after { transform: rotate(180deg); }
.knowledge-links-panel > summary span { font-weight: 650; }
.knowledge-links-panel > summary small {
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-meta, 0.78rem);
}

.knowledge-links-panel__body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-6, 24px);
  padding: 0 var(--space-1, 4px) var(--space-5, 20px);
}

.knowledge-links-panel__body > section h3 {
  margin: 0 0 var(--space-3, 12px);
  font: 650 var(--font-size-body, 0.95rem)/1.4 var(--font-body);
}

.knowledge-links-panel__copy,
.knowledge-mentions {
  grid-column: 1 / -1;
}

.knowledge-links-panel__copy {
  display: flex;
  align-items: center;
  gap: var(--space-3, 12px);
  padding: var(--space-3, 12px);
  background: var(--color-surface-subtle, #edf3ee);
  border-radius: var(--radius-control, 10px);
}

.knowledge-links-panel__copy code {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-links-panel__copy button { margin-left: auto; }

.knowledge-aliases__heading p {
  margin: var(--space-1, 4px) 0 0;
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-meta, 0.8125rem);
}

.knowledge-aliases__list {
  display: grid;
  gap: var(--space-1, 4px);
  margin-top: var(--space-3, 12px);
}

.knowledge-aliases__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2, 8px);
  min-height: 36px;
  padding: var(--space-1, 4px) var(--space-2, 8px);
  border-bottom: 1px solid var(--color-divider, #e3e5df);
}

.knowledge-aliases__item span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.knowledge-aliases__item small {
  color: var(--color-text-muted, #929b96);
}

.knowledge-links-list { display: grid; gap: var(--space-2, 8px); }

.knowledge-links-list__item {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: var(--space-2, 8px) 0;
  border: 0;
  border-bottom: 1px solid var(--color-divider, #e3e5df);
  background: transparent;
  color: inherit;
  text-align: left;
  text-decoration: none;
}

button.knowledge-links-list__item,
.knowledge-links-list__item button {
  width: 100%;
  font: inherit;
  cursor: pointer;
}

.knowledge-links-list__item strong,
.knowledge-links-list__item span,
.knowledge-links-list__item p {
  overflow: hidden;
  text-overflow: ellipsis;
}
.knowledge-links-list__item strong { color: var(--color-text-primary, #26332e); }
.knowledge-links-list__item span,
.knowledge-links-list__item small {
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-meta, 0.78rem);
}
.knowledge-links-list__item p {
  margin: var(--space-1, 4px) 0;
  color: var(--color-text-secondary, #68736e);
  font-size: var(--font-size-small, 0.875rem);
  white-space: nowrap;
}
.knowledge-links-panel__empty {
  margin: 0;
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-small, 0.875rem);
}

.knowledge-links-panel__empty.is-compact {
  grid-column: 1 / -1;
  padding-block: var(--space-1, 4px);
}

.knowledge-mentions {
  padding-top: var(--space-4, 16px);
  border-top: 1px solid var(--color-divider, #e3e5df);
}
.knowledge-mentions__heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4, 16px);
}
.knowledge-mentions__heading h3,
.knowledge-mentions__heading p { margin: 0; }
.knowledge-mentions__heading p {
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-meta, 0.78rem);
}
.knowledge-mentions__results { display: grid; gap: var(--space-3, 12px); margin-top: var(--space-3, 12px); }
.knowledge-mention-result {
  padding: var(--space-3, 12px);
  background: var(--color-surface-subtle, #edf3ee);
  border-radius: var(--radius-container, 12px);
}
.knowledge-mention-result > div,
.knowledge-mention-result footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
}
.knowledge-mention-result p { margin: var(--space-2, 8px) 0; }
.knowledge-mention-result footer button { margin-left: auto; }

.knowledge-link-preview {
  position: fixed;
  z-index: 120;
  display: grid;
  gap: var(--space-2, 8px);
  padding: var(--space-4, 16px);
  border: 1px solid var(--color-border, #d9ddd8);
  border-radius: var(--radius-container, 12px);
  background: var(--color-surface, #fffdf9);
  box-shadow: var(--shadow-popover);
  color: var(--color-text-primary, #26332e);
}
.knowledge-link-preview[hidden] { display: none; }
.knowledge-link-preview small,
.knowledge-link-preview span,
.knowledge-link-preview em { color: var(--color-text-muted, #929b96); font-size: 0.78rem; }
.knowledge-link-preview p { margin: 0; color: var(--color-text-secondary, #68736e); line-height: 1.65; }

.knowledge-resolve-dialog { width: min(600px, calc(100vw - 32px)); }
.knowledge-resolve-dialog__search,
.knowledge-resolve-dialog__module {
  display: grid;
  gap: var(--space-2, 8px);
}
.knowledge-resolve-dialog__module {
  margin-top: var(--space-3, 12px);
}
.knowledge-resolve-dialog__results {
  display: grid;
  max-height: min(42vh, 420px);
  margin-top: var(--space-3, 12px);
  overflow: auto;
}
.knowledge-resolve-dialog__results > button {
  display: grid;
  gap: 2px;
  padding: var(--space-3, 12px);
  border: 0;
  border-bottom: 1px solid var(--color-divider, #e3e5df);
  background: transparent;
  color: inherit;
  text-align: left;
}
.knowledge-resolve-dialog__results > button:hover,
.knowledge-resolve-dialog__results > button:focus-visible {
  background: var(--color-surface-subtle, #edf3ee);
}
.knowledge-resolve-dialog__results span { color: var(--color-text-muted, #929b96); }

.knowledge-autocomplete {
  position: fixed;
  z-index: 125;
  max-height: min(48vh, 360px);
  overflow: auto;
  border: 1px solid var(--color-border, #d9ddd8);
  border-radius: var(--radius-container, 12px);
  background: var(--color-surface, #fffdf9);
  box-shadow: var(--shadow-popover);
}
.knowledge-autocomplete[hidden] { display: none; }
.knowledge-autocomplete [data-knowledge-autocomplete-results] { display: grid; padding: var(--space-2, 8px); }
.knowledge-autocomplete [role="option"] {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 1px var(--space-2, 8px);
  padding: var(--space-2, 8px) var(--space-3, 12px);
  border: 0;
  border-radius: var(--radius-small, 8px);
  background: transparent;
  color: inherit;
  text-align: left;
}
.knowledge-autocomplete [role="option"][aria-selected="true"],
.knowledge-autocomplete [role="option"]:hover {
  background: var(--color-surface-subtle, #edf3ee);
}
.knowledge-autocomplete [role="option"] strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.knowledge-autocomplete [role="option"] small {
  grid-column: 2;
  color: var(--color-text-muted, #929b96);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.knowledge-autocomplete__type {
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--color-text-secondary, #68736e);
  font-size: var(--font-size-meta, 0.78rem);
}
.knowledge-autocomplete > p {
  margin: 0;
  padding: var(--space-2, 8px) var(--space-4, 16px);
  border-top: 1px solid var(--color-divider, #e3e5df);
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-meta, 0.78rem);
}
.knowledge-autocomplete__empty { margin: 0; padding: var(--space-3, 12px); color: var(--color-text-muted, #929b96); }

@media (max-width: 760px) {
  .knowledge-links-panel > summary { align-items: flex-start; flex-direction: column; }
  .knowledge-links-panel__body { grid-template-columns: 1fr; }
  .knowledge-links-panel__copy,
  .knowledge-mentions { grid-column: auto; }
  .knowledge-links-panel__copy,
  .knowledge-mentions__heading { align-items: stretch; flex-direction: column; }
  .knowledge-links-panel__copy button,
  .knowledge-mention-result footer button { margin-left: 0; }
  .knowledge-autocomplete { max-height: min(52vh, 360px); }
}

@media (prefers-reduced-motion: reduce) {
  .knowledge-links-panel > summary::after { transition: none; }
}

/* Global navigation information architecture */
.app-shell {
  transition: grid-template-columns var(--duration-normal) var(--ease-standard);
}

html[data-app-sidebar-collapsed="true"] .app-shell {
  --app-sidebar-width: 72px;
}

.app-shell > .app-global-sidebar.side-panel {
  overflow: visible;
  padding: var(--space-4) var(--space-3);
  transition: padding var(--duration-normal) var(--ease-standard);
}

.app-global-sidebar__header {
  display: flex;
  min-height: 48px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.app-global-sidebar__brand {
  min-width: 0;
  flex: 1 1 auto;
  gap: var(--space-2);
  margin: 0;
}

.app-global-sidebar__brand > span {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
  border-radius: var(--radius-control-sm);
}

.app-sidebar-brand-copy,
.app-sidebar-user-copy {
  min-width: 0;
}

.app-sidebar-collapse,
.app-sidebar-mobile-toggle,
.app-sidebar-backdrop {
  border: 0;
}

.app-sidebar-collapse,
.app-sidebar-mobile-toggle {
  display: inline-grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: var(--radius-control-sm);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard);
}

.app-sidebar-collapse:hover,
.app-sidebar-mobile-toggle:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.app-sidebar-collapse svg,
.app-sidebar-mobile-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.app-sidebar-mobile-toggle,
.app-sidebar-backdrop {
  display: none;
}

.app-global-sidebar__scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

.app-global-nav {
  gap: var(--space-6);
}

.app-global-nav__group {
  display: grid;
  gap: var(--space-1);
}

.app-global-nav__label {
  margin: 0 0 var(--space-2);
  padding: 0 var(--space-3);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.08em;
  line-height: var(--line-height-compact);
}

.app-global-nav__link {
  position: relative;
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-3);
}

.app-global-nav__link svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.55;
}

.app-global-nav__link > span:not(.app-global-nav__module-status-list) {
  min-width: 0;
  flex: 1 1 auto;
  font-weight: 550;
  line-height: var(--line-height-compact);
}

.app-global-nav__link.is-active {
  background: var(--color-primary-soft);
}

/* Expanded navigation already carries visible labels; reserve tooltips for icon-only mode. */
.app-global-sidebar [data-tooltip]::after {
  display: none;
}

@media (min-width: 900px) {
  html[data-app-sidebar-collapsed="true"] .app-global-sidebar [data-tooltip]::after {
    display: block;
  }
}

.app-global-nav__empty {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.app-global-sidebar__workspace-actions {
  gap: var(--space-1);
  margin-top: var(--space-5);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-4);
}

.app-global-sidebar__workspace-actions button {
  display: grid;
  min-height: 38px;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3);
  border: 0;
  padding: 0 var(--space-3);
}

.app-global-sidebar__workspace-actions button b {
  overflow: hidden;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-global-sidebar__account {
  position: relative;
  display: block;
  flex: 0 0 auto;
  margin-top: var(--space-3);
  padding: var(--space-3) 0 0;
}

.app-global-sidebar__identity {
  display: grid;
  width: 100%;
  min-height: 46px;
  grid-template-columns: 34px minmax(0, 1fr) 18px;
  align-items: center;
  gap: var(--space-2);
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  padding: var(--space-1) var(--space-2);
  color: var(--color-text-primary);
  text-align: left;
  cursor: pointer;
}

.app-global-sidebar__identity:hover,
.app-global-sidebar__identity[aria-expanded="true"] {
  background: color-mix(in srgb, var(--color-surface), transparent 28%);
}

.app-global-sidebar__identity > svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
  transition: transform var(--duration-fast) var(--ease-standard);
}

.app-global-sidebar__identity[aria-expanded="true"] > svg {
  transform: rotate(180deg);
}

.app-user-menu {
  position: absolute;
  z-index: 120;
  right: 0;
  bottom: calc(100% + var(--space-2));
  display: grid;
  width: 204px;
  gap: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
  padding: var(--space-2);
}

.app-user-menu[hidden] {
  display: none;
}

.app-user-menu a,
.app-user-menu button {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  border: 0;
  border-radius: var(--radius-control-sm);
  background: transparent;
  padding: 0 var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  text-align: left;
  cursor: pointer;
}

.app-user-menu a:hover,
.app-user-menu button:hover,
.app-user-menu [aria-current="page"] {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.app-user-menu form {
  margin: var(--space-1) 0 0;
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-1);
}

.app-global-sidebar :is(a, button):focus-visible,
.app-sidebar-mobile-toggle:focus-visible {
  outline: 0;
  box-shadow: var(--shadow-focus);
}

html[data-app-sidebar-collapsed="true"] .app-shell > .app-global-sidebar.side-panel {
  padding-right: var(--space-2);
  padding-left: var(--space-2);
}

html[data-app-sidebar-collapsed="true"] .app-global-sidebar__header {
  flex-direction: column;
  margin-bottom: var(--space-4);
}

html[data-app-sidebar-collapsed="true"] .app-global-sidebar__brand {
  flex: 0 0 auto;
}

html[data-app-sidebar-collapsed="true"] .app-sidebar-brand-copy,
html[data-app-sidebar-collapsed="true"] .app-global-nav__label,
html[data-app-sidebar-collapsed="true"] .app-global-nav__link span,
html[data-app-sidebar-collapsed="true"] .app-global-nav__empty,
html[data-app-sidebar-collapsed="true"] .app-global-sidebar__workspace-actions button b,
html[data-app-sidebar-collapsed="true"] .app-sidebar-user-copy,
html[data-app-sidebar-collapsed="true"] .app-global-sidebar__identity > svg {
  display: none;
}

html[data-app-sidebar-collapsed="true"] .app-global-nav__link,
html[data-app-sidebar-collapsed="true"] .app-global-sidebar__workspace-actions button {
  min-height: 40px;
  justify-content: center;
  gap: 0;
  padding: 0;
}

html[data-app-sidebar-collapsed="true"] .app-global-sidebar__identity {
  grid-template-columns: 34px;
  justify-content: center;
  padding: var(--space-1);
}

html[data-app-sidebar-collapsed="true"] .app-user-menu {
  right: auto;
  bottom: 0;
  left: calc(100% + var(--space-2));
}

@media (max-width: 1180px) and (min-width: 900px) {
  .app-shell {
    --app-sidebar-width: 232px;
  }

  html[data-app-sidebar-collapsed="true"] .app-shell {
    --app-sidebar-width: 72px;
  }
}

@media (max-width: 899px) {
  .app-shell,
  html[data-app-sidebar-collapsed="true"] .app-shell {
    --app-sidebar-width: 232px;
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell > .app-global-sidebar.side-panel,
  html[data-app-sidebar-collapsed="true"] .app-shell > .app-global-sidebar.side-panel {
    position: fixed;
    z-index: 100;
    inset: 0 auto 0 0;
    width: min(280px, calc(100vw - 48px));
    height: 100vh;
    height: 100dvh;
    padding: var(--space-4) var(--space-3);
    transform: translateX(-102%);
    transition: transform var(--duration-slow) var(--ease-out);
  }

  .app-shell.is-sidebar-open > .app-global-sidebar.side-panel {
    transform: translateX(0);
  }

  .app-sidebar-backdrop {
    position: fixed;
    z-index: 90;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 42, 35, 0.24);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-slow) var(--ease-standard);
  }

  .app-shell.is-sidebar-open > .app-sidebar-backdrop {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .app-sidebar-mobile-toggle {
    display: inline-grid;
  }

  .app-topbar {
    justify-content: flex-start;
  }

  .app-topbar__actions {
    margin-left: auto;
  }

  html[data-app-sidebar-collapsed="true"] .app-global-sidebar__header {
    flex-direction: row;
    margin-bottom: var(--space-5);
  }

  html[data-app-sidebar-collapsed="true"] .app-global-sidebar__brand {
    flex: 1 1 auto;
  }

  html[data-app-sidebar-collapsed="true"] .app-sidebar-brand-copy,
  html[data-app-sidebar-collapsed="true"] .app-global-nav__label,
  html[data-app-sidebar-collapsed="true"] .app-global-nav__link span,
  html[data-app-sidebar-collapsed="true"] .app-global-sidebar__workspace-actions button b,
  html[data-app-sidebar-collapsed="true"] .app-sidebar-user-copy,
  html[data-app-sidebar-collapsed="true"] .app-global-sidebar__identity > svg {
    display: block;
  }

  html[data-app-sidebar-collapsed="true"] .app-global-nav__link,
  html[data-app-sidebar-collapsed="true"] .app-global-sidebar__workspace-actions button {
    grid-template-columns: 20px minmax(0, 1fr);
    justify-content: initial;
    gap: var(--space-3);
    padding: 0 var(--space-3);
  }

  html[data-app-sidebar-collapsed="true"] .app-global-sidebar__identity {
    grid-template-columns: 34px minmax(0, 1fr) 18px;
    justify-content: initial;
    padding: var(--space-1) var(--space-2);
  }

  html[data-app-sidebar-collapsed="true"] .app-user-menu {
    right: 0;
    bottom: calc(100% + var(--space-2));
    left: auto;
  }

  body.app-sidebar-drawer-open {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell,
  .app-shell > .app-global-sidebar.side-panel,
  .app-sidebar-backdrop {
    transition: none;
  }
}

/* Unified topbar search and page actions */
.app-shell .app-topbar,
.app-shell .app-topbar.workspace-top {
  display: grid;
  grid-template-columns: minmax(84px, 160px) minmax(260px, 620px) minmax(0, auto);
  align-items: center;
  justify-content: initial;
  gap: clamp(var(--space-3), 2vw, var(--space-6));
  overflow: visible;
  padding: 0 var(--space-6);
}

.app-shell .app-topbar.workspace-top .app-topbar__context,
.app-topbar__context {
  min-width: 0;
  flex: none;
}

.app-topbar__title {
  font-size: var(--font-size-supporting);
  font-weight: 600;
}

.app-topbar__search-slot {
  width: 100%;
  min-width: 0;
  max-width: 620px;
  justify-self: center;
}

.app-topbar__search {
  position: relative;
  width: 100%;
}

.app-topbar__search-form {
  display: flex;
  width: 100%;
  height: 42px;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--color-bg-subtle), var(--color-surface) 44%);
  padding: 0 var(--space-3);
  transition: border-color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard), box-shadow var(--duration-fast) var(--ease-standard);
}

.app-topbar__search-form:focus-within {
  border-color: var(--color-border-strong);
  background: var(--color-surface);
  box-shadow: var(--shadow-focus);
}

.app-topbar__search-form > svg,
.app-topbar__search-toggle svg,
.app-topbar__action svg,
.app-topbar__ai-entry svg {
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.app-topbar__search-form > svg {
  color: var(--color-text-muted);
}

.app-topbar__search-form input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
}

.app-topbar__search-form input::placeholder {
  color: var(--color-text-muted);
}

.app-topbar__search-form kbd {
  flex: 0 0 auto;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--color-surface), transparent 18%);
  padding: 2px 6px;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--font-size-micro);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

.app-topbar__search-toggle,
.app-topbar__search-close {
  display: none;
  border: 0;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.app-topbar__search-results {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + var(--space-2));
  right: 0;
  left: 0;
  max-height: min(480px, calc(100vh - 100px));
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
  padding: var(--space-2);
  scrollbar-width: thin;
}

.app-topbar__search-results[hidden] {
  display: none;
}

.app-search-group + .app-search-group {
  margin-top: var(--space-2);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-2);
}

.app-search-group h2 {
  margin: 0;
  padding: var(--space-1) var(--space-2);
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.06em;
}

.app-search-result {
  display: grid;
  min-height: 48px;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1px var(--space-3);
  border-radius: var(--radius-control-sm);
  padding: var(--space-2);
  color: var(--color-text-primary);
}

.app-search-result:hover,
.app-search-result.is-selected,
.app-search-result[aria-selected="true"] {
  background: var(--color-primary-soft);
}

.app-search-result__title {
  overflow: hidden;
  font-size: var(--font-size-supporting);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-search-result__path {
  overflow: hidden;
  max-width: 180px;
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-search-result__snippet {
  overflow: hidden;
  grid-column: 1 / -1;
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-search-result__match {
  align-self: flex-start;
  margin-top: var(--space-1, 4px);
  padding: 2px 7px;
  border-radius: var(--radius-sm, 8px);
  background: var(--color-surface-muted, #edf3ee);
  color: var(--color-text-secondary, #68736e);
  font-size: var(--font-size-xs, 0.75rem);
  line-height: 1.5;
}

.app-search-mode-note {
  margin: 0;
  padding: var(--space-2, 8px) var(--space-3, 12px);
  border-top: 1px solid var(--color-divider, #e5e7e2);
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-xs, 0.75rem);
}

.app-search-empty {
  margin: 0;
  padding: var(--space-5) var(--space-3);
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  text-align: center;
}

.app-search-empty.is-error {
  color: var(--color-error);
}

.app-search-empty.is-loading {
  color: var(--color-text-muted);
}

.app-search-empty.is-loading::before {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  margin-right: var(--space-2);
  animation: app-search-spin 700ms linear infinite;
  border: 1.5px solid var(--color-border-strong);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  content: "";
  vertical-align: -0.08rem;
}

@keyframes app-search-spin {
  to {
    transform: rotate(1turn);
  }
}

.app-shell .app-topbar.workspace-top .app-topbar__actions,
.app-topbar__actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  margin: 0;
}

.app-topbar__action,
.app-topbar__ai-entry {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-control-sm);
  padding: 0 var(--space-3);
  font-size: var(--font-size-supporting);
  white-space: nowrap;
  cursor: pointer;
}

.app-topbar__action.is-secondary,
.app-topbar__ai-entry {
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
}

.app-topbar__action.is-secondary:hover,
.app-topbar__ai-entry:hover {
  border-color: var(--color-border-strong);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.app-topbar__action.is-primary {
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.app-topbar__action.is-primary:hover {
  border-color: var(--color-primary-hover);
  background: var(--color-primary-hover);
}

.app-topbar__ai-entry i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.app-topbar__ai-entry i.is-connected {
  background: var(--color-success);
}

.app-topbar__ai-entry small {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.app-topbar :is(button, a, input):focus-visible,
.app-search-result:focus-visible {
  outline: 0;
  box-shadow: var(--shadow-focus);
}

@media (max-width: 1180px) and (min-width: 900px) {
  .app-shell .app-topbar,
  .app-shell .app-topbar.workspace-top {
    grid-template-columns: minmax(72px, 118px) minmax(220px, 1fr) auto;
    gap: var(--space-3);
    padding: 0 var(--space-4);
  }

  .app-topbar__search-slot {
    max-width: 520px;
  }

  .workspace-actions .app-topbar__action.is-secondary {
    width: 38px;
    padding: 0;
  }

  .workspace-actions .app-topbar__action.is-secondary span,
  .app-topbar__ai-entry small {
    display: none;
  }
}

@media (max-width: 899px) {
  .app-shell .app-topbar,
  .app-shell .app-topbar.workspace-top {
    display: flex;
    gap: var(--space-2);
    padding: 0 var(--space-3);
  }

  .app-topbar__context {
    min-width: 0;
    flex: 1 1 auto;
  }

  .app-topbar__search-slot {
    width: 36px;
    flex: 0 0 36px;
    order: 4;
  }

  .app-topbar__search-toggle {
    display: inline-grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: var(--radius-control-sm);
  }

  .app-topbar__search-toggle:hover {
    background: var(--color-primary-soft);
    color: var(--color-primary);
  }

  .app-topbar__search-form {
    display: none;
  }

  .app-topbar.is-search-open .app-topbar__context,
  .app-topbar.is-search-open .app-topbar__actions {
    display: none;
  }

  .app-topbar.is-search-open .app-topbar__search-slot {
    width: auto;
    min-width: 0;
    max-width: none;
    flex: 1 1 auto;
    order: 1;
  }

  .app-topbar.is-search-open .app-topbar__search-toggle {
    display: none;
  }

  .app-topbar.is-search-open .app-topbar__search-form {
    display: flex;
  }

  .app-topbar.is-search-open .app-topbar__search-close {
    display: inline-grid;
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    place-items: center;
    border-radius: var(--radius-control-sm);
    font-size: 1.2rem;
  }

  .app-topbar__search-form kbd {
    display: none;
  }

  .app-topbar__search-results {
    width: min(620px, calc(100vw - 72px));
    right: 0;
    left: auto;
  }

  .app-topbar__actions {
    flex: 0 0 auto;
    order: 3;
  }

  .app-topbar__ai-entry small {
    display: none;
  }
}

@media (max-width: 767px) {
  .app-topbar:not(.is-search-open) .app-topbar__context {
    display: none;
  }

  .app-topbar:not(.is-search-open) .app-topbar__actions {
    margin-left: auto;
  }

  .workspace-actions .app-topbar__action.is-secondary {
    display: none;
  }

  .app-topbar__action.is-primary {
    min-height: 36px;
    padding: 0 var(--space-3);
  }

  .app-topbar__ai-entry {
    width: 38px;
    padding: 0;
  }

  .app-topbar__ai-entry > span,
  .app-topbar__ai-entry small,
  .app-topbar__ai-entry i {
    display: none;
  }

  .app-search-result {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-search-result__path {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-topbar__search-form,
  .app-topbar__action,
  .app-topbar__ai-entry {
    transition: none;
  }

  .app-search-empty.is-loading::before {
    animation: none;
  }
}

/* Home: today's desk */
.app-shell .home-desk-main {
  background: var(--color-bg-page);
  padding: clamp(var(--space-8), 5vw, var(--space-16)) clamp(var(--space-5), 5vw, var(--space-16));
}

.home-desk {
  width: min(1220px, 100%);
  margin: 0 auto;
  color: var(--color-text-primary);
}

.home-desk__hero {
  max-width: 720px;
  margin-bottom: clamp(var(--space-10), 5vw, var(--space-16));
}

.home-desk__eyebrow,
.home-desk__section-kicker {
  margin: 0;
  color: var(--color-accent-warm);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.16em;
  line-height: var(--line-height-compact);
}

.home-desk__hero h1 {
  margin: var(--space-3) 0 var(--space-3);
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.2;
}

.home-desk__hero > p:last-child {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 1rem;
  line-height: var(--line-height-body);
}

/* Quick record: a quiet writing surface, separate from the AI composer. */
.home-desk .quick-record {
  max-width: 940px;
  margin: 0 0 var(--space-9);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  transition: border-color var(--duration-normal) var(--ease-standard), box-shadow var(--duration-normal) var(--ease-standard);
}

.home-desk .quick-record:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.quick-record__form {
  padding: var(--space-5) var(--space-6) var(--space-4);
}

.quick-record__label {
  display: block;
  margin-bottom: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.08em;
}

.quick-record__editor {
  min-width: 0;
}

.home-desk .quick-record__textarea {
  display: block;
  width: 100%;
  min-height: 86px;
  max-height: 184px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  padding: var(--space-2) 0 var(--space-4);
  color: var(--color-text-primary);
  font: inherit;
  font-size: var(--font-size-body);
  line-height: 1.8;
}

.quick-record__textarea::placeholder {
  color: var(--color-text-muted);
}

.quick-record__meta {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: var(--space-4);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-3);
}

.quick-record__destination {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-supporting);
}

.quick-record__destination button {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  border: 0;
  background: transparent;
  padding: var(--space-1);
  color: var(--color-primary);
  font: inherit;
  cursor: pointer;
}

.quick-record__destination button:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.quick-record__destination button:focus-visible {
  border-radius: var(--radius-control-sm);
  outline: 0;
  box-shadow: var(--shadow-focus);
}

.quick-record__destination small {
  color: var(--color-warning);
  font-size: var(--font-size-micro);
}

.quick-record__shortcut {
  margin-left: auto;
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  white-space: nowrap;
}

.quick-record__save {
  flex: 0 0 auto;
  min-width: 104px;
}

.quick-record__feedback {
  display: flex;
  min-height: 24px;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-2);
}

.quick-record__status {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
}

.quick-record__status.is-error {
  color: var(--color-error);
}

.quick-record__status.is-success {
  color: var(--color-primary);
}

.quick-record__retry,
.quick-record__open {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--color-primary);
  font: inherit;
  font-size: var(--font-size-micro);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.quick-record-dialog.ui-dialog {
  width: min(540px, calc(100vw - 32px));
  padding: 0;
}

.quick-record-dialog__choices {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  border: 0;
  padding: 0;
}

.quick-record-dialog__choice {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-1);
  cursor: pointer;
}

.quick-record-dialog__choice:last-child {
  border-bottom: 0;
}

.quick-record-dialog__choice input {
  accent-color: var(--color-primary);
}

.quick-record-dialog__choice strong,
.quick-record-dialog__choice small {
  display: block;
}

.quick-record-dialog__choice strong {
  font-size: var(--font-size-supporting);
}

.quick-record-dialog__choice small {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.quick-record-dialog__warning {
  margin: var(--space-4) 0 0;
  border-left: 2px solid var(--color-warning);
  background: var(--color-warning-soft);
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
}

.quick-record-dialog__empty {
  margin: 0;
  color: var(--color-text-secondary);
}

.home-desk__continue,
.home-desk__empty {
  position: relative;
  max-width: 940px;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  padding: clamp(var(--space-6), 4vw, var(--space-10));
}

.home-desk__continue::before,
.home-desk__empty::before {
  position: absolute;
  top: var(--space-6);
  bottom: var(--space-6);
  left: 0;
  width: 2px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  background: var(--color-primary);
  content: "";
}

.home-desk__section-heading,
.home-desk__record-meta,
.home-desk__echo-head {
  display: flex;
  min-width: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.home-desk__section-heading span,
.home-desk__section-heading time,
.home-desk__record-meta,
.home-desk__echo a > span,
.home-desk__echo a > small {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
  line-height: var(--line-height-compact);
}

.home-desk__section-heading > div > span {
  display: block;
  overflow: hidden;
  margin-top: var(--space-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-desk__continue-copy {
  max-width: 760px;
  margin-top: var(--space-8);
}

.home-desk__continue-copy h2,
.home-desk__empty h2 {
  margin: 0;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.5vw, 2.15rem);
  font-weight: 500;
  line-height: var(--line-height-tight);
}

.home-desk__continue-copy p,
.home-desk__empty > p:not(.home-desk__section-kicker) {
  margin: var(--space-4) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-body);
  line-height: var(--line-height-reading);
}

.home-desk__continue-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-5);
  margin-top: var(--space-8);
}

.home-desk__text-link {
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
}

.home-desk__text-link:hover {
  color: var(--color-primary);
}

.home-desk__empty {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
}

.home-desk__empty .ui-button {
  margin-top: var(--space-4);
}

.home-desk__flow {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.75fr);
  gap: clamp(var(--space-8), 4vw, var(--space-12));
  align-items: start;
  margin-top: clamp(var(--space-10), 5vw, var(--space-16));
}

.home-desk__flow.is-single-column {
  max-width: 900px;
  grid-template-columns: minmax(0, 1fr);
}

.home-desk__section-heading h2 {
  margin: var(--space-2) 0 0;
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-section-title);
  font-weight: 600;
  line-height: var(--line-height-tight);
}

.home-desk__record-list {
  margin-top: var(--space-5);
  border-top: 1px solid var(--color-divider);
}

.home-desk__record {
  display: grid;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-5) var(--space-2);
  color: var(--color-text-primary);
  transition: background-color var(--duration-fast) var(--ease-standard), padding var(--duration-fast) var(--ease-standard);
}

.home-desk__record:hover {
  background: color-mix(in srgb, var(--color-primary-soft), transparent 36%);
  padding-right: var(--space-4);
  padding-left: var(--space-4);
}

.home-desk__record:focus-visible,
.home-desk__echo a:focus-visible,
.home-desk__asset:focus-visible,
.home-desk__text-link:focus-visible {
  outline: 0;
  border-radius: var(--radius-control-sm);
  box-shadow: var(--shadow-focus);
}

.home-desk__record-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-desk__record-meta time {
  flex: 0 0 auto;
}

.home-desk__record > strong {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 600;
  line-height: var(--line-height-compact);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-desk__record-summary {
  display: -webkit-box;
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.home-desk__aside {
  display: grid;
  gap: var(--space-10);
}

.home-desk__echo {
  border-radius: var(--radius-container);
  background: var(--color-primary-soft);
  padding: var(--space-5);
}

.home-desk__echo[hidden] {
  display: none;
}

.home-desk__echo-head .ui-icon-button {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  background: transparent;
}

.home-desk__echo a {
  display: block;
  margin-top: var(--space-3);
  color: var(--color-text-primary);
}

.home-desk__echo h2 {
  margin: var(--space-3) 0 var(--space-3);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  line-height: var(--line-height-tight);
}

.home-desk__echo a > p {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.home-desk__assets .home-desk__section-heading {
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
}

.home-desk__asset-list {
  display: grid;
}

.home-desk__asset {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: var(--space-3);
  align-items: center;
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-4) 0;
  color: var(--color-text-primary);
}

.home-desk__asset:hover strong {
  color: var(--color-primary);
}

.home-desk__asset-type {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: var(--radius-control-sm);
  background: var(--color-bg-muted);
  color: var(--color-text-secondary);
  font-size: 0.6rem;
  font-weight: 650;
}

.home-desk__asset strong,
.home-desk__asset small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-desk__asset strong {
  font-size: var(--font-size-supporting);
  font-weight: 600;
}

.home-desk__asset small {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

/* Home AI drawer: one persistent chat DOM, moved out of the page reading flow. */
.home-ai-drawer__backdrop {
  position: fixed;
  z-index: var(--z-overlay);
  inset: 0;
  border: 0;
  background: rgba(27, 39, 33, 0.28);
  cursor: default;
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-standard);
}

.home-ai-drawer__backdrop.is-open {
  opacity: 1;
}

.home-ai-drawer__backdrop[hidden],
.home-ai-drawer[hidden] {
  display: none;
}

.home-ai-drawer {
  position: fixed;
  z-index: calc(var(--z-overlay) + 1);
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  width: clamp(480px, 40vw, 600px);
  grid-template-rows: 68px minmax(0, 1fr);
  border-left: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-dialog);
  transform: translateX(100%);
  transition: transform var(--duration-slow) var(--ease-standard);
}

.home-ai-drawer.is-open {
  transform: translateX(0);
}

.home-ai-drawer__header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  padding: 0 var(--space-5);
}

.home-ai-drawer__eyebrow {
  display: block;
  color: var(--color-text-muted);
  font-size: 0.6rem;
  letter-spacing: 0.15em;
}

.home-ai-drawer__header h2 {
  margin: 2px 0 0;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 500;
}

.home-ai-drawer__header-actions,
.home-ai-drawer__connection {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.home-ai-drawer__connection {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.home-ai-drawer__connection i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
}

.home-ai-drawer__connection i.is-connected {
  background: var(--color-success);
}

.ai-page .home-ai-drawer .agent-shell {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: none;
  max-height: none;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  margin: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: var(--color-surface);
  box-shadow: none;
}

.ai-page .home-ai-drawer .agent-topbar {
  min-height: 56px;
}

.ai-page .home-ai-drawer .conversation {
  min-height: 0;
  padding: var(--space-5);
  background: var(--color-bg-page);
}

.ai-page .home-ai-drawer .message-body {
  max-width: 94%;
}

.ai-page .home-ai-drawer .composer {
  padding: var(--space-3) var(--space-4) var(--space-2);
}

.ai-page .home-ai-drawer .privacy-copy {
  padding: var(--space-2) var(--space-4);
}

body.home-ai-drawer-open {
  overflow: hidden;
}

@media (max-width: 1050px) {
  .home-desk__flow {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.75fr);
    gap: var(--space-8);
  }
}

@media (max-width: 899px) {
  .app-shell .home-desk-main {
    padding: var(--space-8) var(--space-5) var(--space-12);
  }

  .home-desk__hero {
    margin-bottom: var(--space-10);
  }

  .home-desk__flow {
    grid-template-columns: minmax(0, 1fr);
  }

  .quick-record__meta {
    flex-wrap: wrap;
  }

  .quick-record__shortcut {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  .home-desk__aside {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-6);
  }

  .home-ai-drawer {
    width: min(600px, calc(100vw - 32px));
  }
}

@media (max-width: 767px) {
  .app-shell .home-desk-main {
    padding: var(--space-6) var(--space-4) var(--space-10);
  }

  .home-desk__hero h1 {
    font-size: 2rem;
  }

  .quick-record__form {
    padding: var(--space-4);
  }

  .quick-record__destination {
    width: 100%;
  }

  .quick-record__save {
    width: 100%;
  }

  .quick-record-dialog__choice {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .quick-record-dialog__choice .ui-status {
    grid-column: 2;
    justify-self: start;
  }

  .home-desk__continue,
  .home-desk__empty {
    padding: var(--space-6) var(--space-5);
  }

  .home-desk__section-heading,
  .home-desk__record-meta {
    display: grid;
    gap: var(--space-2);
  }

  .home-desk__section-heading > time,
  .home-desk__record-meta time {
    justify-self: start;
  }

  .home-desk__aside {
    grid-template-columns: minmax(0, 1fr);
  }

  .home-ai-drawer {
    width: 100vw;
    border-left: 0;
  }

  .ai-page .home-ai-drawer .agent-topbar {
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-3);
  }

  .ai-page .home-ai-drawer .agent-topbar > div:first-child,
  .ai-page .home-ai-drawer .agent-state {
    display: none;
  }

  .ai-page .home-ai-drawer .agent-top-actions {
    width: 100%;
  }

  .ai-page .home-ai-drawer .agent-top-actions #model-choice {
    width: min(190px, 48vw);
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-desk__record,
  .home-ai-drawer,
  .home-ai-drawer__backdrop {
    transition: none;
  }
}

/* Workspace module directory */
.app-shell .workspace-module-sidebar.module-panel {
  position: relative;
  display: block;
  flex: 0 0 288px;
  overflow: hidden;
  border-right: 1px solid var(--color-divider);
  background: var(--color-bg-muted);
  padding: 0;
  transition: flex-basis var(--duration-normal) var(--ease-standard), width var(--duration-normal) var(--ease-standard), opacity var(--duration-fast) var(--ease-standard);
}

.module-panel__surface {
  display: flex;
  width: 288px;
  height: 100%;
  min-height: 0;
  flex-direction: column;
  background: color-mix(in srgb, var(--color-bg-muted) 86%, var(--color-surface));
}

.module-panel__header {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-4);
}

.module-panel__heading { min-width: 0; }
.module-panel__heading span,
.module-panel__heading strong { display: block; }
.module-panel__heading span { margin-bottom: 2px; color: var(--color-text-weak); font-size: var(--font-size-micro); letter-spacing: .08em; }
.module-panel__heading strong { overflow: hidden; color: var(--color-text); font-size: var(--font-size-body); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.module-panel__header-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 2px; }
.module-panel__header-actions .ui-icon-button,
.module-panel__restore { color: var(--color-text-secondary); }
.module-panel__header-actions .ui-icon-button:hover,
.module-panel__restore:hover { background: var(--color-primary-soft); color: var(--color-primary); }
.module-panel__header-actions svg,
.module-panel__restore svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }

.module-panel__search { position: relative; margin: var(--space-3) var(--space-3) var(--space-2); }
.module-panel__search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.module-panel__search > svg { position: absolute; top: 10px; left: 11px; width: 16px; height: 16px; fill: none; stroke: var(--color-text-weak); stroke-width: 1.7; pointer-events: none; }
.module-panel__search input { width: 100%; height: 36px; border: 1px solid transparent; border-radius: var(--radius-control-sm); outline: 0; background: color-mix(in srgb, var(--color-surface) 68%, transparent); padding: 0 34px; color: var(--color-text); font: inherit; font-size: var(--font-size-supporting); }
.module-panel__search input:hover { border-color: var(--color-border); }
.module-panel__search input:focus-visible { border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.module-panel__search button { position: absolute; top: 5px; right: 5px; width: 26px; height: 26px; border: 0; border-radius: var(--radius-control-sm); background: transparent; color: var(--color-text-weak); cursor: pointer; }
.module-panel__search-status { min-height: 16px; margin: 0 var(--space-4) var(--space-1); color: var(--color-text-weak); font-size: var(--font-size-micro); line-height: 1.4; }
.module-panel__tree-scroll { min-height: 0; flex: 1 1 auto; overflow: auto; overscroll-behavior: contain; scrollbar-color: color-mix(in srgb, var(--color-primary) 22%, transparent) transparent; scrollbar-width: thin; }

.app-shell .workspace-module-sidebar .module-tree { position: relative; min-height: 100%; padding: var(--space-1) var(--space-2) var(--space-3); }
.app-shell .workspace-module-sidebar .tree-node,
.app-shell .workspace-module-sidebar .tree-children { margin: 0; border: 0; padding: 0; }
.app-shell .workspace-module-sidebar .module-tree__item.is-current-root > .module-tree__row:not(.is-current) .module-tree__label strong {
  color: var(--color-text-primary);
  font-weight: 600;
}
.app-shell .workspace-module-sidebar .module-tree__group { position: relative; }
.app-shell .workspace-module-sidebar .module-tree__group::before { position: absolute; top: 0; bottom: 0; left: 20px; width: 1px; background: color-mix(in srgb, var(--color-border) 62%, transparent); content: ""; pointer-events: none; }

.app-shell .workspace-module-sidebar .module-tree__row {
  position: relative;
  display: grid;
  min-height: 38px;
  align-items: center;
  grid-template-columns: 22px 18px minmax(0, 1fr) auto 24px 28px;
  gap: 2px;
  border-radius: var(--radius-control-sm);
  padding: 0 3px 0 4px;
  color: var(--color-text-secondary);
  cursor: default;
  transition: background-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), opacity var(--duration-fast) var(--ease-standard);
}
.app-shell .workspace-module-sidebar [data-depth="2"] > .module-tree__row { padding-left: 14px; }
.app-shell .workspace-module-sidebar [data-depth="3"] > .module-tree__row { padding-left: 25px; }
.app-shell .workspace-module-sidebar [data-depth="4"] > .module-tree__row { padding-left: 36px; }
.app-shell .workspace-module-sidebar [data-depth="5"] > .module-tree__row { padding-left: 47px; }
.app-shell .workspace-module-sidebar .module-tree__row:hover,
.app-shell .workspace-module-sidebar .module-tree__row:focus-within { background: color-mix(in srgb, var(--color-primary-soft) 72%, transparent); color: var(--color-text); }
.app-shell .workspace-module-sidebar .module-tree__row.is-current { background: var(--color-primary-soft); color: var(--color-primary); box-shadow: none; }
.app-shell .workspace-module-sidebar .module-tree__row.is-current::after { position: absolute; top: 7px; bottom: 7px; left: 0; width: 3px; border-radius: 2px; background: var(--color-primary); content: ""; }
.app-shell .workspace-module-sidebar .module-tree__row.is-current :is(.module-tree__type, .module-tree__link) { color: var(--color-primary); }
.app-shell .workspace-module-sidebar .module-tree__row.is-current .module-tree__link { font-weight: 600; }
.app-shell .workspace-module-sidebar .module-tree__row.is-current .module-tree__label strong { font-weight: 600; }

.module-tree__toggle,
.module-tree__more { display: inline-grid; width: 28px; height: 32px; place-items: center; border: 0; border-radius: var(--radius-control-sm); background: transparent; color: var(--color-text-weak); cursor: pointer; }
.module-tree__toggle { width: 22px; height: 30px; }
.module-tree__toggle svg,
.module-tree__more svg,
.module-tree__type svg,
.module-tree__status svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.module-tree__toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.module-tree__toggle:hover,
.module-tree__more:hover,
.module-tree__toggle:focus-visible,
.module-tree__more:focus-visible { background: color-mix(in srgb, var(--color-primary) 9%, transparent); color: var(--color-primary); }
.module-tree__toggle-placeholder { display: block; width: 22px; }
.module-tree__type { display: inline-grid; place-items: center; color: var(--color-text-weak); }
.module-tree__link { min-width: 0; align-self: stretch; display: flex; align-items: center; color: inherit; text-decoration: none; }
.module-tree__label { display: block; min-width: 0; }
.module-tree__label strong,
.module-tree__label small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.module-tree__label strong { font-size: var(--font-size-supporting); font-weight: 500; }
.module-tree__label small { margin-top: 1px; color: var(--color-text-weak); font-size: var(--font-size-micro); }
.module-tree__statuses { display: inline-flex; align-items: center; gap: 2px; }
.module-tree__status { display: inline-grid; width: 22px; height: 28px; place-items: center; color: var(--color-text-weak); }
.module-tree__status.is-shared,
.module-tree__status.is-public { color: var(--color-primary); }

.app-shell .workspace-module-sidebar .module-tree__handle { display: inline-grid; width: 24px; height: 30px; place-items: center; color: var(--color-text-weak); cursor: grab !important; font-size: 13px !important; opacity: 0; transition: opacity var(--duration-fast) var(--ease-standard); }
.app-shell .workspace-module-sidebar .module-tree__more { opacity: 0; transition: opacity var(--duration-fast) var(--ease-standard); }
.app-shell .workspace-module-sidebar .module-tree__row:hover .module-tree__handle,
.app-shell .workspace-module-sidebar .module-tree__row:focus-within .module-tree__handle,
.app-shell .workspace-module-sidebar .module-tree__row.is-current .module-tree__handle,
.app-shell .workspace-module-sidebar .module-tree__row.is-dragging .module-tree__handle,
.app-shell .workspace-module-sidebar .module-tree__row:hover .module-tree__more,
.app-shell .workspace-module-sidebar .module-tree__row:focus-within .module-tree__more,
.app-shell .workspace-module-sidebar .module-tree__row.is-current .module-tree__more { opacity: 1; }
.app-shell .workspace-module-sidebar .module-tree__row.is-dragging { opacity: .38; }
.app-shell .workspace-module-sidebar .module-tree__row.drop-before { box-shadow: inset 0 2px 0 var(--color-primary); }
.app-shell .workspace-module-sidebar .module-tree__row.drop-after { box-shadow: inset 0 -2px 0 var(--color-primary); }
.app-shell .workspace-module-sidebar .module-tree__row.drop-inside { background: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface)); box-shadow: inset 0 0 0 1px var(--color-primary); }
.app-shell .workspace-module-sidebar .module-tree__row.drop-invalid { cursor: not-allowed; box-shadow: inset 0 0 0 1px var(--color-danger); }
.app-shell .workspace-module-sidebar .tree-root-drop { display: none; margin: var(--space-2) var(--space-1); border: 1px dashed var(--color-border); border-radius: var(--radius-control-sm); padding: var(--space-2); color: var(--color-text-weak); font-size: var(--font-size-micro); text-align: center; }
.app-shell .workspace-module-sidebar .module-tree.is-drag-active .tree-root-drop { display: block; }
.app-shell .workspace-module-sidebar .tree-root-drop.drop-inside { border-color: var(--color-primary); background: var(--color-primary-soft); color: var(--color-primary); }
.app-shell .workspace-module-sidebar .module-tree.is-filtering .module-tree__row { min-height: 44px; }

.module-tree__empty,
.module-panel__search-empty { padding: var(--space-8) var(--space-5); color: var(--color-text-secondary); text-align: center; }
.module-tree__empty p,
.module-panel__search-empty p { margin: 0; color: var(--color-text); font-size: var(--font-size-body); }
.module-tree__empty span { display: block; margin-top: var(--space-2); color: var(--color-text-weak); font-size: var(--font-size-supporting); line-height: 1.6; }
.module-tree__empty .ui-button { margin-top: var(--space-4); }
.module-panel__search-empty button { margin-top: var(--space-3); border: 0; background: transparent; color: var(--color-primary); cursor: pointer; font: inherit; font-size: var(--font-size-supporting); }
.app-shell .workspace-module-sidebar .tree-help { flex: 0 0 auto; margin: 0; border-top: 1px solid var(--color-divider); padding: var(--space-3) var(--space-4); color: var(--color-text-weak); font-size: var(--font-size-micro); line-height: 1.55; }

.module-tree__header-menu,
.module-tree__context-menu { position: fixed; z-index: var(--z-dropdown); display: grid; min-width: 176px; overflow: hidden; border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface); box-shadow: var(--shadow-popover); padding: var(--space-1); }
.module-tree__header-menu[hidden],
.module-tree__context-menu[hidden] { display: none; }
.module-tree__header-menu button,
.module-tree__context-menu button { display: flex; min-height: 36px; align-items: center; border: 0; border-radius: var(--radius-control-sm); background: transparent; padding: 0 var(--space-3); color: var(--color-text); cursor: pointer; font: inherit; font-size: var(--font-size-supporting); text-align: left; }
.module-tree__header-menu button:hover,
.module-tree__context-menu button:hover,
.module-tree__header-menu button:focus-visible,
.module-tree__context-menu button:focus-visible { background: var(--color-primary-soft); color: var(--color-primary); }
.module-tree__context-menu .is-danger { color: var(--color-danger); }
.module-tree__menu-separator { height: 1px; margin: var(--space-1) var(--space-2); background: var(--color-divider); }

.module-panel__restore { position: absolute; top: var(--space-3); left: var(--space-3); z-index: var(--z-sticky); display: none; min-height: 36px; align-items: center; gap: var(--space-2); border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface); padding: 0 var(--space-3); box-shadow: var(--shadow-popover); cursor: pointer; font: inherit; font-size: var(--font-size-supporting); }
.app-shell .workspace-editor-main { position: relative; }
.app-shell.is-module-panel-collapsed .workspace-module-sidebar.module-panel { width: 0; flex-basis: 0; border-right: 0; opacity: 0; pointer-events: none; visibility: hidden; }
.app-shell.is-module-panel-collapsed .module-panel__restore { display: inline-flex; }
.module-panel__backdrop { display: none; }

@media (max-width: 1180px) and (min-width: 900px) {
  .app-shell .workspace-module-sidebar.module-panel { flex-basis: 260px; }
  .module-panel__surface { width: 260px; }
}

@media (max-width: 899px) {
  body.module-panel-drawer-open { overflow: hidden; }
  .app-shell .workspace-module-sidebar.module-panel,
  .app-shell.is-module-panel-collapsed .workspace-module-sidebar.module-panel { position: fixed; inset: 0 auto 0 0; z-index: calc(var(--z-overlay) + 2); width: min(320px, 86vw); max-width: none; flex-basis: auto; border-right: 1px solid var(--color-divider); opacity: 1; pointer-events: auto; visibility: visible; transform: translateX(-102%); transition: transform var(--duration-normal) var(--ease-standard); }
  .module-panel__surface { width: 100%; }
  .app-shell.is-module-panel-open .workspace-module-sidebar.module-panel { transform: translateX(0); }
  .module-panel__backdrop { position: fixed; inset: 0; z-index: calc(var(--z-overlay) + 1); display: block; border: 0; background: rgba(37, 49, 43, .24); opacity: 0; pointer-events: none; transition: opacity var(--duration-normal) var(--ease-standard); }
  .app-shell.is-module-panel-open .module-panel__backdrop { opacity: 1; pointer-events: auto; }
  .module-panel__restore,
  .app-shell.is-module-panel-collapsed .module-panel__restore { display: inline-flex; }
  .app-shell .workspace-module-sidebar .module-tree__more { opacity: 1; }
  .app-shell .workspace-module-sidebar .module-tree__handle { display: none; }
  .app-shell .workspace-module-sidebar .module-tree__row { grid-template-columns: 28px 20px minmax(0, 1fr) auto 36px; min-height: 44px; }
}

@media (hover: none) {
  .app-shell .workspace-module-sidebar .module-tree__more { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell .workspace-module-sidebar.module-panel,
  .module-panel__backdrop,
  .module-tree__toggle svg { transition: none; }
}

/* Phase 9: shared module icon language and long-form editor surface. */
.module-icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.module-icon,
.module-icon > svg {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.module-icon,
.module-icon > svg,
.app-global-nav__module-status svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.55;
}

.module-icon--root { color: var(--color-primary); }
.module-icon--child { color: var(--color-text-muted); }
.module-icon--folder { opacity: .84; }
.module-icon--documents,
.module-icon--work,
.module-icon--diary,
.module-icon--finance { opacity: .94; }

.app-global-nav__link {
  grid-template-columns: 20px minmax(0, 1fr) auto;
}

.app-global-nav__module-status {
  display: inline-grid;
  width: 20px;
  height: 28px;
  place-items: center;
  color: var(--color-text-muted);
}

.app-global-nav__module-status-list { display: inline-flex; align-items: center; justify-content: flex-end; }

.app-global-nav__module-status svg { width: 14px; height: 14px; }
.app-global-nav__module-status.is-shared,
.app-global-nav__module-status.is-public { color: var(--color-primary); }

.app-shell .workspace-module-sidebar .module-tree__type.module-icon {
  width: 18px;
  height: 18px;
}

html[data-app-sidebar-collapsed="true"] .app-global-nav__module-status-list { display: none; }

.app-shell .workspace-editor-main {
  background: var(--color-bg-page);
  padding: clamp(var(--space-4), 2.4vw, var(--space-8));
}

.app-shell .workspace-editor-main > .note-card[data-workspace-editor] {
  width: min(100%, 1120px);
  min-height: calc(100vh - var(--app-topbar-height) - clamp(32px, 4.8vw, 64px));
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: var(--color-surface);
  box-shadow: none;
}

.app-shell [data-workspace-editor] .workspace-editor__context {
  min-height: 44px;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-2) clamp(var(--space-4), 4vw, var(--space-10));
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: var(--font-size-meta);
}

.workspace-editor__breadcrumb {
  display: flex;
  min-width: 0;
  flex: 1 1 260px;
  align-items: center;
  gap: var(--space-2);
  overflow: hidden;
  white-space: nowrap;
}

.workspace-editor__breadcrumb a,
.workspace-editor__breadcrumb span {
  overflow: hidden;
  color: inherit;
  text-overflow: ellipsis;
  text-decoration: none;
}

.workspace-editor__breadcrumb a:hover,
.workspace-editor__breadcrumb a:focus-visible { color: var(--color-primary); }
.workspace-editor__breadcrumb [aria-current="location"] { color: var(--color-text-secondary); }

.app-shell [data-workspace-editor] .workspace-editor__context-actions {
  display: flex;
  min-width: 0;
  flex: 0 1 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.workspace-editor__save-state {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  color: var(--color-text-muted);
}

.workspace-editor__save-state i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.workspace-editor__save-state[data-state="saved"] { color: color-mix(in srgb, var(--color-success) 72%, var(--color-text-muted)); }
.workspace-editor__save-state[data-state="saving"] { color: var(--color-primary); }
.workspace-editor__save-state[data-state="dirty"] { color: var(--color-text-secondary); }
.workspace-editor__save-state[data-state="error"] { color: var(--color-danger); }

.app-shell [data-workspace-editor] .workspace-editor__visibility {
  min-height: 28px;
  gap: 3px;
  border: 0;
  border-left: 1px solid var(--color-divider);
  padding-left: var(--space-2);
  font-size: var(--font-size-micro);
}

.app-shell [data-workspace-editor] .workspace-editor__visibility select {
  max-width: 92px;
  border: 0;
  border-radius: var(--radius-control-sm);
  background: transparent;
  padding: 3px 20px 3px 5px;
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
}

.workspace-editor__visibility-readonly { color: var(--color-text-muted); font-size: var(--font-size-micro); }
.workspace-editor__more-trigger { flex: 0 0 auto; }

.app-shell [data-workspace-editor] .workspace-editor__title-row {
  display: block;
  width: min(100%, 900px);
  margin: 0 auto;
  padding: clamp(var(--space-8), 5vw, var(--space-12)) clamp(var(--space-5), 5vw, var(--space-10)) var(--space-5);
}

.app-shell [data-workspace-editor] .workspace-editor__title-row textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  overflow: hidden;
  resize: none;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  outline: 0;
  background: transparent;
  padding: 0 0 var(--space-2);
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3vw, 2.5rem);
  font-weight: 500;
  line-height: 1.32;
  transition: border-color var(--duration-fast) var(--ease-standard), background-color var(--duration-fast) var(--ease-standard);
}

.app-shell [data-workspace-editor] .workspace-editor__title-row textarea:hover:not([readonly]) { border-bottom-color: var(--color-divider); }
.app-shell [data-workspace-editor] .workspace-editor__title-row textarea:focus-visible { border-bottom-color: var(--color-primary); box-shadow: none; }

.app-shell [data-workspace-editor] .workspace-editor__modebar {
  width: min(100%, 900px);
  min-height: 40px;
  margin: 0 auto;
  border: 0;
  border-bottom: 1px solid var(--color-divider);
  background: transparent;
  padding: 0 clamp(var(--space-5), 5vw, var(--space-10)) var(--space-3);
}

.workspace-editor__mode-switch {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control-sm);
  background: var(--color-bg-subtle);
  padding: 2px;
}

.app-shell [data-workspace-editor] .workspace-editor__mode-switch button {
  min-height: 28px;
  border-radius: 6px;
  padding: 0 var(--space-3);
  font-size: var(--font-size-micro);
}

.app-shell [data-workspace-editor] .workspace-editor__mode-switch button.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: 0 1px 2px rgba(38, 51, 46, .08);
}

.workspace-editor__mode-readonly { color: var(--color-text-muted); font-size: var(--font-size-meta); }
.app-shell [data-workspace-editor] .modebar-actions > span { color: var(--color-text-muted); font-size: var(--font-size-micro); }
.app-shell [data-workspace-editor] .mode-attachment { min-height: 30px; border-color: transparent; background: transparent; font-size: var(--font-size-micro); }
.app-shell [data-workspace-editor] .mode-attachment:hover { border-color: var(--color-border); background: var(--color-primary-soft); }

.app-shell [data-workspace-editor] .workspace-editor__toolbar {
  width: min(100%, 820px);
  margin: var(--space-3) auto 0;
  gap: 2px;
  border: 0;
  border-bottom: 1px solid var(--color-divider);
  background: transparent;
  padding: 0 0 var(--space-3);
}

.app-shell [data-workspace-editor] .workspace-editor__toolbar button,
.app-shell [data-workspace-editor] .workspace-editor__toolbar label {
  min-width: 30px;
  height: 30px;
  border-radius: var(--radius-control-sm);
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
}

.app-shell [data-workspace-editor] .workspace-editor__toolbar button:hover,
.app-shell [data-workspace-editor] .workspace-editor__toolbar button.is-active,
.app-shell [data-workspace-editor] .workspace-editor__toolbar button[aria-pressed="true"] {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.app-shell [data-workspace-editor] .workspace-editor__body {
  display: flex;
  min-height: clamp(440px, 58vh, 760px);
  overflow: visible;
  background: var(--color-surface);
}

.app-shell [data-workspace-editor] .workspace-editor__richtext,
.app-shell [data-workspace-editor] .workspace-editor__preview {
  width: min(100%, 820px);
  max-width: 820px;
  min-height: 440px;
  margin: 0 auto;
  overflow-wrap: anywhere;
  outline: 0;
  padding: clamp(var(--space-6), 4vw, var(--space-10)) clamp(var(--space-5), 4vw, var(--space-8));
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: clamp(.9375rem, .9rem + .16vw, 1.0625rem);
  line-height: var(--line-height-reading);
}

.app-shell [data-workspace-editor] .workspace-editor__richtext:focus { box-shadow: none; }
.app-shell [data-workspace-editor] .workspace-editor__richtext { position: relative; }
.app-shell [data-workspace-editor] .workspace-editor__richtext.is-empty::before {
  position: absolute;
  top: clamp(var(--space-6), 4vw, var(--space-10));
  left: clamp(var(--space-5), 4vw, var(--space-8));
  color: var(--color-text-muted);
  content: attr(data-placeholder);
  pointer-events: none;
}

.app-shell [data-workspace-editor] .workspace-editor__richtext p,
.app-shell [data-workspace-editor] .workspace-editor__preview p { margin: 0 0 1.05em; }
.app-shell [data-workspace-editor] .workspace-editor__richtext h1,
.app-shell [data-workspace-editor] .workspace-editor__richtext h2,
.app-shell [data-workspace-editor] .workspace-editor__richtext h3,
.app-shell [data-workspace-editor] .workspace-editor__preview h1,
.app-shell [data-workspace-editor] .workspace-editor__preview h2,
.app-shell [data-workspace-editor] .workspace-editor__preview h3 { margin: 1.6em 0 .65em; color: var(--color-text-primary); font-family: var(--font-display); line-height: var(--line-height-tight); }
.app-shell [data-workspace-editor] .workspace-editor__richtext a,
.app-shell [data-workspace-editor] .workspace-editor__preview a { color: var(--color-primary); text-decoration-color: color-mix(in srgb, var(--color-primary) 38%, transparent); text-underline-offset: 3px; }
.app-shell [data-workspace-editor] .workspace-editor__richtext pre,
.app-shell [data-workspace-editor] .workspace-editor__preview pre { max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

.app-shell [data-workspace-editor] .markdown-workspace { min-height: 440px; }
.app-shell [data-workspace-editor] .markdown-workspace > label { width: min(100%, 900px); margin: 0 auto; border-bottom-color: var(--color-divider); }
.app-shell [data-workspace-editor] .markdown-columns { width: min(100%, 1080px); margin: 0 auto; }
.app-shell [data-workspace-editor] .markdown-columns textarea {
  min-height: 520px;
  border-right-color: var(--color-divider);
  background: color-mix(in srgb, var(--color-bg-subtle) 46%, var(--color-surface));
  padding: clamp(var(--space-5), 3vw, var(--space-8));
  color: var(--color-text-primary);
  font-family: var(--font-mono);
  font-size: .875rem;
  line-height: 1.75;
}
.app-shell [data-workspace-editor] .markdown-columns textarea:focus { box-shadow: inset 2px 0 0 var(--color-primary); }

.app-shell [data-workspace-editor] .workspace-editor__attachments,
.app-shell [data-workspace-editor] .workspace-editor__footer {
  width: min(calc(100% - 40px), 820px);
  margin: 0 auto;
  border-top: 1px solid var(--color-divider);
  background: transparent;
}

.app-shell [data-workspace-editor] .workspace-editor__attachments { padding: var(--space-4) 0; }
.app-shell [data-workspace-editor] .workspace-editor__footer { padding: var(--space-4) 0 var(--space-6); }
.app-shell [data-workspace-editor] .workspace-editor__footer span { color: var(--color-text-muted); font-size: var(--font-size-micro); }
.app-shell [data-workspace-editor] .workspace-editor__save-button { min-height: 34px; }

.workspace-editor__menu {
  position: fixed;
  z-index: var(--z-dropdown);
  display: grid;
  min-width: 180px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
  padding: var(--space-1);
}
.workspace-editor__menu[hidden] { display: none; }
.workspace-editor__menu a,
.workspace-editor__menu button { display: flex; min-height: 36px; align-items: center; border: 0; border-radius: var(--radius-control-sm); background: transparent; padding: 0 var(--space-3); color: var(--color-text); cursor: pointer; font: inherit; font-size: var(--font-size-supporting); text-align: left; text-decoration: none; }
.workspace-editor__menu a:hover,
.workspace-editor__menu button:hover,
.workspace-editor__menu a:focus-visible,
.workspace-editor__menu button:focus-visible { background: var(--color-primary-soft); color: var(--color-primary); }
.workspace-editor__menu .is-danger { color: var(--color-danger); }
.workspace-editor__menu-separator { height: 1px; margin: var(--space-1) var(--space-2); background: var(--color-divider); }

@media (max-width: 899px) {
  .app-shell .workspace-editor-main { padding: var(--space-3); }
  .app-shell .workspace-editor-main > .note-card[data-workspace-editor] { min-height: calc(100vh - var(--app-topbar-height) - var(--space-6)); }
  .app-shell [data-workspace-editor] .workspace-editor__context { padding-inline: var(--space-4); }
  .app-shell [data-workspace-editor] .workspace-editor__context-actions { width: 100%; justify-content: flex-start; }
  .app-shell [data-workspace-editor] .workspace-editor__title-row { padding: var(--space-8) var(--space-5) var(--space-4); }
  .app-shell [data-workspace-editor] .workspace-editor__modebar { align-items: flex-start; gap: var(--space-2); padding-inline: var(--space-5); }
  .app-shell [data-workspace-editor] .modebar-actions > span { display: none; }
  .app-shell [data-workspace-editor] .workspace-editor__toolbar { width: calc(100% - 40px); overflow-x: auto; }
  .app-shell [data-workspace-editor] .workspace-editor__richtext,
  .app-shell [data-workspace-editor] .workspace-editor__preview { padding-inline: var(--space-5); }
  .app-shell [data-workspace-editor] .markdown-columns { grid-template-columns: 1fr; }
  .app-shell [data-workspace-editor] .markdown-columns textarea { border-right: 0; border-bottom: 1px solid var(--color-divider); }
  .app-shell [data-workspace-editor] .workspace-editor__footer { align-items: flex-start; gap: var(--space-3); }
}

@media (max-width: 640px) {
  .app-shell [data-workspace-editor] .workspace-editor__visibility { display: none; }
  .app-shell [data-workspace-editor] .workspace-editor__title-row textarea { font-size: 1.8rem; }
  .app-shell [data-workspace-editor] .workspace-editor__modebar { flex-wrap: wrap; }
  .app-shell [data-workspace-editor] .workspace-editor__footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell [data-workspace-editor] .workspace-editor__title-row textarea,
  .workspace-editor__save-state { transition: none; }
}

/* Workspace edit, focus, and reading modes */
.workspace-mode-controls {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 2px;
}

.workspace-mode-controls__button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.55;
}

.workspace-mode-controls__button[aria-pressed="true"] {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.workspace-mode-controls__button[aria-busy="true"] {
  cursor: wait;
  opacity: .64;
}

.workspace-reader[hidden] {
  display: none;
}

.workspace-reader {
  width: 100%;
  min-height: 100%;
  padding: clamp(var(--space-5), 5vw, var(--space-12)) clamp(var(--space-4), 6vw, var(--space-12));
  background: var(--color-bg-page);
  color: var(--color-text-primary);
}

.workspace-reader:focus {
  outline: 0;
}

.workspace-reader__header {
  display: flex;
  width: min(100%, 920px);
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin: 0 auto clamp(var(--space-8), 7vw, var(--space-12));
  border-bottom: 1px solid var(--color-divider);
  padding-bottom: var(--space-4);
}

.workspace-reader__breadcrumb {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
  line-height: var(--line-height-compact);
}

.workspace-reader__breadcrumb a,
.workspace-reader__breadcrumb span {
  overflow: hidden;
  color: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-reader__breadcrumb a:hover,
.workspace-reader__breadcrumb a:focus-visible {
  color: var(--color-primary);
}

.workspace-reader__return {
  flex: 0 0 auto;
  gap: var(--space-2);
}

.workspace-reader__article {
  width: min(100%, 800px);
  margin: 0 auto;
}

.workspace-reader__title {
  overflow-wrap: anywhere;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: clamp(2.15rem, 4.5vw, 3.35rem);
  font-weight: 520;
  letter-spacing: -0.025em;
  line-height: 1.22;
}

.workspace-reader__meta {
  margin: var(--space-4) 0 var(--space-10);
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.workspace-reader__body {
  color: var(--color-text-primary);
  font-size: clamp(1rem, .96rem + .16vw, 1.075rem);
  line-height: 1.86;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.workspace-reader__body > :first-child { margin-top: 0; }
.workspace-reader__body > :last-child { margin-bottom: 0; }
.workspace-reader__body p { margin: 0 0 1.15em; }
.workspace-reader__body h1,
.workspace-reader__body h2,
.workspace-reader__body h3,
.workspace-reader__body h4,
.workspace-reader__body h5,
.workspace-reader__body h6 {
  margin: 1.85em 0 .72em;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-weight: 560;
  line-height: 1.35;
}
.workspace-reader__body h1 { font-size: 1.75em; }
.workspace-reader__body h2 { font-size: 1.48em; }
.workspace-reader__body h3 { font-size: 1.25em; }
.workspace-reader__body :is(ul, ol) { margin: 0 0 1.2em; padding-left: 1.65em; }
.workspace-reader__body li + li { margin-top: .35em; }
.workspace-reader__body blockquote {
  margin: 1.5em 0;
  border-left: 2px solid color-mix(in srgb, var(--color-primary) 34%, var(--color-divider));
  padding: .15em 0 .15em var(--space-5);
  color: var(--color-text-secondary);
}
.workspace-reader__body pre {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-container);
  background: var(--color-bg-subtle);
  padding: var(--space-5);
  font-family: var(--font-mono);
  font-size: .9em;
  line-height: 1.65;
  white-space: pre;
}
.workspace-reader__body code { font-family: var(--font-mono); }
.workspace-reader__body :not(pre) > code {
  border-radius: 5px;
  background: var(--color-bg-subtle);
  padding: .12em .34em;
  font-size: .9em;
}
.workspace-reader__body a {
  color: var(--color-primary);
  text-decoration-color: color-mix(in srgb, var(--color-primary) 38%, transparent);
  text-underline-offset: 3px;
}
.workspace-reader__body :is(img, video, audio) { max-width: 100%; }
.workspace-reader__body img { height: auto; border-radius: var(--radius-control-sm); }
.workspace-reader__body figure { margin: var(--space-8) 0; }
.workspace-reader__body figcaption { margin-top: var(--space-2); color: var(--color-text-muted); font-size: var(--font-size-meta); text-align: center; }
.workspace-reader__body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.workspace-reader__body th,
.workspace-reader__body td { border-bottom: 1px solid var(--color-divider); padding: var(--space-2) var(--space-3); text-align: left; }

.workspace-reader__empty {
  margin-top: var(--space-12);
  color: var(--color-text-muted);
  font-family: var(--font-display);
  font-size: 1.125rem;
  text-align: center;
}

.workspace-reader__attachments {
  margin-top: var(--space-12);
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-6);
}

.workspace-reader__attachments[hidden] { display: none; }
.workspace-reader__attachments h2 { margin: 0 0 var(--space-3); font-family: var(--font-body); font-size: var(--font-size-supporting); font-weight: 650; }
.workspace-reader__attachment-list { display: grid; gap: var(--space-2); }
.workspace-reader__attachment {
  display: grid;
  min-width: 0;
  min-height: 42px;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  border-radius: var(--radius-control-sm);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-secondary);
}
.workspace-reader__attachment:hover,
.workspace-reader__attachment:focus-visible { background: var(--color-primary-soft); color: var(--color-primary); }
.workspace-reader__attachment strong { overflow: hidden; color: inherit; font-size: var(--font-size-supporting); text-overflow: ellipsis; white-space: nowrap; }
.workspace-reader__attachment small { color: var(--color-text-muted); font-size: var(--font-size-micro); }

.app-shell[data-workspace-mode="focus"],
.app-shell[data-workspace-mode="read"] {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell[data-workspace-mode="focus"] > .app-global-sidebar,
.app-shell[data-workspace-mode="read"] > .app-global-sidebar,
.app-shell[data-workspace-mode="focus"] > .app-sidebar-backdrop,
.app-shell[data-workspace-mode="read"] > .app-sidebar-backdrop,
.app-shell[data-workspace-mode="focus"] .app-topbar,
.app-shell[data-workspace-mode="read"] .app-topbar,
.app-shell[data-workspace-mode="focus"] .workspace-module-sidebar,
.app-shell[data-workspace-mode="read"] .workspace-module-sidebar,
.app-shell[data-workspace-mode="focus"] .module-panel__backdrop,
.app-shell[data-workspace-mode="read"] .module-panel__backdrop,
.app-shell[data-workspace-mode="focus"] .module-panel__restore,
.app-shell[data-workspace-mode="read"] .module-panel__restore {
  display: none;
}

.app-shell[data-workspace-mode="focus"] .app-shell__surface,
.app-shell[data-workspace-mode="read"] .app-shell__surface {
  grid-template-rows: minmax(0, 1fr);
}

.app-shell[data-workspace-mode="focus"] .app-shell__content,
.app-shell[data-workspace-mode="read"] .app-shell__content {
  min-height: 0;
}

.app-shell[data-workspace-mode="focus"] .workspace-editor-main,
.app-shell[data-workspace-mode="read"] .workspace-editor-main {
  padding: 0;
  background: var(--color-bg-page);
}

.app-shell[data-workspace-mode="focus"] [data-workspace-editor] {
  width: 100%;
  min-height: 100%;
  border: 0;
  border-radius: 0;
  background: var(--color-surface);
}

.app-shell[data-workspace-mode="focus"] .workspace-editor__context {
  position: sticky;
  z-index: var(--z-sticky);
  top: 0;
  width: 100%;
  max-width: none;
  min-height: 58px;
  background: color-mix(in srgb, var(--color-surface) 96%, transparent);
  padding: 0 clamp(var(--space-5), 5vw, var(--space-12));
}

.app-shell[data-workspace-mode="focus"] .workspace-editor__breadcrumb {
  max-width: 620px;
}

.app-shell[data-workspace-mode="focus"] :is(.workspace-editor__visibility, .workspace-editor__visibility-readonly) {
  display: none;
}

.app-shell[data-workspace-mode="focus"] .workspace-editor__title-row,
.app-shell[data-workspace-mode="focus"] .workspace-editor__modebar,
.app-shell[data-workspace-mode="focus"] .workspace-editor__attachments,
.app-shell[data-workspace-mode="focus"] .workspace-editor__footer {
  width: min(100%, 900px);
  margin-right: auto;
  margin-left: auto;
}

.app-shell[data-workspace-mode="focus"] .workspace-editor__title-row {
  padding-top: clamp(var(--space-10), 8vh, 88px);
}

.app-shell[data-workspace-mode="focus"] .workspace-editor__toolbar {
  width: min(calc(100% - 48px), 860px);
}

.app-shell[data-workspace-mode="focus"] .workspace-editor__richtext,
.app-shell[data-workspace-mode="focus"] .workspace-editor__preview {
  width: min(100%, 840px);
}

.app-shell[data-workspace-mode="read"] [data-workspace-editor] {
  display: none;
}

.app-shell[data-workspace-mode="read"] .workspace-reader:not([hidden]) {
  display: block;
}

@media (max-width: 899px) {
  .workspace-reader { padding: var(--space-5) var(--space-5) var(--space-12); }
  .workspace-reader__header { position: sticky; z-index: var(--z-sticky); top: 0; margin-bottom: var(--space-8); background: var(--color-bg-page); padding-top: var(--space-2); }
  .workspace-reader__title { font-size: clamp(2rem, 8vw, 2.75rem); }
  .workspace-reader__body { font-size: 1rem; line-height: 1.8; }
  .app-shell[data-workspace-mode="focus"] .workspace-editor__context { min-height: 54px; padding-inline: var(--space-4); }
  .app-shell[data-workspace-mode="focus"] .workspace-editor__context-actions { width: auto; margin-left: auto; }
  .app-shell[data-workspace-mode="focus"] .workspace-editor__title-row { padding-top: var(--space-8); }
}

@media (max-width: 640px) {
  .workspace-reader { padding-right: var(--space-4); padding-left: var(--space-4); }
  .workspace-reader__header { align-items: flex-start; }
  .workspace-reader__breadcrumb { padding-top: 9px; }
  .workspace-reader__return { padding-inline: var(--space-3); }
  .workspace-reader__attachment { grid-template-columns: 20px minmax(0, 1fr); }
  .workspace-reader__attachment small { grid-column: 2; }
  .app-shell[data-workspace-mode="focus"] .workspace-editor__breadcrumb { max-width: 42vw; }
  .app-shell[data-workspace-mode="focus"] .workspace-editor__context-actions { gap: var(--space-1); }
  .app-shell[data-workspace-mode="focus"] .workspace-editor__more-trigger { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell[data-workspace-mode],
  .workspace-reader,
  [data-workspace-editor] { transition: none; }
}

/* Authenticated library, finance, settings, and document detail pages */
.app-shell .shell-page-main {
  background: var(--color-bg-page);
}

.app-shell .shell-page,
.app-shell .account-shell.space-settings-shell {
  width: min(100%, 1280px);
  max-width: 1280px;
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(var(--space-6), 4vw, var(--space-10));
}

.app-shell .shell-page > .ui-page-header,
.app-shell .account-shell.space-settings-shell > .ui-page-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: 1px solid var(--color-divider);
}

.app-shell .shell-page > .ui-page-header .ui-page-header__heading,
.app-shell .account-shell.space-settings-shell > .ui-page-header .ui-page-header__heading {
  text-align: left;
}

.app-shell .library-page .search-bar {
  max-width: 720px;
  margin: 0 auto var(--space-8);
}

.app-shell .asset-item {
  min-width: 0;
  border-color: var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  box-shadow: none;
  transition: border-color var(--duration-fast) var(--ease-standard), background var(--duration-fast) var(--ease-standard);
}

.app-shell .asset-item > div {
  min-width: 0;
}

.app-shell .asset-item:hover {
  border-color: var(--color-border-strong);
  background: var(--color-bg-subtle);
  box-shadow: none;
  transform: none;
}

.app-shell .finance-summary > div,
.app-shell .finance-summary > form,
.app-shell .import-preview,
.app-shell .transaction-list,
.app-shell .appearance-settings,
.app-shell .export-all-card {
  border-color: var(--color-border);
  background: var(--color-surface);
  box-shadow: none;
}

.app-shell .preview-panel {
  border-color: var(--color-border);
  background: var(--color-surface);
  box-shadow: none;
}

.app-shell .asset-meta {
  justify-content: flex-start;
  border-bottom-color: var(--color-divider);
  color: var(--color-text-secondary);
}

@media (max-width: 899px) {
  .app-shell .shell-page,
  .app-shell .account-shell.space-settings-shell {
    padding: var(--space-5);
  }

  .app-shell .shell-page > .ui-page-header,
  .app-shell .account-shell.space-settings-shell > .ui-page-header {
    margin-bottom: var(--space-6);
  }

  .app-shell .ui-page-header {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: var(--space-3);
  }

  .app-shell .ui-page-header__actions {
    justify-content: flex-start;
  }
}

@media (max-width: 720px) {
  .app-shell .asset-grid,
  .app-shell .finance-summary,
  .app-shell .appearance-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell .asset-item {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .app-shell .asset-item time {
    display: none;
  }

  .app-shell .settings-section-title {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-4);
  }
}

/* Intelligent document center and versioned document detail */
.app-shell .document-center {
  max-width: 1180px;
}

.app-shell .document-center [data-document-filters] {
  display: grid;
  max-width: none;
  grid-template-columns: minmax(260px, 1fr) minmax(156px, 210px) minmax(132px, 168px) auto;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-6);
}

.app-shell .document-center [data-document-filters] label {
  min-width: 0;
}

.app-shell .document-center [data-document-filters] input,
.app-shell .document-center [data-document-filters] select {
  height: 42px;
  min-height: 42px;
  border-radius: var(--radius-control);
  font-size: var(--font-size-supporting);
}

.app-shell .document-center [data-document-filters] button {
  width: auto;
  min-width: 68px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--color-text-secondary);
}

.document-center__summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}

.document-center__summary p,
.document-center__summary span {
  margin: 0;
}

.document-center__summary p {
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
  font-weight: 650;
}

.document-center__summary span {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.document-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.document-center__empty {
  grid-column: 1 / -1;
  border-top: 1px solid var(--color-divider);
}

.document-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 126px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  transition: border-color var(--duration-fast) var(--ease-standard), background var(--duration-fast) var(--ease-standard);
}

.document-card:hover,
.document-card:focus-within {
  border-color: var(--color-border-strong);
  background: color-mix(in srgb, var(--color-surface), var(--color-primary-soft) 18%);
}

.document-card.is-deleted {
  background: var(--color-bg-muted);
}

.document-card__main {
  display: grid;
  min-width: 0;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5);
  color: inherit;
  text-decoration: none;
}

.document-card__file {
  display: grid;
  width: 46px;
  height: 56px;
  place-items: end center;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-control-sm);
  background: var(--color-bg-subtle);
  padding-bottom: 8px;
  color: var(--color-primary);
  font-size: 0.58rem;
  font-weight: 750;
  letter-spacing: 0.04em;
}

.document-card__body,
.document-card__body strong,
.document-card__body small {
  min-width: 0;
}

.document-card__body {
  display: grid;
  gap: 5px;
}

.document-card__body strong,
.document-card__body small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-card__body strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
  font-weight: 650;
}

.document-card__body small {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.document-card__meta {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: 3px;
  color: var(--color-text-secondary);
  font-size: var(--font-size-micro);
}

.document-card__meta span + span::before {
  content: "·";
  margin-right: var(--space-2);
  color: var(--color-divider);
}

.document-card__aside {
  display: grid;
  min-width: 92px;
  align-content: space-between;
  justify-items: end;
  padding: var(--space-4) var(--space-4) var(--space-3) 0;
}

.document-card__aside time {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.document-card__menu-trigger {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  opacity: 0.45;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.document-card:hover .document-card__menu-trigger,
.document-card:focus-within .document-card__menu-trigger,
.document-card__menu-trigger[aria-expanded="true"] {
  opacity: 1;
}

.document-card__menu {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% - var(--space-3));
  right: var(--space-3);
  display: grid;
  width: 190px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
  padding: var(--space-2);
}

.document-card__menu[hidden] {
  display: none;
}

.document-card__menu a,
.document-card__menu button {
  display: flex;
  min-height: 36px;
  align-items: center;
  border: 0;
  border-radius: var(--radius-control-sm);
  background: transparent;
  padding: 0 var(--space-3);
  color: var(--color-text-primary);
  font: inherit;
  font-size: var(--font-size-supporting);
  text-decoration: none;
  cursor: pointer;
}

.document-card__menu a:hover,
.document-card__menu button:hover,
.document-card__menu a:focus-visible,
.document-card__menu button:focus-visible {
  background: var(--color-bg-subtle);
}

.document-card__menu .is-danger {
  color: var(--color-error);
}

.document-card__menu [role="separator"] {
  height: 1px;
  margin: var(--space-1) var(--space-2);
  background: var(--color-divider);
}

.document-upload-dialog {
  width: min(580px, calc(100vw - 32px));
  padding: 0;
}

.document-upload-dialog > form {
  padding: 0;
}

.document-upload-dialog__body {
  display: grid;
  gap: var(--space-5);
}

.document-form-field {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  font-weight: 600;
}

.document-form-field textarea.ui-input {
  min-height: 110px;
}

.document-duplicate {
  display: grid;
  gap: var(--space-2);
  border: 1px solid rgba(139, 106, 54, 0.22);
  border-radius: var(--radius-control);
  background: var(--color-warning-soft);
  padding: var(--space-4);
}

.document-duplicate[hidden] {
  display: none;
}

.document-duplicate strong,
.document-duplicate p {
  margin: 0;
}

.document-duplicate p {
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
}

.document-duplicate > div {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.document-detail {
  max-width: 1120px;
}

.document-detail__deleted {
  display: flex;
  min-height: 0;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
  border: 1px solid rgba(150, 84, 76, 0.18);
  border-radius: var(--radius-container);
  background: var(--color-error-soft);
  padding: var(--space-5);
  text-align: left;
}

.document-detail__deleted p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
}

.document-detail__overview {
  display: grid;
  grid-template-columns: 1.4fr 0.65fr 0.8fr 0.85fr;
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
}

.document-detail__overview > div {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: var(--space-2);
  padding: var(--space-5);
}

.document-detail__overview > div + div {
  border-left: 1px solid var(--color-divider);
}

.document-detail__overview span {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.06em;
}

.document-detail__overview strong {
  overflow: hidden;
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
  font-weight: 650;
  text-overflow: ellipsis;
}

.document-detail__overview strong.is-success {
  color: var(--color-success);
}

.document-detail__overview strong.is-error {
  color: var(--color-error);
}

.document-detail__overview small {
  overflow: hidden;
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
  line-height: var(--line-height-compact);
  text-overflow: ellipsis;
}

.document-detail__type-control {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto;
  gap: var(--space-2);
}

.document-detail__purpose {
  display: grid;
  grid-column: 1 / -1;
  gap: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
  font-weight: 600;
}

.document-detail__purpose[hidden] {
  display: none;
}

.document-detail__type-control .ui-button {
  min-height: 42px;
  padding-inline: var(--space-3);
  white-space: nowrap;
}

.document-detail__notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-4);
  border-radius: var(--radius-control);
  background: var(--color-warning-soft);
  padding: var(--space-3) var(--space-4);
}

.document-detail__notice p {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
}

.document-detail__section {
  margin-top: var(--space-10);
}

.document-detail__section > header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}

.document-detail__section > header span,
.document-detail__section > header h2,
.document-detail__section > header p {
  margin: 0;
}

.knowledge-index__status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-block: 1px solid var(--color-divider, #e5e7e2);
}

.knowledge-index__status > div {
  min-width: 0;
  padding: var(--space-3, 12px) var(--space-4, 16px);
}

.knowledge-index__status > div + div {
  border-left: 1px solid var(--color-divider, #e5e7e2);
}

.knowledge-index__status span,
.knowledge-index__status strong {
  display: block;
}

.knowledge-index__status span {
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-xs, 0.75rem);
}

.knowledge-index__status strong {
  margin-top: var(--space-1, 4px);
  color: var(--color-text, #26332e);
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: 600;
}

.knowledge-index__notice,
.knowledge-index__suggestion {
  margin-top: var(--space-4, 16px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  border-left: 2px solid var(--color-primary, #254c3d);
  background: var(--color-surface-muted, #edf3ee);
  color: var(--color-text-secondary, #68736e);
}

.knowledge-index__notice.is-muted {
  border-left-color: var(--color-border, #d9ddd8);
}

.knowledge-index__notice.is-error {
  border-left-color: var(--color-danger, #985c50);
}

.knowledge-index__notice p,
.knowledge-index__suggestion p {
  margin: 0;
}

.knowledge-index__analysis {
  padding-top: var(--space-5, 20px);
}

.knowledge-index__generated-label {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-xs, 0.75rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.knowledge-index__generated-label small {
  letter-spacing: normal;
  text-transform: none;
}

.knowledge-index__analysis h3 {
  margin: var(--space-2, 8px) 0 0;
  color: var(--color-text, #26332e);
  font: 600 var(--font-size-md, 1rem)/1.6 var(--font-body);
}

.knowledge-index__summary {
  max-width: 76ch;
  margin: var(--space-2, 8px) 0 0;
  color: var(--color-text-secondary, #68736e);
  line-height: 1.8;
  white-space: pre-wrap;
}

.knowledge-index__tokens,
.knowledge-index__sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2, 8px);
  margin-top: var(--space-4, 16px);
}

.knowledge-index__tokens > strong,
.knowledge-index__sources > strong {
  margin-right: var(--space-1, 4px);
  font-size: var(--font-size-sm, 0.875rem);
}

.knowledge-index__tokens > span,
.knowledge-index__sources > a {
  padding: 3px 9px;
  border-radius: var(--radius-sm, 8px);
  background: var(--color-surface-muted, #edf3ee);
  color: var(--color-primary, #254c3d);
  font-size: var(--font-size-xs, 0.75rem);
  text-decoration: none;
}

.knowledge-index__sources > a:hover {
  text-decoration: underline;
}

.knowledge-index__meta {
  margin: var(--space-4, 16px) 0 0;
  color: var(--color-text-muted, #929b96);
  font-size: var(--font-size-xs, 0.75rem);
}

.knowledge-index__supplement {
  max-width: 76ch;
  margin-top: var(--space-4, 16px);
  color: var(--color-text-secondary, #68736e);
  font-size: var(--font-size-sm, 0.875rem);
}

.knowledge-index__supplement summary {
  color: var(--color-primary, #254c3d);
  cursor: pointer;
}

.knowledge-index__supplement p {
  margin: var(--space-2, 8px) 0 0;
  line-height: 1.7;
}

.knowledge-index__controls {
  display: grid;
  gap: var(--space-3, 12px);
  margin-top: var(--space-5, 20px);
  padding-top: var(--space-4, 16px);
  border-top: 1px solid var(--color-divider, #e5e7e2);
}

.knowledge-index__consent {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2, 8px);
  max-width: 84ch;
  color: var(--color-text-secondary, #68736e);
  font-size: var(--font-size-sm, 0.875rem);
  line-height: 1.65;
}

.knowledge-index__consent input {
  flex: 0 0 auto;
  margin-top: 0.35em;
  accent-color: var(--color-primary, #254c3d);
}

.knowledge-index__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
}

.knowledge-index__edit {
  max-width: 760px;
  margin-top: var(--space-4, 16px);
}

.knowledge-index__edit summary {
  color: var(--color-primary, #254c3d);
  cursor: pointer;
  font-size: var(--font-size-sm, 0.875rem);
}

.knowledge-index__edit form {
  display: grid;
  gap: var(--space-3, 12px);
  margin-top: var(--space-3, 12px);
}

.knowledge-index__edit label {
  display: grid;
  gap: var(--space-1, 4px);
  color: var(--color-text-secondary, #68736e);
  font-size: var(--font-size-sm, 0.875rem);
}

.knowledge-index__edit textarea {
  min-height: 128px;
  resize: vertical;
}

.document-chunk:target {
  scroll-margin-top: 88px;
  outline: 2px solid color-mix(in srgb, var(--color-primary, #254c3d) 24%, transparent);
  outline-offset: 3px;
}

@media (max-width: 780px) {
  .knowledge-index__status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .knowledge-index__status > div:nth-child(3) {
    border-left: 0;
  }

  .knowledge-index__status > div:nth-child(n + 3) {
    border-top: 1px solid var(--color-divider, #e5e7e2);
  }
}

.document-detail__section > header span {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 700;
  letter-spacing: 0.14em;
}

.document-detail__section > header h2 {
  margin-top: var(--space-1);
  color: var(--color-text-primary);
  font-size: var(--font-size-section-title);
}

.document-detail__section > header p {
  max-width: 48ch;
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
  line-height: var(--line-height-compact);
  text-align: right;
}

.document-structure__list {
  border-top: 1px solid var(--color-divider);
}

.document-chunk {
  border-bottom: 1px solid var(--color-divider);
}

.document-chunk summary {
  display: grid;
  grid-template-columns: minmax(120px, 0.42fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-2);
  cursor: pointer;
}

.document-chunk summary:hover {
  background: var(--color-bg-subtle);
}

.document-chunk__location {
  overflow: hidden;
  color: var(--color-primary);
  font-size: var(--font-size-meta);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-chunk summary strong {
  overflow: hidden;
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-chunk summary small {
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.document-chunk > pre {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  border-top: 1px solid var(--color-divider);
  background: color-mix(in srgb, var(--color-bg-subtle), transparent 38%);
  padding: var(--space-5) clamp(var(--space-5), 5vw, var(--space-12));
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-body);
  line-height: var(--line-height-reading);
  white-space: pre-wrap;
}

.version-history__table-wrap {
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
}

.version-history .ui-table {
  min-width: 900px;
}

.version-history .ui-table tr.is-current {
  background: var(--color-primary-soft);
}

.version-history .ui-table td {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.version-history .ui-table td:first-child {
  overflow: visible;
}

.version-history .ui-table td:first-child strong {
  margin-right: var(--space-2);
}

.version-history__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.version-history__actions a,
.version-history__actions button {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--color-primary);
  font: inherit;
  font-size: var(--font-size-meta);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.document-compare {
  max-width: 1080px;
}

.document-compare__chooser {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr) auto;
  align-items: end;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
  border-bottom: 1px solid var(--color-divider);
  padding-bottom: var(--space-6);
}

.document-compare__chooser label {
  display: grid;
  gap: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
}

.document-compare__chooser > span {
  align-self: center;
  color: var(--color-text-muted);
}

.document-compare__summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: var(--space-8);
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
}

.document-compare__summary > div {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-5);
}

.document-compare__summary > div + div {
  border-left: 1px solid var(--color-divider);
}

.document-compare__summary span {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.document-compare__summary strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
}

.document-compare__summary .is-added {
  color: var(--color-success);
}

.document-compare__summary .is-removed {
  color: var(--color-error);
}

.document-diff {
  display: grid;
  gap: var(--space-5);
}

.document-diff__change {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
}

.document-diff__change > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-4);
}

.document-diff__change > header span {
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
}

.document-diff__change > div {
  display: grid;
  gap: 1px;
  background: var(--color-divider);
}

.document-diff__change pre {
  overflow: auto;
  margin: 0;
  background: var(--color-surface);
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--font-size-meta);
  line-height: var(--line-height-body);
  white-space: pre-wrap;
}

.document-diff__change pre.is-added {
  background: var(--color-success-soft);
  color: var(--color-success);
}

.document-diff__change pre.is-removed {
  background: var(--color-error-soft);
  color: var(--color-error);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

@media (max-width: 980px) {
  .app-shell .document-center [data-document-filters] {
    grid-template-columns: minmax(220px, 1fr) minmax(150px, 190px) auto;
  }

  .app-shell .document-center [data-document-filters] label:nth-of-type(3) {
    display: none;
  }

  .document-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .document-detail__overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .document-detail__overview > div:nth-child(3) {
    border-left: 0;
    border-top: 1px solid var(--color-divider);
  }

  .document-detail__overview > div:nth-child(4) {
    border-top: 1px solid var(--color-divider);
  }
}

@media (max-width: 720px) {
  .app-shell .document-center [data-document-filters] {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .app-shell .document-center [data-document-filters] label:nth-of-type(2),
  .app-shell .document-center [data-document-filters] label:nth-of-type(3) {
    display: none;
  }

  .document-card {
    grid-template-columns: minmax(0, 1fr) 58px;
  }

  .document-card__main {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: var(--space-3);
    padding: var(--space-4);
  }

  .document-card__file {
    width: 40px;
    height: 49px;
  }

  .document-card__aside {
    min-width: 0;
    padding-right: var(--space-3);
  }

  .document-card__aside > .ui-status,
  .document-card__aside > time {
    display: none;
  }

  .document-detail__overview {
    grid-template-columns: minmax(0, 1fr);
  }

  .document-detail__overview > div + div,
  .document-detail__overview > div:nth-child(3),
  .document-detail__overview > div:nth-child(4) {
    border-top: 1px solid var(--color-divider);
    border-left: 0;
  }

  .document-detail__type-control {
    grid-template-columns: minmax(0, 1fr);
  }

  .document-detail__section > header {
    align-items: start;
    flex-direction: column;
    gap: var(--space-2);
  }

  .document-detail__section > header p {
    text-align: left;
  }

  .document-chunk summary {
    grid-template-columns: minmax(80px, 0.4fr) minmax(0, 1fr);
    gap: var(--space-2);
  }

  .document-chunk summary small {
    display: none;
  }

  .document-compare__chooser {
    grid-template-columns: minmax(0, 1fr);
  }

  .document-compare__chooser > span {
    display: none;
  }

  .document-compare__summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .document-compare__summary > div:nth-child(3) {
    border-top: 1px solid var(--color-divider);
    border-left: 0;
  }

  .document-compare__summary > div:nth-child(4) {
    border-top: 1px solid var(--color-divider);
  }
}

@media (prefers-reduced-motion: reduce) {
  .document-card,
  .document-card__menu-trigger {
    transition: none;
  }
}

/* Stage 16: research exploration
   This layer composes the existing App Shell and UI primitives. */
.app-shell .research-explore,
.app-shell .research-report {
  width: min(1120px, 100%);
  margin-inline: auto;
}

.research-explore__composer,
.research-history,
.research-report__section,
.research-rerun {
  border-top: 1px solid var(--color-divider);
  padding-block: var(--space-8);
}

.research-explore__composer > div:first-child,
.research-history > header,
.research-report__section > header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.research-explore__composer h2,
.research-history h2,
.research-report__section h2,
.research-report__pending h2 {
  margin: 0;
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: var(--font-size-section-title);
  line-height: var(--line-height-tight);
}

.research-explore__composer > div > p,
.research-history > header > p,
.research-report__section > header small {
  max-width: 42rem;
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-compact);
}

.research-history > header > div > span,
.research-report__section > header > div > span,
.research-history > header span {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 700;
  letter-spacing: 0.14em;
}

.research-explore__composer form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-5) var(--space-6);
}

.research-field {
  display: grid;
  align-content: start;
  gap: var(--space-2);
  margin: 0;
  min-width: 0;
}

.research-field > span,
.research-field > legend,
.research-rerun label > span {
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
  font-weight: 650;
}

.research-field > span b {
  color: var(--color-error);
  font-weight: inherit;
}

.research-field--wide,
.research-field--types,
.research-field--check,
.research-explore__submit {
  grid-column: 1 / -1;
}

.research-field--types {
  border: 0;
  padding: 0;
}

.research-field--types > div {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.research-field--types label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 6px 11px;
  background: var(--color-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: var(--font-size-supporting);
}

.research-field--types label:has(input:checked) {
  border-color: var(--color-border-strong);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.research-field--types input,
.research-field--check input {
  accent-color: var(--color-primary);
}

.research-field--check {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  column-gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-container);
}

.research-field--check input {
  margin-top: 4px;
}

.research-field--check small {
  grid-column: 2;
  color: var(--color-text-secondary);
}

.research-explore__submit {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4);
}

.research-explore__submit p,
.research-rerun [data-research-form-status] {
  margin: 0 auto 0 0;
  color: var(--color-error);
  font-size: var(--font-size-supporting);
}

.research-history__list {
  display: grid;
  gap: var(--space-2);
}

.research-history__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-4) var(--space-2);
}

.research-history__item > a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-5);
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.research-history__item > a:hover h3 {
  color: var(--color-primary);
}

.research-history__item h3,
.research-history__item p {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.research-history__item h3 {
  font-size: var(--font-size-card-title);
  font-weight: 650;
}

.research-history__item p,
.research-history__item small {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.research-history__actions {
  display: flex;
  gap: var(--space-1);
}

.research-report__status {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-block: 1px solid var(--color-divider);
  margin-block: var(--space-6) var(--space-8);
}

.research-report__status > div {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-4);
}

.research-report__status > div + div {
  border-left: 1px solid var(--color-divider);
}

.research-report__status span {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.research-report__status strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-body);
  font-weight: 650;
}

.research-report__pending,
.research-report__notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  border-radius: var(--radius-container);
  padding: var(--space-5);
  background: var(--color-bg-subtle);
}

.research-report__pending {
  margin-bottom: var(--space-6);
}

.research-report__pending p,
.research-report__notice p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-secondary);
}

.research-report__notice {
  display: block;
  margin-bottom: var(--space-4);
}

.research-report__notice.is-calm {
  border-left: 3px solid var(--color-warning);
  background: var(--color-warning-soft);
}

.research-report__origin {
  margin-bottom: var(--space-6);
  border-left: 2px solid var(--color-border-strong);
  padding-left: var(--space-4);
}

.research-report__origin span {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.research-report__origin p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-primary);
  font-family: var(--font-display);
  font-size: 1.15rem;
  line-height: var(--line-height-body);
}

.research-understanding {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-8);
  margin: 0;
}

.research-understanding > div {
  display: grid;
  gap: var(--space-2);
  border-bottom: 1px solid var(--color-divider);
  padding-bottom: var(--space-4);
}

.research-understanding dt {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.research-understanding dd {
  margin: 0;
  line-height: var(--line-height-body);
}

.research-understanding dd > span {
  display: inline-block;
  margin: 0 var(--space-2) var(--space-1) 0;
}

.research-understanding ul {
  margin: 0;
  padding-left: var(--space-5);
}

.research-material-groups {
  display: grid;
  gap: var(--space-8);
}

.research-material-groups > section {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.research-material-groups > section > h3 {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  font-weight: 700;
}

.research-source {
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  padding: var(--space-4);
  background: var(--color-surface);
}

.research-source__meta,
.research-source__footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}

.research-source__meta span + span::before,
.research-source__footer span + span::before {
  content: "·";
  margin-right: var(--space-3);
  color: var(--color-border-strong);
}

.research-source h3 {
  margin: var(--space-2) 0;
  font-size: var(--font-size-card-title);
}

.research-source h3 a {
  color: var(--color-text-primary);
  text-decoration: none;
}

.research-source h3 a:hover {
  color: var(--color-primary);
}

.research-source blockquote {
  display: -webkit-box;
  overflow: hidden;
  margin: var(--space-3) 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  line-height: var(--line-height-body);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.research-source.is-unavailable {
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
}

.research-findings {
  display: grid;
  gap: var(--space-4);
}

.research-findings > article {
  border-left: 2px solid var(--color-border-strong);
  padding: var(--space-1) 0 var(--space-1) var(--space-4);
}

.research-report__section.is-inference .research-findings > article {
  border-left-color: var(--color-warning);
}

.research-report__section.is-suggestion .research-findings > article {
  border-left-color: var(--color-primary);
}

.research-findings article > p {
  margin: 0;
  color: var(--color-text-primary);
  line-height: var(--line-height-reading);
}

.research-finding__sources {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
  padding: 0;
  list-style: none;
}

.research-finding__sources a,
.research-finding__sources span,
.research-finding__conflict {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 4px 9px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--font-size-meta);
  text-decoration: none;
}

.research-finding__conflict {
  margin-top: var(--space-2);
  background: var(--color-warning-soft);
  color: var(--color-warning);
}

.research-source-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding-left: var(--space-6);
}

.research-source-list a,
.research-source-list li > span {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr);
  gap: var(--space-2);
  color: var(--color-text-secondary);
  text-decoration: none;
}

.research-source-list a:hover {
  color: var(--color-primary);
}

.research-report__empty {
  margin: 0;
  color: var(--color-text-muted);
}

.research-rerun summary {
  color: var(--color-primary);
  cursor: pointer;
  font-weight: 650;
}

.research-rerun form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.research-rerun label {
  display: grid;
  gap: var(--space-2);
}

.research-rerun label:nth-child(2),
.research-rerun label:nth-child(4),
.research-rerun form > div {
  grid-column: 1 / -1;
}

.research-rerun form > div {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4);
}

@media (max-width: 880px) {
  .research-explore__composer form,
  .research-rerun form,
  .research-understanding,
  .research-material-groups > section {
    grid-template-columns: minmax(0, 1fr);
  }

  .research-field,
  .research-rerun label,
  .research-material-groups > section > h3 {
    grid-column: 1;
  }

  .research-report__status {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .research-report__status > div:nth-child(3) {
    border-top: 1px solid var(--color-divider);
    border-left: 0;
  }

  .research-report__status > div:nth-child(4) {
    border-top: 1px solid var(--color-divider);
  }

  .research-history__item {
    grid-template-columns: minmax(0, 1fr);
  }

  .research-history__actions {
    justify-content: flex-end;
  }
}

@media (max-width: 620px) {
  .research-explore__composer > div:first-child,
  .research-history > header,
  .research-report__section > header {
    flex-direction: column;
    gap: var(--space-2);
  }

  .research-history__item > a {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .research-history__item > a > small {
    grid-column: 1 / -1;
  }

  .research-report__status {
    grid-template-columns: minmax(0, 1fr);
  }

  .research-report__status > div + div,
  .research-report__status > div:nth-child(4) {
    border-top: 1px solid var(--color-divider);
    border-left: 0;
  }

  .research-field--types > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Stage 22: calm block editor and block-level knowledge links. */
.editor-mode-notice {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: min(100%, 920px);
  margin: 0 auto var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-text-secondary);
  background: var(--color-bg-subtle);
  font-size: var(--font-size-supporting);
}

.editor-mode-notice > div {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}

.editor-mode-notice strong {
  flex: none;
  color: var(--color-primary);
  font-size: var(--font-size-body);
}

.editor-mode-notice > .ui-button {
  margin-inline-start: auto;
  white-space: nowrap;
}

.editor-mode-notice__actions {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 2px;
  margin-inline-start: auto;
}

.editor-mode-notice__actions .ui-icon-button {
  width: 32px;
  min-width: 32px;
  height: 32px;
  color: var(--color-text-muted);
}

.editor-mode-notice.is-compact {
  width: min(100%, 920px);
  min-height: 32px;
  justify-content: flex-start;
  margin-bottom: var(--space-2);
  border-color: transparent;
  background: transparent;
  padding: 0;
}

.editor-mode-notice.is-compact [data-block-onboarding-description] {
  display: none;
}

.editor-mode-notice.is-compact strong {
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-pill);
  background: var(--color-bg-subtle);
  padding: 3px 9px;
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
  font-weight: 600;
}

.editor-mode-notice.is-compact .editor-mode-notice__actions {
  margin-inline-start: var(--space-1);
}

.block-upgrade-notice {
  margin-bottom: var(--space-5);
}

.block-upgrade-notice > details {
  margin-inline-start: auto;
}

.block-upgrade-notice__help {
  position: relative;
  flex: none;
}

.block-upgrade-notice__help p {
  position: absolute;
  z-index: var(--z-dropdown);
  inset-inline-end: 0;
  width: min(360px, calc(100vw - 40px));
  margin-top: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
}

.block-upgrade-notice pre {
  max-width: min(720px, 70vw);
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
}

.block-editor {
  width: min(100%, 920px);
  margin-inline: auto;
  padding: 0 clamp(var(--space-4), 4vw, var(--space-10)) var(--space-8);
}

.block-editor__chrome {
  display: flex;
  min-height: 46px;
  min-width: 0;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  padding: 5px 6px 5px var(--space-3);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-container);
  background: color-mix(in srgb, var(--color-bg-subtle) 70%, var(--color-surface));
}

.block-editor__chrome .editor-mode-notice {
  width: auto;
  min-width: 0;
  min-height: 34px;
  flex: 1 1 auto;
  gap: var(--space-2);
  margin: 0;
  border: 0;
  background: transparent;
  padding: 0;
}

.block-editor__mode-icon {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border-radius: 8px;
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.block-editor__mode-icon svg,
.block-editor__toolbar .ui-icon-button svg {
  display: block;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.block-editor__mode-copy {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: var(--space-2);
}

.block-editor__chrome .block-editor__mode-copy strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
  font-weight: 650;
  white-space: nowrap;
}

.block-editor__mode-copy [data-block-onboarding-description] {
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.block-editor__chrome .editor-mode-notice.is-compact strong {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
}

.block-editor__toolbar-separator {
  width: 1px;
  height: 18px;
  margin-inline: 3px;
  background: var(--color-divider);
}

.block-editor__toolbar,
.block-editor__footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.block-editor__toolbar {
  min-height: 34px;
  flex: 0 0 auto;
  gap: 2px;
  margin: 0;
  border: 0;
}

.block-editor__hint {
  margin-inline-start: auto;
}

.block-editor__toolbar-help {
  margin-inline-start: 0;
}

.block-editor__attachment {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 34px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-control-sm);
  cursor: pointer;
}

.block-editor__attachment:hover {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.block-editor__attachment input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.block-editor__chrome .block-editor__toolbar .ui-icon-button,
.block-editor__chrome .block-editor__attachment {
  width: 34px;
  height: 34px;
  min-height: 34px;
  flex-basis: 34px;
  border-color: transparent;
  border-radius: var(--radius-control-sm);
  background: transparent;
  padding: 0;
}

.block-editor__chrome .block-editor__toolbar .ui-icon-button:hover,
.block-editor__chrome .block-editor__attachment:hover {
  border-color: transparent;
  background: var(--color-primary-soft);
}

.block-editor__chrome .block-editor__toolbar .ui-icon-button:disabled {
  opacity: 0.36;
  cursor: default;
}

.block-editor__chrome .block-editor__toolbar .ui-icon-button:disabled:hover {
  background: transparent;
  color: var(--color-text-secondary);
}

.block-editor__list {
  display: grid;
  gap: 2px;
}

.block-editor__item {
  position: relative;
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  min-width: 0;
  border-inline-start: 2px solid transparent;
  border-radius: 0 var(--radius-control-sm) var(--radius-control-sm) 0;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    opacity var(--duration-fast) ease;
}

.block-editor__item:hover,
.block-editor__item:focus-within {
  background: color-mix(in srgb, var(--color-bg-subtle) 76%, transparent);
}

.block-editor__item.is-child {
  margin-inline-start: clamp(18px, 4vw, 36px);
  border-inline-start-color: var(--color-divider);
}

.block-editor__item.is-dragging {
  opacity: 0.44;
}

.block-editor__item.is-drop-before {
  border-block-start: 2px solid var(--color-primary);
}

.block-editor__item.is-drop-after {
  border-block-end: 2px solid var(--color-primary);
}

.block-editor__item.is-linked-target {
  border-inline-start-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.block-editor__rail {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  padding-top: 7px;
  opacity: 0.28;
  transition: opacity var(--duration-fast) ease;
}

.block-editor__item:hover .block-editor__rail,
.block-editor__item:focus-within .block-editor__rail,
.block-editor__item.is-dragging .block-editor__rail {
  opacity: 1;
}

.block-editor__handle,
.block-editor__more {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  color: var(--color-text-muted);
  background: transparent;
  cursor: pointer;
}

.block-editor__handle {
  width: 28px;
  cursor: grab;
  font-size: 18px;
  touch-action: none;
  user-select: none;
}

.block-editor__handle:active {
  cursor: grabbing;
}

.block-editor__handle:hover,
.block-editor__more:hover {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.block-editor__body {
  min-width: 0;
  padding: 4px var(--space-2) 4px var(--space-1);
}

.block-editor__body textarea,
.block-editor__body > input:not([type="checkbox"]) {
  width: 100%;
  min-height: 38px;
  padding: 7px 5px;
  border: 0;
  outline: 0;
  resize: none;
  color: var(--color-text);
  background: transparent;
  font: inherit;
  line-height: var(--line-height-body);
  overflow: hidden;
}

.block-editor__body textarea::placeholder {
  color: var(--color-text-weak);
}

.block-editor__item--heading_1 textarea {
  font-family: var(--font-display);
  font-size: var(--font-size-section-title);
  font-weight: 600;
}

.block-editor__item--heading_2 textarea {
  font-size: var(--font-size-card-title);
  font-weight: 650;
}

.block-editor__item--heading_3 textarea {
  font-weight: 650;
}

.block-editor__item--quote .block-editor__body,
.block-editor__item--callout .block-editor__body {
  margin-block: var(--space-1);
  border-inline-start: 2px solid var(--color-primary);
  background: var(--color-primary-soft);
}

.block-editor__item--callout select,
.block-editor__language {
  width: auto;
  min-height: 28px;
  margin: var(--space-1) var(--space-1) 0;
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  font-size: var(--font-size-meta);
}

.block-editor__item--code textarea,
.block-editor__item--raw_markdown textarea {
  font-family: var(--font-mono);
  font-size: var(--font-size-supporting);
}

.block-editor__item--todo .block-editor__body {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: start;
}

.block-editor__item--todo input[type="checkbox"] {
  margin-top: 13px;
}

.block-editor__item--divider hr {
  margin: var(--space-4) 0;
  border: 0;
  border-top: 1px solid var(--color-divider);
}

.block-editor__table {
  width: 100%;
  border-collapse: collapse;
}

.block-editor__table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.block-editor__table th,
.block-editor__table td {
  padding: 0;
  border: 1px solid var(--color-border);
}

.block-editor__table input {
  width: 100%;
  min-width: 80px;
  padding: var(--space-2);
  border: 0;
  color: var(--color-text);
  background: transparent;
}

.block-editor__table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.block-editor__asset {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  color: var(--color-primary);
}

.block-editor__asset img {
  display: block;
  max-width: min(100%, 720px);
  max-height: 520px;
  border-radius: var(--radius-control);
  object-fit: contain;
}

.block-editor__asset audio {
  width: min(100%, 560px);
}

.block-editor__asset video {
  display: block;
  width: min(100%, 760px);
  max-height: 560px;
  border-radius: var(--radius-control);
  background: var(--color-text);
}

.block-editor__asset small {
  color: var(--color-text-muted);
}

/* Shared paste/drop queue for record composers and both note editors. */
.record-attachments {
  display: grid;
  gap: var(--space-2);
  margin-block: var(--space-3);
}

.record-attachments[hidden] {
  display: none;
}

.record-attachment-picker {
  position: relative;
  display: inline-flex;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  justify-content: center;
  align-items: center;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  font-size: var(--font-size-meta);
  cursor: pointer;
  transition: color var(--duration-fast), border-color var(--duration-fast), background-color var(--duration-fast);
}

.record-attachment-picker:hover {
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
  color: var(--color-primary);
  background: var(--color-primary-soft);
}

.record-attachment-picker:focus-within {
  outline: 0;
  box-shadow: var(--shadow-focus);
}

.record-attachment-picker input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}

.record-attachment-picker__icon {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  pointer-events: none;
}

.record-attachment-picker__icon svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.record-attachment-picker__count {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  padding-inline: 4px;
  border: 2px solid var(--color-surface);
  border-radius: 999px;
  color: var(--color-surface);
  background: var(--color-primary);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.record-attachment-picker__count[hidden] {
  display: none;
}

.record-attachment {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-bg-subtle);
}

.record-attachment > img,
.record-attachment > video {
  width: 56px;
  height: 44px;
  border-radius: var(--radius-control-sm);
  object-fit: cover;
}

.record-attachment > audio {
  width: 180px;
  height: 36px;
}

.record-attachment__copy {
  display: grid;
  min-width: 0;
  line-height: 1.35;
}

.record-attachment__copy strong,
.record-attachment__copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-attachment__copy strong {
  color: var(--color-text);
  font-size: var(--font-size-body);
}

.record-attachment__copy span {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.record-attachment__status {
  color: var(--color-text-secondary) !important;
}

.record-attachment.is-failed,
.record-attachment.is-invalid {
  border-color: color-mix(in srgb, var(--color-danger) 32%, var(--color-border));
}

.record-attachment.is-success {
  border-color: color-mix(in srgb, var(--color-success) 24%, var(--color-border));
}

.record-attachment progress {
  width: 80px;
  accent-color: var(--color-primary);
}

.record-attachment__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.is-attachment-dragover {
  outline: 2px solid color-mix(in srgb, var(--color-primary) 56%, transparent);
  outline-offset: -4px;
  background-color: color-mix(in srgb, var(--color-primary-soft) 48%, transparent);
}

.block-editor.is-attachment-dragover .block-editor__list,
#note-dropzone.is-attachment-dragover {
  min-height: 180px;
}

@media (max-width: 640px) {
  .record-attachment {
    grid-template-columns: 48px minmax(0, 1fr) auto;
  }

  .record-attachment > audio {
    grid-column: 1 / -1;
    width: 100%;
  }

  .record-attachment progress {
    grid-column: 1 / -1;
    width: 100%;
  }
}

.block-editor__caption {
  margin-top: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
}

.block-editor__empty {
  margin: var(--space-8) 62px;
  color: var(--color-text-muted);
}

.block-editor__footer {
  justify-content: flex-end;
  margin-top: var(--space-5);
  border-top: 1px solid var(--color-divider);
}

.block-editor__footer[data-block-transient-actions] {
  min-height: 0;
  margin-top: var(--space-2);
  border-top: 0;
  padding: 0;
}

.block-editor__footer[data-block-transient-actions][hidden] {
  display: none;
}

.block-editor-menu,
.block-link-picker {
  position: fixed;
  z-index: var(--z-dropdown);
  max-height: min(480px, calc(100vh - 24px));
  padding: var(--space-2);
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
}

.block-editor-menu[hidden],
.block-link-picker[hidden] {
  display: none;
}

.block-editor-menu label {
  display: block;
  padding: var(--space-1);
}

.block-editor-menu label input {
  width: 100%;
}

.block-editor-menu [role="listbox"],
.block-editor-menu--context,
.block-link-picker__blocks {
  display: grid;
  gap: 2px;
}

.block-editor-menu button,
.block-link-picker button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 38px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-control-sm);
  color: var(--color-text);
  background: transparent;
  text-align: start;
}

.block-editor-menu button:hover,
.block-editor-menu button[aria-selected="true"],
.block-link-picker button:hover {
  background: var(--color-primary-soft);
}

.block-editor-menu button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.block-editor-menu__empty {
  margin: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--font-size-supporting);
}

.block-editor-menu button b {
  display: inline-grid;
  place-items: center;
  width: 30px;
  color: var(--color-text-secondary);
}

.block-editor-menu--context div[role="separator"] {
  margin: var(--space-1) 0;
  border-top: 1px solid var(--color-divider);
}

.block-link-picker__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.block-link-picker__target,
.block-link-picker__block {
  flex-direction: column;
  align-items: flex-start !important;
}

.block-link-picker small,
.block-link-picker span,
.block-link-picker > p {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.block-link-picker__blocks {
  margin: var(--space-1) 0 var(--space-2) var(--space-4);
  padding-inline-start: var(--space-3);
  border-inline-start: 1px solid var(--color-divider);
}

.block-backlinks-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-dialog);
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: var(--shadow-dialog);
}

.block-backlinks-dialog::backdrop {
  background: rgba(25, 42, 35, 0.24);
}

.block-backlinks-dialog > div:last-child {
  padding: var(--space-5);
}

.block-backlinks-dialog li {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-divider);
}

.block-backlinks-dialog p {
  margin: var(--space-1) 0 0;
  color: var(--color-text-secondary);
}

.block-editor-help {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
}

.block-editor-help__content {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-5);
  color: var(--color-text-secondary);
}

.block-editor-help__content p {
  margin: 0;
}

.block-editor-help kbd {
  padding: 0.1em 0.42em;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  color: var(--color-text);
  background: var(--color-bg-subtle);
  font: 0.9em var(--font-mono);
}

.note-block-reader {
  scroll-margin-top: 96px;
}

.note-block-reader.is-block-target,
.knowledge-link-target-unavailable {
  border-inline-start: 2px solid var(--color-primary);
  padding-inline-start: var(--space-3);
}

.knowledge-wiki-link__status {
  margin-inline-start: 0.25em;
  color: var(--color-text-muted);
  font-size: 0.86em;
  font-weight: 400;
}

@media (hover: none) {
  .block-editor__rail {
    opacity: 1;
  }
}

@media (max-width: 700px) {
  .block-editor {
    padding-inline: var(--space-2);
  }

  .block-editor__hint {
    display: none;
  }

  .block-editor__item {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .block-editor__item.is-child {
    margin-inline-start: 14px;
  }

  .editor-mode-notice,
  .editor-mode-notice > div,
  .block-upgrade-notice {
    align-items: flex-start;
    flex-direction: column;
  }

  .editor-mode-notice > .ui-button,
  .block-upgrade-notice > details {
    margin-inline-start: 0;
  }

  .block-editor__handle,
  .block-editor__more {
    width: 28px;
    min-height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .block-editor__item,
  .block-editor__rail {
    transition: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .research-source h3 a {
    transition: none;
  }
}

/* Stage 19: unified trash and open export */
.trash-shell,
.exports-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.trash-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-block: var(--space-4);
  border-block: 1px solid var(--color-divider);
}

.trash-toolbar__count {
  color: var(--color-text-muted);
  font-size: var(--font-size-supporting);
}

.trash-toolbar__bulk {
  display: flex;
  gap: var(--space-2);
  margin-inline-start: auto;
}

.trash-list {
  display: grid;
  gap: 0;
}

.trash-item {
  display: grid;
  grid-template-columns: auto 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  min-height: 92px;
  padding: var(--space-4) var(--space-2);
  border-bottom: 1px solid var(--color-divider);
}

.trash-item__select input {
  width: 18px;
  height: 18px;
  accent-color: var(--color-primary);
}

.trash-item__icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-control-sm);
  color: var(--color-primary);
  background: var(--color-primary-soft);
  font-size: var(--font-size-supporting);
}

.trash-item__content,
.trash-item__heading {
  min-width: 0;
}

.trash-item__heading {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.trash-item__heading > strong {
  overflow: hidden;
  color: var(--color-text-primary);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.trash-item__content > p {
  margin: var(--space-1) 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
}

.trash-item__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.trash-item__actions {
  display: flex;
  gap: var(--space-2);
}

.trash-confirmation {
  display: grid;
  gap: var(--space-2);
}

.ui-error-state.is-error {
  color: var(--color-error);
  background: var(--color-error-soft);
}

.exports-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
}

.export-builder {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-6);
  border: 1px solid var(--color-divider);
  background: var(--color-surface);
}

.export-builder > h2,
.export-jobs__heading h2 {
  margin: 0;
  font-size: var(--font-size-section-title);
}

.export-builder > label {
  display: grid;
  gap: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  font-weight: 600;
}

.export-options {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-4) 0 0;
  border: 0;
  border-top: 1px solid var(--color-divider);
}

.export-options legend {
  padding: 0;
  color: var(--color-text-primary);
  font-weight: 650;
}

.export-options label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-secondary);
}

.export-options input {
  width: 17px;
  height: 17px;
  accent-color: var(--color-primary);
}

.export-builder__notice {
  padding: var(--space-4);
  border-radius: var(--radius-control);
  color: var(--color-text-secondary);
  background: var(--color-bg-subtle);
  font-size: var(--font-size-supporting);
}

.export-builder__notice p {
  margin: var(--space-1) 0 0;
}

.export-jobs {
  min-width: 0;
}

.export-jobs__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
}

.export-jobs__heading .eyebrow {
  margin: 0 0 var(--space-1);
}

.export-job-list {
  display: grid;
}

.export-job {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2) var(--space-4);
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--color-divider);
}

.export-job > div:first-child {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.export-job p,
.export-job small {
  grid-column: 1;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.export-job__actions {
  grid-column: 2;
  grid-row: 1 / span 3;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.ui-status--queued,
.ui-status--processing {
  color: var(--color-warning);
  background: var(--color-warning-soft);
}

.ui-status--succeeded,
.ui-status--partial {
  color: var(--color-success);
  background: var(--color-success-soft);
}

.ui-status--failed,
.ui-status--cancelled,
.ui-status--expired {
  color: var(--color-text-secondary);
  background: var(--color-bg-muted);
}

@media (max-width: 900px) {
  .exports-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .trash-item {
    grid-template-columns: auto 36px minmax(0, 1fr);
  }

  .trash-item__actions {
    grid-column: 3;
  }
}

@media (max-width: 620px) {
  .trash-toolbar__bulk {
    width: 100%;
    margin-inline-start: 0;
  }

  .trash-item {
    gap: var(--space-3);
    padding-block: var(--space-5);
  }

  .trash-item__actions,
  .export-job__actions {
    flex-wrap: wrap;
  }

  .export-job {
    grid-template-columns: minmax(0, 1fr);
  }

  .export-job__actions {
    grid-column: 1;
    grid-row: auto;
  }
}
/* Stage 25: public offline shell. It contains no account or cached content. */
.offline-page {
  min-height: 100vh;
  background: var(--color-page, #f7f6f1);
}

.offline-shell {
  box-sizing: border-box;
  width: min(640px, calc(100% - 48px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: var(--space-4, 16px);
}

.offline-shell h1,
.offline-shell p {
  margin: 0;
}

.offline-shell h1 {
  font-family: var(--font-display);
  color: var(--color-text);
}

.offline-shell > p:not(.eyebrow) {
  max-width: 34rem;
  color: var(--color-text-secondary);
}

.offline-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-container);
  color: var(--color-content);
  background: var(--color-primary);
  font-family: var(--font-display);
  font-size: 22px;
}

.offline-draft-dialog {
  width: min(620px, calc(100vw - 32px));
}

.offline-draft-dialog__meta {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}

.offline-draft-dialog__comparison {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-block: var(--space-4);
}

.offline-draft-dialog__comparison section {
  min-width: 0;
  padding: var(--space-3);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-sm);
}

.offline-draft-dialog__comparison h3 {
  margin: 0 0 var(--space-2);
  font: 600 var(--font-size-meta)/1.5 var(--font-body);
  color: var(--color-text-secondary);
}

.offline-draft-dialog__comparison p {
  margin: 0;
  color: var(--color-text);
  font-size: var(--font-size-meta);
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .offline-draft-dialog__comparison {
    grid-template-columns: 1fr;
  }
}

/* Personal status timeline */
.status-main { overflow: auto; }
.status-layout {
  width: min(100%, 880px);
  margin: 0 auto;
  padding: clamp(var(--space-6), 4vw, var(--space-10));
}
.status-page-header { margin-bottom: var(--space-7, 28px); }
.status-page-header h1 {
  margin: 0;
  color: var(--color-text-primary);
  font: 400 var(--font-size-page-title)/var(--line-height-tight) var(--font-display);
}
.status-page-header > p:last-child {
  margin: var(--space-2) 0 0;
  color: var(--color-text-secondary);
}
.status-composer {
  padding: var(--space-6);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-container);
  background: var(--color-surface);
}
.status-composer h2,
.status-timeline > h2 {
  margin: 0 0 var(--space-4);
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
}
.status-composer textarea,
.status-comment-form textarea,
.status-comment__reply textarea {
  width: 100%;
  min-height: 112px;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-text-primary);
  background: var(--color-surface-strong);
  line-height: var(--line-height-body);
  resize: vertical;
}
.status-composer__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
}
.status-composer__attachments {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-supporting);
  cursor: pointer;
}
.status-composer__attachments input {
  max-width: min(360px, 45vw);
  margin-inline-start: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.status-composer__hint {
  margin: var(--space-2) 0 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.status-composer .ui-error {
  margin: 0 0 var(--space-3);
  color: var(--color-danger);
}
.status-timeline { margin-top: var(--space-8); }
.status-post {
  padding: var(--space-6) 0;
  border-bottom: 1px solid var(--color-divider);
}
.status-post:first-of-type { padding-top: var(--space-3); }
.status-post__meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.status-post__meta time {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.status-post__identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--space-3);
}
.status-post__identity > div {
  display: grid;
  min-width: 0;
  gap: 2px;
}
.status-post__identity strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
  font-weight: 650;
}
.status-post__avatar {
  display: grid;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  color: var(--color-primary);
  background: var(--color-bg-subtle);
  font-size: var(--font-size-meta);
  font-weight: 700;
}
.status-post__content {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-body);
  line-height: 1.8;
  overflow-wrap: anywhere;
}
.status-post__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.status-post__actions details { position: relative; }
.status-post__actions summary,
.status-post__actions > form button {
  border: 0;
  color: var(--color-text-muted);
  background: transparent;
  font-size: var(--font-size-meta);
  cursor: pointer;
}
.status-post__actions summary:hover { color: var(--color-primary); }
.status-post__actions > form button:hover { color: var(--color-danger); }
.status-post__menu > summary {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  list-style: none;
}
.status-post__menu > summary::-webkit-details-marker { display: none; }
.status-post__menu-popover {
  position: absolute;
  z-index: var(--z-dropdown);
  top: calc(100% + var(--space-2));
  right: 0;
  width: 152px;
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  background: var(--color-surface);
  box-shadow: var(--shadow-popover);
}
.status-post__menu-popover form { margin: 0; }
.status-post__menu-popover button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: var(--radius-control-sm);
  color: var(--color-danger);
  background: transparent;
  font-size: var(--font-size-meta);
  text-align: left;
  cursor: pointer;
}
.status-post__menu-popover button:hover {
  background: var(--color-danger-soft);
}
.status-comments {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
}
.status-comments__list,
.status-comment__replies {
  display: grid;
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}
.status-comment {
  min-width: 0;
}
.status-comment > article,
.status-comment__replies > li > article {
  min-width: 0;
}
.status-comment__replies {
  margin: var(--space-3) 0 0 var(--space-7);
  padding-inline-start: var(--space-4);
  border-inline-start: 1px solid var(--color-border);
}
.status-comment__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: var(--space-3);
}
.status-comment__meta > span {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  min-width: 0;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.status-comment__meta strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
}
.status-comment__meta form {
  flex: 0 0 auto;
}
.status-comment article > p {
  margin: var(--space-2) 0 0;
  color: var(--color-text-primary);
  line-height: var(--line-height-body);
  overflow-wrap: anywhere;
}
.status-comment__attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.status-comment__attachments img {
  display: block;
  width: min(220px, 100%);
  max-height: 260px;
  border-radius: var(--radius-control);
  object-fit: contain;
  background: var(--color-bg-subtle);
}
.status-comment__attachments audio {
  width: min(420px, 100%);
}
.status-comment__reply {
  margin-top: var(--space-2);
}
.status-comment__reply summary {
  width: max-content;
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
  cursor: pointer;
}
.status-comment__reply form,
.status-comment-form {
  display: grid;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.status-comment-form textarea,
.status-comment__reply textarea {
  min-height: 68px;
}
.status-comment-form__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.status-comment-form__actions label {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-meta);
  cursor: pointer;
}
.status-comment-form__actions input {
  max-width: min(320px, 42vw);
  color: var(--color-text-muted);
}
.status-comments__composer {
  margin-top: var(--space-3);
}
.status-comments__composer > summary {
  width: fit-content;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  color: var(--color-text-secondary);
  background: var(--color-bg-subtle);
  font-size: var(--font-size-meta);
  cursor: pointer;
  list-style: none;
}
.status-comments__composer > summary::-webkit-details-marker { display: none; }
.status-comments__composer[open] > summary {
  color: var(--color-primary);
  background: var(--color-primary-soft);
}
.status-attachments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.status-attachment {
  min-width: 0;
  border-radius: var(--radius-container);
  background: var(--color-bg-subtle);
}
.status-attachment--image {
  display: block;
  overflow: hidden;
  min-height: 160px;
}
.status-attachment--image img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 520px;
  object-fit: contain;
  background: var(--color-bg-subtle);
}
.status-attachment--media {
  grid-column: 1 / -1;
  padding: var(--space-3);
}
.status-attachment--media strong {
  display: block;
  margin-bottom: var(--space-2);
  overflow-wrap: anywhere;
  font-size: var(--font-size-supporting);
}
.status-attachment--media audio,
.status-attachment--media video {
  display: block;
  width: 100%;
  max-height: 520px;
}
.status-attachment--document {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
}
.status-attachment--document strong,
.status-attachment--document span {
  display: block;
  overflow-wrap: anywhere;
}
.status-attachment--document span {
  margin-top: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.status-attachment--document > div:last-child {
  display: flex;
  flex: 0 0 auto;
  gap: var(--space-3);
  color: var(--color-primary);
  font-size: var(--font-size-meta);
}
.status-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6) 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.diary-statuses {
  width: min(100%, 880px);
  margin: var(--space-8) auto var(--space-10);
  padding: var(--space-6) clamp(var(--space-4), 4vw, var(--space-8));
  border-top: 1px solid var(--color-divider);
}
.diary-statuses__header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-4);
}
.diary-statuses__header p {
  margin: 0 0 var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.12em;
}
.diary-statuses__header h2 {
  margin: 0;
  color: var(--color-text-primary);
  font: 400 var(--font-size-section-title)/var(--line-height-tight) var(--font-display);
}
.diary-statuses__header > a {
  color: var(--color-primary);
  font-size: var(--font-size-meta);
}
.status-post--diary {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  column-gap: var(--space-4);
}
.status-post--diary .status-post__meta {
  grid-column: 1;
  grid-row: 1 / span 2;
  margin: 0;
}
.status-post--diary .status-post__content,
.status-post--diary .status-attachments,
.status-post--diary .status-comments { grid-column: 2; }

.diary-calendar {
  width: min(100% - var(--space-8), 880px);
  margin: var(--space-5) auto var(--space-4);
  padding: var(--space-4) clamp(var(--space-3), 3vw, var(--space-5));
  border-bottom: 1px solid var(--color-divider);
}
.diary-calendar__summary {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-secondary);
  cursor: pointer;
  list-style: none;
}
.diary-calendar__summary::-webkit-details-marker { display: none; }
.diary-calendar__summary > span {
  color: var(--color-text-muted);
  font-size: var(--font-size-meta);
}
.diary-calendar__summary > strong {
  color: var(--color-text-primary);
  font-size: var(--font-size-supporting);
}
.diary-calendar__summary > small {
  margin-inline-start: auto;
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}
.diary-calendar__summary::after {
  color: var(--color-text-muted);
  content: "⌄";
  transition: transform var(--duration-fast) var(--ease-standard);
}
.diary-calendar[open] > .diary-calendar__summary::after { transform: rotate(180deg); }
.diary-calendar__body { padding-top: var(--space-2); }
.diary-calendar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}
.diary-calendar__header p {
  margin: 0 0 2px;
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  font-weight: 650;
  letter-spacing: 0.08em;
}
.diary-calendar__header h2 {
  margin: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-card-title);
  font-weight: 650;
}
.diary-calendar__navigation {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.diary-calendar__weekdays,
.diary-calendar__week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--space-1);
}
.diary-calendar__weekdays {
  margin-bottom: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
  text-align: center;
}
.diary-calendar__grid {
  display: grid;
  gap: var(--space-1);
}
.diary-calendar__day {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 42px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  color: var(--color-text-muted);
  background: transparent;
  text-decoration: none;
  transition:
    color var(--duration-fast) var(--ease-standard),
    background-color var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard);
}
.diary-calendar__day:hover {
  color: var(--color-primary);
  background: var(--color-bg-subtle);
}
.diary-calendar__day.is-recorded {
  color: var(--color-primary);
  font-weight: 650;
}
.diary-calendar__day.is-selected {
  border-color: var(--color-primary);
  background: var(--color-bg-subtle);
}
.diary-calendar__day.is-today .diary-calendar__number {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 4px;
}
.diary-calendar__marker {
  position: absolute;
  bottom: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-border-strong);
}
.diary-calendar__day.is-recorded .diary-calendar__marker {
  width: 6px;
  height: 3px;
  border-radius: 1px;
  background: var(--color-primary);
}
.diary-calendar__day--outside {
  pointer-events: none;
}
.diary-calendar__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
  color: var(--color-text-muted);
  font-size: var(--font-size-micro);
}
.diary-calendar__legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.diary-calendar__legend i {
  display: inline-block;
  width: 7px;
  height: 7px;
  border: 1px solid var(--color-border-strong);
  border-radius: 50%;
}
.diary-calendar__legend i.is-recorded {
  border: 0;
  border-radius: 1px;
  background: var(--color-primary);
}
.diary-calendar__legend i.is-today {
  border-color: var(--color-primary);
  background: transparent;
  transform: rotate(45deg);
}

/* Stage 24.2: shared desktop rhythm for content-first pages. */
@media (min-width: 1280px) {
  .app-shell {
    --desktop-content-max: 1180px;
    --desktop-reading-max: 960px;
    --desktop-page-gutter: clamp(28px, 3vw, 48px);
  }

  .app-shell__main {
    scrollbar-gutter: stable;
  }

  .app-shell .home-desk-main {
    padding: var(--space-8) var(--desktop-page-gutter) var(--space-12);
  }

  .home-desk {
    width: min(var(--desktop-content-max), 100%);
  }

  .home-desk__hero {
    margin-bottom: var(--space-8);
  }

  .home-desk__hero h1 {
    margin-block: var(--space-2);
    font-size: clamp(2.15rem, 3vw, 2.85rem);
  }

  .home-desk .quick-record {
    max-width: var(--desktop-reading-max);
    margin-bottom: var(--space-7);
  }

  .quick-record__form {
    padding: var(--space-4) var(--space-5) var(--space-3);
  }

  .home-desk .quick-record__textarea {
    min-height: 72px;
    padding-bottom: var(--space-3);
  }

  .home-desk__continue,
  .home-desk__empty {
    max-width: var(--desktop-reading-max);
    padding: var(--space-6);
  }

  .home-desk__continue-copy {
    margin-top: var(--space-5);
  }

  .home-desk__continue-actions {
    margin-top: var(--space-5);
  }

  .home-desk__flow {
    margin-top: var(--space-9);
    gap: var(--space-10);
  }

  .block-editor {
    width: min(100%, var(--desktop-reading-max));
    padding-inline: var(--space-6);
  }

  .block-editor__chrome {
    margin-bottom: var(--space-3);
  }

  .block-editor__chrome .editor-mode-notice {
    font-size: var(--font-size-meta);
  }

  .block-editor__chrome .editor-mode-notice [data-block-onboarding-description] {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .block-editor__toolbar,
  .block-editor__footer {
    min-height: 38px;
  }

  .block-editor__chrome .block-editor__toolbar {
    min-height: 34px;
  }

  .block-editor__empty {
    margin: var(--space-2) 54px var(--space-4);
  }

  .block-editor__hint {
    max-width: 440px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .block-editor__item {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .block-editor__item--file .block-editor__asset {
    display: grid;
    max-width: 620px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-control);
    background: var(--color-bg-subtle);
  }

  .block-editor__item--file .block-editor__asset small {
    grid-column: 2;
    grid-row: 1;
    white-space: nowrap;
  }

  .block-editor__upload-queue .record-attachment,
  .workspace-editor__upload-queue .record-attachment {
    min-height: 46px;
    padding-block: var(--space-1);
  }

  .block-editor__upload-queue .record-attachment > img,
  .block-editor__upload-queue .record-attachment > video,
  .workspace-editor__upload-queue .record-attachment > img,
  .workspace-editor__upload-queue .record-attachment > video {
    width: 48px;
    height: 38px;
  }

  .diary-calendar {
    width: min(calc(100% - var(--space-8)), var(--desktop-reading-max));
    margin-block: var(--space-2);
    padding: var(--space-1) var(--space-4);
  }

  .diary-calendar__body {
    padding-top: var(--space-1);
  }

  .diary-calendar__summary {
    min-height: 40px;
    gap: var(--space-2);
  }

  .diary-calendar__summary > span {
    line-height: 1;
  }

  .diary-calendar__summary > strong {
    color: var(--color-primary);
    font-size: var(--font-size-body);
    font-weight: 650;
  }

  .diary-calendar__summary > small {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
  }

  .diary-calendar__header {
    min-height: 38px;
    margin-bottom: var(--space-2);
  }

  .diary-calendar__header h2 {
    font-size: var(--font-size-body);
  }

  .diary-calendar__day {
    min-height: 34px;
  }

  .diary-calendar__legend {
    margin-top: var(--space-2);
  }

  .knowledge-links-panel {
    margin-block: var(--space-2);
  }

  .knowledge-links-panel > summary {
    min-height: 40px;
    padding: var(--space-2) var(--space-1);
  }

  .knowledge-links-panel[data-empty="true"] > summary small {
    display: none;
  }

  .app-shell .app-topbar,
  .app-shell .app-topbar.workspace-top {
    align-content: center;
  }

  .app-topbar__context,
  .app-topbar__search-slot,
  .app-topbar__actions {
    align-self: center;
  }

  .app-topbar__context,
  .app-topbar__actions {
    min-height: 42px;
    align-items: center;
  }

  .status-layout {
    width: min(100%, var(--desktop-reading-max));
    padding: var(--space-8) var(--desktop-page-gutter) var(--space-12);
  }

  .status-page-header {
    margin-bottom: var(--space-5);
  }

  .status-composer {
    padding: var(--space-5);
  }

  .status-composer textarea {
    min-height: 92px;
  }

  .status-timeline {
    display: grid;
    gap: var(--space-4);
    margin-top: var(--space-7);
  }

  .status-timeline > h2 {
    margin-bottom: 0;
  }

  .status-post {
    padding: var(--space-5);
    border: 1px solid var(--color-divider);
    border-radius: var(--radius-container);
    background: var(--color-surface);
  }

  .status-post:first-of-type {
    padding-top: var(--space-5);
  }

  .status-comments {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
  }

  .status-comment > article,
  .status-comment__replies > li > article {
    padding: var(--space-3);
    border-radius: var(--radius-control);
    background: var(--color-bg-subtle);
  }

  .status-attachments {
    gap: var(--space-2);
  }

  .status-attachment--document,
  .status-attachment--media {
    border-radius: var(--radius-control);
  }

  .status-composer .record-attachments,
  .status-comment-form .record-attachments,
  .status-comment__reply .record-attachments,
  .quick-record .record-attachments {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-composer .record-attachment,
  .status-comment-form .record-attachment,
  .status-comment__reply .record-attachment,
  .quick-record .record-attachment {
    min-width: 0;
    min-height: 48px;
  }
}

@media (max-width: 700px) {
  .status-layout { padding: var(--space-5) var(--space-4); }
  .status-composer { padding: var(--space-4); }
  .status-composer__actions,
  .status-attachment--document {
    align-items: stretch;
    flex-direction: column;
  }
  .status-composer__attachments {
    align-items: flex-start;
    flex-direction: column;
    gap: var(--space-2);
  }
  .status-composer__attachments input {
    max-width: 100%;
    margin-inline-start: 0;
  }
  .status-attachments { grid-template-columns: 1fr; }
  .status-attachment--media { grid-column: auto; }
  .status-post--diary { grid-template-columns: 1fr; }
  .status-post--diary .status-post__meta,
  .status-post--diary .status-post__content,
  .status-post--diary .status-attachments,
  .status-post--diary .status-comments { grid-column: 1; }
  .status-post--diary .status-post__meta {
    grid-row: auto;
    margin-bottom: var(--space-2);
  }
  .status-comment__replies {
    margin-inline-start: var(--space-3);
    padding-inline-start: var(--space-3);
  }
  .status-comment-form__actions {
    align-items: stretch;
    flex-direction: column;
  }
  .status-comment-form__actions label {
    align-items: flex-start;
    flex-direction: column;
  }
  .status-comment-form__actions input { max-width: 100%; }
  .diary-calendar {
    width: calc(100% - var(--space-4));
    padding-inline: var(--space-2);
  }
  .diary-calendar__day { min-height: 40px; }
}
