:root {
    --bg:           #0d1117;
    --bg-panel:     #161b22;
    --bg-inset:     #0d1117;
    --border:       #30363d;
    --border-soft:  rgba(48, 54, 61, 0.6);
    --text:         #e6edf3;
    --muted:        #7d8590;
    --muted-light:  #a0aab4;
    --accent:       #58a6ff;
    --accent-dim:   rgba(88, 166, 255, 0.12);
    --success:      #3fb950;
    --warning:      #d29922;
    --danger:       #f85149;
    --radius-lg:    10px;
    --radius-md:    8px;
    --radius-sm:    6px;
    --font-ui:      "IBM Plex Sans", system-ui, sans-serif;
    --font-mono:    "IBM Plex Mono", "Cascadia Code", Consolas, monospace;
    --transition:   140ms ease;
    --glow-accent:  rgba(88, 166, 255, 0.06);
    --glow-success: rgba(63, 185, 80,  0.05);
}

/* Light mode only overrides variables, so all components pick up the new colors automatically. */
:root[data-theme="light"] {
    --bg:           #f6f8fa;
    --bg-panel:     #ffffff;
    --bg-inset:     #f6f8fa;
    --border:       #d0d7de;
    --border-soft:  rgba(208, 215, 222, 0.75);
    --text:         #24292f;
    --muted:        #57606a;
    --muted-light:  #57606a;
    --accent:       #0969da;
    --accent-dim:   rgba(9, 105, 218, 0.11);
    --success:      #1a7f37;
    --warning:      #9a6700;
    --danger:       #cf222e;
    --glow-accent:  rgba(9, 105, 218, 0.06);
    --glow-success: rgba(26, 127, 55, 0.04);
}

*, *::before, *::after { box-sizing: border-box; }

/* color-scheme lets native browser UI, such as scrollbars, match the active theme. */
html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-ui);
    font-size: 0.9375rem;
    line-height: 1.6;
    color: var(--text);
    background-color: var(--bg);
    background-image:
            radial-gradient(ellipse 60% 40% at 70% -10%, var(--glow-accent), transparent),
            radial-gradient(ellipse 40% 30% at 0% 80%,   var(--glow-success), transparent);
}

/* Layout */

.app {
    width: min(880px, calc(100% - 32px));
    margin: 0 auto;
    padding: 32px 0 56px;
    display: grid;
    gap: 0;
}

/* Header */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}

.logo-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    font-size: 1.35rem;
    background: var(--accent-dim);
    border: 1px solid rgba(88, 166, 255, 0.3);
    border-radius: var(--radius-md);
}

.logo-text {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

.header-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.settings-menu-wrapper {
    position: relative;
    display: inline-flex;
}

/* The dropdown is anchored to the settings button and sits above the page content. */
.settings-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 20;
    width: 176px;
    padding: 8px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 12px 32px rgba(1, 4, 9, 0.28);
    animation: slide-down 140ms ease;
}

