/* SEO Content Checker - tool-specific styles on top of the shared
 * primitives in code/assets/css/tools.css.
 *
 * Composes:
 *   - .tool-form-card, .text-input, .primary-btn, .ghost-btn
 *   - .progress-region, .errors-region, .history-region
 *   - .toasts, .quota-region/.quota-chip
 *   - .modal-backdrop, .modal-card chrome
 *
 * Adds:
 *   1. Stacked form (URL + focus keyword, both required).
 *   2. Live keyword-data preview chip below the keyword input.
 *   3. Keyword-stats card above the score panel (the differentiator).
 *   4. Score panel (overall + 5-category grid).
 *   5. Recommendations card.
 *   6. Per-category findings (<details> blocks).
 *   7. History list with grade badge.
 *   8. Quota chip override (same as DAC/WAC/SSC).
 */

/* ========================================================================
   Editor-mode layout (third mode: real-time scoring sidebar)
   ======================================================================== */
.check-shell {
    display: block;
}
.check-shell.is-editor {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr);
    gap: 18px;
    align-items: start;
}
@media (max-width: 1100px) {
    .check-shell.is-editor {
        grid-template-columns: minmax(0, 1.2fr) minmax(300px, 1fr);
    }
}
@media (max-width: 920px) {
    .check-shell.is-editor {
        grid-template-columns: 1fr;
    }
    .check-shell.is-editor .check-sidebar {
        position: static !important;
        max-height: none !important;
    }
}

/* The sidebar sticks to the viewport while the user types in the
 * left-pane textarea on tall viewports. Cap max-height so the inner
 * findings list scrolls independently if it overflows. */
.check-sidebar[hidden] { display: none; }
.check-shell.is-editor .check-sidebar {
    position: sticky;
    top: 16px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-right: 2px;
}

/* In editor mode, hide the submit button (no submit needed) and
 * hide the kw-preview chip below the focus-keyword input (the
 * keyword stats card in the sidebar already shows the same data,
 * so the preview duplicates info). */
.check-shell.is-editor #submit-row { display: none; }
.check-shell.is-editor #kw-preview { display: none; }

/* In editor mode, the content textarea (which is in the paste-mode
 * panel) gets taller so it's the main attraction. */
.check-shell.is-editor #paste-content-input {
    min-height: 460px;
}

/* Compact scoreboard regions live INSIDE the sidebar. CSS classes
 * scope all the size adjustments so the full-width versions of the
 * same regions (URL / Paste mode results) are unaffected. */
.kwstats-region--compact {
    padding: 14px 16px;
}
.kwstats-region--compact .kwstats-header { margin-bottom: 10px; }
.kwstats-region--compact .kwstats-title {
    font-size: 17px;
    line-height: 1.3;
}
.kwstats-grid--compact {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.kwstats-grid--compact .kwstats-card {
    padding: 8px 10px;
    min-height: 0;
    gap: 2px;
}
.kwstats-grid--compact .kwstats-value { font-size: 16px; }
.kwstats-grid--compact .kwstats-trend { min-height: 24px; }
.kwstats-grid--compact .kwstats-trend svg { height: 28px; }

.score-region--compact {
    padding: 16px 18px;
}
.score-region--compact .score-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--ink-100);
}
.score-region--compact .score-overall {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    gap: 2px 12px;
    align-items: end;
}
.score-region--compact .score-overall-number {
    grid-row: 1; grid-column: 1;
    font-size: 48px;
    letter-spacing: -2px;
    transition: color 0.2s ease;
}
.score-region--compact .score-overall-grade {
    grid-row: 1 / span 2; grid-column: 2;
    align-self: center;
    width: 56px; height: 56px;
    font-size: 28px;
    transition: background 0.2s ease, color 0.2s ease;
}
.score-region--compact .score-overall-label {
    grid-row: 2; grid-column: 1;
    font-size: 10px;
    letter-spacing: 1.2px;
}
.score-region--compact .category-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.score-region--compact .cat-card {
    padding: 10px 12px;
    grid-template-rows: auto auto;
    gap: 2px 8px;
}
.score-region--compact .cat-card-label { font-size: 10px; letter-spacing: 0.5px; }
.score-region--compact .cat-card-grade {
    width: 28px; height: 28px;
    font-size: 14px;
}
.score-region--compact .cat-card-score { font-size: 18px; }

