/* ───────────── Theme ─────────────
   Light is the base; body.night-mode (the default, see index.php) switches to dark.
   --node-rgb / --node-alpha colour the node network drawn by nodes.js. */
:root {
    color-scheme: light;
}

body {
    --bg: #eef1f7;
    --bg-glow: rgba(99, 102, 241, 0.10);
    --surface: rgba(255, 255, 255, 0.78);
    --surface-solid: #ffffff;
    --surface-2: rgba(15, 23, 42, 0.04);
    --surface-3: rgba(15, 23, 42, 0.07);
    --border: rgba(15, 23, 42, 0.10);
    --border-strong: rgba(15, 23, 42, 0.18);
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --accent: #4f46e5;
    --accent-2: #6366f1;
    --accent-soft: rgba(79, 70, 229, 0.10);
    --accent-text: #ffffff;
    --success: #059669;
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.08);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --node-rgb: 79, 70, 229;
    --node-alpha: 0.45;
    --radius: 14px;
    --radius-sm: 10px;
}

body.night-mode {
    color-scheme: dark;
    --bg: #080b12;
    --bg-glow: rgba(99, 102, 241, 0.12);
    --surface: rgba(17, 22, 33, 0.74);
    --surface-solid: #111621;
    --surface-2: rgba(255, 255, 255, 0.035);
    --surface-3: rgba(255, 255, 255, 0.07);
    --border: rgba(148, 163, 184, 0.13);
    --border-strong: rgba(148, 163, 184, 0.24);
    --text: #e6e9f0;
    --text-2: #c3c9d6;
    --muted: #8b93a7;
    --accent: #6366f1;
    --accent-2: #818cf8;
    --accent-soft: rgba(99, 102, 241, 0.14);
    --accent-text: #ffffff;
    --success: #34d399;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.10);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
    --node-rgb: 129, 140, 248;
    --node-alpha: 0.75;
}

/* ───────────── Base ───────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 10% -10%, var(--bg-glow), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, var(--bg-glow), transparent 55%),
        var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s, color 0.3s;
}

.node-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
}

.topbar, .shell, #overlay, .popup {
    position: relative;
    z-index: 1;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    color: var(--text);
    letter-spacing: -0.01em;
}

a {
    color: var(--accent-2);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--surface-3);
    color: var(--text-2);
}

svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

::selection {
    background: var(--accent-soft);
}

:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

/* ───────────── Top bar ───────────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(16px, 4vw, 40px);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    color: var(--accent-text);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.3);
}

.brand-mark svg {
    width: 22px;
    height: 22px;
}

.brand h1 {
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-sub {
    margin: 0;
    font-size: 12.5px;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ───────────── Buttons ───────────── */
button, .btn {
    font: inherit;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, border-color 0.2s, transform 0.1s, box-shadow 0.2s;
}

.btn:hover {
    background: var(--surface-3);
}

.btn:active {
    transform: translateY(1px);
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    border-color: transparent;
    color: var(--accent-text);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.28);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    box-shadow: 0 8px 22px rgba(99, 102, 241, 0.38);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-2);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-2);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.mode-toggle .sun {
    display: none;
}

body.night-mode .mode-toggle .sun {
    display: block;
}

body.night-mode .mode-toggle .moon {
    display: none;
}

/* ───────────── Layout ───────────── */
.shell {
    max-width: 1240px;
    margin: 0 auto;
    padding: 28px clamp(16px, 4vw, 40px) 80px;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 24px;
    align-items: start;
    margin-top: 24px;
}

