/* NexDrive shared form controls — loaded by both the customer site and
   the admin tool, after tokens.css and before site.css / admin.css.

   Two components live here because they appear on both surfaces and
   must look the same on each:

     .upload-field  — a drop-zone around a native <input type="file">.
                      Pure CSS gives the styled box; upload.js adds
                      previews, remove buttons and drag-and-drop.
     .combobox      — the type-to-filter select combobox.js builds in
                      front of a <select data-searchable>. Without JS the
                      native select renders instead and none of this
                      applies.

   Everything is token-driven; the surfaces only tweak spacing. */

/* ---------- Upload field ---------- */

.upload-field {
  display: block;
}

.upload-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: var(--space-4) var(--space-3);
  border: 1.5px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface-soft);
  text-align: center;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.upload-zone:focus-within,
.upload-zone.is-dragging {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.upload-icon {
  width: 28px;
  height: 28px;
  stroke: var(--color-text-faint);
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-copy {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.upload-copy strong {
  font-weight: 500;
  color: var(--color-text);
}

.upload-copy span {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

/* No-JS: the native input sits inside the zone, styled as plainly as
   the engines allow. It stays fully functional. */
.upload-zone input[type="file"] {
  width: auto;
  max-width: 100%;
  margin-top: 0.25rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--color-text-muted);
}

/* Enhanced: the native input is kept for the form but taken out of the
   layout; the zone itself becomes the target. */
.upload-field.is-enhanced .upload-zone {
  cursor: pointer;
}

.upload-field.is-enhanced .upload-zone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.upload-choose {
  margin-top: 0.25rem;
}

.upload-error {
  margin: 0.5rem 0 0;
  color: var(--color-danger);
  font-size: 0.82rem;
}

.upload-previews {
  list-style: none;
  margin: var(--space-3) 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2);
}

.upload-previews[hidden] {
  display: none;
}

.upload-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  min-width: 0;
}

.upload-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--color-surface-soft);
}

.upload-item-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.74rem;
  color: var(--color-text-muted);
  min-width: 0;
}

.upload-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-item-size {
  flex: none;
  color: var(--color-text-faint);
}

.upload-item-remove {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--radius-pill);
  background: rgba(20, 16, 14, 0.7);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.upload-item-remove:hover,
.upload-item-remove:focus-visible {
  background: var(--color-primary);
  outline: none;
}

/* Existing (already stored) items on an edit form. The checkbox is the
   real control — "keep this photo" — and stays visible without JS;
   enhanced, it's hidden behind the same × button new files get. */
.upload-item-existing .upload-keep {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  cursor: pointer;
}

.upload-item-existing .upload-keep input {
  width: auto;
  margin: 0;
}

.upload-field.is-enhanced .upload-item-existing .upload-keep {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.upload-item-existing.is-removed img,
.upload-item-existing:has(.upload-keep input:not(:checked)) img {
  opacity: 0.35;
}

/* ---------- Combobox ---------- */

.combobox {
  position: relative;
}

.combobox-native {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}

.field .combobox-input,
.combobox-input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23726b64' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'></circle><path d='M20 20l-3.5-3.5'></path></svg>");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  background-size: 15px;
  padding-right: 2.4rem !important;
}

.combobox-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(20, 16, 14, 0.12);
}

.combobox-list[hidden] {
  display: none;
}

.combobox-option,
.combobox-empty {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
}

.combobox-empty {
  color: var(--color-text-faint);
  cursor: default;
}

.combobox-option[aria-selected="true"] {
  font-weight: 500;
}

.combobox-option.is-active,
.combobox-option:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
