/* Scoped document-template library. Existing editor chrome and document content are unchanged. */
.cd-brief-context { margin: 0 0 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: 12px; background: var(--card); min-width: 0; }
.cd-drafting-brief { color: var(--foreground); font-size: .875rem; line-height: 1.6; overflow-wrap: anywhere; }
.cd-drafting-brief h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
.cd-drafting-brief p { margin: .35rem 0 .75rem; max-width: 75ch; }
.cd-drafting-brief ul { padding-left: 1.25rem; margin: .4rem 0 1rem; }
.cd-brief-point { border-top: 1px solid var(--border); padding-top: .8rem; margin-top: .8rem; }
.cd-brief-point blockquote { margin: .75rem 0; padding: .75rem; background: var(--muted); border-radius: 8px; }
.cd-brief-point blockquote span, .cd-brief-missing { font-size: .8125rem; color: var(--muted-foreground); }
.cd-brief-details { margin-top: .75rem; }
.cd-source-link { border: 0; background: transparent; color: var(--foreground); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font: inherit; padding: .25rem 0; }
.cd-source-dialog { width: min(1000px, 94vw); max-height: 90dvh; padding: 1.25rem; color: var(--foreground); background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.cd-source-dialog::backdrop { background: rgba(0,0,0,.55); }
.cd-source-dialog header, .cd-source-actions { display:flex; gap:.75rem; justify-content:space-between; align-items:center; flex-wrap:wrap; }
.cd-source-dialog h2 { font-size:1.1rem; overflow-wrap:anywhere; }
.cd-source-dialog button { padding:.5rem .75rem; color:var(--foreground); background:var(--background); border:1px solid var(--border); border-radius:8px; font:inherit; cursor:pointer; }
.cd-source-dialog button:disabled { opacity:.5; cursor:default; }
.cd-source-dialog pre { white-space:pre-wrap; overflow-wrap:anywhere; max-height:45dvh; overflow:auto; font:inherit; line-height:1.65; padding:.75rem; background:var(--background); }
.cd-source-dialog iframe { width:100%; height:50dvh; margin-top:1rem; border:1px solid var(--border); }
.cd-source-dialog :focus-visible, .cd-source-link:focus-visible { outline:2px solid var(--primary); outline-offset:3px; }
.cd-source-coverage { border-top: 1px solid var(--border); margin-top: 1rem; padding-top: .75rem; font-size: .8125rem; line-height: 1.6; color: var(--foreground); }
.cd-source-coverage label { display: grid; gap: .4rem; margin-top: .75rem; font-weight: 600; }
.cd-source-coverage select { width: 100%; max-width: 100%; padding: .6rem; font: inherit; color: var(--foreground); background: var(--background); border: 1px solid var(--border); border-radius: 8px; }
.cd-source-coverage select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.cd-brief-details summary { cursor: pointer; padding: .5rem 0; color: var(--foreground); }
.cd-brief-details summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.tl-library {
  --muted-foreground: #61616b;
}
html.dark .tl-library {
  --muted-foreground: #b5bcc5;
}
#cd-grid-view.tl-library {
  display: flex !important;
  flex-direction: column;
  min-height: 100%;
  width: 100%;
  padding: 0;
  color: var(--foreground);
}
#cd-grid-view.tl-library[style*="display: none"],
#cd-grid-view.tl-library[style*="display:none"] {
  display: none !important;
}
.tl-library * {
  box-sizing: border-box;
}
.tl-library button,
.tl-dialog button {
  font: inherit;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}
