/* =====================================================================
   Shivam Tools — shared components for the v2 tools
   (search & category filter, upload drop zones, stats, progress,
   before/after compare, checkerboard, file lists, segmented tabs).
   Loaded after styles.css and only uses its existing design tokens.
   ===================================================================== */

/* ---------- Tool search & category filter ---------- */
.tool-filter { display: flex; flex-direction: column; gap: 14px; margin-bottom: 24px; }
.tool-search { position: relative; max-width: 520px; }
.tool-search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--muted); pointer-events: none; }
.tool-search input[type="search"] {
  width: 100%; min-height: 50px; padding: 12px 44px 12px 44px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 999px;
  font-size: 1rem; box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
.tool-search input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.tool-search input[type="search"]:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.tool-search-clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.tool-search-clear:hover { background: var(--surface-2); color: var(--text); }
.tool-search-clear[hidden], .tool-empty[hidden], .busy-overlay[hidden], .dropzone[hidden] { display: none; }
.tool-search-clear .icon { position: static; transform: none; width: 18px; height: 18px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; border: 0; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-2); font-weight: 600; font-size: .875rem; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary); }
.chip .chip-count { font-size: .75rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.chip[aria-pressed="true"] .chip-count { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary-text); }
.tool-results-status { font-size: .875rem; color: var(--muted); margin: 0; }
.tool-empty { padding: 32px 20px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); color: var(--muted); }
.tool-empty p { margin: 0 0 12px; }
.tool-card[hidden] { display: none; }
.tool-card .cat-label { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 14px 0 -8px; }

/* ---------- Upload drop zone ---------- */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 190px; padding: 28px 18px; text-align: center;
  border: 2px dashed var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-2); color: var(--text-2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-drag { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .dz-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--surface); color: var(--primary-text); box-shadow: var(--shadow-sm); }
