/* ==========================================================================
   MyAITools — platform styles: homepage directory, tool pages, shared
   tool components. Loaded in addition to css/style.css on directory &
   tool pages. Uses the same design tokens.
   ========================================================================== */

/* ---------- Breadcrumb ---------- */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  padding: 1rem 0 0;
}

.breadcrumb ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.breadcrumb li::after {
  content: "›";
  margin-left: 0.35rem;
  color: var(--color-border);
}

.breadcrumb li:last-child::after {
  content: "";
}

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

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

/* ---------- Tool page header ---------- */
.tool-head {
  padding: 1.5rem 0 0.5rem;
  text-align: center;
}

.tool-head h1 {
  margin-bottom: 0.4rem;
}

.tool-head .lead {
  color: var(--color-text-muted);
  font-size: 1.05rem;
  max-width: 680px;
  margin: 0 auto;
}

.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--color-success-soft);
  color: var(--color-success);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 0.9rem;
}

/* ---------- Tool shell ---------- */
.tool-shell {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: clamp(1rem, 3vw, 2rem);
  margin: 1.5rem 0 2rem;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 1.25rem;
}

/* ---------- Homepage directory ---------- */
.tool-search {
  max-width: 520px;
  margin: 0 auto 2rem;
  position: relative;
}

.tool-search input {
  width: 100%;
  padding: 0.8rem 1rem 0.8rem 2.8rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 1rem;
  min-height: 48px;
}

.tool-search svg {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.tool-category {
  margin-bottom: 2.5rem;
}

.tool-category h2 {
  font-size: 1.3rem;
  margin-bottom: 0.25rem;
}

.tool-category .cat-lead {
  color: var(--color-text-muted);
  font-size: 0.92rem;
  margin-bottom: 1.25rem;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
}

.tool-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-decoration: none;
  color: var(--color-text);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
}

.tool-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  color: var(--color-text);
}

.tool-card .tool-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  display: grid;
  place-items: center;
  margin-bottom: 0.75rem;
}

.tool-card .tool-icon svg {
  width: 21px;
  height: 21px;
}

.tool-card h3 {
  font-size: 1.05rem;
  margin: 0 0 0.25rem;
}

.tool-card p {
  margin: 0 0 0.9rem;
  color: var(--color-text-muted);
  font-size: 0.88rem;
  flex: 1;
}

.tool-card .open-label {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--color-primary);
}

.tools-empty {
  text-align: center;
  color: var(--color-text-muted);
  padding: 2rem 0;
  display: none;
}

.tools-empty.is-visible {
  display: block;
}

/* ---------- Related tools ---------- */
.related-tools {
  margin-top: 2.5rem;
}

.related-tools h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.related-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.related-list a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--color-text);
  font-weight: 500;
  font-size: 0.92rem;
  transition: border-color 0.15s, background 0.15s;
}

.related-list a:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.related-list svg {
  width: 18px;
  height: 18px;
  color: var(--color-primary);
  flex-shrink: 0;
}

/* ---------- Result list (batch tools) ---------- */
.result-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.result-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
}

.result-list .rl-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}

.result-list .rl-meta {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  flex: 1;
}

.result-list .rl-saved {
  color: var(--color-success);
  font-weight: 700;
  font-size: 0.82rem;
}

/* ---------- Page/preview grid ---------- */
.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}

.page-card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: center;
}

.page-card.is-selected {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.page-card canvas,
.page-card img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: #fff;
}

.page-card .page-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin: 0;
}

.page-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.page-chip {
  min-width: 44px;
  min-height: 40px;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}

.page-chip[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ---------- File list (merge etc.) ---------- */
.file-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-list li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.8rem;
  cursor: grab;
}

.file-list li.is-dragging {
  opacity: 0.45;
}

.file-list li.is-dropTarget {
  outline: 2px solid var(--color-primary);
}

.file-list .fl-index {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.file-list .fl-name {
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.file-list .fl-size {
  color: var(--color-text-muted);
  font-size: 0.8rem;
}

.file-list .fl-actions {
  display: flex;
  gap: 0.25rem;
}

/* ---------- Text tools ---------- */
.text-tool textarea,
.text-tool pre.output {
  width: 100%;
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.5;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.stat-card {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.error-box {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border: 1px solid color-mix(in srgb, var(--color-danger) 40%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.error-box[hidden] {
  display: none;
}

.ok-box {
  background: var(--color-success-soft);
  color: var(--color-success);
  border: 1px solid color-mix(in srgb, var(--color-success) 40%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.ok-box[hidden] {
  display: none;
}

/* ---------- Password / QR display ---------- */
.password-display {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin: 1rem 0;
}

.password-display output,
.password-display input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.15rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-alt);
  word-break: break-all;
  min-height: 48px;
  display: flex;
  align-items: center;
}

.strength-track {
  height: 8px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.strength-fill {
  height: 100%;
  width: 0;
  background: var(--color-danger);
  transition: width 0.25s, background 0.25s;
}

.qr-display {
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-top: 1rem;
  min-height: 200px;
}

.qr-display img,
.qr-display svg {
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
}

/* ---------- Cropper ---------- */
.crop-stage {
  position: relative;
  margin-top: 1rem;
  background: repeating-conic-gradient(var(--color-border) 0 25%, transparent 0 50%) 0 0 / 20px 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.crop-stage canvas {
  display: block;
  max-width: 100%;
  cursor: move;
}

.crop-info {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}

/* ---------- Preview pane ---------- */
.preview-pane {
  margin-top: 1rem;
  display: grid;
  place-items: center;
  background: repeating-conic-gradient(var(--color-border) 0 25%, transparent 0 50%) 0 0 / 20px 20px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  min-height: 120px;
}

.preview-pane img {
  max-width: 100%;
  max-height: 420px;
  border-radius: var(--radius-sm);
}

/* ---------- Segmented options ---------- */
.seg-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.seg-group button {
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  min-height: 40px;
  color: var(--color-text);
}

.seg-group button[aria-pressed="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ---------- Two-column compare ---------- */
.compare-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.compare-grid figure {
  margin: 0;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  text-align: center;
}

.compare-grid figcaption {
  font-size: 0.82rem;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
}

/* ---------- Homepage hero tweaks ---------- */
.hero-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

@media (max-width: 640px) {
  .result-list .rl-name {
    max-width: 100%;
  }
  .password-display {
    flex-direction: column;
  }
}
