/* tool-ui.css: the shared tool layouts.
 *
 * Five layouts, one per kind of job, in the way Semrush has a few page shapes
 * rather than one: a tool picks the one that fits what it does.
 *
 *   .tu-hub      Overview hub   numbers, trend, what changed, next actions
 *   .tu-audit    Audit report   score and verdict, issues by severity, detail
 *   .tu-track    Tracker        tracked items with trends, filters, history
 *   .tu-explore  Explorer       query, summary strip, a big sortable table
 *   .tu-gen      Generator      settings on the left, live output on the right
 *
 * Every layout shares the same parts: page header, buttons, fields, chips,
 * cards, section headings, empty state, loading and error. Colours come from
 * the platform tokens (_sidebar.js / citerank.css), so light and dark mode and
 * the contrast work already done there carry over. Radii stay on the
 * platform scale {4, 6, 8, 12, 16, 999}.
 */

/* ── Page frame ─────────────────────────────────────────────────────── */
.tu { max-width: 1240px; margin: 0 auto; padding: 28px 32px 72px; box-sizing: border-box; }
.tu *, .tu *::before, .tu *::after { box-sizing: border-box; }

/* Header: what this is, in one line, and the page's own actions. */
.tu-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin: 0 0 24px; }
.tu-head-text { min-width: 0; }
.tu-head h1, .tu-title { margin: 0; font-size: 1.5rem; line-height: 1.25; font-weight: 700; letter-spacing: -.015em; color: var(--text); }
.tu-head p, .tu-sub { margin: 6px 0 0; max-width: 720px; font-size: .9375rem; line-height: 1.55; color: var(--text-2); }
.tu-head-actions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.tu-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; font-size: .875rem; line-height: 1; font-family: inherit; white-space: nowrap; cursor: pointer; text-decoration: none;
  background: var(--accent-strong, #3949ab); color: #fff;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.tu-btn:hover { background: color-mix(in srgb, var(--accent-strong, #3949ab) 88%, #000); }
.tu-btn:focus-visible, .tu-chip:focus-visible, .tu-input:focus-visible, .tu-tab:focus-visible, .tu-link:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.tu-btn:disabled, .tu-btn[aria-busy="true"] { opacity: .55; cursor: default; }
.tu-btn--quiet { background: var(--bg-card); color: var(--text); border-color: var(--border); }
.tu-btn--quiet:hover { background: var(--bg-hover); border-color: var(--border-strong, var(--border)); }
.tu-btn--ghost { background: transparent; color: var(--text-2); }
.tu-btn--ghost:hover { background: var(--bg-hover); color: var(--text); }
.tu-btn--sm { height: 32px; padding: 0 12px; font-size: .8125rem; border-radius: 6px; }
.tu-btn--block { width: 100%; }

.tu-link { color: var(--accent-ink, var(--accent)); font-weight: 600; text-decoration: none; font-size: .875rem; border-radius: 4px; }
.tu-link:hover { text-decoration: underline; }

/* ── Fields ─────────────────────────────────────────────────────────── */
.tu-field { display: block; margin: 0 0 18px; }
.tu-field:last-child { margin-bottom: 0; }
.tu-label { display: flex; align-items: baseline; justify-content: flex-start; gap: 6px; margin: 0 0 8px; font-size: .8125rem; font-weight: 600; color: var(--text); }
.tu-label small { font-weight: 500; color: var(--text-3); font-size: .75rem; }
.tu-hint { margin: 6px 0 0; font-size: .8125rem; line-height: 1.5; color: var(--text-3); }
.tu-input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 8px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  font-weight: 400; font-size: .9375rem; line-height: 1.4; font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.tu-input { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; }
.tu-input::placeholder { color: var(--text-3); }
.tu-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

/* A one-line query bar: the explorer, audit and tracker set-up use it. */
.tu-bar { display: flex; gap: 10px; align-items: flex-end; padding: 16px; flex-wrap: wrap; }
.tu-bar > .tu-field { flex: 1 1 260px; margin: 0; }
.tu-bar > .tu-btn { flex-shrink: 0; }

/* Choice chips: one or many of a short list. aria-pressed carries state. */
.tu-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tu-chip {
  height: 30px; padding: 0 11px; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-2); border: 1px solid var(--border);
  font-weight: 500; font-size: .8125rem; line-height: 1; font-family: inherit; transition: background .15s, border-color .15s, color .15s;
}
.tu-chip:hover { border-color: var(--accent-border, var(--accent)); color: var(--text); }
.tu-chip.active, .tu-chip[aria-pressed="true"] { background: var(--accent-bg); border-color: var(--accent); color: var(--accent-ink, var(--accent)); font-weight: 600; }