.settings-menu-title {
    margin: 2px 8px 6px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.settings-option {
    display: block;
    width: 100%;
    padding: 8px 10px;
    color: var(--muted-light);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    text-align: left;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.settings-option:hover,
.settings-option:focus-visible {
    color: var(--text);
    background: var(--bg-inset);
    border-color: var(--border-soft);
    outline: none;
}

/* Buttons */

button { font: inherit; }

.btn-ghost,
.btn-icon,
.btn-analyze {
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), transform var(--transition), color var(--transition);
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    color: var(--muted-light);
    background: transparent;
    border-color: var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.btn-ghost:hover {
    color: var(--text);
    background: var(--bg-panel);
    border-color: var(--muted);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    color: var(--muted-light);
    background: transparent;
    border-color: var(--border);
    border-radius: var(--radius-sm);
    transition: color var(--transition), background var(--transition), border-color var(--transition);
}

.btn-icon:hover {
    color: var(--text);
    background: var(--bg-panel);
    border-color: var(--muted);
}

.btn-analyze {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 200px;
    padding: 12px 28px;
    color: #fff;
    font-weight: 600;
    font-size: 0.9375rem;
    background: var(--accent);
    border-radius: var(--radius-md);
    border-color: transparent;
    box-shadow: 0 0 0 0 rgba(88, 166, 255, 0.4);
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn-analyze:hover:not(:disabled) {
    background: #79b8ff;
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(88, 166, 255, 0.3);
}

.btn-analyze:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: none;
}

.btn-analyze:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* Tips panel */

.tips-panel {
    margin-bottom: 20px;
    padding: 16px 18px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-md);
    animation: slide-down 180ms ease;
}

@keyframes slide-down {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tips-title {
    margin: 0 0 12px;
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--warning);
}

.tips-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.tip-item {
    padding: 10px 14px;
    color: var(--muted-light);
    background: var(--bg-inset);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    line-height: 1.55;
}

.tip-item::before {
    content: "›  ";
    color: var(--warning);
    font-weight: 700;
}

/* Section labels */

.section-label {
    margin: 0 0 8px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

.code-section {
    margin-bottom: 0;
}

/* Code panel */

.code-panel {
    overflow: hidden;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.code-editor {
    display: flex;
    width: 100%;
    height: 460px;
    overflow: hidden;
    background: transparent;
    font: 0.9rem/1.75 var(--font-mono);
}

.line-numbers {
    padding: 20px 10px;
    min-width: 20px;
    background: rgba(255,255,255,0.02);
    border-right: 1px solid var(--border);
    color: var(--muted);
    text-align: right;
    font: inherit;
    line-height: inherit;
    overflow: hidden;
    margin: 0;
}

.code-textarea {
    flex: 1;
    min-height: 380px;
    padding: 20px 22px;
    border: 0;
    outline: none;
    resize: none;
    color: var(--text);
    background: transparent;
    font: inherit;
    line-height: inherit;
    overflow: auto;
    white-space: pre;
    tab-size: 4;
    position: relative;
    z-index: 2;
}

.code-panel-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 16px;
    background: var(--bg-inset);
    border-bottom: 1px solid var(--border);
}

.code-dots {
    display: inline-flex;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot-red   { background: #ff5f56; }
.dot-amber { background: #ffbd2e; }
.dot-green { background: #27c93f; }

.code-lang {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--muted);
    letter-spacing: 0.06em;
}

.code-textarea {
    display: block;
    width: 100%;
    min-height: 380px;
    padding: 20px 22px;
    border: 0;
    color: var(--text);
    background: transparent;
    resize: none;
    outline: none;
    font: 0.9rem/1.75 var(--font-mono);
    tab-size: 4;
}

.code-textarea::placeholder {
    color: #3d454e;
}

/* Analyze row */

.analyze-row {
    display: flex;
    justify-content: center;
    padding: 20px 0 10px;
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    opacity: 0;
    animation: spin 0.75s linear infinite;
    flex-shrink: 0;
}

.btn-analyze.loading .spinner { opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }

/* Results panel */

.results-section {
    margin-top: 8px;
}

.results-panel {
    padding: 20px 22px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.results-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 14px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border-soft);
}

.results-meta {
    display: block;
}

.results-summary {
    margin: 4px 0 0;
    color: var(--muted-light);
    font-size: 0.9rem;
    line-height: 1.55;
}

.results-status {
    display: inline-block;
    padding: 5px 12px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--bg-inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    white-space: nowrap;
    flex-shrink: 0;
}

.results-status.ok    { color: var(--success); border-color: rgba(63, 185, 80, 0.35); }
.results-status.error { color: var(--danger);  border-color: rgba(248, 81, 73, 0.35); }

.results-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 8px;
}

.results-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-inset);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    color: var(--muted-light);
    font-size: 0.875rem;
    line-height: 1.6;
}

.results-list li.finding-warn   { border-left: 3px solid var(--warning); color: var(--text); }
.results-list li.finding-danger { border-left: 3px solid var(--danger);  color: var(--text); }
.results-list li.finding-info   { border-left: 3px solid var(--accent); }
.results-list li.finding-disclaimer { border-left: 3px solid var(--danger); color: var(--text); background: rgba(248, 81, 73, 0.08); }

.results-list li.finding-clickable {
    cursor: pointer;
    transition: filter var(--transition);
}

.results-list li.finding-clickable:hover {
    filter: brightness(1.15);
}

.line-badge {
    flex-shrink: 0;
    margin-left: auto;
    padding: 0 6px;
    height: 1.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    line-height: 2;
    color: var(--muted);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.severity-badge {
    flex-shrink: 0;
    height: 1.4rem;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 2;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.severity-critical {
    color: var(--danger);
    border-color: rgba(248, 81, 73, 0.45);
    background: rgba(248, 81, 73, 0.08);
}

.severity-warning {
    color: var(--warning);
    border-color: rgba(210, 153, 34, 0.45);
    background: rgba(210, 153, 34, 0.08);
}

.severity-info {
    color: var(--accent);
    border-color: rgba(88, 166, 255, 0.4);
    background: rgba(88, 166, 255, 0.08);
}

.finding-message {
    min-width: 0;
    display: inline-flex;
    align-items: center;
}

/* Accessibility */

/* Visually hidden but still readable by screen readers. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Code highlighting */

/* Overlay for colored code-line highlights.
   translateY is applied via JS to keep highlights in sync with textarea scroll.
   No overflow clipping here — code-editor clips based on the visual (post-transform) position. */
.code-highlights {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Each highlight is absolutely positioned; top/height are set in JS from computed px values. */
.code-highlight-line {
    position: absolute;
    left: 0;
    right: 0;
    opacity: 0.18;
    transition: opacity 600ms ease;
}

.code-highlight-line.code-highlight-active {
    opacity: 0.55;
    transition: opacity 0ms;
}

.code-highlight-critical { background: var(--danger); }
.code-highlight-warning  { background: var(--warning); }
.code-highlight-info     { background: var(--accent); }

/* Tooltip shown when hovering a highlighted code line. */
.code-tooltip {
    position: fixed;
    z-index: 100;
    max-width: 320px;
    padding: 8px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.tooltip-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 3px 0;
}

.tooltip-message {
    font-size: 0.8rem;
    color: var(--muted-light);
    line-height: 1.45;
    overflow-wrap: break-word;
}

/* position relative is required so the overlay aligns inside the editor. */
.code-editor {
    position: relative;
}

/* Responsive */

@media (max-width: 640px) {
    .app { width: calc(100% - 20px); padding-top: 20px; }

    .site-header,
    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .btn-ghost { flex: 1; justify-content: center; }

    .settings-menu {
        right: 0;
        width: min(176px, calc(100vw - 32px));
    }

    .code-textarea { min-height: 300px; padding: 16px; }

    .results-panel { padding: 16px; }

    .results-list li {
        flex-direction: column;
        gap: 6px;
        align-items: flex-start;
    }
}
