/* ==========================================================================
   Image Converter — workspace UI
   Loaded only on /tools/image-converter.

   Design intent: no panel, no border, no "embedded widget" frame. The tool sits
   directly on the page background; the only elevated things are the controls
   the user can actually press.
   ========================================================================== */

/* ------------------------------------------------------------------- hero */

.tool-hero {
  text-align: center;
  padding-block: var(--space-7) var(--space-5);
  max-width: 46rem;
  margin-inline: auto;
}

.tool-hero h1 {
  margin-bottom: var(--space-3);
  font-size: clamp(2rem, 1.4rem + 2.4vw, 2.75rem);
}

.tool-hero__sub {
  margin: 0;
  font-size: var(--text-lg);
  color: var(--fg-muted);
}

/* Privacy note as a quiet line, not a filled banner box. */
.tool-hero__trust {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--success);
}
.tool-hero__trust svg { flex: 0 0 auto; }

/* -------------------------------------------------------------- workspace */

.converter {
  max-width: 760px;
  margin: 0 auto var(--space-8);
}

/* Whole-page drop affordance: a dashed outline appears only while dragging. */
.converter__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  background: var(--surface);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.converter__empty:hover,
.converter[data-dragover="true"] .converter__empty {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary-soft) 35%, var(--surface));
}

.drop-illus {
  display: inline-grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  color: var(--primary);
  margin-bottom: var(--space-2);
}

.converter__empty h2 {
  margin: 0;
  font-size: var(--text-2xl);
  font-weight: 700;
}

.converter__hint {
  margin: 0 0 var(--space-3);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  max-width: 480px;
}

.converter__trust {
  margin: var(--space-2) 0 0;
  font-size: var(--text-xs);
  color: var(--fg-subtle);
}

/* --------------------------------------------------------- split chooser */

.chooser {
  position: relative;
  display: inline-flex;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.chooser__main,
.chooser__toggle {
  border: 0;
  background: var(--primary);
  color: var(--fg-on-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}

.chooser__main {
  min-height: 56px;
  padding: 0 var(--space-6);
  font-size: var(--text-lg);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.chooser__toggle {
  display: grid;
  place-items: center;
  width: 52px;
  min-height: 56px;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  /* Hairline divider without a real border, so the button reads as one unit. */
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.25);
}

.chooser__main:hover,
.chooser__toggle:hover { background: var(--primary-hover); }
.chooser__main:active,
.chooser__toggle:active { background: var(--primary-active); }

.chooser__toggle svg { transition: transform var(--dur) var(--ease); }
.chooser__toggle[aria-expanded="true"] svg { transform: rotate(180deg); }

.chooser__menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  right: 0;
  z-index: 20;
  min-width: 260px;
  padding: var(--space-2);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: left;
}
.chooser__menu[hidden] { display: none; }

.chooser__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.chooser__item:hover { background: var(--surface-2); }
.chooser__item svg { flex: 0 0 auto; color: var(--fg-subtle); }

.chooser__note {
  margin: var(--space-1) 0 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  color: var(--fg-muted);
}

.converter__hint {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}

/* -------------------------------------------------------------- work bars */

.workbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.workbar--top { margin-bottom: var(--space-4); }

.workbar--bottom {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  /* A single hairline is enough separation — no filled footer bar. */
  border-top: 1px solid var(--border);
}

.workbar__summary {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}

.workbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ------------------------------------------------------------- file rows */

.filerows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.filerow {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur) var(--ease);
}
.filerow:hover { box-shadow: var(--shadow-md); }

.filerow__thumb {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--fg-subtle);
}
.filerow__thumb img { width: 100%; height: 100%; object-fit: cover; }

.filerow__info {
  flex: 1 1 12rem;
  min-width: 0;
}

.filerow__name {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  /* Truncation is the point: long names must not push the controls off-row. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filerow__meta {
  display: block;
  font-size: var(--text-xs);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.filerow__meta strong { color: var(--success); font-weight: 600; }

.filerow__controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 auto;
  margin-inline-start: auto;
}

.filerow__label {
  font-size: var(--text-sm);
  color: var(--fg-muted);
  white-space: nowrap;
}

.filerow__select {
  min-height: 40px;
  padding: 0 var(--space-6) 0 var(--space-3);
  background-color: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.filerow__select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 25%, transparent);
}

.filerow__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--fg-subtle);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.filerow__icon:hover { background: var(--surface-2); color: var(--fg); }
.filerow__icon--danger:hover { background: var(--danger-soft); color: var(--danger-soft-fg); }

/* A dot marks a row whose advanced options differ from the defaults. */
.filerow__icon { position: relative; }
.filerow__icon[data-modified="true"]::after {
  content: "";
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--surface);
}

.filerow--done { background: var(--success-soft); }
.filerow--done .filerow__meta { color: var(--success-soft-fg); }
.filerow--error { background: var(--danger-soft); }
.filerow--error .filerow__meta { color: var(--danger-soft-fg); }

.filerow__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

/* Mobile: name on its own line, controls wrap underneath. */
@media (max-width: 599px) {
  .filerow {
    flex-wrap: wrap;
    row-gap: var(--space-3);
  }
  .filerow__info { flex-basis: calc(100% - 52px); }
  .filerow__controls {
    flex-basis: 100%;
    margin-inline-start: 0;
    justify-content: space-between;
  }
  .filerow__select { flex: 1; }
  .filerow__label { display: none; }
}

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: var(--space-4);
}
.modal[hidden] { display: none; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 11, 22, 0.55);
  backdrop-filter: blur(2px);
  border: 0;
  padding: 0;
  cursor: pointer;
}

.modal__dialog {
  position: relative;
  width: min(100%, 520px);
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--dur-slow) var(--ease);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .modal__dialog { animation: none; }
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.modal__head h2 { margin: 0; font-size: var(--text-lg); }
.modal__head p { margin: 2px 0 0; font-size: var(--text-xs); color: var(--fg-muted); }

.modal__body {
  padding: 0 var(--space-5) var(--space-5);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.modal__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
}

.optgroup { display: flex; flex-direction: column; gap: var(--space-2); }

.optgroup__label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--fg);
}
.optgroup__hint {
  font-size: var(--text-xs);
  color: var(--fg-muted);
  margin: 0;
}

.optgroup__pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.swatch-row input[type="color"] {
  width: 52px;
  height: 44px;
  padding: 3px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}
.swatch-row .input { flex: 1; font-family: var(--font-mono); text-transform: uppercase; }

/* Quality slider reads its value inline so the number is never hidden. */
.slider-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

/* ------------------------------------------------------------ result area */

.converter__status {
  min-height: 22px;
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--fg-muted);
}
