.case-editor {
  --editor-padding: clamp(16px, 3vw, 30px);
  max-width: 860px;
  border-top: 2px solid var(--ink);
}

.case-editor-main {
  display: grid;
  gap: 17px;
  padding: var(--editor-padding);
}

.case-editor .field { color: var(--ink); font-size: 13px; }
.case-editor .field-input { background: var(--surface); }
.case-editor .field-input:hover { border-color: var(--muted); }

.case-editor textarea.case-editor-textarea {
  min-height: clamp(172px, 24vw, 252px);
  padding: 12px 14px;
  line-height: 1.7;
}

.case-editor-heading { font-size: 19px; }
.case-file-manager-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 15px;
}

.case-editor-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 450;
  line-height: 1.6;
}

.case-file-manager, .case-editor-more, .case-editor-actions { border-top: 1px solid var(--line); }
.case-file-manager { padding: var(--editor-padding); }
.case-file-manager-head .case-editor-help { margin-top: 4px; }

.case-attachment-picker { max-width: 100%; }
label.case-attachment-picker { position: relative; cursor: pointer; }
label.case-attachment-picker:focus-within { outline: 2px solid var(--green); outline-offset: 3px; }
label.case-attachment-picker > input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.case-attachment-list { margin: 12px 0 0; padding: 0; list-style: none; }
.case-attachment-list:empty { display: none; }
.case-attachment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px 12px;
  padding-block: 10px;
  border-top: 1px solid var(--line);
}
.case-attachment-row:has(.case-attachment-vis) { grid-template-columns: minmax(0, 1fr) repeat(3, auto); }
.case-attachment-meta { min-width: 0; overflow-wrap: anywhere; }
.case-attachment-meta strong { font-weight: 680; }
.case-attachment-meta :is(small, span) {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.case-file-manager > .case-editor-help { margin-top: 9px; }
.case-attachment-vis { min-width: 0; }
select.case-attachment-vis, .case-attachment-vis select {
  max-width: 100%;
  min-height: 40px;
  padding-inline: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
}
.case-attachment-scope {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
button.case-attachment-remove, .case-attachment-download {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 4px;
}
button.case-attachment-remove { padding-inline: 6px; color: var(--muted); }
.case-attachment-download { display: inline-flex; align-items: center; justify-self: end; padding-inline: 8px; }
:is(button.case-attachment-remove, .case-attachment-download):hover { color: var(--green-dark); background: var(--green-light); }

.case-editor-more > summary {
  padding: 12px var(--editor-padding);
  color: var(--green-dark);
  font-weight: 650;
  cursor: pointer;
}
.case-editor-more > summary:hover { background: var(--green-light); }
.case-editor-more > summary:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -2px;
}
.case-editor-more .field-grid { padding: 4px var(--editor-padding) var(--editor-padding); }
.case-editor-actions {
  position: sticky;
  z-index: 2;
  bottom: 0;
  justify-content: flex-end;
  padding: 12px var(--editor-padding) max(12px, env(safe-area-inset-bottom));
  border-radius: 0 0 var(--panel-radius) var(--panel-radius);
  background: var(--surface);
}
.case-editor-actions > .case-editor-help { flex: 1 1 200px; }

.case-workspace-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 650;
  text-underline-offset: 4px;
}
.case-workspace-section { margin-block: 25px; }
.case-workspace-section h2 { margin-bottom: 9px; font-size: clamp(20px, 3vw, 25px); }
.case-workspace-section h2 small { margin-inline-start: 5px; color: var(--muted); font-size: 13px; }
.case-workspace-list, .case-workspace-empty {
  margin: 0;
  padding: 0;
  border-block: 1px solid var(--line-strong);
  background: var(--surface);
  list-style: none;
}
.case-workspace-empty { padding: 18px; color: var(--muted); }
.case-workspace-list li, .case-saved {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
  padding: 13px clamp(12px, 2.5vw, 22px);
}
.case-workspace-list li + li { border-top: 1px solid var(--line); }
.case-workspace-list li p, .case-saved p { margin-top: 3px; color: var(--muted); font-size: 13px; }
.case-saved { flex-wrap: wrap; }
.case-reference {
  max-width: 860px;
  margin-bottom: 16px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface-muted);
}
.case-reference summary { color: var(--green-dark); font-weight: 680; cursor: pointer; }
.case-reference p { margin-block: 9px; color: var(--muted); font-size: 13px; }
.case-reference dl { display: grid; gap: 7px 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); }
.case-reference dt { font-weight: 680; }
.case-reference dd { margin-top: 4px; color: var(--muted); }
.case-reference .button { margin-top: 13px; }

.case-content {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  line-height: 1.75;
}
.case-reading .case-story-plain > .case-section:first-child { padding-inline: 0; background: transparent; }
.case-search-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 5px 14px;
  min-height: 36px;
  margin-block: 5px 8px;
}
.case-search-status .case-count { margin: 0; }
.case-search-reset {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding-inline: 4px;
  border: 0;
  background: transparent;
  color: var(--green-dark);
  font-weight: 620;
  text-underline-offset: 4px;
}

@media (max-width: 510px) {
  .case-editor .field-input, select.case-attachment-vis, .case-attachment-vis select { font-size: 16px; }
  .case-attachment-row:has(.case-attachment-vis) { grid-template-columns: minmax(0, 1fr) auto auto; }
  .case-attachment-row:has(.case-attachment-vis) .case-attachment-meta { grid-column: 1 / -1; }
  .case-attachment-row > .case-attachment-remove:last-child { grid-column: -2 / -1; }
  .case-attachment-remove, .case-attachment-download { justify-self: end; }
  .case-editor-actions { gap: 5px 8px; }
  .case-editor-actions > .case-editor-help { flex-basis: 100%; }
  .case-workspace-list li { align-items: flex-start; }
}
