.attachment-editor {
  margin-top: 6px;
  min-width: 0;
  color: var(--muted, #64748b);
  font-size: 13px;
  line-height: 1.4;
}

.attachment-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.attachment-upload, .attachment-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid var(--line-strong, #cbd5e1);
  border-radius: 5px;
  background: #fff;
  color: var(--accent-dark, #2456b8);
  font: inherit;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
}
.attachment-upload:hover, .attachment-control:hover {
  border-color: #86a4e8;
  background: var(--accent-soft, #edf3ff);
}
.attachment-upload:disabled, .attachment-control:disabled {
  cursor: not-allowed;
  opacity: .6;
}
.attachment-hint { flex: 1; min-width: 150px; font-size: 12px; line-height: 1.4; }
.attachment-jobs:empty, .attachment-inserted-list:empty { display: none; }
.attachment-jobs, .attachment-inserted-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  align-items: start;
  gap: 6px;
  margin-top: 6px;
}
.attachment-job, .attachment-inserted {
  display: flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  min-width: 0;
  min-height: 52px;
  padding: 4px 6px;
  border: 1px solid var(--line, #dce4ef);
  border-radius: 6px;
  background: #f6f8fc;
}
.attachment-open {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--accent-dark, #2456b8);
  font: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.attachment-open:hover .attachment-name { text-decoration: underline; text-underline-offset: 2px; }
.attachment-info { flex: 1; min-width: 0; }
.attachment-name, .attachment-job-name {
  display: block;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink, #1e293b);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-meta, .attachment-job-status {
  display: block;
  margin-top: 2px;
  color: var(--muted, #64748b);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.attachment-actions { display: flex; flex-shrink: 0; align-items: center; gap: 4px; }
.attachment-control { min-width: 32px; padding: 5px 7px; font-size: 12px; }
.attachment-control svg { display: block; width: 16px; height: 16px; }
.attachment-job.failed { border-color: #efb2a8; background: #fff5f3; }
.attachment-job.failed .attachment-job-status { color: #a33122; }
.attachment-job.failed .attachment-info { overflow: visible; }
.attachment-job progress {
  display: block;
  width: 100%;
  max-width: 180px;
  height: 5px;
  margin-top: 4px;
  border: 0;
  border-radius: 3px;
  accent-color: var(--accent, #2d5be3);
}
.attachment-dragover { outline: 3px solid #5278ed; outline-offset: 2px; }
.attachment-thumbnail-frame {
  display: inline-flex;
  flex: 0 0 56px;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 40px;
}
.attachment-thumbnail, img.attachment-job-preview {
  display: block;
  flex: 0 0 56px;
  box-sizing: border-box;
  width: 56px;
  height: 40px;
  max-width: 56px;
  max-height: 40px;
  border: 1px solid #d6e1f2;
  border-radius: 3px;
  background: #fff;
  object-fit: contain;
}
.attachment-thumbnail-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 56px;
  height: 40px;
  border: 1px solid #d6e1f2;
  border-radius: 3px;
  background: #edf2f8;
  color: #526480;
  font-size: 12px;
}
.attachment-file-icon {
  display: inline-flex;
  flex: 0 0 28px;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 32px;
  border-radius: 3px;
  background: #e7edf7;
  color: var(--muted, #64748b);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}
.attachment-file-icon svg { width: 23px; height: 27px; }
.attachment-reference {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  box-sizing: border-box;
  max-width: 100%;
  min-height: 44px;
  margin: 3px 4px 3px 0;
  padding: 3px 6px;
  border: 1px solid #cad9f0;
  border-radius: 5px;
  background: #f5f8ff;
  color: var(--accent-dark, #2456b8);
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  vertical-align: middle;
  white-space: normal;
  cursor: pointer;
}
.attachment-reference .attachment-info { max-width: 220px; }
.attachment-reference > .attachment-name { max-width: 220px; }
.attachment-reference small { display: block; font-size: 12px; color: var(--muted, #64748b); }
.attachment-reference:hover { border-color: #86a4e8; background: #edf3ff; }
.attachment-open:focus-visible, .attachment-upload:focus-visible, .attachment-control:focus-visible,
.attachment-reference:focus-visible, .attachment-preview-dialog button:focus-visible,
.attachment-preview-dialog a:focus-visible { outline: 2px solid #315fe8; outline-offset: 2px; }

dialog.attachment-preview-dialog {
  box-sizing: border-box;
  width: min(920px, calc(100vw - 32px));
  max-width: min(920px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line, #dce4ef);
  border-radius: 12px;
  background: #fff;
  color: var(--ink, #1e293b);
  box-shadow: 0 24px 90px rgb(12 29 57 / 25%);
}
.attachment-preview-dialog::backdrop { background: rgb(13 23 42 / 65%); }
.attachment-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line, #dce4ef);
}
.attachment-preview-header h2, .attachment-preview-header h3, .attachment-preview-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.attachment-preview-header button {
  flex: 0 0 44px;
  width: 44px;
  min-height: 44px;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  background: #f0f3f8;
  color: #526480;
  font-size: 24px;
  cursor: pointer;
}
.attachment-preview-header button:hover { background: #e6ecf7; }
.attachment-preview-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  padding: 16px;
  background: #f5f7fa;
}
.attachment-preview-content img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
}
.attachment-preview-content img[hidden], .attachment-preview-status[hidden] { display: none; }
.attachment-preview-status { margin: 16px 0; color: var(--muted, #64748b); font-size: 14px; }
.attachment-preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line, #dce4ef);
  font-size: 12px;
  color: var(--muted, #64748b);
}
.attachment-preview-footer .attachment-control { min-height: 44px; }
.attachment-preview-footer p { margin: 0; }

@media (max-width: 600px), (pointer: coarse) {
  .attachment-control, .attachment-upload { min-width: 44px; min-height: 44px; }
  .attachment-open { min-height: 44px; }
  .attachment-actions { gap: 8px; }
}
@media (max-width: 600px) {
  .attachment-jobs, .attachment-inserted-list { grid-template-columns: minmax(0, 1fr); }
  .attachment-job, .attachment-inserted { padding: 3px 5px; }
  .attachment-hint { min-width: 150px; }
  .attachment-reference .attachment-info, .attachment-reference > .attachment-name { max-width: 180px; }
  .attachment-preview-header, .attachment-preview-footer { padding: 8px 10px; }
  .attachment-preview-content { padding: 10px; }
  .attachment-preview-content img { max-height: 60vh; }
}
@media (prefers-reduced-motion: reduce) {
  .attachment-editor *, .attachment-reference, .attachment-preview-dialog, .attachment-preview-dialog * {
    animation: none !important;
    transition: none !important;
  }
}