.main-col {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.side-col {
    position: sticky;
    top: 92px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#listsContainer {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px) saturate(130%);
    -webkit-backdrop-filter: blur(12px) saturate(130%);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.card-head h2 {
    font-size: 15px;
    font-weight: 650;
}

/* ───────────── Search card ───────────── */
.search-card {
    padding: 22px;
}

.search-row {
    display: flex;
    gap: 12px;
}

.search-field {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--muted);
    transition: border-color 0.2s, box-shadow 0.2s;
    cursor: text;
}

.search-field:focus-within {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-field input {
    flex: 1;
    min-width: 0;
    height: 50px;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 16px;
}

.search-field input::placeholder {
    color: var(--muted);
}

.search-row .btn-primary {
    padding: 0 28px;
    font-size: 15px;
    border-radius: 12px;
}

.search-field.small {
    margin-top: 12px;
    padding: 0 12px;
}

.search-field.small input {
    height: 40px;
    font-size: 14px;
}

.controls {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
    gap: 14px;
    margin-top: 16px;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.control label, .inline-form label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

select, .inline-form input[type="text"] {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background-color: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:focus, .inline-form input[type="text"]:focus {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

select option {
    background: var(--surface-solid);
    color: var(--text);
}

.slider-container {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 40px;
    column-gap: 12px;
    align-items: center;
}

.slider-container label {
    grid-column: 1 / -1;
}

.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--surface-3);
    outline: none;
    cursor: pointer;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-2);
    border: 3px solid var(--surface-solid);
    box-shadow: 0 0 0 1px var(--accent-2), 0 2px 6px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-2);
    border: 3px solid var(--surface-solid);
    box-shadow: 0 0 0 1px var(--accent-2);
}

.pill {
    min-width: 36px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-2);
    font-weight: 700;
    font-size: 13px;
    text-align: center;
}

#externalApiKeyInput {
    margin-top: 14px;
}

.inline-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.inline-form-row {
    display: flex;
    gap: 10px;
}

.inline-form-row input {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.key-status {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}

#message:not(:empty) {
    margin-left: auto;
    color: var(--success);
}

/* ───────────── Meta description ───────────── */
.meta-box {
    position: relative;
    min-height: 64px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
    cursor: copy;
    transition: border-color 0.2s, background 0.2s;
}

.meta-box:hover {
    border-color: var(--accent-2);
    background: var(--accent-soft);
}

.meta-box:empty::before {
    content: "Run a search and a meta description written from the top results appears here.";
    color: var(--muted);
}

.meta-foot {
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
}

#metaLength.over {
    color: var(--danger);
    font-weight: 700;
}

/* ───────────── Fetched websites ───────────── */
#websiteContent {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

#websiteContent:empty::before {
    content: "Results from each website — headings and their text — will show up here after a search.";
    display: block;
    padding: 40px 24px;
    border-radius: var(--radius);
    border: 1px dashed var(--border-strong);
    background: var(--surface);
    color: var(--muted);
    text-align: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#websiteContent > p {
    margin: 0;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 13px;
    word-break: break-all;
}

.website-result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px) saturate(130%);
    -webkit-backdrop-filter: blur(12px) saturate(130%);
    animation: rise 0.35s ease both;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.website-result > h2 {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    font-size: 16px;
    font-weight: 650;
    line-height: 1.4;
}

.website-link {
    margin: 4px 0 12px;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.website-link a {
    color: var(--success);
}

.report-website {
    flex-shrink: 0;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.report-website:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-soft);
}

.headingSearch {
    width: 100%;
    height: 38px;
    margin-bottom: 12px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
    outline: none;
}

.headingSearch:focus {
    border-color: var(--accent-2);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.website-content > p {
    margin: 8px 0 0;
    color: var(--text-2);
    font-size: 14px;
}

/* Headings (also used by the two side lists) */
.heading-section {
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    overflow: hidden;
}

.heading-section:last-child {
    margin-bottom: 0;
}

.extracted-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 10px 12px;
    font-size: 14px !important;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.extracted-heading:hover {
    background: var(--surface-3);
}

.heading-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.heading-text {
    flex: 1;
    min-width: 0;
    color: var(--text);
}

.heading-num {
    color: var(--muted);
    font-weight: 500;
}

h1.extracted-heading .heading-num::before,
h2.extracted-heading .heading-num::before,
h3.extracted-heading .heading-num::before {
    display: inline-block;
    margin-right: 6px;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--accent-soft);
    color: var(--accent-2);
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    vertical-align: 1px;
}

