:root {
  --upload-surface: #f6faf8;
  --upload-active-surface: #edf7f3;
  --upload-border: #b0c9bf;
  --upload-grid-line: #2f91730a;
  --upload-ink: #234b40;
  --upload-muted: #516e64;
  --upload-accent: #11745f;
  --upload-tile-hover: #fffdfbe6;
  --upload-actions: #f5fbf8f2;
}
html[data-theme="warm"] {
  --upload-surface: #fcfaf4;
  --upload-active-surface: #f8f2e5;
  --upload-border: #d5c5a5;
  --upload-grid-line: #9374370e;
  --upload-ink: #4e3c23;
  --upload-muted: #6e5e46;
  --upload-accent: #846128;
  --upload-actions: #fffbf2f2;
}
.upload-image-grid {
  --upload-tile-gap: 9px;
  --upload-pattern:
    linear-gradient(var(--upload-grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--upload-grid-line) 1px, transparent 1px);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: var(--upload-tile-gap);
  min-width: 0;
  padding: 9px;
  border: 1px dashed var(--upload-border);
  border-radius: 12px;
  background: var(--upload-pattern);
  background-size: 16px 16px;
  background-color: var(--upload-surface);
  color: var(--upload-ink);
  transition: border-color .16s, background-color .16s;
}
.upload-image-grid[hidden] { display: none; }
.upload-image-grid[data-empty] > .upload-image-add { grid-column: 1 / -1; min-height: 124px; aspect-ratio: auto; padding: 12px; }
.upload-image-grid:is(:hover, :focus-within, .dragover, .is-dragging) {
  border-color: var(--upload-accent);
  background-color: var(--upload-active-surface);
}
.upload-image-tile, button.upload-image-add {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
  aspect-ratio: 1;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  padding: 0;
  margin: 0;
  background: var(--surface, #fff);
}
button.upload-image-add {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  padding: 4px;
  color: var(--upload-ink);
  border: 1px solid transparent;
  background: transparent;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 600;
  white-space: normal;
  cursor: pointer;
}
button.upload-image-add:hover, button.upload-image-add:focus-visible { background: var(--upload-tile-hover); border-color: var(--upload-border); }
.upload-image-add > svg { width: 23px; height: 23px; color: var(--upload-accent); }
[data-empty] > .upload-image-add > svg { width: 28px; height: 28px; margin-bottom: 3px; }
[data-empty] > .upload-image-add > .upload-image-add-label { font-size: 13px; }
.upload-image-detail { display: block; max-width: 100%; color: var(--upload-muted); font-size: 11px; font-weight: 400; text-align: center; overflow-wrap: anywhere; }
button.upload-image-open { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
button.upload-image-open > img { display: block; width: 100%; height: 100%; object-fit: cover; border: 0; margin: 0; }
.upload-image-actions {
  position: absolute;
  inset: auto 0 0;
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 3px;
  background: var(--upload-actions);
  color: var(--upload-ink);
  pointer-events: none;
}
.upload-image-actions:empty { display: none; }
.upload-image-actions button {
  display: grid;
  place-items: center;
  flex: 0 1 32px;
  width: 32px;
  min-width: 0;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
}
.upload-image-actions button > svg { width: 17px; height: 17px; }
.upload-image-actions button:hover { background: var(--upload-active-surface); color: var(--upload-accent); }
.upload-image-actions button:disabled, button.upload-image-add:disabled { opacity: .5; cursor: not-allowed; }
.upload-image-actions button:focus-visible, .upload-image-open:focus-visible { outline: 2px solid var(--upload-accent); outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) {
  .upload-image-tile:not(:hover):not(:focus-within) .upload-image-actions { opacity: 0; }
  .upload-image-tile:not(:hover):not(:focus-within) .upload-image-actions button { pointer-events: none; }
}
.upload-image-viewer {
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  padding: 42px 10px 10px;
  color: #fff;
  background: #13231f;
  border: 1px solid #4f665e;
  border-radius: 10px;
}
.upload-image-viewer::backdrop { background: #0a1714d9; }
.upload-image-viewer img { display: block; max-width: min(1100px, calc(100vw - 46px)); max-height: calc(100dvh - 80px); object-fit: contain; }
button.upload-image-close { position: absolute; top: 6px; right: 9px; width: 30px; height: 30px; padding: 0; border: 1px solid #6d847b; border-radius: 5px; background: #263e36; color: #fff; font-size: 20px; cursor: pointer; }
.upload-image-file { display: none !important; }
.app.image-tool-mode .image-tool-selected.upload-image-grid {
  display: grid;
  margin-top: 0;
  background: var(--upload-pattern);
  background-size: 16px 16px;
  background-color: var(--upload-surface);
  border-color: var(--upload-border);
  box-shadow: none;
}
.app.image-tool-mode .image-tool-selected.upload-image-grid[hidden] { display: none; }
.app.image-tool-mode .image-tool-selected.upload-image-grid:is(:hover, :focus-within, .is-dragging) {
  border-color: var(--upload-accent);
  background-color: var(--upload-active-surface);
}
.creation-attachments:has(.upload-image-grid) { display: grid; max-height: min(34dvh, 250px); overflow: auto; }
.creation-attachments > .upload-image-grid { grid-template-columns: repeat(3, minmax(0, 92px)); }
.layout-visual > .upload-image-tile { height: 100%; min-height: inherit; z-index: 3; }
.layout-visual > .upload-image-tile .upload-image-actions { z-index: 3; }
@media (prefers-reduced-motion: reduce) {
  .upload-image-grid { transition: none; }
}
@media (max-width: 390px) {
  .upload-image-grid { --upload-tile-gap: 6px; padding: 6px; }
  .upload-image-actions { gap: 2px; padding: 2px; }
}