/* ── Surfaces ───────────────────────────────────────────────────────── */
.tu-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; }
.tu-card-pad { padding: 20px; }
.tu-section { margin: 32px 0 0; }
.tu-section-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 0 0 12px; }
.tu-section-h h2, .tu-section-h h3 { margin: 0; font-size: 1rem; font-weight: 700; color: var(--text); letter-spacing: -.005em; }
.tu-section-h p { margin: 0; font-size: .8125rem; color: var(--text-3); }
.tu-divider { height: 1px; background: var(--border); border: 0; margin: 18px 0; }
.tu-eyebrow { display: block; font-size: .75rem; font-weight: 600; color: var(--text-3); margin: 0 0 8px; }

/* Key numbers: a row of 2-5 tiles. */
.tu-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tu-kpi { padding: 16px 18px; }
.tu-kpi b { display: block; font-size: 1.75rem; line-height: 1.1; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tu-kpi b small { font-size: .875rem; font-weight: 600; color: var(--text-3); margin-left: 2px; letter-spacing: 0; }
.tu-kpi span { display: block; margin-top: 6px; font-size: .8125rem; color: var(--text-2); }
.tu-kpi .tu-delta { display: inline-block; margin-top: 6px; font-size: .75rem; font-weight: 600; }
.tu-up { color: var(--green-ink, var(--green)); }
.tu-down { color: var(--red-ink, var(--red)); }

/* Tabs under a result header. */
.tu-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tu-tab {
  position: relative; padding: 10px 14px; background: none; border: 0; cursor: pointer; white-space: nowrap;
  font-weight: 600; font-size: .875rem; line-height: 1; font-family: inherit; color: var(--text-3); border-radius: 6px 6px 0 0;
}
.tu-tab:hover { color: var(--text); }
.tu-tab[aria-selected="true"], .tu-tab.active { color: var(--text); }
.tu-tab[aria-selected="true"]::after, .tu-tab.active::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 4px; background: var(--accent); }
.tu-tab .tu-count { margin-left: 6px; padding: 2px 6px; border-radius: 999px; background: var(--bg-hover); color: var(--text-2); font-size: .6875rem; }

/* ── States: empty, loading, error ──────────────────────────────────── */
/* An empty tool shows what it will produce and where to start, not a pitch. */
.tu-empty { padding: 28px; }
.tu-empty h2, .tu-empty h3 { margin: 0 0 6px; font-size: 1rem; font-weight: 700; color: var(--text); }
.tu-empty > p { margin: 0 0 18px; font-size: .875rem; line-height: 1.55; color: var(--text-2); max-width: 560px; }
.tu-empty-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.tu-empty-list li { display: flex; gap: 10px; font-size: .875rem; line-height: 1.5; color: var(--text-2); }
.tu-empty-list li::before { content: ''; flex: none; width: 6px; height: 6px; margin-top: 8px; border-radius: 999px; background: var(--accent); }
.tu-empty-list b { color: var(--text); font-weight: 600; }

/* A ghost of the output, so an empty pane shows the shape of what is coming. */
.tu-ghost { display: grid; gap: 8px; margin-top: 20px; padding: 16px; border-radius: 8px; background: var(--bg); border: 1px dashed var(--border); }
.tu-ghost i { display: block; height: 9px; border-radius: 4px; background: var(--bg-hover); }
.tu-ghost i:nth-child(3n+1) { width: 42%; } .tu-ghost i:nth-child(3n+2) { width: 74%; } .tu-ghost i:nth-child(3n) { width: 58%; margin-left: 16px; }