.recommendations-region--compact {
    padding: 14px 16px;
}
.recommendations-region--compact .section-h {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 0 0 8px 0;
}
.recommendations-region--compact .recommendations-list li {
    font-size: 12.5px;
    padding: 4px 0;
}
.recommendations-list .rec-empty {
    list-style: none;
    margin-left: -18px;
    font-style: italic;
    color: var(--ink-500);
}

.findings-region--compact {
    padding: 14px 16px;
}
.findings-region--compact .section-h {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin: 0;
}
.findings-region--compact .cat-details summary {
    padding: 6px 0;
    font-size: 12.5px;
}
.findings-region--compact .cat-details-name { font-size: 12.5px; }
.findings-region--compact .cat-details-meta { font-size: 10px; }
.findings-region--compact .cat-details-score { font-size: 13px; }
.findings-region--compact .cat-details-grade {
    width: 18px; height: 18px;
    font-size: 9px;
}
.findings-region--compact .findings-sub-h {
    font-size: 9.5px;
    letter-spacing: 1px;
}
.findings-region--compact .finding-row {
    grid-template-columns: 18px 1fr;
    padding: 5px 0;
}
.findings-region--compact .finding-icon {
    width: 14px; height: 14px;
    font-size: 9px;
}
.findings-region--compact .finding-label { font-size: 12px; }
.findings-region--compact .finding-summary { font-size: 11.5px; }
.findings-region--compact .finding-excerpt {
    padding: 4px 8px;
    font-size: 11px;
}

/* Pulse the score number when it changes (visual feedback for typing) */
@keyframes scc-score-pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}
.score-overall-number.is-changed {
    animation: scc-score-pulse 0.35s ease-out;
}

/* Drafts region (editor mode only) */
.drafts-region {
    margin-top: 24px;
    padding: 18px 22px;
    border-top: 1px solid var(--ink-100);
}
.drafts-region[hidden] { display: none; }

/* ========================================================================
   Initial audit labeling (editor mode, post-submit)
   ========================================================================
   When the user submits a URL/Paste audit, the page auto-transitions
   to editor mode. The original full-width score panel + findings
   region stay visible BELOW the editor as a snapshot of "what the
   audit found at submission". The .is-initial-audit class is added
   by tool.js and surfaces an "Initial audit" label so the user can
   tell this is the frozen snapshot, not the live editor score. */
.score-region.is-initial-audit,
.findings-region.is-initial-audit {
    margin-top: 22px;
}
.score-region.is-initial-audit::before,
.findings-region.is-initial-audit::before {
    content: 'Initial audit';
    display: block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--ink-500);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--ink-100);
}
.findings-region.is-initial-audit::before {
    content: 'Initial audit findings';
}

/* ========================================================================
   Mode toggle (URL vs Paste vs Editor)
   ======================================================================== */
/* Disable the shared 2-button slider pseudo-element. The shared
 * tools.css `.mode-toggle::before` is a 50%-width sliding pill that
 * assumes exactly 2 buttons (used by single/bulk toggles elsewhere).
 * SCC has 3 buttons, so the pseudo would leak from the active button
 * into the second one. Our active button has its own white-pill
 * treatment via `.mode-btn.is-active`. */
.mode-toggle::before { content: none; }

/* The pill-toggle math: container radius must equal button radius
 * + container padding, otherwise the active pill's curved corner
 * pokes past the container's inner curve. We use 8px container / 4px
 * inner padding / 4px button radius so the active pill sits flush
 * inside the inner curve. */
.mode-toggle {
    display: inline-flex;
    background: var(--ink-50);
    border: 1px solid var(--ink-100);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 18px;
    gap: 2px;
}
.mode-btn {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    padding: 7px 16px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-600);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.mode-btn:hover:not(.is-active) { color: var(--ink); }
/* Active button: solid white pill with a thin border. No box-shadow,
 * which would extend below the container's bottom edge. */
