/* =========================================================
   Tools Page - Giorgi Samukashvili Portfolio
   ========================================================= */

.tools-hero {
  padding-top: calc(var(--nav-height) + var(--space-16));
  padding-bottom: var(--space-16);
  border-bottom: 1px solid var(--border-subtle);
}

.tools-hero__title {
  margin-bottom: var(--space-4);
}

.tools-hero__desc {
  font-size: var(--size-lg);
  color: var(--text-secondary);
  max-width: 56ch;
}

.tool-section {
  padding-block: var(--space-20);
}

.tools-grid-section {
  padding-block: var(--space-20);
}

.tools__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  grid-auto-rows: 1fr;
  gap: var(--space-5);
  max-width: calc((4 * 380px) + (3 * var(--space-5)));
  margin-inline: auto;
}

.tool-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 340px;
  padding: var(--space-8);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  transition: border-color var(--transition-base), background var(--transition-base), transform var(--transition-base);
}

.tool-card:hover {
  border-color: var(--border-medium);
  background: rgba(255, 255, 255, 0.04);
  transform: translateY(-3px);
}

.tool-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.tool-card__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--text-muted);
  transition: border-color var(--transition-base), color var(--transition-base);
}

.tool-card:hover .tool-card__icon {
  border-color: var(--border-medium);
  color: var(--text-secondary);
}

.tool-card__body {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.tool-card__name {
  margin-bottom: var(--space-2);
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: var(--size-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-base);
}

.tool-card__platform {
  margin-bottom: var(--space-5);
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: var(--size-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.tool-card__desc {
  flex: 1;
  margin-bottom: var(--space-8);
  color: var(--text-secondary);
  font-size: var(--size-sm);
}

.tool-card__cta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  transition: color var(--transition-fast), gap var(--transition-fast);
}

.tool-card:hover .tool-card__cta {
  gap: var(--space-3);
  color: var(--text-primary);
}

.tool-page-hero__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-8);
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: var(--size-sm);
  transition: color var(--transition-fast);
}

.tool-page-hero__back:hover {
  color: var(--text-secondary);
}

.texture-tool {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--glass-bg);
  overflow: hidden;
}

.texture-tool__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  padding: var(--space-8) var(--space-8) 0;
}

.tool-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.texture-tool__intro {
  max-width: 72ch;
  padding: 0 var(--space-8);
  margin-top: var(--space-4);
  font-size: var(--size-base);
  color: var(--text-secondary);
}

.texture-tool__workspace {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: var(--space-6);
  padding: var(--space-8);
}

.texture-tool__controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.upload-tile {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: var(--space-4);
  align-items: center;
  min-height: 112px;
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.upload-tile:hover,
.upload-tile.is-dragover {
  border-color: var(--border-medium);
  background: rgba(255, 255, 255, 0.04);
}

.upload-tile.is-disabled,
.tool-check.is-disabled {
  opacity: 0.45;
}

.upload-tile.is-disabled {
  cursor: not-allowed;
}

.upload-tile input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.upload-tile__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  background: var(--bg-raised);
}

.upload-tile--red .upload-tile__icon {
  color: #d66a6a;
  border-color: rgba(214, 106, 106, 0.24);
}

.upload-tile--green .upload-tile__icon {
  color: #70c18b;
  border-color: rgba(112, 193, 139, 0.24);
}

.upload-tile--blue .upload-tile__icon {
  color: #6f9ee8;
  border-color: rgba(111, 158, 232, 0.24);
}

.upload-tile--alpha .upload-tile__icon {
  color: #d7d7d7;
  border-color: rgba(215, 215, 215, 0.24);
}

.upload-tile--normal .upload-tile__icon {
  color: #8fb7ff;
  border-color: rgba(143, 183, 255, 0.24);
}

.upload-tile--batch .upload-tile__icon {
  color: #d9b66f;
  border-color: rgba(217, 182, 111, 0.24);
}

.upload-tile--compress .upload-tile__icon {
  color: #7fc7c2;
  border-color: rgba(127, 199, 194, 0.24);
}

.upload-tile--seamless .upload-tile__icon {
  color: #d9a66f;
  border-color: rgba(217, 166, 111, 0.24);
}

.upload-tile--md .upload-tile__icon {
  color: #a78bfa;
  border-color: rgba(167, 139, 250, 0.24);
}

.upload-tile--img-ref .upload-tile__icon {
  color: #60a5fa;
  border-color: rgba(96, 165, 250, 0.24);
}

/* ── Markdown-to-PDF: document preview ── */

.md-pdf-workspace {
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
}

.doc-preview-wrap {
  position: relative;
  min-height: 520px;
  max-height: 780px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: #1c1c1c;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.doc-preview-area {
  display: flex;
  justify-content: center;
  padding: var(--space-5);
  box-sizing: border-box;
  min-width: 0;
}