/* Recent runs: one click to reopen. */
.tu-recent { list-style: none; margin: 0; padding: 0; }
.tu-recent li + li { border-top: 1px solid var(--border); }
.tu-recent button, .tu-recent a {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 4px; background: none; border: 0; cursor: pointer;
  text-align: left; text-decoration: none; color: var(--text); font-weight: 500; font-size: .875rem; line-height: 1.3; font-family: inherit; border-radius: 6px;
}
.tu-recent button:hover, .tu-recent a:hover { background: var(--bg-hover); }
.tu-recent .tu-recent-meta { margin-left: auto; color: var(--text-3); font-size: .8125rem; white-space: nowrap; }

.tu-loading { display: flex; align-items: center; gap: 14px; padding: 22px; color: var(--text-2); font-size: .9375rem; }
.tu-spinner { width: 22px; height: 22px; flex: none; border-radius: 999px; border: 2px solid var(--border); border-top-color: var(--accent); animation: tu-spin .8s linear infinite; }
@keyframes tu-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .tu-spinner { animation-duration: 2.4s; } }
.tu-error { padding: 14px 16px; border-radius: 8px; background: var(--red-bg); border: 1px solid var(--red-border, var(--red)); color: var(--red-ink, var(--red)); font-size: .875rem; line-height: 1.5; }

/* Pills for status in rows and headers. */
.tu-pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: var(--bg-hover); color: var(--text-2); }
.tu-pill--good { background: var(--green-bg); color: var(--green-ink, var(--green)); }
.tu-pill--warn { background: var(--yellow-bg); color: var(--amber-ink, var(--yellow)); }
.tu-pill--bad  { background: var(--red-bg); color: var(--red-ink, var(--red)); }
.tu-pill--info { background: var(--accent-bg); color: var(--accent-ink, var(--accent)); }

/* ── Generator: settings left, output right ─────────────────────────── */
.tu-gen { display: grid; grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.tu-gen-config { position: sticky; top: calc(var(--sb-topbar, 52px) + 16px); max-height: calc(100vh - var(--sb-topbar, 52px) - 32px); overflow-y: auto; padding: 20px; scrollbar-width: thin; }
.tu-gen-config .tu-btn--block + .tu-btn--block { margin-top: 8px; }
.tu-gen-out { min-width: 0; }
.tu-gen-out > * + * { margin-top: 16px; }

/* ── Explorer: summary strip, then a table with its own toolbar ─────── */
.tu-explore-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 20px 0; }
.tu-table-tools { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tu-table-tools .tu-input { height: 34px; max-width: 280px; }
.tu-table-tools .tu-spacer { flex: 1; }
.tu-table-wrap { overflow-x: auto; }
.tu-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.tu-table th { position: sticky; top: 0; z-index: 1; text-align: left; padding: 10px 14px; font-size: .75rem; font-weight: 600; color: var(--text-3); background: var(--bg-card); border-bottom: 1px solid var(--border); white-space: nowrap; }
.tu-table th[aria-sort] { cursor: pointer; user-select: none; }
.tu-table th[aria-sort="ascending"]::after { content: ' \2191'; } .tu-table th[aria-sort="descending"]::after { content: ' \2193'; }
.tu-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.tu-table tr:last-child td { border-bottom: 0; }
.tu-table tbody tr:hover td { background: var(--bg-hover); }
.tu-num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Audit: verdict header, issues by severity ──────────────────────── */
.tu-verdict { display: flex; align-items: center; gap: 24px; padding: 22px 24px; }
.tu-score { position: relative; width: 88px; height: 88px; flex: none; }
.tu-score svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.tu-score b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.625rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.tu-verdict h2 { margin: 0; font-size: 1.125rem; font-weight: 700; color: var(--text); line-height: 1.35; }
.tu-verdict p { margin: 6px 0 0; font-size: .875rem; color: var(--text-2); line-height: 1.5; }
.tu-issue { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px 18px; }
.tu-issue + .tu-issue { border-top: 1px solid var(--border); }
.tu-sev { width: 8px; height: 8px; border-radius: 999px; }
.tu-sev--high { background: var(--red); } .tu-sev--med { background: var(--yellow); } .tu-sev--low { background: var(--text-3); }

/* ── Tracker: set-up line, then the tracked table ───────────────────── */
.tu-track-setup { display: flex; align-items: center; gap: 12px; padding: 12px 16px; flex-wrap: wrap; font-size: .875rem; color: var(--text-2); }
.tu-spark { width: 96px; height: 28px; display: block; }

/* ── Hub: tiles of different weights ────────────────────────────────── */
.tu-hub-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.tu-span-4 { grid-column: span 4; } .tu-span-6 { grid-column: span 6; } .tu-span-8 { grid-column: span 8; } .tu-span-12 { grid-column: span 12; }

/* ── Small screens ──────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .tu-gen { grid-template-columns: 1fr; }
  .tu-gen-config { position: static; max-height: none; }
  .tu-span-4, .tu-span-6, .tu-span-8 { grid-column: span 12; }
}
@media (max-width: 640px) {
.tu { padding: 20px 16px 56px; }
  .tu-head { flex-direction: column; gap: 14px; }
  .tu-head-actions { justify-content: flex-start; }
  .tu-head h1, .tu-title { font-size: 1.3125rem; }
  .tu-bar { padding: 14px; }
  .tu-bar > .tu-btn { width: 100%; }
  .tu-verdict { flex-direction: column; align-items: flex-start; gap: 14px; padding: 18px; }
  .tu-empty { padding: 20px; }
  .tu-issue { grid-template-columns: auto 1fr; }
  .tu-issue > :last-child { grid-column: 2; }
}

/* Segmented choice between two or three modes. */
.tu-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; padding: 3px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); }
.tu-seg button { height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--text-2); font-weight: 600; font-size: .8125rem; line-height: 1; font-family: inherit; cursor: pointer; transition: background .15s, color .15s; }
.tu-seg button:hover { color: var(--text); }
.tu-seg button[aria-checked="true"], .tu-seg button[aria-pressed="true"] { background: var(--bg-card); color: var(--text); box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(0,0,0,.12); }
.tu-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Existing pages toggle their loading box with style.display = 'block';
 * keep the spinner beside its message when they do. */
