/* ==========================================================================
   SMToolsAI, tool-page.css
   Shared UI for all 100 tool pages: breadcrumb, tool shell, dropzone,
   options panel, file list, previews, progress, results, content body,
   FAQ accordion, related tools, sticky mobile download bar.
   Load AFTER main.css. Depends on the tokens defined there.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. PAGE HEAD (breadcrumb + H1 + intro)
   -------------------------------------------------------------------------- */
.breadcrumb {
  padding-top: var(--sp-6);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.breadcrumb ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.breadcrumb li {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.breadcrumb li + li::before {
  content: "\203A";
  color: var(--border-strong);
}

.breadcrumb a {
  color: var(--text-muted);
}

.breadcrumb a:hover {
  color: var(--accent-strong);
}

.breadcrumb [aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

.tool-head {
  padding-block: var(--sp-6) var(--sp-4);
  max-width: 780px;
}

.tool-head h1 {
  font-size: var(--fs-3xl);
  margin-bottom: var(--sp-3);
}

.tool-intro {
  font-size: var(--fs-lg);
  color: var(--text-muted);
  line-height: var(--lh-content);
  margin: 0;
}

.privacy-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--success-soft);
  color: var(--success);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.privacy-pill svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notice {
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-4);
  border: 1px solid transparent;
}

.notice-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.notice-info {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

[data-theme="dark"] .notice-info {
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   2. TOOL SHELL
   -------------------------------------------------------------------------- */
.tool-shell {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
}

.tool-shell + .tool-shell {
  margin-top: var(--sp-6);
}

.tool-section-title {
  font-size: var(--fs-lg);
  margin-bottom: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.tool-section-title .badge {
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   3. DROPZONE
   -------------------------------------------------------------------------- */
.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: var(--sp-3);
  text-align: center;
  min-height: 240px;
  padding: var(--sp-8) var(--sp-4);
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--bg);
  cursor: pointer;
  transition: border-color var(--speed) var(--ease),
    background-color var(--speed) var(--ease), transform var(--speed) var(--ease);
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

.dropzone-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

[data-theme="dark"] .dropzone-icon {
  color: var(--accent);
}

.dropzone-icon svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dropzone-title {
  font-size: var(--fs-lg);
  font-weight: 700;
  margin: 0;
}

.dropzone-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  max-width: 46ch;
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   4. OPTIONS PANEL
   -------------------------------------------------------------------------- */
.options {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  margin-top: var(--sp-6);
  padding-top: var(--sp-6);
  border-top: 1px solid var(--border);
}

.field {
  display: grid;
  gap: var(--sp-2);
}

.field > label,
.field-label {
  font-size: var(--fs-sm);
  font-weight: 600;
}

.field-hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin: 0;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="email"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  transition: border-color var(--speed) var(--ease),
    box-shadow var(--speed) var(--ease);
}

.field textarea {
  min-height: 160px;
  resize: vertical;
  line-height: var(--lh-normal);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-error {
  font-size: var(--fs-xs);
  color: var(--danger);
  min-height: 1em;
  margin: 0;
}

.range-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

input[type="range"] {
  flex: 1;
  accent-color: var(--accent-strong);
  height: 24px;
}

.range-value {
  min-width: 56px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--fs-sm);
  background: var(--surface-2);
  border-radius: var(--r-pill);
  padding: var(--sp-1) var(--sp-2);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
}

.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-strong);
  flex: none;
}

.segmented {
  display: inline-flex;
  padding: var(--sp-1);
  gap: var(--sp-1);
  background: var(--surface-2);
  border-radius: var(--r-md);
  flex-wrap: wrap;
}

.segmented button {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: var(--sp-2) var(--sp-4);
  min-height: 36px;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
}

.actions .spacer {
  margin-left: auto;
}

/* --------------------------------------------------------------------------
   5. FILE LIST & PREVIEWS
   -------------------------------------------------------------------------- */
.file-list {
  list-style: none;
  margin: var(--sp-6) 0 0;
  padding: 0;
  display: grid;
  gap: var(--sp-2);
}

.file-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
}

.file-thumb {
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: var(--r-sm);
  object-fit: cover;
  background: var(--surface-2);
}

.file-meta {
  min-width: 0;
  flex: 1;
}

.file-name {
  display: block;
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-size {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

.file-remove {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.file-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.file-remove svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.compare {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-top: var(--sp-6);
}

.compare-pane {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  padding: var(--sp-3);
}

.compare-pane h3 {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--sp-3);
}

.compare-pane img,
.compare-pane canvas {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

/* --------------------------------------------------------------------------
   5b. CROP STAGE (image cropper)
   -------------------------------------------------------------------------- */
.crop-stage {
  margin-top: var(--sp-6);
}

.crop-stage[hidden] {
  display: none;
}

.crop-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  background: var(--surface-2);
  border-radius: var(--r-md);
  overflow: hidden;
  touch-action: none;
}

.crop-canvas-wrap canvas {
  display: block;
  max-width: 100%;
}

.crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.55);
  cursor: move;
  touch-action: none;
}

.crop-box::before,
.crop-box::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-color: rgba(255, 255, 255, 0.45);
  border-style: solid;
}

.crop-box::before {
  border-width: 0 1px;
  left: 33.333%;
  right: 33.333%;
  inset-block: 0;
}

.crop-box::after {
  border-width: 1px 0;
  top: 33.333%;
  bottom: 33.333%;
  inset-inline: 0;
}

.crop-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--bg);
  border: 2px solid var(--accent);
  border-radius: 50%;
  touch-action: none;
}

