/* ==========================================================================
   QuickFileTools – Image Resizer
   Design System: "The Desk" (tokens.css + components.css)
   ========================================================================== */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--bg);
  font-family: var(--font-sans);
  line-height: var(--line-height-body, 1.6);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font-family: inherit;
  font-size: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--action);
  text-decoration: underline;
}

:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

main {
  max-width: var(--max-content, 1120px);
  margin: 0 auto;
  padding: 0 var(--space-4, 16px) var(--space-12, 48px);
}

/* ---------- Hero ---------- */

.tool-hero {
  padding: var(--space-6, 24px) 0 var(--space-4, 16px);
  text-align: left;
}

.hero-copy {
  text-align: left;
}

.hero-copy h1 {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--font-size-h1);
  font-weight: var(--font-weight-heading);
  line-height: var(--line-height-heading);
  letter-spacing: -0.02em;
  color: var(--ink);
}

.hero-copy p {
  margin: 0 0 var(--space-3, 12px);
  max-width: var(--max-measure, 70ch);
  color: var(--ink-muted);
  font-size: var(--font-size-base);
}

/* ---------- Main Tool Sheet ---------- */

.resizer-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(400px, 1.15fr);
  background: var(--sheet);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sheet);
  box-shadow: var(--elevation-sheet);
  overflow: hidden;
  margin-top: var(--space-4, 16px);
}

[data-theme="dark"] .resizer-shell {
  border: 1px solid var(--hairline);
  box-shadow: none;
}

/* ---------- Upload Side ---------- */

.upload-panel {
  padding: var(--space-6, 24px);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
}

