/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, p, ul, li, figure { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: #f9fafb;
    color: #111827;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    /* Guards against any single element (e.g. a wide table) overflowing and widening the whole
       page on mobile — since #site-header is position:fixed with no width of its own, a wider-
       than-viewport body pushes it off-screen along with the rest of the horizontal overflow. */
    overflow-x: hidden;
    /* Reserves space for the fixed #site-header, which no longer occupies document flow.
       --header-height is measured in JS (varies by page — some have a subnav, some don't). */
    padding-top: var(--header-height, 3rem);
}

/* ── Navigation ──────────────────────────────────────────────────────────── */
/* Wraps .site-nav + the optional .site-subnav below it so both stay pinned to the top of the
   viewport as a single fixed unit. */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
}

.site-nav {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}
.site-nav-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: 3rem;
    gap: 1.5rem;
}
.nav-brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.nav-brand-logo {
    height: 2.25rem;
    width: auto;
    display: block;
}
.nav-top-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
}
.nav-top-link {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.875rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    text-decoration: none;
    transition: color 0.15s, background-color 0.15s;
    white-space: nowrap;
}
.nav-top-link:hover  { color: #111827; background: #f3f4f6; }
.nav-top-link.active { color: #111827; background: #f3f4f6; }

.nav-logout {
    font-size: 0.75rem;
    color: #9ca3af;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
    flex-shrink: 0;
}
.nav-logout:hover { color: #6b7280; }

/* Burger toggle — hidden on desktop, shown only once the main nav collapses below */
.nav-toggle {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.625rem;
    background: none;
    border: none;
    border-radius: 0.375rem;
    color: #374151;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}
.nav-toggle:hover { background: #f3f4f6; }

/* Docs/Logout/credit-balance, grouped so they can be pushed flush right in the desktop flex row
   via the auto margin below — that gap reads as its own separation, so no divider is needed
   there. Hidden on desktop; the mobile media query further down turns it into a visible
   horizontal rule instead, since the stacked column has no equivalent "big gap" of its own. */
.nav-menu-divider { display: none; }
.nav-account-group { display: flex; align-items: center; gap: 0.25rem; margin-left: auto; }

/* ── Sub-navigation ──────────────────────────────────────────────────────── */
.site-subnav {
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
}
.site-subnav-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    height: 2.5rem;
    gap: 0.125rem;
}
.subnav-link {
    display: inline-flex;
    align-items: center;
    padding: 0.3125rem 0.625rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    color: #6b7280;
    text-decoration: none;
    transition: color 0.15s, background-color 0.15s;
    white-space: nowrap;
}
.subnav-link:hover  { color: #111827; background: #ebebed; }
.subnav-link.active { color: #111827; background: #e5e7eb; font-weight: 500; }

/* Usage pill — SerpAPI credit indicator in subnav */
.usage-pill {
    font-size: 0.75rem;
    color: #6b7280;
    background: none;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    padding: 0.1875rem 0.5rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
    white-space: nowrap;
    font-family: inherit;
}
.usage-pill:hover    { background: #ebebed; }
.usage-pill.low      { color: #d97706; border-color: #fde68a; background: #fef9c3; }
.usage-pill.critical { color: #dc2626; border-color: #fca5a5; background: #fee2e2; }

/* ── Page layout ─────────────────────────────────────────────────────────── */
.page-main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 1.5rem;
}
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.page-title    { font-size: 1.5rem;  font-weight: 700; color: #111827; }
.page-title-sm { font-size: 1.25rem; font-weight: 700; color: #111827; }
.page-subtitle { font-size: 0.875rem; color: #6b7280; margin-top: 0.125rem; }
.page-actions  { display: flex; align-items: center; gap: 0.625rem; flex-wrap: wrap; }
.header-divider { width: 1px; align-self: stretch; min-height: 1.5rem; background: #e5e7eb; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 0.15s, border-color 0.15s;
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; }

.btn-primary { background: #4f46e5; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #4338ca; }

.btn-secondary { background: #fff; color: #374151; border-color: #d1d5db; }
.btn-secondary:hover:not(:disabled) { background: #f9fafb; }

.btn-danger { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.btn-danger:hover:not(:disabled) { background: #fecaca; }

/* Inline text action links */
.btn-link { font-size: 0.75rem; background: none; border: none; cursor: pointer; padding: 0; color: #6b7280; font-family: inherit; }
.btn-link:hover { color: #111827; }
.btn-link-blue { color: #4f46e5; }
.btn-link-blue:hover { color: #4338ca; }
.btn-link-red  { color: #dc2626; }
.btn-link-red:hover  { color: #b91c1c; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
}
.card-pad    { padding: 1rem; }
.card-pad-sm { padding: 0.75rem 1rem; }
.card-section-header {
    padding: 0.625rem 1rem;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-yellow { background: #fef9c3; color: #854d0e; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-input {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: #111827;
    width: 100%;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}
.form-input::placeholder { color: #9ca3af; }
textarea.form-input { resize: vertical; min-height: 4.5rem; }

.form-label  { display: block; font-size: 0.75rem; font-weight: 500; color: #6b7280; margin-bottom: 0.25rem; }
.label-hint  { color: #9ca3af; font-weight: 400; }
.form        { display: flex; flex-direction: column; gap: 1rem; }
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-actions { display: flex; gap: 0.75rem; padding-top: 0.5rem; }
.form-actions .btn { flex: 1; }
.form-error  { font-size: 0.875rem; color: #b91c1c; }

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.75rem;
    padding: 1.5rem;
    width: 100%;
    max-width: 28rem;
    color: #111827;
    box-shadow: 0 20px 60px rgba(0,0,0,0.12);
}
.modal-lg  { max-width: 36rem; }
.modal-xl  { max-width: 56rem; padding: 0; }
.modal::backdrop { background: rgba(0,0,0,0.4); }
.modal-title { font-size: 1.125rem; font-weight: 600; color: #111827; margin-bottom: 1rem; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
}
.modal-header h2 { font-size: 1rem; font-weight: 600; color: #111827; }
.modal-close { font-size: 1.25rem; line-height: 1; background: none; border: none; cursor: pointer; color: #9ca3af; }
.modal-close:hover { color: #6b7280; }
.modal-body { padding: 1.25rem; max-height: 70vh; overflow-y: auto; }
.modal-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px)  { .modal-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .modal-grid { grid-template-columns: 1fr 1fr 1fr; } }

/* ── History table ───────────────────────────────────────────────────────── */
.history-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.history-table th { text-align: left; font-weight: 600; color: #6b7280; padding: 0.5rem 0.75rem; border-bottom: 1px solid #e5e7eb; }
.history-table td { padding: 0.625rem 0.75rem; border-bottom: 1px solid #f3f4f6; color: #374151; vertical-align: middle; }
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: #f9fafb; }

/* ── Lists ───────────────────────────────────────────────────────────────── */
.list    { display: flex; flex-direction: column; gap: 0.75rem; }
.list-sm { display: flex; flex-direction: column; gap: 0.5rem; }

/* ── Item rows ───────────────────────────────────────────────────────────── */
.item-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 1rem;
}
.item-row + .item-row { border-top: 1px solid #f3f4f6; }
.item-name    { font-weight: 500; color: #111827; font-size: 0.875rem; }
.item-slug    { font-size: 0.75rem; color: #9ca3af; margin-top: 0.125rem; }
.item-meta    { font-size: 0.75rem; color: #6b7280; margin-top: 0.375rem; line-height: 1.6; }
.item-tags    { display: flex; align-items: center; gap: 0.375rem; margin-top: 0.375rem; flex-wrap: wrap; }
.item-actions { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.item-text    { flex: 1; min-width: 0; margin-right: 1rem; font-size: 0.875rem; color: #111827; }

/* ── Check group ─────────────────────────────────────────────────────────── */
.check-group { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.25rem; }
.check-label { display: flex; align-items: center; gap: 0.375rem; font-size: 0.875rem; color: #374151; cursor: pointer; }
.check-label input[type="checkbox"] { accent-color: #6366f1; }

/* ── Group header (queries page) ─────────────────────────────────────────── */
.group-header {
    padding: 0.5rem 1rem;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

/* ── Filters ─────────────────────────────────────────────────────────────── */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.filters-right { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.filter-select { width: auto; min-width: 110px; }

/* ── Helpers ─────────────────────────────────────────────────────────────── */
.hidden       { display: none !important; }
.text-empty   { text-align: center; padding: 3rem 1rem; color: #9ca3af; font-size: 0.875rem; }
.text-muted   { color: #6b7280; font-size: 0.75rem; }

/* ── Dashboard: engine chips ─────────────────────────────────────────────── */
.engine-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.chip-openai     { background: #d1fae5; color: #065f46; }
.chip-gemini     { background: #dbeafe; color: #1e40af; }
.chip-claude     { background: #ffedd5; color: #9a3412; }
.chip-perplexity { background: #ede9fe; color: #5b21b6; }
.chip-google_ai  { background: #fee2e2; color: #991b1b; }

/* ── Dashboard: stat cards ───────────────────────────────────────────────── */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.stat-card     { padding: 1rem; }
.stat-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.stat-pct      { font-size: 1.5rem; font-weight: 700; }
.stat-pct-green  { color: #16a34a; }
.stat-pct-yellow { color: #d97706; }
.stat-pct-red    { color: #dc2626; }
.stat-pct-empty  { color: #9ca3af; }
.stat-desc     { font-size: 0.75rem; color: #6b7280; margin-bottom: 0.5rem; }
.run-delta     { font-size: 0.875rem; font-weight: 600; margin-left: 0.375rem; vertical-align: middle; }
.delta-better  { color: #16a34a; }
.delta-worse   { color: #dc2626; }
.stat-bar      { background: #e5e7eb; border-radius: 9999px; height: 6px; overflow: hidden; }
.stat-bar-fill { background: #6366f1; height: 6px; border-radius: 9999px; transition: width 0.3s; }

/* ── Dashboard: engines dropdown ─────────────────────────────────────────── */
.engines-dropdown-wrap { position: relative; }
.engines-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 0.25rem);
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    z-index: 20;
    padding: 0.75rem;
    min-width: 10rem;
}
.engines-dropdown .check-label { padding: 0.25rem 0; }

/* ── Dashboard: results accordion ───────────────────────────────────────── */
.results-label { font-size: 0.875rem; font-weight: 600; color: #374151; margin-bottom: 0.75rem; }
.results-list  { background: #fff; border: 1px solid #e5e7eb; border-radius: 0.5rem; overflow: hidden; }

/* Digital Analyst: this list renders inside a .section-card that's already bordered/rounded, so
   its own border+radius doubled up into a "card within a card" look with a rounded top corner
   over the first row. Flush drops those in favour of the outer card's own edge, keeping only a
   straight divider line above the first row. */
.results-list-flush { border: none; border-top: 1px solid #e5e7eb; border-radius: 0; overflow: visible; }

/* Same list label, styled as a proper section heading (size/weight/padding) instead of the
   compact inline default — used above a flush list sitting directly in a card, where the
   default's cramped, edge-to-edge look reads as a stray line of text rather than a heading. */
.results-heading { font-size: 1rem; font-weight: 700; color: #111827; padding: 0.875rem 1rem 0; margin-bottom: 0.625rem; }

.query-block    { border-bottom: 1px solid #e5e7eb; }
.query-block:last-child { border-bottom: none; }
.query-toggle   { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; cursor: pointer; transition: background 0.15s; gap: 0.75rem; }
.query-toggle:hover { background: #f9fafb; }
.query-text     { font-size: 0.875rem; color: #111827; flex: 1; min-width: 0; }
.query-meta     { display: flex; align-items: center; gap: 0.375rem; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.query-mentioned { font-size: 0.75rem; color: #4f46e5; font-weight: 500; white-space: nowrap; }
.query-lastrun  { font-size: 0.75rem; color: #9ca3af; white-space: nowrap; }
.query-trend, .engine-trend { font-size: 0.75rem; font-weight: 700; }
.query-body     { border-top: 1px solid #e5e7eb; }

.run-dots    { display: flex; align-items: center; gap: 3px; }
.run-dot     { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.run-dot-mentioned     { background: #16a34a; }
.run-dot-not-mentioned { background: #ef4444; }
.run-dot-not-run       { background: #e5e7eb; }

.engine-result { border-bottom: 1px solid #f9fafb; }
.engine-result:last-child { border-bottom: none; }
.engine-result-toggle { display: flex; align-items: center; justify-content: space-between; padding: 0.625rem 1.5rem; transition: background 0.15s; }
.engine-result-toggle.clickable { cursor: pointer; }
.engine-result-toggle.clickable:hover { background: #f9fafb; }
.engine-result-left { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.engine-mention    { font-size: 0.75rem; color: #16a34a; font-weight: 500; }
.engine-no-mention { font-size: 0.75rem; color: #9ca3af; }
.engine-not-run    { font-size: 0.75rem; color: #9ca3af; }

.engine-response { padding: 0.75rem 1.5rem; background: #f9fafb; border-top: 1px solid #f3f4f6; }
.engine-response p { font-size: 0.75rem; color: #4b5563; white-space: pre-wrap; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden; }
.view-full { margin-top: 0.5rem; font-size: 0.75rem; color: #4f46e5; background: none; border: none; cursor: pointer; padding: 0; font-family: inherit; }
.view-full:hover { text-decoration: underline; }

/* Tone & position badges */
.tone-positive { background: #fef9c3; color: #854d0e; }
.tone-neutral  { background: #f3f4f6; color: #4b5563; }
.tone-negative { background: #fee2e2; color: #b91c1c; }
.pos-top    { background: #fef9c3; color: #854d0e; }
.pos-middle { background: #dbeafe; color: #1d4ed8; }
.pos-end    { background: #fee2e2; color: #b91c1c; }

/* Chevrons */
.chevron, .run-chevron, .eng-chevron { flex-shrink: 0; transition: transform 0.2s; }
.chevron     { width: 1rem;    height: 1rem;    color: #9ca3af; }
.run-chevron { width: 1rem;    height: 1rem;    color: #d1d5db; }
.eng-chevron { width: 0.875rem; height: 0.875rem; color: #d1d5db; }

/* Compare modal cards */
.compare-card     { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 0.5rem; padding: 0.75rem; }
.compare-query    { font-size: 0.75rem; color: #9ca3af; margin-bottom: 0.25rem; }
.compare-response { font-size: 0.75rem; color: #4b5563; margin-top: 0.25rem; white-space: pre-wrap; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.compare-divider  { border: none; border-top: 1px solid #e5e7eb; margin: 0.5rem 0; }

/* Workflow status */
.workflow-status     { font-size: 0.75rem; }
.workflow-status a   { text-decoration: none; color: inherit; }
.status-queued    { color: #d97706; }
.status-running   { color: #4f46e5; }
.status-success   { color: #16a34a; }
.status-failure   { color: #dc2626; }
.status-neutral   { color: #6b7280; }

/* ── Analytics ───────────────────────────────────────────────────────────── */
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
@media (min-width: 1024px) { .chart-grid { grid-template-columns: 1fr 1fr; } }
.chart-card  { padding: 1rem; }
.chart-title { font-size: 0.875rem; font-weight: 600; color: #374151; margin-bottom: 1rem; }

.table-wrap  { overflow-x: auto; }
.data-table  { width: 100%; font-size: 0.875rem; border-collapse: collapse; }
.data-table thead { background: #f9fafb; }
.data-table th { padding: 0.625rem 1rem; text-align: left; font-size: 0.75rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid #e5e7eb; }
.data-table th.tc, .data-table td.tc { text-align: center; }
.data-table th.td-num, .data-table th.td-pos { text-align: right; }
.data-table td { padding: 0.625rem 1rem; color: #374151; border-bottom: 1px solid #f3f4f6; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f9fafb; }
.td-truncate { max-width: 16rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #111827; }
.rate-bar-wrap { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.rate-bar      { width: 4rem; background: #e5e7eb; border-radius: 9999px; height: 6px; overflow: hidden; }
.rate-bar-fill { background: #6366f1; height: 6px; border-radius: 9999px; }
.sentiment-positive { color: #16a34a; }
.sentiment-negative { color: #dc2626; }
.sentiment-neutral  { color: #6b7280; }

/* ── Site audit ──────────────────────────────────────────────────────────── */
.audit-issue-group { margin-bottom: 0.75rem; padding: 0; overflow: hidden; }
.audit-issue-group > summary { list-style: none; cursor: pointer; user-select: none; }
.audit-issue-group > summary::-webkit-details-marker { display: none; }
.audit-issue-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.75rem 1rem; }
details[open] > summary.audit-issue-header { border-bottom: 1px solid #f3f4f6; }
.audit-issue-type   { font-weight: 600; font-size: 0.875rem; color: #111827; flex: 1; }
.audit-issue-count  { margin-left: auto; }
.audit-chevron      { flex-shrink: 0; color: #9ca3af; transition: transform 0.15s ease; }
details[open] .audit-chevron { transform: rotate(180deg); }
.audit-issue-rows   { display: flex; flex-direction: column; }
.audit-issue-row    { display: flex; flex-direction: column; gap: 0.125rem; padding: 0.5rem 1rem; border-bottom: 1px solid #f9fafb; }
.audit-issue-row:last-child { border-bottom: none; }
.audit-issue-url    { font-size: 0.8125rem; color: #374151; }
.audit-issue-detail { font-size: 0.75rem; color: #6b7280; white-space: pre-line; }
.audit-page-url     { font-size: 0.8125rem; color: #374151; word-break: break-all; }

.audit-severity-chip        { display: inline-flex; align-items: center; padding: 0.125rem 0.5rem; border-radius: 9999px; font-size: 0.6875rem; font-weight: 600; }
.audit-severity-label       { display: inline-flex; align-items: center; padding: 0.25rem 0.625rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; }
.severity-critical          { background: #fee2e2; color: #b91c1c; }
.severity-warning           { background: #fef9c3; color: #a16207; }
.severity-info              { background: #dbeafe; color: #1d4ed8; }

.audit-summary { padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.run-summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
@media (min-width: 640px) { .run-summary-grid { grid-template-columns: repeat(3, 1fr); } }
.run-summary-label { display: block; font-size: 0.6875rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.125rem; }
.run-summary-value { font-size: 0.9375rem; font-weight: 600; color: #111827; }

.page-detail-grid    { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 480px) { .page-detail-grid { grid-template-columns: 1fr 1fr; } }

.two-col-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 768px) { .two-col-grid { grid-template-columns: 1fr 1fr; } }
.page-detail-section { padding: 0.75rem; background: #f9fafb; border-radius: 0.375rem; }
.page-detail-heading { font-size: 0.75rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.375rem; }
.page-detail-value   { font-size: 0.8125rem; color: #111827; margin-bottom: 0.25rem; }
.page-detail-meta    { font-size: 0.75rem; color: #6b7280; margin-bottom: 0.125rem; }

.psi-score      { display: inline-flex; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem; border-radius: 50%; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }
.psi-good       { background: #dcfce7; color: #15803d; }
.psi-ok         { background: #fef9c3; color: #a16207; }
.psi-poor       { background: #fee2e2; color: #b91c1c; }

.section-title    { font-size: 0.9375rem; font-weight: 600; color: #111827; margin: 0; }
.max-pages-label  { display: flex; align-items: center; gap: 0.375rem; font-size: 0.8125rem; color: #6b7280; white-space: nowrap; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 0.75rem; padding: 2rem; width: 100%; max-width: 24rem; box-shadow: 0 4px 24px rgba(0,0,0,0.06); }
.login-logo     { display: block; height: 3.5rem; width: auto; margin: 0 auto 0.75rem; }
.login-subtitle { font-size: 0.875rem; color: #6b7280; margin-bottom: 1.5rem; text-align: center; }
.login-error { margin-bottom: 1rem; padding: 0.625rem 0.75rem; border-radius: 0.375rem; background: #fee2e2; border: 1px solid #fca5a5; color: #b91c1c; font-size: 0.875rem; }
.login-form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-form .btn-primary { width: 100%; margin-top: 0.25rem; }

/* ── Nav dropdowns ───────────────────────────────────────────────────────── */
.nav-dropdown { position: relative; }
.nav-dropdown-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.875rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: color 0.15s, background-color 0.15s;
    white-space: nowrap;
    line-height: 1;
}
.nav-dropdown-btn:hover         { color: #111827; background: #f3f4f6; }
.nav-dropdown-btn.active        { color: #111827; background: #f3f4f6; }
.nav-dropdown-btn svg           { flex-shrink: 0; }
.nav-dropdown:hover .nav-dropdown-btn { color: #111827; background: #f3f4f6; }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    min-width: 11rem;
    z-index: 100;
    padding: 0.25rem;
}
/* Invisible bridge over the gap above the menu — without it, moving the
   mouse from the button down to the menu crosses a dead zone that belongs
   to neither element, which drops :hover on .nav-dropdown and closes the
   menu before the pointer arrives. */
.nav-dropdown-menu::before {
    content: '';
    position: absolute;
    top: -0.25rem;
    left: 0;
    right: 0;
    height: 0.25rem;
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    color: #374151;
    text-decoration: none;
    border-radius: 0.25rem;
    white-space: nowrap;
    gap: 0.5rem;
}
.nav-dropdown-item:hover        { background: #f3f4f6; color: #111827; }
.nav-dropdown-item.active       { color: #4f46e5; background: #eef2ff; font-weight: 500; }
.nav-dropdown-item-soon         { font-size: 0.6875rem; color: #d1d5db; font-weight: 500; letter-spacing: 0.03em; }

/* Mobile nav collapse — must come after the base .nav-top-links/.nav-dropdown-menu rules above,
   since identical selectors at equal specificity resolve by source order regardless of the
   @media condition; declaring this first would let the unconditional desktop rules win at
   every viewport width. */
@media (max-width: 900px) {
    /* Only .nav-brand + .nav-toggle remain in the flex row at this width (.nav-top-links drops
       out of flow below) — push the toggle to the far right instead of leaving it stranded
       right after the logo with empty space trailing it. */
    .nav-toggle { display: inline-flex; margin-left: auto; }

    .nav-top-links {
        display: none;
        position: absolute;
        top: 3rem;
        left: 0;
        right: 0;
        flex: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0.125rem;
        background: #fff;
        border-bottom: 1px solid #e5e7eb;
        box-shadow: 0 8px 16px -4px rgba(0,0,0,0.08);
        padding: 0.5rem;
        max-height: calc(100vh - 3rem);
        overflow-y: auto;
    }
    .nav-top-links.open { display: flex; }
    .nav-top-link { width: 100%; }

    .nav-dropdown { width: 100%; }
    .nav-dropdown-btn { width: 100%; justify-content: space-between; }
    .nav-dropdown-menu {
        display: none;
        position: static;
        box-shadow: none;
        border: none;
        min-width: 0;
        padding: 0 0 0 0.75rem;
    }
    .nav-dropdown-menu::before { display: none; }
    /* Hover doesn't apply reliably on touch — rely on the .open class (toggled by click) instead */
    .nav-dropdown:hover .nav-dropdown-menu { display: none; }
    .nav-dropdown.open .nav-dropdown-menu { display: block; }
    .nav-dropdown.open .nav-dropdown-btn svg { transform: rotate(180deg); }

    /* Docs/Logout/credit-balance, appended after the section links inside the same collapsible
       menu — full-width stacked rows like everything else in the column, instead of the
       right-aligned inline group desktop gets. No auto-margin gap to read as separation here,
       so the divider (hidden by default, see base rule above) becomes visible instead. */
    .nav-menu-divider { display: block; width: auto; height: 1px; min-height: 0; margin: 0.375rem 0.5rem; background: #e5e7eb; }
    .nav-account-group { flex-direction: column; align-items: stretch; gap: 0.125rem; margin-left: 0; width: 100%; }
    .nav-top-links form { width: 100%; }
    .nav-top-links .nav-logout {
        width: 100%;
        text-align: left;
        padding: 0.375rem 0.875rem;
        font-size: 0.75rem;
        color: #6b7280;
        border-radius: 0.375rem;
    }
    .nav-top-links .nav-logout:hover { background: #f3f4f6; color: #111827; }
    .nav-top-links .usage-pill {
        width: 100%;
        text-align: left;
        border: none;
        border-radius: 0.375rem;
        padding: 0.375rem 0.875rem;
    }
}

/* ── Overview (home) page ────────────────────────────────────────────────── */
.overview-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 640px)  { .overview-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .overview-grid { grid-template-columns: repeat(3, 1fr); } }

.overview-card {
    display: block;
    padding: 1.25rem;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
a.overview-card:hover {
    border-color: #c7d2fe;
    box-shadow: 0 2px 8px rgba(99,102,241,0.08);
}
.overview-card-label  { font-size: 0.75rem; font-weight: 600; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.5rem; }
.overview-card-value  { font-size: 1.875rem; font-weight: 700; color: #111827; line-height: 1; margin-bottom: 0.375rem; }
.overview-card-sub    { font-size: 0.8125rem; color: #6b7280; }
.overview-card-footer { margin-top: 1rem; font-size: 0.75rem; color: #9ca3af; }
a.overview-card .overview-card-footer { color: #6366f1; }

/* ── Delta indicators ────────────────────────────────────────────────────── */
.delta { font-size: 0.75rem; font-weight: 600; margin-left: 0.375rem; }
.delta-up   { color: #16a34a; }
.delta-down { color: #dc2626; }
.delta-flat { color: #9ca3af; }

/* ── GSC / analytics pages ───────────────────────────────────────────────── */
.period-tabs, .sales-tabs { display: flex; gap: 0.25rem; }
.period-tab, .sales-tab {
    padding: 0.3125rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.period-tab:hover, .sales-tab:hover   { background: #f3f4f6; color: #374151; }
.period-tab.active, .sales-tab.active { background: #fff; border-color: #d1d5db; color: #111827; font-weight: 600; }
.store-tabs { display: flex; gap: 0.25rem; }
.store-tab {
    display: inline-flex;
    align-items: center;
    padding: 0.3125rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.store-tab:hover  { background: #f3f4f6; color: #374151; }
.store-tab.active { background: #4f46e5; border-color: #4f46e5; color: #fff; font-weight: 600; }

.content-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.75rem 1rem 0;
}
.content-tab {
    padding: 0.3125rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #6b7280;
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.content-tab:hover  { background: #f3f4f6; color: #374151; }
.content-tab.active { background: #eef2ff; border-color: #c7d2fe; color: #4338ca; font-weight: 600; }
.content-tab-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem 0.5rem;
    gap: 0.75rem;
}

.custom-date-range { display: none; align-items: center; gap: 0.375rem; }
.custom-date-range.visible { display: flex; }
.custom-date-sep   { color: #d1d5db; font-size: 0.75rem; padding: 0 0.125rem; }
.custom-date-input {
    padding: 0.3125rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    background: #fff;
    border: 1px solid #d1d5db;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.25;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.custom-date-input:hover { border-color: #9ca3af; }
.custom-date-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 640px)  { .metrics-grid { grid-template-columns: repeat(4, 1fr); } }

.metric-card        { padding: 1.25rem; }
.metric-label       { font-size: 0.75rem; font-weight: 600; color: #9ca3af; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.metric-value       { font-size: 1.5rem; font-weight: 700; color: #111827; line-height: 1; }
.metric-delta       { margin-top: 0.375rem; font-size: 0.8125rem; color: #6b7280; min-height: 1.25rem; }

.section-card       { margin-bottom: 1.5rem; }
.section-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    gap: 0.75rem;
}
.section-card-title { font-size: 0.875rem; font-weight: 600; color: #374151; }
.section-card-title-wrap { display: inline-flex; align-items: center; gap: 0.375rem; }

/* ── Info icons / tooltips ───────────────────────────────────────────────── */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    font-size: 0.6875rem;
    font-weight: 700;
    font-style: italic;
    font-family: Georgia, serif;
    cursor: help;
    position: relative;
    user-select: none;
}
.info-icon:hover, .info-icon.active { background: #c7d2fe; color: #4338ca; }
.info-icon::after {
    content: attr(data-tip);
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    width: 17rem;
    max-width: 60vw;
    background: #1f2937;
    color: #f3f4f6;
    font-size: 0.75rem;
    font-weight: 400;
    font-style: normal;
    font-family: inherit;
    line-height: 1.45;
    text-transform: none;
    letter-spacing: normal;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 200;
    white-space: normal;
}
.info-icon:hover::after, .info-icon.active::after { display: block; }

.th-sort { cursor: pointer; user-select: none; }
.th-sort:hover { color: #374151; }
.sort-icon { color: #d1d5db; font-size: 0.75rem; margin-left: 0.25rem; }
.sort-icon.asc, .sort-icon.desc { color: #6366f1; }

.td-url { max-width: 22rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-num { text-align: right; font-variant-numeric: tabular-nums; }
.td-pos { text-align: right; font-variant-numeric: tabular-nums; color: #374151; }
.pos-good    { color: #16a34a; font-weight: 600; }
.pos-ok      { color: #d97706; font-weight: 600; }
.pos-poor    { color: #dc2626; font-weight: 600; }

.chart-wrap { padding: 1rem; position: relative; height: 260px; }
.loading-state { text-align: center; padding: 3rem 1rem; color: #9ca3af; font-size: 0.875rem; }
.empty-state   { text-align: center; padding: 2rem 1rem; color: #9ca3af; font-size: 0.875rem; }

/* Home dashboard chat box */
.chat-card { margin-top: 1.5rem; }
.chat-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.chat-card-title { font-size: 1rem; font-weight: 600; color: #111827; margin: 0; }
.chat-card-subtitle { font-size: 0.8125rem; color: #6b7280; margin: 0.125rem 0 0; }
.chat-usage {
    font-size: 0.75rem;
    color: #6b7280;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    padding: 0.25rem 0.75rem;
    white-space: nowrap;
    cursor: help;
}
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 22rem;
    overflow-y: auto;
    padding: 0.25rem;
    margin-bottom: 0.75rem;
}
.chat-message {
    max-width: 80%;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.45;
    white-space: normal;
}
.chat-message-user {
    align-self: flex-end;
    background: #4f46e5;
    color: #fff;
}
.chat-message-assistant {
    align-self: flex-start;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    color: #111827;
}
.chat-thinking { font-size: 0.8125rem; color: #6b7280; margin-bottom: 0.5rem; }
.chat-error {
    font-size: 0.8125rem;
    color: #b91c1c;
    background: #fee2e2;
    border: 1px solid #fca5a5;
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}
.chat-input-row { display: flex; gap: 0.5rem; }
.chat-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-family: inherit;
    font-size: 0.875rem;
}
.chat-input:disabled { background: #f9fafb; color: #9ca3af; }

.chat-tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.75rem;
}
.chat-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 0 0 0.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
}
.chat-tab.active { color: #4f46e5; border-bottom-color: #4f46e5; }
.chat-history-list {
    max-height: 22rem;
    overflow-y: auto;
    margin-bottom: 0.75rem;
}
.chat-history-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-bottom: 1px solid #f3f4f6;
    padding: 0.625rem 0.25rem;
    cursor: pointer;
    font-family: inherit;
}
.chat-history-item:hover { background: #f9fafb; }
.chat-history-item-question {
    font-size: 0.8125rem;
    color: #111827;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-history-item-date { font-size: 0.75rem; color: #9ca3af; margin-top: 0.125rem; }
.chat-history-back {
    background: none;
    border: none;
    color: #4f46e5;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0 0 0.75rem;
}
