/* ============================================================
   TOOL UI — The Ai Toolz
   PDF tool workspace, utility tool workspace, image tool,
   options panel, bottom sheet, result screen.
   ============================================================ */

/* ── Tool page header ── */
.tool-header {
  padding-block: var(--space-8) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-8);
}
.tool-header__inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}
.tool-header__icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-card);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-3);
  flex-shrink: 0;
}
.tool-header__title {
  font-size: var(--text-h2);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-2);
}
.tool-header__desc {
  font-size: 1.0625rem;
  color: var(--color-text-muted);
  max-width: 56ch;
  line-height: var(--line-height-relaxed);
}
.tool-header__privacy {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-success);
  font-weight: var(--font-weight-medium);
}
.tool-header__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

/* ── Privacy notice (inline, every tool page) ── */
.privacy-note {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  border-radius: var(--radius-card);
  font-size: var(--text-xs);
  color: var(--color-success);
  font-weight: var(--font-weight-medium);
  margin-bottom: var(--space-6);
}

/* ═══════════════════════════════════════════════════════════
   PDF TOOL WORKSPACE
   ═══════════════════════════════════════════════════════════ */
.pdf-workspace {}

.pdf-workspace[data-state="idle"] .ws-processing { display: none; }
.pdf-workspace[data-state="idle"] .ws-result      { display: none; }
.pdf-workspace[data-state="processing"] .ws-idle  { display: none; }
.pdf-workspace[data-state="processing"] .ws-result { display: none; }
.pdf-workspace[data-state="done"] .ws-idle        { display: none; }
.pdf-workspace[data-state="done"] .ws-processing  { display: none; }

.ws-idle .dropzone {
  min-height: 280px;
  border-radius: var(--radius-hero);
}

.ws-processing {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}
@media (min-width: 1024px) {
  .ws-processing { grid-template-columns: 1fr 340px; align-items: start; }
}

.ws-files-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.ws-files-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ws-files-panel__title { font-weight: var(--font-weight-semibold); }
.ws-add-more {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.pdf-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--space-3);
}
.pdf-thumb {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  aspect-ratio: 3/4;
  cursor: pointer;
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
}
.pdf-thumb:hover { border-color: var(--color-primary); box-shadow: var(--shadow-2); }
.pdf-thumb[data-selected="true"] {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary);
}
.pdf-thumb canvas,
.pdf-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pdf-thumb__num {
  position: absolute;
  bottom: 4px;
  left: 50%;
  translate: -50% 0;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  font-weight: var(--font-weight-semibold);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}
.pdf-thumb__check {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  background: var(--color-primary);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.pdf-thumb[data-selected="true"] .pdf-thumb__check { display: flex; }

.ws-options-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
}
@media (min-width: 1024px) {
  .ws-options-panel { position: sticky; top: calc(var(--header-h) + var(--space-4)); }
}
.ws-options-panel__header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-sm);
}
.ws-options-panel__body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-5); }
.ws-options-panel__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
.ws-options-panel__footer .btn { width: 100%; }

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  visibility: hidden;
}
.bottom-sheet[data-open="true"] { visibility: visible; }
.bottom-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity var(--trans-normal);
}
.bottom-sheet[data-open="true"] .bottom-sheet__backdrop { opacity: 1; }
.bottom-sheet__panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-bg);
  border-radius: var(--radius-hero) var(--radius-hero) 0 0;
  max-height: 85dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  translate: 0 100%;
  transition: translate var(--trans-normal);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-sheet[data-open="true"] .bottom-sheet__panel { translate: 0 0; }
.bottom-sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: var(--radius-full);
  margin: var(--space-3) auto var(--space-2);
}
.bottom-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-bg);
  z-index: 1;
}
.bottom-sheet__title { font-weight: var(--font-weight-semibold); }
.bottom-sheet__body { padding: var(--space-5); }
.bottom-sheet__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  bottom: 0;
}
.bottom-sheet__footer .btn { width: 100%; }

.mobile-options-trigger {
  position: fixed;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  right: var(--space-4);
  z-index: var(--z-raised);
  box-shadow: var(--shadow-4);
}
@media (min-width: 1024px) { .mobile-options-trigger { display: none; } }