.drop-zone {
  border: 2px dashed var(--rule);
  border-radius: var(--radius-sheet);
  background: var(--paper);
  min-height: 280px;
  flex: 1;
  padding: var(--space-6, 24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.drop-zone:hover {
  border-color: var(--action);
}

.drop-zone.dragging,
.drop-zone.is-dragover {
  border-color: var(--action);
  background: var(--marker);
  color: var(--on-marker);
}

.upload-icon {
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2, 8px);
  display: grid;
  place-items: center;
  color: var(--action);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.drop-zone.dragging .upload-icon,
.drop-zone.is-dragover .upload-icon {
  color: var(--on-marker);
  background: transparent;
}

.upload-icon svg {
  width: 28px;
  height: 28px;
}

.drop-zone h2 {
  margin: var(--space-1, 4px) 0;
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
}

.drop-zone p {
  margin: 0 0 var(--space-3, 12px);
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

.drop-zone small {
  margin-top: var(--space-3, 12px);
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

.privacy-note {
  margin-top: var(--space-4, 16px);
  padding: 8px var(--space-3, 12px);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2, 8px);
  border-radius: var(--radius-control);
  background: var(--marker);
  color: var(--on-marker);
  font-size: var(--font-size-sm);
}

.privacy-note span {
  font-size: 1.1rem;
  line-height: 1.2;
}

.privacy-note strong {
  display: block;
  font-weight: var(--font-weight-semibold);
  color: var(--on-marker);
}

.privacy-note p {
  margin: 2px 0 0;
  color: var(--on-marker);
  font-size: 0.8125rem;
}

/* ---------- Settings Side ---------- */

.settings-panel {
  padding: var(--space-6, 24px);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3, 12px);
  min-height: 40px;
  margin-bottom: var(--space-2, 8px);
}

.panel-head h2 {
  margin: 0;
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
}

.step-label {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

/* ---------- Mode Tabs (Segmented Control) ---------- */

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin: var(--space-3, 12px) 0 var(--space-4, 16px);
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.mode-tab {
  min-height: 44px;
  border: 0;
  border-radius: calc(var(--radius-control) - 2px);
  color: var(--ink-muted);
  background: transparent;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mode-tab:hover {
  color: var(--ink);
}

.mode-tab.active {
  background: var(--paper);
  color: var(--ink);
  font-weight: var(--font-weight-heading);
}

/* ---------- Form Controls & Fields ---------- */

.field-grid {
  display: grid;
  gap: var(--space-3, 12px);
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: block;
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2, 8px);
  margin-bottom: var(--space-1, 4px);
}

.field small {
  color: var(--ink-muted);
  font-weight: var(--font-weight-regular);
}

input[type="number"],
select {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  color: var(--ink);
  background: var(--sheet);
  font-family: inherit;
  font-size: var(--font-size-base);
  transition: border-color 0.15s ease;
}

select {
  padding-right: 32px;
}

.input-suffix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-suffix input {
  padding-right: 44px;
}

.input-suffix > span {
  position: absolute;
  right: 12px;
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  pointer-events: none;
}

.input-suffix.compact {
  width: 105px;
  flex: 0 0 105px;
}

.range-row {
  display: flex;
  align-items: center;
  gap: var(--space-3, 12px);
}

input[type="range"] {
  width: 100%;
  min-height: 24px;
  accent-color: var(--action);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
  margin-top: var(--space-3, 12px);
}

.chip {
  min-height: 38px;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--sheet);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.chip:hover {
  border-color: var(--action);
  color: var(--action);
}

.setting-row {
  margin-top: var(--space-3, 12px);
}

/* ---------- Toggle Switch ---------- */

.toggle-row {
  margin-top: var(--space-3, 12px);
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: var(--space-2, 8px);
  cursor: pointer;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.fake-toggle {
  width: 44px;
  height: 26px;
  padding: 2px;
  display: block;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.fake-toggle::after {
  content: "";
  width: 20px;
  height: 20px;
  display: block;
  border-radius: 50%;
  background: var(--rule);
  transition: transform 0.15s ease, background 0.15s ease;
}

.toggle-row input:checked + .fake-toggle {
  background: var(--action);
  border-color: var(--action);
}

.toggle-row input:checked + .fake-toggle::after {
  transform: translateX(18px);
  background: var(--on-action);
}

.toggle-row input:focus-visible + .fake-toggle {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

.toggle-row strong {
  display: block;
  color: var(--ink);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.toggle-row small {
  display: block;
  color: var(--ink-muted);
  font-size: 0.8125rem;
}

.helper {
  margin: var(--space-2, 8px) 0 0;
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

/* ---------- Buttons ---------- */

.primary-btn,
.resize-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2, 8px);
  min-height: 44px;
  padding: 10px var(--space-6, 24px);
  border: 1px solid var(--action);
  border-radius: var(--radius-control);
  background: var(--action);
  color: var(--on-action);
  font-family: inherit;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.resize-btn {
  width: 100%;
  margin-top: var(--space-4, 16px);
}

.primary-btn:hover:not(:disabled),
.resize-btn:hover:not(:disabled) {
  opacity: 0.92;
  color: var(--on-action);
}

.primary-btn:disabled,
.resize-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  background: var(--sheet);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.secondary-btn:hover {
  border-color: var(--action);
  color: var(--action);
}

.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 8px;
  border: 0;
  background: transparent;
  color: var(--action);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}

.text-btn:hover {
  text-decoration: underline;
}

.text-btn.danger {
  color: var(--error);
}

/* ---------- File Area & Results List ---------- */

.file-area {
  max-width: var(--max-content, 1120px);
  margin: var(--space-6, 24px) auto 0;
  padding: var(--space-5, 20px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sheet);
  background: var(--sheet);
  box-shadow: var(--elevation-sheet);
}

[data-theme="dark"] .file-area {
  border: 1px solid var(--hairline);
  box-shadow: none;
}

.file-area-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4, 16px);
}

.file-area h2 {
  margin: 0;
  font-size: var(--font-size-h3);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
}

.file-area p {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
}

.head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
}

.file-list {
  margin-top: var(--space-4, 16px);
  display: grid;
  gap: var(--space-2, 8px);
}

.file-card {
  padding: var(--space-2, 8px) var(--space-3, 12px);
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3, 12px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--paper);
}

.thumb {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border-radius: 4px;
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--ink);
}

.file-meta {
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 0.8125rem;
}

.file-status {
  margin-top: 2px;
  color: var(--ok);
  font-size: 0.8125rem;
  font-weight: var(--font-weight-semibold);
}

.file-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-control);
  color: var(--ink-muted);
  background: var(--sheet);
  font-size: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  color: var(--error);
  border-color: var(--error);
}