.tl-library svg,
.tl-dialog svg {
  flex-shrink: 0;
}
.tl-library .tl-button,
.tl-dialog .tl-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  color: var(--foreground);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: none;
  white-space: nowrap;
}
.tl-library .tl-button:hover,
.tl-dialog .tl-button:hover {
  background: var(--secondary);
}
.tl-library .tl-accent,
.tl-dialog .tl-accent {
  color: var(--workspace-accent, #8c4100);
  background: var(--workspace-accent-soft, #fff0e2);
  border-color: transparent;
}
.tl-library .tl-accent:hover,
.tl-dialog .tl-accent:hover {
  border-color: var(--workspace-accent, #8c4100);
  background: var(--workspace-accent-soft, #fff0e2);
}
.tl-button svg {
  width: 16px;
  height: 16px;
}
.tl-library button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.tl-library :is(button, input):focus-visible,
.tl-dialog :is(button, input, select):focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 3px;
}
.tl-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.tl-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
  font-size: 13px;
}
.tl-breadcrumbs ol {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  min-width: 0;
}
.tl-breadcrumbs li {
  display: flex;
  align-items: center;
  min-width: 0;
}
.tl-breadcrumbs button {
  border: 0;
  background: none;
  color: var(--muted-foreground);
  font-size: 13px;
  padding: 6px 2px;
  min-height: 36px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-breadcrumbs button[aria-current],
.tl-breadcrumbs > span[aria-current] {
  color: var(--foreground);
  font-weight: 500;
  overflow-wrap: anywhere;
}
.tl-breadcrumbs > span:not([aria-current]) {
  color: var(--muted-foreground);
}
.tl-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tl-command-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  padding-block: 22px;
}
.tl-search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: min(100%, 480px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  padding: 0 13px;
}
.tl-search > svg {
  color: var(--muted-foreground);
  width: 17px;
  height: 17px;
}
.tl-library .tl-search input {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 42px;
  border: 0;
  box-shadow: none;
  outline-offset: -3px;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 13px;
}
.tl-search input::placeholder {
  color: var(--muted-foreground);
}
.tl-switch {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
  padding: 3px;
  border-radius: 8px;
  background: var(--secondary);
}
.tl-switch button {
  background: transparent;
  color: var(--muted-foreground);
  border: 0;
  border-radius: 6px;
  min-height: 34px;
  padding: 8px 12px;
  font-size: 12px;
}
.tl-switch button[aria-pressed="true"] {
  color: var(--foreground);
  background: var(--card);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.08);
}
.tl-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 0 22px;
}
.tl-heading > div {
  flex: 1;
  min-width: 200px;
}
.tl-heading h2 {
  font-size: 19px;
  line-height: 1.4;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
  outline: none;
  overflow-wrap: anywhere;
}
.tl-heading p {
  margin: 5px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted-foreground);
}
.tl-library .tl-folder-actions {
  font: inherit;
  font-size: 12px;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  min-height: 38px;
  width: auto;
  max-width: 190px;
  margin: 0;
  box-shadow: none;
  background-image: none;
  appearance: auto;
}
.tl-library .tl-folder-actions:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 3px;
}
.tl-status {
  font-size: 13px;
  color: var(--workspace-accent);
  line-height: 1.5;
}
.tl-status:empty {
  display: none;
}
.tl-error {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--foreground);
  font-size: 13px;
  background: var(--card);
  flex-wrap: wrap;
}
.tl-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  flex: 1;
  min-width: 0;
}
.tl-workspace.has-selection {
  grid-template-columns: minmax(0, 1fr) 330px;
}
.tl-browser {
  min-width: 0;
}
.tl-folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.tl-folder {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 6px;
  text-align: left;
  padding: 20px 18px;
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--foreground);
  transition:
    background 150ms ease,
    border-color 150ms ease;
}
.tl-folder:hover {
  background: var(--secondary);
  border-color: var(--muted-foreground);
}
.tl-folder > svg {
  width: 32px;
  height: 32px;
  grid-row: 1/3;
  color: var(--workspace-accent, #8c4100);
  stroke-width: 1.35;
}
.tl-folder strong {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.tl-folder > span {
  font-size: 12px;
  color: var(--muted-foreground);
}
.tl-list {
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--card);
}
.tl-list-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 100px;
  gap: 16px;
  padding: 13px 50px 13px 58px;
  background: var(--secondary);
  font-size: 11px;
  color: var(--muted-foreground);
}
.tl-template-row {
  width: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 120px 100px 16px;
  gap: 16px;
  align-items: center;
  text-align: left;
  padding: 19px 18px;
  border: 0;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: var(--card);
  color: var(--foreground);
}
.tl-template-row:hover {
  background: var(--secondary);
}
.tl-template-row.is-selected {
  background: var(--workspace-accent-soft);
}
.tl-file-icon {
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
}
.tl-file-icon svg {
  width: 23px;
  height: 23px;
}
.tl-template-name {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.tl-template-name strong {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.tl-template-name small {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-template-state,
.tl-template-date {
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}
.tl-template-row > svg {
  width: 15px;
  height: 15px;
  color: var(--workspace-accent);
}
.tl-preview {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  padding: 20px;
  position: sticky;
  top: 0;
}
.tl-preview[hidden] {
  display: none;
}
.tl-preview-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--muted-foreground);
}
.tl-icon-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tl-icon-button:hover {
  background: var(--secondary);
}
.tl-preview h3 {
  font-size: 16px;
  line-height: 1.5;
  font-weight: 600;
  margin: 12px 0 5px;
  overflow-wrap: anywhere;
  outline: none;
}
.tl-preview-meta {
  font-size: 12px;
  color: var(--muted-foreground);
  margin: 0 0 18px;
}
.tl-paper {
  padding: 22px 19px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 5px;
  max-height: 310px;
  overflow: auto;
  min-height: 190px;
}
.tl-paper > strong {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.tl-paper p {
  font-size: 12px;
  line-height: 1.9;
  margin: 18px 0 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tl-preview-caption {
  font-size: 11px;
  color: var(--muted-foreground);
  line-height: 1.7;
  margin: 12px 0 16px;
}
.tl-case {
  width: 100%;
  justify-content: flex-start !important;
  white-space: normal !important;
  text-align: left;
  margin-bottom: 14px;
}
.tl-case > span {
  overflow-wrap: anywhere;
}
.tl-preview-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tl-manage {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 16px;
  margin-top: 16px;
  border-top: 1px solid var(--border);
}
.tl-manage .tl-button {
  flex: 1;
  font-size: 11px;
}
.tl-manage .tl-delete-template {
  flex-basis: 100%;
  color: var(--workspace-danger, #b42318);
}
.tl-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  min-height: 320px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 35px;
  text-align: center;
}
.tl-empty > svg {
  width: 38px;
  height: 38px;
  color: var(--muted-foreground);
  margin-bottom: 18px;
}
.tl-empty h3 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
}
.tl-empty p {
  font-size: 13px;
  line-height: 1.8;
  color: var(--muted-foreground);
  max-width: 45ch;
  margin: 10px 0 20px;
}
.tl-loading {
  padding: 24px 0;
  font-size: 13px;
  color: var(--muted-foreground);
}
.tl-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--foreground);
  padding: 26px;
  width: min(440px, calc(100% - 32px));
  box-shadow: 0 24px 70px rgb(0 0 0 / 0.2);
}
.tl-dialog::backdrop {
  background: rgb(0 0 0 / 0.4);
}
.tl-dialog h2 {
  font-size: 18px;
  line-height: 1.5;
  margin: 0 0 24px;
}
.tl-dialog label {
  display: block;
  font-size: 13px;
  margin-bottom: 9px;
}
.tl-dialog input,
.tl-dialog select {
  box-sizing: border-box;
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 11px 12px;
}
.tl-dialog p {
  font-size: 13px;
  line-height: 1.7;
}
.tl-dialog-error {
  color: var(--workspace-danger, #b42318);
  font-size: 12px;
}
.tl-dialog-error:empty {
  display: none;
}
.tl-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}
@media (max-width: 1200px) {
  .tl-workspace.has-selection {
    grid-template-columns: minmax(0, 1fr) 290px;
    gap: 18px;
  }
  .tl-template-row {
    grid-template-columns: 25px minmax(0, 1fr) 90px 16px;
    gap: 12px;
  }
  .tl-template-date {
    display: none;
  }
  .tl-list-head {
    grid-template-columns: minmax(0, 1fr) 90px;
    padding-right: 45px;
  }
  .tl-list-head > span:last-child {
    display: none;
  }
}
@media (max-width: 850px) {
  .tl-workspace.has-selection {
    grid-template-columns: minmax(0, 1fr);
  }
  .tl-preview {
    position: static;
    grid-row: 1;
  }
  .tl-paper {
    max-height: 220px;
  }
  .tl-preview-actions {
    flex-direction: row;
  }
  .tl-preview-actions > * {
    flex: 1;
  }
  .tl-command-row {
    flex-wrap: wrap;
    gap: 14px;
  }
  .tl-search {
    width: 100%;
  }
  .tl-toolbar {
    gap: 14px;
  }
}
@media (max-width: 560px) {
  .tl-toolbar {
    align-items: start;
    gap: 12px;
    padding-bottom: 18px;
  }
  .tl-toolbar-actions {
    gap: 6px;
    width: 100%;
  }
  .tl-library .tl-button {
    font-size: 11px;
    padding: 8px 10px;
    min-height: 38px;
  }
  .tl-toolbar-actions .tl-button {
    flex: 1;
  }
  .tl-toolbar-actions .tl-button svg {
    width: 14px;
  }
  .tl-toolbar-actions .tl-button:last-child {
    flex-basis: 100%;
    justify-content: space-between;
  }
  .tl-heading {
    padding-bottom: 18px;
  }
  .tl-heading h2 {
    font-size: 18px;
  }
  .tl-heading p {
    font-size: 12px;
  }
  .tl-heading > div {
    min-width: 100%;
  }
  .tl-heading > .tl-button {
    flex: 1;
  }
  .tl-folder-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .tl-folder {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    padding: 17px 14px;
    min-height: 130px;
    row-gap: 8px;
  }
  .tl-folder > svg {
    grid-row: auto;
    width: 30px;
    height: 30px;
  }
  .tl-folder strong {
    font-size: 13px;
  }
  .tl-folder > span {
    font-size: 11px;
  }
  .tl-template-row {
    grid-template-columns: 23px minmax(0, 1fr) 15px;
    padding: 16px 12px;
    gap: 10px;
  }
  .tl-template-state {
    display: none;
  }
  .tl-list-head {
    grid-template-columns: 1fr;
    padding-left: 45px;
  }
  .tl-list-head > span:not(:first-child) {
    display: none;
  }
  .tl-preview {
    padding: 17px;
  }
  .tl-preview-actions {
    flex-direction: column;
  }
  .tl-switch {
    width: 100%;
  }
  .tl-switch button {
    flex: 1;
  }
  .tl-search input {
    font-size: 12px !important;
  }
  .tl-breadcrumbs button {
    max-width: 180px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .tl-folder {
    transition: none;
  }
}
.tl-folder > svg {transform-origin:50% 80%;transition:transform 200ms cubic-bezier(.16,1,.3,1);}
@media(hover:hover){.tl-folder:hover > svg {transform:translateY(-2px) rotate(-4deg);}}
.tl-library :is(.tl-folder,.tl-button,.tl-icon-button):active {transform:scale(.985);}
.tl-template-name strong {font-weight:550;letter-spacing:-.015em;}
.tl-template-date {font-variant-numeric:tabular-nums;}
@media(prefers-reduced-motion:reduce){html:not([data-motion-reduced=false]) .tl-library :is(button,svg){transition:none!important;transform:none!important;}}
html[data-motion-reduced=true] .tl-library :is(button,svg){transition:none!important;transform:none!important;}