.crop-handle[data-handle="nw"] {
  top: -11px;
  left: -11px;
  cursor: nwse-resize;
}
.crop-handle[data-handle="ne"] {
  top: -11px;
  right: -11px;
  cursor: nesw-resize;
}
.crop-handle[data-handle="sw"] {
  bottom: -11px;
  left: -11px;
  cursor: nesw-resize;
}
.crop-handle[data-handle="se"] {
  bottom: -11px;
  right: -11px;
  cursor: nwse-resize;
}

[data-crop-readout] {
  margin-top: var(--sp-3);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   6. PROGRESS & RESULTS
   -------------------------------------------------------------------------- */
.progress {
  margin-top: var(--sp-6);
}

.progress[hidden] {
  display: none;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
}

.progress-track {
  height: 8px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: var(--r-pill);
  background: var(--gradient);
  transition: width 180ms linear;
}

.results {
  margin-top: var(--sp-6);
  display: grid;
  gap: var(--sp-3);
}

.results[hidden] {
  display: none;
}

.result-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg);
  flex-wrap: wrap;
}

.result-item .file-meta {
  min-width: 160px;
}

.result-stat {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--success);
  background: var(--success-soft);
  border-radius: var(--r-pill);
  padding: 2px var(--sp-2);
  white-space: nowrap;
}

.result-stat.is-up {
  color: var(--warning);
  background: var(--warning-soft);
}

.status-msg {
  margin-top: var(--sp-4);
  font-size: var(--fs-sm);
  min-height: 1.4em;
}

.status-msg.is-error {
  color: var(--danger);
  font-weight: 600;
}

.status-msg.is-success {
  color: var(--success);
  font-weight: 600;
}

.output-box {
  width: 100%;
  min-height: 220px;
  padding: var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-6);
}

.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  text-align: center;
}

.stat-value {
  display: block;
  font-size: var(--fs-2xl);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-label {
  display: block;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--sp-1);
}

/* --------------------------------------------------------------------------
   7. CONTENT BODY (SEO prose, steps, features)
   -------------------------------------------------------------------------- */
.content-body {
  max-width: 760px;
  line-height: var(--lh-content);
  font-size: var(--fs-base);
}

.content-body h2 {
  font-size: var(--fs-2xl);
  margin-top: var(--sp-12);
}

.content-body h2:first-child {
  margin-top: 0;
}

.content-body h3 {
  font-size: var(--fs-xl);
  margin-top: var(--sp-8);
}

.content-body ul,
.content-body ol {
  padding-left: var(--sp-6);
}

.content-body li {
  margin-bottom: var(--sp-2);
}

.steps {
  counter-reset: step;
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--sp-4);
}

.steps li {
  counter-increment: step;
  position: relative;
  padding-left: 52px;
  min-height: 36px;
  margin: 0;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  font-weight: 800;
  font-size: var(--fs-sm);
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--sp-3);
}

.feature-list li {
  position: relative;
  padding-left: 30px;
  margin: 0;
}

.feature-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.5em;
  width: 14px;
  height: 8px;
  border-left: 2.5px solid var(--accent-strong);
  border-bottom: 2.5px solid var(--accent-strong);
  transform: rotate(-45deg);
}

[data-theme="dark"] .feature-list li::before {
  border-color: var(--accent);
}

/* --------------------------------------------------------------------------
   8. FAQ ACCORDION
   -------------------------------------------------------------------------- */
.faq {
  display: grid;
  gap: var(--sp-3);
  max-width: 820px;
}

.faq details {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
  overflow: hidden;
}

.faq summary {
  cursor: pointer;
  list-style: none;
  padding: var(--sp-4);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 44px;
}

.faq summary::-webkit-details-marker {
  display: none;
}

.faq summary::after {
  content: "+";
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1;
  color: var(--text-muted);
  flex: none;
  transition: transform var(--speed) var(--ease);
}

.faq details[open] summary::after {
  transform: rotate(45deg);
}

.faq .faq-answer {
  padding: 0 var(--sp-4) var(--sp-4);
  color: var(--text-muted);
  line-height: var(--lh-content);
}

.faq .faq-answer p:last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   9. RELATED TOOLS
   -------------------------------------------------------------------------- */
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
}

.related-card {
  display: block;
  padding: var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--text);
  transition: transform var(--speed) var(--ease),
    border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}

.related-card:hover {
  text-decoration: none;
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.related-card strong {
  display: block;
  font-size: var(--fs-base);
  margin-bottom: var(--sp-1);
}

.related-card span {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   10. STICKY MOBILE DOWNLOAD BAR
   -------------------------------------------------------------------------- */
.sticky-download {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  padding: var(--sp-3) var(--sp-4);
  padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.12);
  display: none;
}

.sticky-download.is-visible {
  display: block;
}

@media (min-width: 769px) {
  .sticky-download {
    display: none !important;
  }
}

@media (max-width: 768px) {
  body.has-sticky-download {
    padding-bottom: 84px;
  }

  .tool-shell {
    padding: var(--sp-4);
  }

  .dropzone {
    min-height: 200px;
    padding: var(--sp-6) var(--sp-3);
  }

  .actions .btn {
    flex: 1 1 100%;
  }

  .actions .spacer {
    margin-left: 0;
  }
}

@media (max-width: 480px) {
  .tool-head h1 {
    font-size: var(--fs-2xl);
  }

  .result-item {
    flex-direction: column;
    align-items: stretch;
  }

  .result-item .btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dropzone.is-dragover,
  .related-card:hover {
    transform: none;
  }
  .progress-fill {
    transition: none;
  }
}