.tu-loading[style*="block"] { display: flex !important; }

/* The empty state steps aside the moment there is something to show, with
 * no change to the page's own render code. */
.tu-gen-out:has(#results:not(:empty)) #tu-empty,
.tu-gen-out:has(#loading[style*="block"]) #tu-empty,
.tu-gen-out:has(#error-msg[style*="block"]) #tu-empty { display: none; }

.tu code { font-family: 'SF Mono', Menlo, Monaco, monospace; font-size: .85em; padding: 1px 5px; border-radius: 4px; background: var(--bg-hover); color: var(--text); }

/* Inside the app frame, .cr-main already pads the page; do not double it. */
.cr-main > .tu, .cr-page-content > .tu { padding: 0; }
/* `hidden` must win over the display a layout class sets. */
/* Text for screen readers only, e.g. a label for an icon-only column. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.tu [hidden] { display: none !important; }
/* A native select styled as a field, with the platform's chevron. */
select.tu-input { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238494a6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
/* citerank.css resets every light-mode select with `background: ... !important`,
 * which also erased the chevron. Restore only the image. */
html[data-theme="light"] select.tu-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: right 12px center !important; }

/* On a phone the breadcrumb is hidden (citerank.css) and the top bar already
 * names the page, so a bar with nothing else in it is an empty band. */
@media (max-width: 640px) {
  .cr-tool-bar:not(:has(.cr-tool-bar-right, .cr-tool-bar-inputs, .cr-tool-bar-left)) { display: none; }
}

/* Labels read in sentence case across the shared layouts. Older markup
 * inside a .tu page sets uppercase inline; this brings it in line. */
.tu [style*="text-transform:uppercase"], .tu [style*="text-transform: uppercase"] { text-transform: none !important; letter-spacing: normal !important; }

/* citerank.css uppercases these shared labels; inside the shared layouts
 * labels are sentence case. */
.tu .cr-card-title,
.tu .cr-cat-name,
.tu .cr-gap-side label,
.tu .cr-insight-label,
.tu .cr-matrix-col,
.tu .cr-matrix-dim,
.tu .cr-metric-label,
.tu .cr-nav-badge,
.tu .cr-probe-key,
.tu .cr-rec-dim,
.tu .cr-sidebar-group-head,
.tu .cr-stat-chip-lbl,
.tu .cr-table thead th,
.tu .cr-badge,
.tu .cr-field-label,
.tu .cr-kw-cat,
.tu .cr-sidebar-label,
.tu .cr-section-head,
.tu .cr-section-head * { text-transform: none; letter-spacing: normal; }