.dropzone .dz-icon .icon { width: 28px; height: 28px; }
.dropzone strong { font-size: 1.05rem; color: var(--text); }
.dropzone p { margin: 0; font-size: .875rem; color: var(--muted); }
.dropzone input[type="file"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.dropzone input[type="file"]:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.dropzone.compact { min-height: 0; padding: 16px; flex-direction: row; flex-wrap: wrap; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.stat-value { display: block; font-size: 1.6rem; font-weight: 750; line-height: 1.15; color: var(--text); letter-spacing: -0.02em; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.stat-label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-top: 4px; }
.stat.accent { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 30%, transparent); }
.stat.accent .stat-value { color: var(--primary-text); }
.stat.good .stat-value { color: var(--success); }

/* ---------- Key/value table (breakdowns) ---------- */
.kv-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.kv-table th, .kv-table td { padding: 10px 4px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.kv-table td { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; overflow-wrap: anywhere; }
.kv-table th { font-weight: 500; color: var(--text-2); }
.kv-table tr.total th, .kv-table tr.total td { font-weight: 750; font-size: 1.05rem; color: var(--text); border-bottom: 0; border-top: 2px solid var(--border-strong); }

/* ---------- Progress & spinner ---------- */
.progress { width: 100%; height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--primary); border-radius: inherit; transition: width .2s; }
.progress.indeterminate > span { width: 35%; animation: st-indeterminate 1.2s ease-in-out infinite; }
@keyframes st-indeterminate { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: st-spin .7s linear infinite; vertical-align: -3px; }
@keyframes st-spin { to { transform: rotate(360deg); } }
.btn.is-loading { pointer-events: none; opacity: .8; }
.busy-overlay { position: absolute; inset: 0; display: grid; place-items: center; gap: 10px; align-content: center; background: color-mix(in srgb, var(--surface) 78%, transparent); border-radius: inherit; z-index: 3; font-weight: 600; color: var(--text-2); text-align: center; padding: 16px; }

/* ---------- Image preview helpers ---------- */
.checker {
  background-color: #fff;
  background-image: linear-gradient(45deg, #e5e7eb 25%, transparent 25%), linear-gradient(-45deg, #e5e7eb 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e5e7eb 75%), linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.img-frame { position: relative; display: grid; place-items: center; min-height: 220px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.img-frame img, .img-frame canvas { display: block; max-width: 100%; max-height: 60vh; width: auto; height: auto; object-fit: contain; }

/* Before / after slider */
.compare { position: relative; overflow: hidden; border-radius: var(--radius); border: 1px solid var(--border); line-height: 0; user-select: none; touch-action: pan-y; }
.compare img { display: block; width: 100%; height: auto; max-height: none; pointer-events: none; }
.compare .compare-after { position: absolute; inset: 0; clip-path: inset(0 0 0 var(--pos, 50%)); }
.compare .compare-after img { width: 100%; height: 100%; object-fit: contain; }
.compare .compare-line { position: absolute; top: 0; bottom: 0; left: var(--pos, 50%); width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 0 1px rgba(15, 23, 42, .35); pointer-events: none; }
.compare .compare-line::after { content: "⟷"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 36px; height: 36px; border-radius: 50%; background: #fff; color: #0f172a; display: grid; place-items: center; font-size: 16px; line-height: 36px; text-align: center; box-shadow: var(--shadow); }
.compare .compare-tag { position: absolute; top: 10px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; line-height: 1.6; background: rgba(15, 23, 42, .72); color: #fff; pointer-events: none; }
.compare .compare-tag.left { left: 10px; }
.compare .compare-tag.right { right: 10px; }
.compare input[type="range"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.compare input[type="range"]:focus-visible ~ .compare-line { box-shadow: 0 0 0 3px var(--focus); }

/* ---------- File list (PDF tools) ---------- */
.file-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; }
.file-row .file-badge { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: .7rem; font-weight: 800; }
.file-row .file-meta { flex: 1; min-width: 0; }
.file-row .file-name { display: block; font-weight: 600; font-size: .925rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-row .file-sub { display: block; font-size: .8rem; color: var(--muted); }
.file-row .file-actions { display: flex; gap: 2px; flex: none; }
.file-row .file-actions .btn-text { min-height: 36px; padding: 6px 8px; }

/* ---------- Tabs (segmented, button based) ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; padding: 0; }
.tabs [role="tab"] { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-weight: 600; font-size: .9rem; cursor: pointer; }
.tabs [role="tab"]:hover { background: var(--surface-2); }
.tabs [role="tab"][aria-selected="true"] { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary); }
.tabs [role="tab"] .icon { width: 17px; height: 17px; }

/* ---------- Misc ---------- */
.result-box { padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.inline-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-fields .field { flex: 1 1 140px; }
.how-steps { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.how-steps li { position: relative; padding-left: 40px; color: var(--text-2); }
.how-steps li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-text); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; font-size: .8em; font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); }
.size-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.size-badge.good { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, transparent); }

@media (max-width: 640px) {
  .stat-value { font-size: 1.35rem; }
  .tool-search { max-width: none; }
  .chip-row { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; scrollbar-width: thin; }
  .chip { flex: none; }
  .dropzone { min-height: 160px; padding: 22px 14px; }
}

/* ---------- v3: premium search bar & category chips ---------- */
.tool-filter { gap: 16px; margin-bottom: 30px; }
.tool-search { max-width: 640px; }
.tool-search input[type="search"] {
  min-height: 58px; padding-left: 52px; font-size: 1.05rem;
  border-color: var(--border); background: var(--surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 14px 34px -20px rgba(67, 56, 202, .45);
}
.tool-search > .icon { left: 18px; width: 22px; height: 22px; color: var(--primary-text); }
.tool-search input[type="search"]:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent), 0 14px 34px -20px rgba(67, 56, 202, .55); }
.chip {
  min-height: 42px; padding: 8px 16px; border-color: var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
  transition: background .2s, border-color .2s, color .2s, box-shadow .2s, transform .2s;
}
.chip:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); color: var(--primary-text); background: var(--surface); }
.chip[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; border-color: transparent;
  box-shadow: 0 8px 20px -10px rgba(79, 70, 229, .8);
}
.chip[aria-pressed="true"] .chip-count { background: rgba(255, 255, 255, .22); color: #fff; }
.tool-empty { background: var(--surface); }