.mode-btn.is-active {
    background: #fff;
    color: var(--ink);
    border-color: var(--ink-100);
}
.mode-btn:focus-visible {
    outline: 2px solid var(--brand-red, var(--brand));
    outline-offset: 2px;
}

.mode-panel[hidden] { display: none; }

/* ========================================================================
   Paste-content textarea (legacy, kept in case any callsite still uses
   it; current paste/editor mode uses .wysiwyg-shell below)
   ======================================================================== */
.text-input-area {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    min-height: 220px;
    padding: 12px 14px;
    white-space: pre-wrap;
}

/* ========================================================================
   WYSIWYG editor (contenteditable + toolbar)

   Replaces the plain textarea in Paste and Live-editor modes. The
   contenteditable div hosts real HTML (h1-h3, p, strong, em, ul, ol,
   li, a). tool.js sanitizes paste and converts to Markdown-ish for
   the catalog on every recompute.
   ======================================================================== */
.wysiwyg-shell {
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md, 8px);
    background: #fff;
    overflow: hidden;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.wysiwyg-shell:focus-within {
    border-color: var(--brand-red, #dc1717);
    box-shadow: 0 0 0 3px rgba(220, 23, 23, 0.10);
}

/* Toolbar */
.wysiwyg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--ink-50);
    border-bottom: 1px solid var(--ink-100);
}
.wysiwyg-toolbar .wy-btn {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--ink-700);
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1;
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    border-radius: var(--r-sm, 6px);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.wysiwyg-toolbar .wy-btn:hover {
    background: #fff;
    color: var(--ink);
    border-color: var(--ink-100);
}
.wysiwyg-toolbar .wy-btn.is-active {
    background: #fff;
    color: var(--brand-red, #dc1717);
    border-color: var(--ink-100);
}
.wysiwyg-toolbar .wy-btn:focus-visible {
    outline: 2px solid var(--brand-red, var(--brand));
    outline-offset: 1px;
}
.wysiwyg-toolbar .wy-btn strong { font-weight: 800; }
.wysiwyg-toolbar .wy-btn em { font-style: italic; }
.wysiwyg-toolbar .wy-sep {
    width: 1px;
    height: 18px;
    background: var(--ink-100);
    margin: 0 4px;
}

/* The contenteditable surface */
.wysiwyg-editor {
    min-height: 220px;
    padding: 14px 18px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink);
    outline: none;            /* focus ring is on the shell */
    overflow-wrap: break-word;
    word-break: break-word;
}
.wysiwyg-editor:empty::before,
.wysiwyg-editor.is-empty::before {
    content: attr(data-placeholder);
    color: var(--ink-400);
    pointer-events: none;
}
.wysiwyg-editor[contenteditable="false"] {
    background: var(--ink-50);
    cursor: not-allowed;
    color: var(--ink-500);
}
.wysiwyg-editor h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.4px;
    line-height: 1.2;
    margin: 18px 0 10px;
    color: var(--ink);
}
.wysiwyg-editor h1:first-child { margin-top: 0; }
.wysiwyg-editor h2 {
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -0.3px;
    line-height: 1.25;
    margin: 18px 0 8px;
    color: var(--ink);
}
.wysiwyg-editor h3 {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
    margin: 16px 0 6px;
    color: var(--ink);
}
.wysiwyg-editor p {
    margin: 0 0 14px;
}
.wysiwyg-editor p:last-child { margin-bottom: 0; }
.wysiwyg-editor ul,
.wysiwyg-editor ol {
    margin: 0 0 14px;
    padding-left: 24px;
}
.wysiwyg-editor ul li { list-style: disc; }
.wysiwyg-editor ol li { list-style: decimal; }
.wysiwyg-editor li { margin: 4px 0; }
.wysiwyg-editor a {
    color: var(--brand-red, #dc1717);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.wysiwyg-editor strong, .wysiwyg-editor b { font-weight: 700; }
.wysiwyg-editor em, .wysiwyg-editor i { font-style: italic; }

@media (max-width: 720px) {
    .wysiwyg-toolbar .wy-btn { font-size: 12px; padding: 0 6px; }
    .wysiwyg-editor { padding: 12px 14px; font-size: 14px; }
}
.input-feedback {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}
.feedback-counter {
    font-size: 11px;
    color: var(--ink-500);
    font-feature-settings: var(--tnum);
    white-space: nowrap;
}
.feedback-counter.is-over {
    color: var(--brand-red, #dc1717);
    font-weight: 600;
}
.field-hint code {
    background: var(--ink-100);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 11px;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* ========================================================================
   Stacked form (URL + focus keyword)
   ======================================================================== */
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 6px 0;
}
.field-label + .text-input { margin-bottom: 0; }
.field-hint {
    margin-left: 6px;
    color: var(--ink-500);
    font-weight: 400;
    font-size: 12px;
}
.input-form .text-input { width: 100%; }
.input-form .field-label:not(:first-child) { margin-top: 16px; }
.submit-row {
    margin-top: 18px;
    display: flex;
    justify-content: flex-end;
}
.submit-row .primary-btn { min-width: 200px; justify-content: center; }
@media (max-width: 720px) {
    .submit-row { justify-content: stretch; }
    .submit-row .primary-btn { flex: 1; }
}

/* Live keyword-data preview chip below the keyword input. Visible
   as the user types a focus keyword (debounced ~500ms); hidden if
   upstream returns no data. */
.kw-preview {
    margin-top: 12px;
    padding: 12px 14px;
    background: var(--ink-50);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-sm);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.kw-preview[hidden] { display: none; }
.kw-preview-row { display: flex; flex-direction: column; gap: 2px; }
.kw-preview-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink-500);
}
.kw-preview-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    font-feature-settings: var(--tnum);
}
@media (max-width: 480px) {
    .kw-preview { grid-template-columns: 1fr 1fr; }
}