.doc-preview-area > div {
  flex-shrink: 0;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
  border-radius: 2px;
}

.upload-tile__title,
.tool-field span,
.tool-check span,
.tool-range span {
  font-family: var(--font-heading);
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
}

.upload-tile__meta {
  display: block;
  grid-column: 2;
  margin-top: calc(var(--space-4) * -1);
  color: var(--text-muted);
  font-size: var(--size-sm);
  overflow-wrap: anywhere;
}

.tool-options {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
}

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

.tool-field select,
.tool-range input {
  min-height: 42px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-primary);
  font: inherit;
}

.tool-range {
  display: grid;
  gap: var(--space-2);
}

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

.tool-range output {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.tool-range input {
  width: 100%;
  padding-inline: 0;
  accent-color: var(--text-primary);
}

.tool-check {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.tool-check--with-tooltip {
  align-items: center;
}

.tool-field--with-tooltip > span,
.tool-range--with-tooltip > span {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.tool-check--with-tooltip > span:first-of-type {
  flex: 1 1 auto;
  min-width: 0;
}

.tool-check--with-tooltip > .tool-help,
.tool-field--with-tooltip > span > .tool-help,
.tool-range--with-tooltip > span > .tool-help {
  flex: 0 0 auto;
  align-self: center;
}

.tool-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--text-primary);
}

.tool-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  align-self: center;
}

.tool-help .tool-help__icon {
  display: grid;
  place-items: center;
  position: relative;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  background: var(--bg-raised);
  color: var(--text-muted);
  font-size: 0;
  line-height: 1;
  cursor: help;
}

.tool-help .tool-help__icon::before {
  content: '?';
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  font-family: var(--font-body);
  font-size: var(--size-xs);
  font-weight: var(--weight-semibold);
  line-height: 1;
}

.tool-help__bubble {
  position: absolute;
  right: 0;
  bottom: calc(100% + var(--space-2));
  z-index: 5;
  width: min(280px, calc(100vw - var(--space-8)));
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--text-secondary);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32);
  font-family: var(--font-body);
  font-size: var(--size-xs);
  font-weight: var(--weight-regular);
  line-height: 1.5;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.tool-help:hover .tool-help__bubble,
.tool-help:focus-within .tool-help__bubble {
  opacity: 1;
  transform: translateY(0);
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.tool-actions .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--compact {
  min-height: 34px;
  padding: 0 var(--space-3);
  font-size: var(--size-xs);
}

.tool-status {
  min-height: 1.8em;
  color: var(--text-muted);
  font-size: var(--size-sm);
}

.tool-status.is-error {
  color: #d28b78;
}

.texture-tool__preview {
  position: relative;
  min-width: 0;
}

.preview-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 520px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: #151515;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.06) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.preview-viewer {
  touch-action: none;
  user-select: none;
}

.preview-canvas {
  display: none;
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  image-rendering: auto;
}

.preview-pan-target {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  transition: transform var(--transition-fast);
  will-change: transform;
  -webkit-user-drag: none;
  user-select: none;
}

.preview-viewer.is-pannable {
  cursor: grab;
}

.preview-viewer.is-pannable:active {
  cursor: grabbing;
}

.preview-frame.has-image .preview-canvas {
  display: block;
}

.preview-tool-overlay {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  z-index: 6;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  max-width: calc(100% - var(--space-6));
}

.preview-tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(18, 18, 18, 0.86);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: var(--size-xs);
  font-weight: var(--weight-medium);
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}

.preview-tool-button:hover {
  border-color: var(--border-medium);
  background: var(--bg-raised);
  color: var(--text-primary);
}

.preview-compare-before {
  display: none;
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  image-rendering: auto;
}

.preview-compare-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  width: 100%;
  overflow: hidden;
  clip-path: inset(0 calc(100% - var(--preview-compare, 50%)) 0 0);
  pointer-events: none;
}

.preview-viewer.is-comparing.has-image .preview-compare-layer,
.preview-viewer.is-comparing.has-image .preview-compare-before {
  display: block;
}

.preview-viewer.is-comparing.has-image .preview-canvas,
.preview-viewer.is-comparing.has-image .image-compressor-preview__img {
  display: block;
}

.preview-compare-slider {
  position: absolute;
  left: 50%;
  bottom: var(--space-4);
  z-index: 7;
  display: none;
  width: min(320px, calc(100% - var(--space-8)));
  transform: translateX(-50%);
  accent-color: var(--text-primary);
}

.preview-viewer.is-comparing.has-image .preview-compare-slider {
  display: block;
}

.preview-compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--preview-compare, 50%);
  z-index: 5;
  width: 1px;
  background: rgba(255, 255, 255, 0.78);
  pointer-events: none;
  display: none;
}