/* ═══════════════════════════════════════════════════════════
   RESULT SCREEN
   ═══════════════════════════════════════════════════════════ */
.ws-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-12) var(--space-8);
  text-align: center;
  max-width: 540px;
  margin-inline: auto;
}
.ws-result__icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-success-bg);
  border: 2px solid var(--color-success-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-success);
}
.ws-result__title { font-size: var(--text-h3); font-weight: var(--font-weight-bold); }
.ws-result__meta  { font-size: var(--text-sm); color: var(--color-text-muted); }
.ws-result__size-compare {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.ws-result__size-val { font-weight: var(--font-weight-semibold); }
.ws-result__size-reduction { color: var(--color-success); font-weight: var(--font-weight-semibold); }
.ws-result__actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
}
.ws-result__actions .btn { min-width: 140px; }
.ws-result__continue {
  width: 100%;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-6);
}
.ws-result__continue-title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  margin-bottom: var(--space-4);
}

.related-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  width: 100%;
}
@media (min-width: 640px) { .related-strip { grid-template-columns: repeat(4, 1fr); } }

/* ═══════════════════════════════════════════════════════════
   UTILITY TOOL WORKSPACE
   ═══════════════════════════════════════════════════════════ */
.util-workspace {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.util-options {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
}
.util-options__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.util-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.util-toolbar__left,
.util-toolbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.util-toolbar__divider {
  width: 1px;
  height: 20px;
  background: var(--color-border);
  flex-shrink: 0;
}

.util-panels {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}
@media (min-width: 1024px) {
  .util-panels { grid-template-columns: 1fr 1fr; }
}

.util-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  min-height: 320px;
}
.util-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}
.util-panel__label {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--color-text-muted);
}
.util-panel__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.util-panel__body {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.util-panel__textarea {
  width: 100%;
  height: 100%;
  min-height: 280px;
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
  border: none;
  outline: none;
  resize: none;
}
.util-panel__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
  flex-shrink: 0;
}
.util-panel__counter {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.util-panel__live-badge {
  font-size: var(--text-xs);
  color: var(--color-success);
  display: flex;
  align-items: center;
  gap: 4px;
}
.util-panel__live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-success);
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}
@media (prefers-reduced-motion: reduce) {
  .util-panel__live-dot { animation: none; }
}

/* ═══════════════════════════════════════════════════════════
   IMAGE TOOL WORKSPACE
   ═══════════════════════════════════════════════════════════ */
.img-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}
@media (min-width: 1024px) {
  .img-workspace { grid-template-columns: 1fr 280px; align-items: start; }
}

.img-stage {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  background: repeating-conic-gradient(var(--color-surface-2) 0% 25%, var(--color-bg) 0% 50%) 0 0 / 16px 16px;
  overflow: hidden;
  position: relative;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.img-stage:active { cursor: grabbing; }
.img-stage canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  box-shadow: var(--shadow-3);
}
.img-stage__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.img-zoom-bar {
  position: absolute;
  bottom: var(--space-3);
  left: 50%;
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-btn);
  padding: 2px;
  box-shadow: var(--shadow-2);
}
.img-zoom-label {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  padding-inline: var(--space-2);
  min-width: 44px;
  text-align: center;
  color: var(--color-text-muted);
}

.tool-sidebar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (min-width: 1024px) {
  .tool-sidebar { position: sticky; top: calc(var(--header-h) + var(--space-4)); }
}
.tool-sidebar__section {
  padding: var(--space-5);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.tool-sidebar__section:last-child { border-bottom: none; }
.tool-sidebar__section-title {
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  color: var(--color-text-muted);
}

.processing-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: rgba(var(--color-bg), 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--trans-normal), visibility var(--trans-normal);
}
.processing-overlay[data-visible="true"] { visibility: visible; opacity: 1; }
.processing-overlay__title { font-size: var(--text-h4); font-weight: var(--font-weight-bold); }
.processing-overlay__sub   { font-size: var(--text-sm); color: var(--color-text-muted); }

.feature-unavailable {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6);
  background: var(--color-warning-bg);
  border: 1px solid var(--color-warning-border);
  border-radius: var(--radius-card);
  margin-bottom: var(--space-6);
}
.feature-unavailable__text { font-size: var(--text-sm); color: var(--color-text); }
