:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --ink: #061638;
  --muted: #6f7a96;
  --line: #dfe5ef;
  --accent: #18b8aa;
  --accent-strong: #087f78;
  --accent-soft: #c9f6ed;
  --sidebar: #1c2a50;
  --sidebar-soft: #263760;
  --sidebar-muted: #aab7d6;
  --yellow: #f3c455;
  --rose: #e05757;
  --rose-soft: #fff6f4;
  --shadow: 0 10px 28px rgba(21, 34, 72, 0.06);
  --shadow-strong: 0 18px 42px rgba(6, 22, 56, 0.12);
  --radius: 8px;
  --radius-sm: 6px;
  --content: 1180px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 15px;
  font-weight: 400;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  flex: none;
}

code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.sidebar-state {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ds-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.ds-sidebar,
.library-panel {
  color: #ffffff;
  background: var(--sidebar);
}

.ds-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px;
  transition: width 0.18s ease, height 0.18s ease, padding 0.18s ease;
}

.ds-main {
  min-width: 0;
  padding: 28px;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.ds-sidebar > .brand-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 38px;
}

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand-row strong,
.brand-row span {
  display: block;
}

.brand-row span {
  max-width: 170px;
  color: var(--sidebar-muted);
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
}

.logo-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  color: #ffffff;
  background: var(--accent);
  border-radius: var(--radius);
  place-items: center;
}

.logo-mark .logo-initials {
  display: grid;
  width: 100%;
  height: 100%;
  color: #ffffff;
  max-width: none;
  overflow: visible;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
  text-overflow: clip;
}

.logo-mark.small {
  width: 34px;
  height: 34px;
}

.logo-mark.small .logo-initials {
  font-size: 11px;
}