/* ========================================================================
   Keyword stats card (above the score panel; tool differentiator)
   ======================================================================== */
.kwstats-region {
    background: #fff;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: 18px 22px;
    margin-bottom: 16px;
}
.kwstats-region[hidden] { display: none; }
.kwstats-header { margin-bottom: 14px; }
.kwstats-eyebrow {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--ink-500);
    margin-bottom: 4px;
}
.kwstats-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.4px;
    word-break: break-word;
}
.kwstats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
@media (max-width: 720px) {
    .kwstats-grid { grid-template-columns: repeat(2, 1fr); }
}
.kwstats-card {
    background: var(--ink-50);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-sm);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 80px;
}
.kwstats-card--trend { gap: 8px; }
.kwstats-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink-500);
}
.kwstats-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
    font-feature-settings: var(--tnum);
    line-height: 1.1;
}
.kwstats-trend {
    flex: 1;
    min-height: 36px;
    display: flex;
    align-items: stretch;
}
.kwstats-trend svg {
    width: 100%;
    height: 36px;
}

/* ========================================================================
   Quota chip (same as DAC/WAC/SSC; reused verbatim)
   ======================================================================== */
.quota-region {
    background: #fff;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
}
.quota-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
}
.quota-title {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1.4px;
    color: var(--ink-500);
}
.quota-upgrade { font-size: 12px; font-weight: 600; color: var(--brand-red); }
.quota-chips { display: grid; grid-template-columns: 1fr; gap: 10px; }
.quota-chip {
    display: flex; flex-direction: column; gap: 4px;
    padding: 10px 12px;
    border-radius: var(--r-sm);
    background: var(--ink-50);
    border: 1px solid var(--ink-100);
}
.quota-chip-label {
    font-size: 11px; font-weight: 700;
    letter-spacing: 0.6px; text-transform: uppercase;
    color: var(--ink-500);
}
.quota-chip-text {
    font-feature-settings: var(--tnum);
    font-size: 13px; font-weight: 600;
    color: var(--ink);
}
.quota-chip-bar {
    display: block; height: 4px;
    background: var(--ink-200);
    border-radius: 999px; overflow: hidden;
}
.quota-chip-fill {
    display: block; height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--brand-red) 0%, var(--brand-red-light) 100%);
    transition: width 0.4s ease;
}
.quota-chip.is-warning .quota-chip-fill { background: linear-gradient(90deg, #d97706 0%, #f59e0b 100%); }
.quota-chip.is-danger  .quota-chip-fill { background: linear-gradient(90deg, var(--bad-fg) 0%, #ef4444 100%); }
.quota-chip.is-warning .quota-chip-text { color: #b45309; }
.quota-chip.is-danger  .quota-chip-text { color: var(--bad-fg); }

/* ========================================================================
   Score panel - overall score + letter grade + 6 category cards
   ======================================================================== */
.score-region {
    background: #fff;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 20px;
}
.score-header {
    display: grid;
    grid-template-columns: minmax(220px, 280px) 1fr;
    gap: 24px;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--ink-100);
    margin-bottom: 20px;
}
.score-overall {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-rows: auto auto;
    gap: 4px 16px;
    align-items: end;
    text-align: left;
}
.score-overall-number {
    grid-row: 1; grid-column: 1;
    font-size: 72px; font-weight: 800; line-height: 1;
    font-feature-settings: var(--tnum);
    color: var(--ink);
    letter-spacing: -3px;
}
.score-overall-grade {
    /* Span both rows so the circle is vertically centered against the
       full "number + SEO SCORE label" stack, not just the number. */
    grid-row: 1 / span 2;
    grid-column: 2;
    align-self: center;
    /* Circular grade badge sized to sit next to the 72px score number
       as a visual peer. 84x84 circle with 44px letter (~50% fill) is
       legible without overwhelming the number beside it. */
    width: 84px; height: 84px;
    border-radius: 50%;
    font-size: 44px;
    font-weight: 800;
    line-height: 1;
    background: var(--ink-100);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    letter-spacing: -1px;
}
.score-overall-grade.grade-A { background: rgba(22, 163, 74, 0.14); color: rgb(15, 109, 49); }
.score-overall-grade.grade-B { background: rgba(45, 167, 167, 0.14); color: rgb(20, 110, 110); }
.score-overall-grade.grade-C { background: rgba(217, 119, 6, 0.16); color: rgb(146, 64, 14); }
.score-overall-grade.grade-D { background: rgba(234, 88, 12, 0.18); color: rgb(154, 52, 18); }
.score-overall-grade.grade-F { background: rgba(220, 38, 38, 0.18); color: rgb(159, 18, 18); }
.score-overall-label {
    /* Sit under the number only; the grade circle now spans rows 1-2
       in column 2 next to this stack. */
    grid-row: 2; grid-column: 1;
    font-size: 12px; font-weight: 700;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--ink-500);
}
.score-meta {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    align-content: center;
    min-width: 0;
}
.score-meta-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 12px;
    align-items: baseline;
}
/* `display: grid` beats the UA `[hidden]` rule on specificity, so the
   focus-keyword row stays visible without this explicit override. */
.score-meta-row[hidden] { display: none; }
.score-meta-label {
    font-size: 11px; font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--ink-500);
}
.score-meta-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    word-break: break-all;
    min-width: 0;
    line-height: 1.45;
}
#score-meta-url {
    font-size: 17px;
    font-weight: 600;
    color: var(--brand-red);
    letter-spacing: -0.2px;
}
#score-meta-url a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dashed currentColor;
    padding-bottom: 1px;
    transition: border-bottom-style 0.12s;
}
#score-meta-url a:hover {
    border-bottom-style: solid;
}

