:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #17201c;
  --muted: #637068;
  --line: #d9dfd9;
  --blue: #2d6f95;
  --blue-dark: #1e5575;
  --green: #3f7d3a;
  --red: #b34335;
  --shadow: 0 10px 30px rgba(23, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  min-height: 64px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 245, 0.94);
  backdrop-filter: blur(10px);
}

.brand {
  font-size: 1.18rem;
  font-weight: 800;
  text-decoration: none;
}

.topnav {
  display: flex;
  gap: 16px;
}

.topnav a {
  color: var(--muted);
  font-weight: 650;
  text-decoration: none;
}

.topnav a:hover {
  color: var(--ink);
}

.logout-form {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0;
}

.signed-in,
.muted,
small {
  color: var(--muted);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.button-primary {
  background: var(--blue);
  color: white;
}

.button-primary:hover {
  background: var(--blue-dark);
}

.button-secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button-danger {
  border-color: #e3b5ae;
  background: #fff4f2;
  color: var(--red);
}

.button-wide {
  width: 100%;
}

.auth-page {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(247, 248, 245, 0.2), rgba(247, 248, 245, 1)),
    url("https://images.unsplash.com/photo-1455390582262-044cdead277a?auto=format&fit=crop&w=1800&q=80")
      center / cover fixed;
}

.auth-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(100%, 440px);
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 6px 0 22px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 60px;
}

.page.narrow {
  width: min(820px, calc(100% - 32px));
}

.page-header {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 2.2rem;
  line-height: 1.1;
}

h2 {
  margin: 0 0 14px;
  font-size: 1rem;
}

.document-list,
.token-list {
  display: grid;
  gap: 10px;
}

.document-row,
.token-row,
.empty-state,
.form-panel,
.table-panel,
.token-reveal,
.set-card,
.presence-panel,
.properties-panel,
.comment-composer,
.comment-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 32, 28, 0.03);
}

.document-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 16px;
  text-decoration: none;
}

.document-row:hover {
  border-color: #b6c5ba;
  box-shadow: var(--shadow);
}

.document-row strong,
.document-row small,
.token-row strong,
.token-row small {
  display: block;
}