.preview-viewer.is-comparing.has-image .preview-compare-divider {
  display: block;
}

.preview-compare-label {
  position: absolute;
  top: var(--space-4);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(18, 18, 18, 0.78);
  color: var(--text-secondary);
  font-family: var(--font-heading);
  font-size: var(--size-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  backdrop-filter: blur(10px);
}

.preview-compare-label--before {
  right: var(--space-2);
}

.preview-compare-label--after {
  left: var(--space-2);
}

.preview-viewer:not(.has-preview-navigation) [data-preview-action="previous"],
.preview-viewer:not(.has-preview-navigation) [data-preview-action="next"] {
  display: none;
}

.preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: var(--size-sm);
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
}

.preview-frame.has-image .preview-empty {
  display: none;
}

.preview-updating {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-3);
  background: rgba(12, 12, 12, 0.62);
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

.preview-frame.is-updating .preview-updating {
  display: flex;
}

.preview-updating__spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: preview-spin 0.8s linear infinite;
}

@keyframes preview-spin {
  to {
    transform: rotate(360deg);
  }
}

.preview-stats {
  margin-top: var(--space-3);
  color: var(--text-muted);
  font-size: var(--size-sm);
}

.file-queue {
  display: grid;
  gap: var(--space-3);
  max-height: 520px;
  overflow: auto;
}

.image-compressor-preview {
  min-height: clamp(520px, 62vh, 760px);
  margin-bottom: var(--space-4);
}

.image-compressor-toolbar {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 2;
  margin-bottom: 0;
}

.image-compressor-preview .preview-compare-before {
  max-height: min(720px, 58vh);
}

.image-compressor-preview__img {
  display: none;
  max-width: 100%;
  max-height: min(720px, 58vh);
  width: auto;
  height: auto;
  object-fit: contain;
}

.preview-frame.has-image .image-compressor-preview__img {
  display: block;
}

.image-compressor-queue {
  max-height: 300px;
}

.image-compressor-queue__empty {
  grid-template-columns: minmax(0, 1fr);
  min-height: 74px;
  border-style: dashed;
  background: rgba(255, 255, 255, 0.015);
}

.file-queue-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-3);
}

.file-queue-toolbar .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.file-queue__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
}

.file-queue__name {
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: var(--size-sm);
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.file-queue__meta {
  margin-top: var(--space-1);
  color: var(--text-muted);
  font-size: var(--size-sm);
}

.file-queue__status {
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: var(--size-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;
}

.file-queue__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}

.file-queue__remove:hover {
  border-color: var(--border-medium);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
}

.file-queue__item.is-error .file-queue__status,
.file-queue__item.is-error .file-queue__meta {
  color: #d28b78;
}

.tool-toast {
  position: fixed;
  right: clamp(var(--space-4), 3vw, var(--space-8));
  bottom: clamp(var(--space-4), 3vw, var(--space-8));
  z-index: 20;
  max-width: min(360px, calc(100vw - var(--space-8)));
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-raised);
  color: var(--text-secondary);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.32);
  font-size: var(--size-sm);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.tool-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.tool-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.tool-modal.is-visible {
  display: flex;
}

.tool-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.tool-modal__panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - var(--space-10)));
  overflow: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
}

.tool-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.tool-modal__header h2 {
  margin: 0;
  font-size: var(--size-xl);
}

.tool-modal__body {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-6);
  color: var(--text-secondary);
  font-size: var(--size-sm);
}

.license-list {
  display: grid;
  gap: var(--space-4);
  padding-left: var(--space-5);
}

.license-list li {
  padding-left: var(--space-1);
}

.license-list a,
.tool-modal__body a {
  display: inline-flex;
  margin-left: var(--space-2);
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

@media (max-width: 980px) {
  .texture-tool__workspace {
    grid-template-columns: 1fr;
  }

  .preview-frame {
    min-height: 420px;
  }

  .image-compressor-preview {
    min-height: clamp(440px, 56vh, 620px);
  }

  .image-compressor-preview__img {
    max-height: min(580px, 52vh);
  }
}

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

  .tool-card {
    min-height: 0;
    padding: var(--space-6);
  }

  .texture-tool__header {
    flex-direction: column;
    padding: var(--space-6) var(--space-6) 0;
  }

  .tool-header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .texture-tool__intro {
    padding-inline: var(--space-6);
  }

  .texture-tool__workspace {
    padding: var(--space-6);
  }

  .upload-tile {
    grid-template-columns: 40px 1fr;
    min-height: 96px;
    padding: var(--space-4);
  }

  .upload-tile__icon {
    width: 40px;
    height: 40px;
  }

  .tool-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .preview-frame {
    min-height: 320px;
  }

  .image-compressor-preview {
    min-height: 360px;
  }

  .image-compressor-preview__img {
    max-height: 340px;
  }
}