@media (max-width: 720px) {
    .score-header {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .score-meta-row {
        grid-template-columns: 100px 1fr;
        gap: 8px;
    }
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
}
@media (max-width: 960px) {
    .category-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
}
@media (max-width: 720px) {
    .category-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    .category-grid { grid-template-columns: 1fr; }
}

.cat-card {
    background: var(--ink-50);
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    padding: 14px;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 4px 12px;
    transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
    cursor: pointer;
}
.cat-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.cat-card:focus-visible {
    outline: 2px solid var(--brand-red);
    outline-offset: 2px;
}
/* All categories share the same neutral background. The category
 * name carries the meaning; the grade letter + numeric score on
 * each card carry the pass/warn/fail signal. No per-category color
 * accent - that was being mistaken for a status indicator. */
.cat-card.cat-placement,
.cat-card.cat-usage,
.cat-card.cat-quality,
.cat-card.cat-structure,
.cat-card.cat-serp {
    background: var(--ink-50);
    border-color: var(--ink-100);
}
.cat-card.cat-placement .cat-card-label,
.cat-card.cat-usage     .cat-card-label,
.cat-card.cat-quality   .cat-card-label,
.cat-card.cat-structure .cat-card-label,
.cat-card.cat-serp      .cat-card-label {
    color: var(--ink-700);
}

.cat-card-label {
    grid-row: 1; grid-column: 1;
    font-size: 12px; font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--ink-500);
}
.cat-card-grade {
    grid-row: 1 / span 2; grid-column: 2;
    align-self: center;
    width: 40px; height: 40px;
    border-radius: 50%;
    font-size: 20px; font-weight: 800;
    color: var(--ink);
    background: rgba(0, 0, 0, 0.06);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cat-card-score {
    grid-row: 2; grid-column: 1;
    font-size: 28px; font-weight: 700;
    font-feature-settings: var(--tnum);
    color: var(--ink);
    line-height: 1;
}

/* ========================================================================
   Recommendations card
   ======================================================================== */
.recommendations-region {
    background: #fff;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.section-h {
    font-size: 17px;
    font-weight: 700;
    color: var(--ink);
    margin: 0 0 12px 0;
    letter-spacing: -0.2px;
}
.recommendations-list {
    margin: 0;
    padding-left: 22px;
    list-style: decimal;
}
.recommendations-list li {
    padding: 6px 0;
    font-size: 14px;
    color: var(--ink-700);
    line-height: 1.5;
}
.recommendations-list .rec-label {
    font-weight: 600;
    color: var(--ink);
}
.recommendations-list .rec-summary { color: var(--ink-500); }

/* ========================================================================
   Findings (per-category collapsible)
   ======================================================================== */
.findings-region {
    background: #fff;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.findings-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.findings-toolbar .section-h { margin: 0; }
.findings-actions .export-form { display: inline-flex; gap: 8px; flex-wrap: wrap; }

.cat-details {
    border-top: 1px solid var(--ink-100);
    padding: 8px 0;
}
.cat-details:first-of-type { border-top: 0; }
.cat-details summary {
    cursor: pointer;
    list-style: none;
    padding: 10px 0;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.cat-details summary::-webkit-details-marker { display: none; }
.cat-details-title {
    display: flex; align-items: center; gap: 10px;
}
.cat-details-marker {
    display: inline-block;
    transition: transform 0.15s;
    color: var(--ink-400);
}
.cat-details[open] .cat-details-marker { transform: rotate(90deg); color: var(--brand-red); }
.cat-details-name {
    font-weight: 600;
    color: var(--ink);
    font-size: 15px;
}
.cat-details-meta {
    font-size: 12px;
    color: var(--ink-500);
    font-feature-settings: var(--tnum);
}
.cat-details-meta .meta-pass { color: rgb(15, 109, 49); }
.cat-details-meta .meta-warn { color: rgb(146, 64, 14); }
.cat-details-meta .meta-fail { color: rgb(159, 18, 18); }
.cat-details-score {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    font-feature-settings: var(--tnum);
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
}
.cat-details-score .cat-details-grade {
    width: 24px; height: 24px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    background: var(--ink-100);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cat-details-grade.grade-A { background: rgba(22, 163, 74, 0.16); color: rgb(15, 109, 49); }
.cat-details-grade.grade-B { background: rgba(45, 167, 167, 0.16); color: rgb(20, 110, 110); }
.cat-details-grade.grade-C { background: rgba(217, 119, 6, 0.18); color: rgb(146, 64, 14); }
.cat-details-grade.grade-D { background: rgba(234, 88, 12, 0.18); color: rgb(154, 52, 18); }
.cat-details-grade.grade-F { background: rgba(220, 38, 38, 0.2); color: rgb(159, 18, 18); }

.findings-rows {
    margin-top: 6px;
    margin-bottom: 12px;
}
/* Sub-section header within a category (Important / Other). Only
   rendered when the category contains a mix of severities; when
   everything is the same level, the header is suppressed by JS. */
.findings-sub-h {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--ink-500);
    margin: 14px 0 4px 0;
    padding-top: 6px;
    border-top: 1px solid var(--ink-50);
}
.findings-rows .findings-sub-h:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}
.finding-row {
    display: grid;
    grid-template-columns: 22px 1fr;
    gap: 0 12px;
    padding: 8px 0;
    border-top: 1px solid var(--ink-50);
    align-items: start;
}
.finding-row:first-child { border-top: 0; }
.finding-row .finding-icon {
    grid-row: 1 / span 2;
    grid-column: 1;
    margin-top: 2px;
    width: 18px; height: 18px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}
.finding-row.status-pass .finding-icon { background: rgba(22, 163, 74, 0.2); color: rgb(15, 109, 49); }
.finding-row.status-warn .finding-icon { background: rgba(217, 119, 6, 0.22); color: rgb(146, 64, 14); }
.finding-row.status-fail .finding-icon { background: rgba(220, 38, 38, 0.22); color: rgb(159, 18, 18); }
.finding-row .finding-label {
    grid-row: 1; grid-column: 2;
    font-weight: 600;
    color: var(--ink);
    font-size: 14px;
}
.finding-row .finding-summary {
    grid-row: 2; grid-column: 2;
    font-size: 13px;
    color: var(--ink-500);
    line-height: 1.5;
}
/* Quoted snippet of the actual content (title, description, canonical
   URL, OG values, H1 text, etc.). Sits between the summary and the
   fix/details. */
.finding-row .finding-excerpt {
    grid-row: 3; grid-column: 2;
    margin-top: 4px;
    padding: 6px 10px;
    background: var(--ink-50);
    border-left: 3px solid var(--ink-200);
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
    font-size: 13px;
    color: var(--ink);
    line-height: 1.45;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.finding-row .finding-value {
    /* Pin to column 2 explicitly. Without this, auto-placement drops
       the value into column 1 (the 22px icon column) and breaks every
       word onto its own line. */
    grid-row: 3; grid-column: 2;
    font-size: 12px;
    color: var(--ink-500);
    font-feature-settings: var(--tnum);
    margin-top: 2px;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.finding-row .finding-fix {
    grid-row: 4; grid-column: 2;
    font-size: 12.5px;
    color: var(--ink-700);
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px dashed var(--ink-100);
}
.finding-row .finding-fix .fix-prefix {
    font-weight: 700;
    color: var(--brand-red);
}
.finding-row .finding-details-btn {
    grid-row: 5; grid-column: 2;
    appearance: none;
    background: transparent;
    border: 1px solid var(--ink-200);
    border-radius: var(--r-sm);
    padding: 4px 10px;
    margin-top: 6px;
    justify-self: start;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-700);
    cursor: pointer;
    transition: border-color 0.12s, color 0.12s;
}
.finding-row .finding-details-btn:hover {
    border-color: var(--brand-red);
    color: var(--brand-red);
}

/* Details-modal body styles (.modal-body max-height, .detail-list,
   .detail-tag, .detail-main) lifted to shared code/assets/css/tools.css
   when SEO Optimizer started consuming the same modal. */
/* The "critical" severity badge was misleading because it
   coloured the label red even when the check passed - users
   read it as "this is failing". Severity now only affects
   ordering in the recommendations list. */

/* ========================================================================
   History strip
   ======================================================================== */
.history-region {
    margin-top: 32px;
    padding: 20px 24px;
    border-top: 1px solid var(--ink-100);
}
.history-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 10px;
}
.history-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}
.history-item:hover { border-color: var(--brand-red); transform: translateY(-1px); }
.history-item-grade {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    font-weight: 800;
    font-size: 14px;
    border-radius: 50%;
    background: var(--ink-100); color: var(--ink);
}
.history-item-grade.grade-A { background: rgba(22, 163, 74, 0.18); color: rgb(15, 109, 49); }
.history-item-grade.grade-B { background: rgba(45, 167, 167, 0.18); color: rgb(20, 110, 110); }
.history-item-grade.grade-C { background: rgba(217, 119, 6, 0.2); color: rgb(146, 64, 14); }
.history-item-grade.grade-D { background: rgba(234, 88, 12, 0.2); color: rgb(154, 52, 18); }
.history-item-grade.grade-F { background: rgba(220, 38, 38, 0.22); color: rgb(159, 18, 18); }
.history-item-body { min-width: 0; }
.history-item-url {
    font-size: 13px; font-weight: 600;
    color: var(--ink);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-item-kw {
    font-size: 11px;
    color: var(--ink-700);
    font-style: italic;
    margin-top: 1px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-item-paste-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    background: var(--ink-100);
    color: var(--ink-700);
    padding: 1px 6px;
    border-radius: 999px;
    margin-right: 6px;
    vertical-align: 1px;
}
.history-item-kw::before { content: ''; }
.history-item-meta { font-size: 11px; color: var(--ink-500); }

/* `.detail-main mark` lifted to shared tools.css. */

.history-item-delete {
    appearance: none; border: 0; background: transparent;
    color: var(--ink-400);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.history-item:hover .history-item-delete { opacity: 1; }
.history-item-delete:hover { color: rgb(159, 18, 18); background: rgba(220, 38, 38, 0.1); }

/* ========================================================================
   Notice banner (SPA detected, HTTP error, etc.)
   ======================================================================== */
.notice-region {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 16px;
    align-items: start;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--r-md);
    padding: 14px 18px;
    margin-bottom: 16px;
}
.notice-region[hidden] { display: none; }
.notice-region.notice-http_error {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.2);
}
.notice-icon {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #f59e0b;
    color: #fff;
    font-weight: 800;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    margin-top: 2px;
}
.notice-region.notice-http_error .notice-icon {
    background: rgb(220, 38, 38);
}
.notice-title {
    margin: 0 0 4px 0;
    font-size: 14px;
    font-weight: 700;
    color: #92400e;
}
.notice-region.notice-http_error .notice-title { color: rgb(159, 18, 18); }
.notice-msg {
    margin: 0;
    font-size: 13px;
    color: var(--ink-700);
    line-height: 1.5;
}

/* ========================================================================
   Errors region
   ======================================================================== */
.errors-region {
    background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.2);
    border-radius: var(--r-md);
    padding: 16px 20px;
    margin-bottom: 16px;
}
.errors-title {
    margin: 0 0 6px 0;
    font-size: 14px;
    font-weight: 700;
    color: rgb(159, 18, 18);
}
.errors-msg { margin: 0; font-size: 13px; color: var(--ink-700); }

/* ========================================================================
   Back-to-top button
   ======================================================================== */
.back-to-top {
    /* Fixed bottom-right, lifted clear of the reCAPTCHA badge which
       lives at ~14px from each edge. Higher z-index than page chrome
       but below the details modal backdrop. */
    position: fixed;
    bottom: 90px;
    right: 20px;
    z-index: 50;
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--brand-red);
    color: #fff;
    border: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.12s;
}
.back-to-top.is-visible {
    opacity: 1;
    transform: translateY(0);
}
.back-to-top[hidden] { display: none; }
.back-to-top:hover { background: var(--brand-red-dark, #a32626); }
.back-to-top:focus-visible {
    outline: 2px solid var(--brand-red);
    outline-offset: 3px;
}
@media (max-width: 480px) {
    .back-to-top { bottom: 78px; right: 14px; width: 40px; height: 40px; }
}

/* ========================================================================
   Disabled buttons
   ======================================================================== */
.primary-btn:disabled,
.ghost-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