.download-btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--action);
  border-radius: var(--radius-control);
  color: var(--on-action);
  background: var(--action);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.download-btn:hover {
  opacity: 0.92;
}

/* ---------- Result Actions (Highlighter) ---------- */

.results-actions {
  margin-top: var(--space-4, 16px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4, 16px);
  border-radius: var(--radius-control);
  background: var(--marker);
  color: var(--on-marker);
  border: 1px solid var(--hairline);
}

.results-actions strong {
  display: block;
  color: var(--on-marker);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.results-actions span {
  display: block;
  margin-top: 2px;
  color: var(--on-marker);
  font-size: 0.8125rem;
}

/* ---------- Content Sections, FAQ & Related Tools ---------- */

.content-section {
  padding: var(--space-10, 40px) 0;
  border-top: 1px solid var(--hairline);
}

.content-section.alt {
  background: transparent;
}

.content-wrap {
  max-width: var(--max-content, 1120px);
  margin: 0 auto;
  text-align: left;
}

.section-heading h2,
.two-col-copy h2 {
  margin: 0 0 var(--space-3, 12px);
  font-size: var(--font-size-h2);
  font-weight: var(--font-weight-heading);
  color: var(--ink);
  line-height: var(--line-height-heading);
}

.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4, 16px);
  margin-top: var(--space-4, 16px);
}

.steps-grid article {
  padding: var(--space-5, 20px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.steps-grid article > span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--paper);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  margin-bottom: var(--space-2, 8px);
}

.steps-grid h3 {
  margin: 0 0 var(--space-2, 8px);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--ink);
}

.steps-grid p,
.two-col-copy p,
.info-card p,
.faq-wrap details p {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-body);
  margin: 0;
}

.two-col-copy {
  display: grid;
  grid-template-columns: 1.35fr 0.65fr;
  gap: var(--space-8, 32px);
  align-items: start;
}

.feature-list {
  margin: var(--space-4, 16px) 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: var(--space-2, 8px);
}

.feature-list li {
  color: var(--ink-muted);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: baseline;
  gap: var(--space-2, 8px);
}

.feature-list li::before {
  content: "✓";
  color: var(--ok);
  font-weight: bold;
  flex-shrink: 0;
}

.info-card {
  padding: var(--space-5, 20px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.info-card h3 {
  margin: 0 0 var(--space-2, 8px);
  color: var(--ink);
  font-size: var(--font-size-base);
}

.info-card a {
  display: inline-block;
  margin-top: var(--space-3, 12px);
  color: var(--action);
  text-decoration: underline;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
}

.faq-wrap {
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2, 8px);
  margin-top: var(--space-4, 16px);
}

.faq-wrap details {
  padding: var(--space-3, 12px) var(--space-4, 16px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-control);
  background: var(--sheet);
}

.faq-wrap summary {
  color: var(--ink);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  min-height: 24px;
}

.faq-wrap details p {
  margin-top: var(--space-2, 8px);
}

/* ---------- Utility / Toast ---------- */

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1000;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  color: var(--sheet);
  border-radius: var(--radius-control);
  background: var(--ink);
  font-size: var(--font-size-sm);
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .resizer-shell {
    grid-template-columns: 1fr;
  }

  .upload-panel {
    border-right: 0;
    border-bottom: 1px solid var(--hairline);
  }

  .steps-grid {
    grid-template-columns: 1fr;
  }

  .two-col-copy {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .field-grid.two {
    grid-template-columns: 1fr;
  }

  .file-card {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .thumb {
    width: 52px;
    height: 52px;
  }

  .file-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .results-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .results-actions #downloadAllBtn {
    width: 100%;
  }

  .file-area-head {
    flex-direction: column;
    align-items: stretch;
  }

  .head-actions {
    justify-content: space-between;
  }
}

/* ---------- Reduced Motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}