/* Enne - shared record attachments component (static/js/attachments.js).
   Built on the modern.css tokens, so [data-theme="dark"] needs no overrides.
   One accent at a time: jade (--primary) for the drop target and progress,
   rust (--danger) only for delete and errors. Everything else is neutral. */

.enne-attachments {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  outline: none;
}

/* ---------- drop zone ---------- */

.enne-attachments__drop {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  border: 1px dashed var(--input-border);
  border-radius: 12px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.enne-attachments__drop:hover {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--input-border));
}

.enne-attachments.is-dragover .enne-attachments__drop {
  border-style: solid;
  border-color: var(--primary);
  background: var(--primary-light);
}

.enne-attachments__drop-icon {
  width: 1.5rem;
  height: 1.5rem;
  flex-shrink: 0;
  color: var(--foreground-secondary);
  transition: color 0.15s ease;
}

.enne-attachments.is-dragover .enne-attachments__drop-icon {
  color: var(--primary);
}

.enne-attachments__drop-text {
  flex: 1 1 auto;
  min-width: 0;
}

.enne-attachments__drop-title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--foreground);
}

.enne-attachments__drop-hint {
  margin: 0.125rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--foreground-secondary);
}

.enne-attachments__when-touch {
  display: none;
}

.enne-attachments__add {
  flex-shrink: 0;
}

/* Hidden but still clickable from script (older iOS ignores .click() on
   display:none file inputs). Never a tab stop: the Add files button is. */
.enne-attachments__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  clip: rect(0 0 0 0);
}

/* ---------- lists ---------- */

.enne-attachments__files {
  min-width: 0;
}

.enne-attachments__list,
.enne-attachments__queue {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.enne-attachments__queue[hidden] {
  display: none;
}

/* Tab-sized panels scroll the list itself; the 2px pad keeps focus rings
   inside the scroll box. Compact (dialog) mounts let the dialog scroll. */
.enne-attachments:not(.enne-attachments--compact) .enne-attachments__list {
  max-height: min(520px, 55vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
  margin: -2px;
}

.enne-attachments__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: inset 0 1px 0 var(--surface-edge), var(--shadow-rest);
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.enne-attachments__item:hover,
.enne-attachments__item:focus-within {
  border-color: color-mix(in srgb, var(--primary) 30%, var(--surface-border));
}

.enne-attachments__item.is-busy {
  opacity: 0.55;
}

.enne-attachments__item--upload[data-state="error"] {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

.enne-attachments__tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--secondary);
  color: var(--foreground-secondary);
}

.enne-attachments__tile-icon {
  width: 1.125rem;
  height: 1.125rem;
}

.enne-attachments__item--upload[data-state="uploading"] .enne-attachments__tile {
  background: var(--primary-light);
  color: var(--primary);
}

.enne-attachments__item--upload[data-state="error"] .enne-attachments__tile {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
}

.enne-attachments__main {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  flex: 1 1 auto;
  min-width: 0;
}

.enne-attachments__name {
  overflow: hidden;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--foreground);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.enne-attachments__meta {
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--foreground-secondary);
  font-variant-numeric: tabular-nums lining-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.enne-attachments__item--upload[data-state="error"] .enne-attachments__meta {
  color: var(--danger);
  white-space: normal;
  overflow-wrap: anywhere;
}

.enne-attachments__progress {
  display: block;
  height: 3px;
  margin-top: 0.375rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border-light);
}

.enne-attachments__bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 0.2s linear;
}

.enne-attachments__item--upload[data-state="queued"] .enne-attachments__progress {
  opacity: 0.6;
}

/* ---------- actions ---------- */

.enne-attachments__actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.enne-attachments__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--foreground-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.enne-attachments__icon-btn:hover {
  background: var(--secondary);
  color: var(--foreground);
}

.enne-attachments__icon-btn.is-danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
}

.enne-attachments__icon-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: progress;
}

.enne-attachments__btn-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

/* ---------- notice + states ---------- */

.enne-attachments__notice-slot:empty {
  display: none;
}

.enne-attachments__notice {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.375rem 0.375rem 0.75rem;
  border-radius: 10px;
  background: var(--secondary);
  color: var(--foreground);
  font-size: 0.8125rem;
}

.enne-attachments__notice[data-tone="error"] {
  background: color-mix(in srgb, var(--danger) 9%, transparent);
  color: var(--danger);
}

.enne-attachments__notice > span {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.enne-attachments__notice .enne-attachments__icon-btn {
  color: inherit;
}

.enne-attachments__state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--foreground-secondary);
}

.enne-attachments__state p {
  margin: 0;
}

.enne-attachments__state-title {
  font-weight: 500;
  color: var(--foreground);
}

.enne-attachments__state[data-tone="error"] .enne-attachments__state-title {
  color: var(--danger);
  overflow-wrap: anywhere;
}

.enne-attachments__state .neu-btn {
  margin-top: 0.5rem;
}

.enne-attachments__item.is-skeleton {
  animation: enne-attachments-pulse 1.2s ease-in-out infinite;
}

.enne-attachments__skel {
  display: block;
  width: 55%;
  height: 0.625rem;
  border-radius: 999px;
  background: var(--secondary);
}

.enne-attachments__skel.is-short {
  width: 30%;
  margin-top: 0.375rem;
}

@keyframes enne-attachments-pulse {
  50% { opacity: 0.55; }
}

.enne-attachments__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- compact (inside a dialog / sheet) ---------- */

.enne-attachments--compact {
  gap: 0.5rem;
}

.enne-attachments--compact .enne-attachments__drop {
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: 10px;
}

.enne-attachments--compact .enne-attachments__drop-icon {
  width: 1.125rem;
  height: 1.125rem;
}

.enne-attachments--compact .enne-attachments__drop-title {
  font-size: 0.8125rem;
}

.enne-attachments--compact .enne-attachments__drop-hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.enne-attachments--compact .enne-attachments__item {
  gap: 0.5rem;
  padding: 0.4375rem 0.5rem;
  border-radius: 8px;
}

.enne-attachments--compact .enne-attachments__tile {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 6px;
}

.enne-attachments--compact .enne-attachments__tile-icon {
  width: 0.9375rem;
  height: 0.9375rem;
}

.enne-attachments--compact .enne-attachments__name {
  font-size: 0.8125rem;
}

.enne-attachments--compact .enne-attachments__state {
  padding: 0.75rem;
}

/* ---------- touch + small screens ---------- */

@media (hover: none) and (pointer: coarse) {
  .enne-attachments__when-pointer { display: none; }
  .enne-attachments__when-touch { display: inline; }

  .enne-attachments__icon-btn {
    width: 2.5rem;
    height: 2.5rem;
  }
}

@media (max-width: 640px) {
  .enne-attachments__drop {
    flex-wrap: wrap;
  }

  .enne-attachments__drop-text {
    flex-basis: calc(100% - 2.5rem);
  }

  .enne-attachments__add {
    width: 100%;
  }

  .enne-attachments__item {
    padding: 0.5rem 0.625rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .enne-attachments__item.is-skeleton {
    animation: none;
  }

  .enne-attachments__drop,
  .enne-attachments__drop-icon,
  .enne-attachments__item,
  .enne-attachments__bar,
  .enne-attachments__icon-btn {
    transition: none;
  }
}