.sidebar-toggle {
  display: inline-grid;
  width: 38px;
  min-height: 38px;
  color: #dce7ff;
  background: transparent;
  border-radius: var(--radius);
  place-items: center;
  transition: background 0.15s, color 0.15s, transform 0.18s ease;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-toggle svg {
  transition: transform 0.18s ease;
}

.sidebar-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.nav-item,
.tag-pill {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 9px 10px;
  color: #ffffff;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font-weight: 500;
}

.nav-item:hover,
.nav-item.active,
.tag-pill:hover,
.tag-pill.active {
  background: rgba(255, 255, 255, 0.14);
}

.nav-pill-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.sidebar-logout-link {
  position: sticky;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 8px;
  width: max-content;
  margin-top: auto;
  padding: 12px 0 2px;
  color: #eef6f4;
  background: var(--sidebar);
  border: 0;
  font-weight: 700;
  text-align: left;
}

.sidebar-logout-link:hover,
.sidebar-logout-link:focus-visible {
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

body:has(#sidebar-toggle:checked) .ds-shell {
  grid-template-columns: 72px minmax(0, 1fr);
}

body:has(#sidebar-toggle:checked) .ds-sidebar {
  padding: 14px;
}

body:has(#sidebar-toggle:checked) .ds-sidebar > .brand-row {
  grid-template-columns: 42px;
  justify-content: center;
}

body:has(#sidebar-toggle:checked) .ds-sidebar .brand-text,
body:has(#sidebar-toggle:checked) .ds-sidebar .nav-text {
  display: none;
}

body:has(#sidebar-toggle:checked) .ds-sidebar .sidebar-toggle {
  margin-top: 8px;
  width: 42px;
}

body:has(#sidebar-toggle:checked) .ds-sidebar .sidebar-toggle svg {
  transform: rotate(180deg);
}

body:has(#sidebar-toggle:checked) .ds-sidebar .nav-item {
  justify-content: center;
  width: 42px;
  min-height: 42px;
  padding: 0;
}

body:has(#sidebar-toggle:checked) .ds-sidebar .nav-pill-label {
  justify-content: center;
}

body:has(#sidebar-toggle:checked) .ds-sidebar .sidebar-content {
  align-items: center;
}

body:has(#sidebar-toggle:checked) .sidebar-logout-link {
  align-self: center;
  width: 42px;
  min-height: 42px;
  justify-content: center;
  padding: 0;
}

.ds-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
  gap: 28px;
  align-items: center;
  max-width: var(--content);
  min-height: 420px;
  margin: 0 auto 24px;
  padding: 18px 0 34px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.ds-hero h1 {
  max-width: 760px;
  margin: 0;
  font-size: 40px;
  line-height: 1.04;
}

.hero-copy {
  max-width: 640px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.68;
}

.auth-panel,
.loading-card,
.component-panel,
.token-card,
.public-document {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(440px, 100%);
  padding: 30px;
}

.auth-panel h2 {
  margin: 16px 0 10px;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.05;
}

.auth-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.preview-auth {
  justify-self: end;
}

.ds-section {
  max-width: var(--content);
  margin: 0 auto;
  padding: 34px 0;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  margin: 0 0 12px;
  font-size: 24px;
  line-height: 1.18;
}

.token-grid,
.component-grid,
.pattern-grid {
  display: grid;
  gap: 12px;
}

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

.token-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 5px 12px;
  align-items: center;
  min-height: 82px;
  padding: 14px;
}

.token-card strong,
.token-card code {
  min-width: 0;
}

.token-card code {
  color: var(--muted);
  font-size: 12px;
}

.swatch {
  grid-row: span 2;
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
}

.swatch.bg {
  background: var(--bg);
  border: 1px solid var(--line);
}

.swatch.panel {
  background: var(--panel);
  border: 1px solid var(--line);
}

.swatch.ink {
  background: var(--ink);
}

.swatch.muted {
  background: var(--muted);
}

.swatch.accent {
  background: var(--accent);
}

.swatch.sidebar {
  background: var(--sidebar);
}

.swatch.rose {
  background: var(--rose);
}

.swatch.yellow {
  background: var(--yellow);
}

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

.component-panel {
  min-width: 0;
  padding: 18px;
}

.component-panel h3,
.public-document h3,
.empty-state h3 {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.2;
}

.button-row,
.tag-selector,
.inline-delete-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn,
.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  color: var(--ink);
  background: #f6f8fb;
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
}

.btn:hover,
.upload-button:hover {
  color: var(--accent-strong);
  background: #edf8f5;
}

.btn.primary {
  color: #ffffff;
  background: var(--accent);
}

.btn.primary:hover {
  color: #ffffff;
  background: var(--accent-strong);
}

.btn.ghost {
  background: transparent;
}

.btn.icon {
  width: 38px;
  padding: 0;
}

.btn.danger {
  color: var(--rose);
  background: #fff4f3;
}

.btn.danger.solid {
  color: #ffffff;
  background: var(--rose);
}

.btn.large {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.form-stack {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.field input,
.field select,
.quick-create input,
.search-row input,
.title-editor textarea,
.meta-row select {
  min-width: 0;
  padding: 9px 10px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.field input:focus,
.field select:focus,
.quick-create input:focus,
.search-row input:focus,
.title-editor textarea:focus,
.meta-row select:focus,
.document-surface textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(24, 184, 170, 0.18);
  outline-offset: 1px;
}

.tag-selector {
  margin: 8px 0 12px;
}

.tag-selector button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  color: var(--accent-strong);
  background: transparent;
  border: 0;
  border-radius: 0;
  font-weight: 600;
  line-height: 1.45;
}

.tag-selector button:hover,
.tag-selector button:focus-visible,
.tag-selector button.selected {
  color: var(--accent-strong);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.share-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  padding: 10px;
  background: #f0fbf8;
  border: 1px solid #c5e7df;
  border-radius: var(--radius);
}

.share-row a {
  color: var(--accent-strong);
  font-weight: 700;
}

.workspace-preview {
  display: grid;
  grid-template-columns: 220px minmax(230px, 0.8fr) minmax(320px, 1.2fr);
  min-height: 640px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.library-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px;
}

.library-panel .btn.ghost {
  color: #ffffff;
  background: transparent;
}

.upload-button {
  width: 100%;
  margin-top: 10px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.nav-section {
  margin: 20px 0 0;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: #cbd5df;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.documents-panel,
.reader-panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.documents-panel {
  padding: 18px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.reader-panel {
  padding: 20px 24px;
  background: var(--panel);
}

.documents-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.search-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: #4d5b78;
}

.search-row input {
  width: 100%;
}

.documents-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.documents-title span,
.documents-title strong {
  display: block;
}

.documents-title span {
  color: var(--muted);
  font-size: 13px;
}

.documents-title strong {
  margin-top: 2px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}

.file-list {
  display: grid;
  gap: 2px;
}

.file-row,
.search-result-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 7px 8px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.file-row:hover,
.file-row.active,
.search-result-row:hover,
.search-result-row.active {
  color: var(--accent-strong);
  background: #edf8f5;
}

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

.reader-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  margin-bottom: 12px;
}

.title-editor {
  min-width: 0;
}

.title-editor textarea {
  width: 100%;
  min-height: 42px;
  padding: 4px 0 10px;
  overflow: hidden;
  color: var(--ink);
  resize: none;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  font-size: 23px;
  font-weight: 600;
  line-height: 1.18;
}

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

.reader-meta {
  display: grid;
  grid-column: 1 / -1;
  gap: 8px;
  min-width: 0;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  color: var(--accent-strong);
  background: #edf8f5;
  border: 1px solid #c5e7df;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.mode-tabs {
  display: flex;
  gap: 6px;
  margin: 12px 0;
  border-bottom: 1px solid var(--line);
}

.mode-tabs button {
  padding: 9px 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-weight: 600;
}

.mode-tabs button.active {
  color: var(--accent-strong);
  border-bottom: 3px solid var(--accent);
}

.markdown-body {
  min-width: 0;
  max-width: 820px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.68;
}

.markdown-body.compact {
  font-size: 14px;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  font-weight: 600;
  line-height: 1.18;
}

.markdown-body h1 {
  font-size: 25px;
}

.markdown-body h2 {
  font-size: 21px;
}

.markdown-body h3 {
  font-size: 18px;
}

.markdown-body p {
  margin: 0 0 14px;
}

.markdown-body pre {
  padding: 14px;
  overflow: auto;
  color: #f8fafc;
  background: #101b3a;
  border-radius: var(--radius);
}

.markdown-body code {
  padding: 2px 4px;
  background: #edf2f8;
  border-radius: 5px;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
}

.markdown-body blockquote {
  margin-left: 0;
  padding-left: 16px;
  color: #51607e;
  border-left: 4px solid var(--accent);
}

.markdown-body table {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

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

.pattern-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
}

.public-document {
  padding: clamp(18px, 4vw, 34px);
}

.public-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.public-header h3 {
  margin: 4px 0 0;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.05;
}

.empty-state,
.empty-reader {
  display: grid;
  min-height: 220px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  place-items: center;
}

.empty-state p {
  max-width: 320px;
  margin: 0 auto 14px;
  line-height: 1.6;
}

.empty-state .logo-mark {
  margin-bottom: 12px;
}

.confirm-delete {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  color: #7f2e2e;
  background: var(--rose-soft);
  border: 0;
  border-radius: var(--radius);
}

.confirm-delete strong,
.confirm-delete span {
  display: block;
}

.confirm-delete span {
  margin-top: 3px;
  color: #9a4a45;
}

.confirm-delete > div:last-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 1120px) {
  .ds-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  body:has(#sidebar-toggle:checked) .ds-shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

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

  .workspace-preview {
    grid-template-columns: 190px minmax(220px, 0.8fr) minmax(300px, 1.2fr);
  }

  .ds-hero h1 {
    font-size: 36px;
  }
}

@media (max-width: 900px) {
  .ds-shell {
    display: block;
  }

  .ds-sidebar {
    position: fixed;
    z-index: 40;
    inset: 0 0 auto;
    display: grid;
    height: 62px;
    min-height: 62px;
    padding: 8px 10px;
    overflow: hidden;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .ds-main {
    padding: 90px 20px 20px;
  }

  .ds-sidebar > .brand-row {
    grid-template-columns: auto minmax(0, 1fr) 42px;
    gap: 8px;
    align-items: center;
    margin-bottom: 0;
  }

  .ds-sidebar .logo-mark {
    width: 44px;
    height: 44px;
  }

  .ds-sidebar .brand-text,
  body:has(#sidebar-toggle:checked) .ds-sidebar .brand-text {
    display: block;
  }

  .ds-sidebar .brand-row span {
    max-width: none;
  }

  .ds-sidebar .sidebar-toggle,
  body:has(#sidebar-toggle:checked) .ds-sidebar .sidebar-toggle {
    width: 42px;
    min-height: 42px;
    margin-top: 0;
  }

  .ds-sidebar .sidebar-toggle svg {
    transform: rotate(-90deg);
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar .sidebar-toggle svg {
    transform: rotate(90deg);
  }

  .ds-sidebar .sidebar-content,
  .ds-sidebar .sidebar-logout-link {
    display: none;
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar {
    display: flex;
    height: 100dvh;
    min-height: 100dvh;
    padding: 18px;
    overflow: auto;
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar > .brand-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 42px;
    justify-content: stretch;
    margin-bottom: 18px;
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar .sidebar-content {
    display: flex;
    align-items: stretch;
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar .nav-text {
    display: inline;
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar .nav-item {
    justify-content: space-between;
    width: 100%;
    min-height: 38px;
    padding: 9px 10px;
  }

  body:has(#sidebar-toggle:checked) .ds-sidebar .nav-pill-label {
    justify-content: flex-start;
  }

  body:has(#sidebar-toggle:checked) .sidebar-logout-link {
    display: inline-flex;
    align-self: flex-start;
    justify-content: flex-start;
    width: max-content;
    min-height: 38px;
    padding: 12px 0 2px;
  }

  .ds-hero,
  .pattern-grid {
    grid-template-columns: 1fr;
  }

  .preview-auth {
    justify-self: stretch;
  }

  .workspace-preview {
    grid-template-columns: 1fr;
  }

  .workspace-preview .library-panel {
    display: grid;
    min-height: 62px;
    padding: 18px;
  }

  .workspace-preview .library-panel .brand-row {
    margin-bottom: 0;
  }

  .library-panel,
  .documents-panel,
  .reader-panel {
    min-height: auto;
  }

  .documents-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .ds-main {
    padding: 90px 16px 16px;
  }

  .ds-hero h1 {
    font-size: 32px;
  }

  .token-grid,
  .component-grid {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .reader-header,
  .documents-toolbar,
  .confirm-delete,
  .public-header {
    display: grid;
    grid-template-columns: 1fr;
  }

  .reader-actions,
  .confirm-delete > div:last-child {
    justify-content: flex-start;
  }
}