.row-meta {
  display: flex;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.empty-state,
.form-panel,
.table-panel,
.token-reveal {
  padding: 22px;
}

.notice {
  padding: 12px;
  border-radius: 7px;
}

.notice-error {
  border: 1px solid #e3b5ae;
  background: #fff4f2;
  color: var(--red);
}

.notice-warning {
  border: 1px solid #e3d3a5;
  background: #fff9e6;
}

.stack-form,
.set-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.token-reveal code {
  display: block;
  overflow-x: auto;
  padding: 12px;
  border-radius: 7px;
  background: #15221d;
  color: #d8f0db;
}

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

.sets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.set-card {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.lookup-options {
  display: grid;
  gap: 6px;
}

.lookup-option {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.lookup-option:hover {
  border-color: #aebdb2;
  background: white;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.document-body {
  background: #f4f5f1;
}

.document-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 20px 0;
}

.document-main {
  min-width: 0;
}

.document-header {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: flex-end;
  margin-bottom: 14px;
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  min-width: 190px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.tab-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 750;
}

.tab-button.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(23, 32, 28, 0.08);
}

.document-surface {
  min-height: calc(100vh - 170px);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.markdown-body {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.markdown-body h1 {
  margin: 0 0 22px;
  font-size: 2.55rem;
  line-height: 1.08;
}

.markdown-body .note-title {
  max-width: 860px;
  margin-bottom: 6px;
}

.note-sync {
  margin: 0 0 28px;
  color: var(--muted);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-size: 0.92rem;
  font-weight: 650;
}

.markdown-body h2 {
  margin: 40px 0 16px;
  font-size: 1.86rem;
  line-height: 1.18;
}

.markdown-body h3 {
  margin: 30px 0 12px;
  font-size: 1.42rem;
  line-height: 1.22;
}

.markdown-body h4 {
  margin: 24px 0 10px;
  font-size: 1.18rem;
  line-height: 1.25;
}

.properties-list {
  display: grid;
  gap: 0;
  margin: 0 0 34px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.property-row {
  display: grid;
  grid-template-columns: minmax(104px, 172px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-width: 0;
  padding: 6px 0;
}

.property-row + .property-row {
  border-top: 1px solid #edf0ed;
}

.property-row dt {
  min-width: 0;
  margin: 0;
  padding-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.property-row dd {
  margin: 0;
}

.property-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
}

.property-values span {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.property-kind-tags .property-values span,
.property-kind-list .property-values span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #d8e1da;
  border-radius: 999px;
  background: #f7faf8;
  color: var(--ink);
  font-size: 0.86rem;
  line-height: 1;
}

.property-kind-tags .property-values span {
  border-color: #c7d8c8;
  background: #eef6ef;
  color: var(--green);
}

.property-kind-checkbox .property-values span {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.property-kind-checkbox .property-values span::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 1px solid #aab8af;
  border-radius: 3px;
  background: white;
}

.property-kind-checkbox .property-values span.is-checked::before {
  border-color: var(--blue);
  background:
    linear-gradient(135deg, transparent 54%, white 55% 68%, transparent 69%),
    linear-gradient(45deg, transparent 48%, white 49% 62%, transparent 63%),
    var(--blue);
}

.property-kind-json .property-values,
.property-values-block {
  display: grid;
  gap: 6px;
}

.property-kind-json .property-values span,
.property-values-block span {
  display: block;
  color: var(--ink);
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.35;
  white-space: pre-wrap;
}

.markdown-body img {
  max-width: 100%;
  border-radius: 8px;
}

.markdown-body table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 10px;
  border: 1px solid var(--line);
}

.markdown-body pre,
.raw-surface pre {
  overflow-x: auto;
  padding: 14px;
  border-radius: 7px;
  background: #15221d;
  color: #e4efe7;
}

.raw-surface {
  padding: 0;
}

.raw-surface pre {
  min-height: calc(100vh - 172px);
  margin: 0;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.comments-panel {
  position: sticky;
  top: 84px;
  align-self: start;
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.presence-panel,
.properties-panel,
.comment-composer,
.comment-card {
  padding: 14px;
}

.properties-panel {
  background: #fbfcfb;
}

.properties-panel summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}

.properties-panel summary span {
  color: var(--ink);
  margin-left: 4px;
}

.properties-panel summary small {
  float: right;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.properties-panel[open] summary {
  margin-bottom: 10px;
}

.sidebar-properties {
  margin: 0;
  padding: 8px 0 0;
  border-bottom: 0;
}

.sidebar-properties .property-row {
  grid-template-columns: 1fr;
  gap: 3px;
  padding: 8px 0;
}

.sidebar-properties .property-row:first-child {
  padding-top: 0;
}

.sidebar-properties .property-row dt {
  font-size: 0.78rem;
}

.sidebar-properties .property-values {
  font-size: 0.86rem;
}

.presence-avatars {
  min-height: 38px;
}

.presence-avatar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.presence-avatar {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  overflow: hidden;
  border: 2px solid white;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 850;
}

.presence-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.presence-avatars .muted {
  margin: 10px 0 0;
  font-size: 0.86rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.comment-composer {
  border-color: #b4c7d5;
}

.selection-preview {
  max-height: 88px;
  overflow: hidden;
  margin: 0 0 10px;
  padding-left: 10px;
  border-left: 3px solid var(--blue);
  color: var(--muted);
  font-size: 0.92rem;
}

.comment-selection-highlight {
  border-radius: 2px;
  background: #fff0a8;
  box-shadow: 0 0 0 2px rgba(255, 224, 114, 0.38);
  color: inherit;
}

.composer-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

.comments-list {
  display: grid;
  gap: 10px;
}

.comment-card.resolved {
  opacity: 0.68;
}

.comment-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.84rem;
}

.comment-quote {
  margin: 10px 0;
  padding-left: 10px;
  border-left: 3px solid var(--green);
  color: var(--muted);
  font-size: 0.92rem;
}

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.reaction-button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 750;
}

.reaction-button.active {
  border-color: #9bb8cc;
  background: #eef6fb;
  color: var(--blue-dark);
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 12px 16px;
  }

  .topnav,
  .logout-form,
  .row-meta {
    flex-wrap: wrap;
  }

  .page-header,
  .document-header {
    align-items: stretch;
    flex-direction: column;
  }

  .document-layout {
    grid-template-columns: 1fr;
  }

  .comments-panel {
    position: static;
    max-height: none;
  }

  .document-surface {
    min-height: 50vh;
    padding: 24px;
  }

  .markdown-body h1 {
    font-size: 2.2rem;
  }

  .markdown-body h2 {
    font-size: 1.68rem;
  }
}

@media (max-width: 560px) {
  .document-row,
  .token-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .token-row {
    display: grid;
  }

  h1 {
    font-size: 1.75rem;
  }

  .markdown-body h1 {
    font-size: 1.95rem;
  }

  .markdown-body h2 {
    font-size: 1.5rem;
  }

  .property-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}