h1.extracted-heading .heading-num::before { content: "H1"; }
h2.extracted-heading .heading-num::before { content: "H2"; }
h3.extracted-heading .heading-num::before { content: "H3"; }

.heading-actions {
    display: flex;
    gap: 2px;
    opacity: 0.55;
    transition: opacity 0.2s;
}

.extracted-heading:hover .heading-actions {
    opacity: 1;
}

.copy-icon, .report-icon {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.copy-icon svg, .report-icon svg {
    width: 15px;
    height: 15px;
}

.copy-icon:hover {
    background: var(--accent-soft);
    color: var(--accent-2);
}

.report-icon:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.toggle-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
}

.toggle-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.collapsible-content {
    padding: 4px 14px 12px;
    border-top: 1px solid var(--border);
    color: var(--text-2);
    font-size: 13.5px;
}

.collapsible-content p {
    margin: 8px 0 0;
}

/* ───────────── Side lists ───────────── */
.list-card {
    padding: 8px;
}

.list-card .heading-section {
    border: 0;
    background: transparent;
}

.list-card .extracted-heading {
    padding: 8px 10px;
}

.list-card .extracted-heading .heading-text {
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}

.list-card ul {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 280px;
    overflow-y: auto;
}

.list-card li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 7px 4px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    color: var(--text-2);
    word-break: break-word;
}

.list-card li:last-child {
    border-bottom: 0;
}

.list-card .collapsible-content {
    border-top: 0;
    padding: 0 6px 6px;
}

.remove-site, .remove-heading {
    flex-shrink: 0;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.remove-site:hover, .remove-heading:hover {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--danger-soft);
}

/* ───────────── Results overlay ───────────── */
#overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    padding: 6vh 16px;
    overflow-y: auto;
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

#overlayContent {
    max-width: 820px;
    margin: 0 auto;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    animation: rise 0.25s ease both;
}

.overlay-head {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-solid);
}

.overlay-head h2 {
    font-size: 16px;
}

#overlayResults {
    padding: 8px 20px 20px;
}

#overlayResults > p {
    color: var(--muted);
}

.result {
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}

.result:last-child {
    border-bottom: 0;
}

.result h3 {
    font-size: 16px;
    font-weight: 650;
    line-height: 1.4;
}

.result .link {
    margin: 2px 0 8px;
    font-size: 12.5px;
    color: var(--success);
    word-break: break-all;
}

.result .meta-description {
    margin: 6px 0 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 14px;
    cursor: copy;
}

.result .meta-description:hover {
    background: var(--accent-soft);
}

.seo-score {
    display: inline-block;
    margin: 4px 0 6px;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-2);
    font-size: 12.5px;
    font-weight: 700;
}

.result ul {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 12.5px;
    color: var(--muted);
}

/* ───────────── Toasts ───────────── */
.popup {
    position: fixed !important;
    left: 50%;
    bottom: 28px;
    z-index: 100;
    transform: translateX(-50%);
    max-width: min(92vw, 480px);
    padding: 11px 18px;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface-solid);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

/* ───────────── Scrollbars ───────────── */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* ───────────── Small screens ───────────── */
@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .side-col {
        position: static;
        order: -1;
    }

    #listsContainer {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 14px;
    }

    .brand-sub {
        display: none;
    }

    .brand-mark {
        width: 34px;
        height: 34px;
    }

    #logoutButton {
        padding: 9px 12px;
    }

    .search-row {
        flex-direction: column;
    }

    .search-row .btn-primary {
        height: 46px;
    }

    .controls {
        grid-template-columns: 1fr;
    }

    #listsContainer {
        grid-template-columns: 1fr;
    }

    .inline-form-row {
        flex-direction: column;
    }

    .card, .website-result {
        padding: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
