/* Nathan — Research Optimizer | arvak.io/nathan */

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a24;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --success: #22c55e;
    --warning: #eab308;
    --error: #ef4444;
    --border-color: #2a2a35;
    --code-bg: #16161e;
    --nathan-accent: #22d3ee; /* cyan for Nathan branding */
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
    overflow-y: auto;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ---- Header ---- */
.nathan-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: 56px;
}

.nathan-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
}

.nathan-logo-icon {
    width: 28px;
    height: 28px;
    background: var(--accent-gradient);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: white;
}

.nathan-logo-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.nathan-logo-text span {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s;
}

.header-link:hover { color: var(--text-primary); }

.btn-cta {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-cta:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

/* ---- Hero ---- */
.nathan-hero {
    text-align: center;
    padding: 2rem 1.5rem 1.5rem;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.nathan-hero h1 {
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.nathan-hero > p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 640px;
    margin: 0 auto 0.75rem;
    line-height: 1.6;
}

.nathan-hero > p.hero-secondary {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.nathan-hero > p.hero-secondary code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    color: var(--nathan-accent);
}

.install-pills {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.install-pill {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    user-select: all;
}

.install-pill:hover {
    color: var(--nathan-accent);
    border-color: var(--nathan-accent);
    background: rgba(34, 211, 238, 0.05);
}

.install-pill.all {
    color: var(--accent-primary);
    border-color: rgba(99, 102, 241, 0.3);
}

.install-pill.all:hover {
    color: var(--accent-secondary);
    border-color: var(--accent-secondary);
    background: rgba(99, 102, 241, 0.08);
}

.example-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.example-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-right: 0.25rem;
}

.example-btn {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.example-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

/* ---- Main Layout ---- */
.nathan-main {
    display: flex;
    height: calc(100vh - 56px - 140px);
    min-height: 500px;
}

/* ---- Editor Panel (Left) ---- */
.editor-panel {
    flex: 0 0 60%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    min-width: 0;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 0.5rem;
}

.language-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
}

.language-tab {
    padding: 0.35rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.language-tab:hover { color: var(--text-secondary); }
.language-tab.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.backend-select {
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    outline: none;
}

.backend-select:focus {
    border-color: var(--accent-primary);
}

.btn-analyze {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 0.4rem 1.25rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-analyze:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-analyze:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-analyze .spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn-analyze.loading .spinner { display: block; }
.btn-analyze.loading .btn-text { display: none; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

.editor-container {
    flex: 1;
    overflow: hidden;
}

/* CodeMirror overrides */
.cm-editor {
    height: 100%;
    font-size: 14px;
}

.cm-editor .cm-content {
    font-family: 'JetBrains Mono', monospace;
}

.cm-editor .cm-gutters {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    color: var(--text-muted);
}

.cm-editor .cm-activeLineGutter {
    background: var(--bg-tertiary);
}

.cm-editor .cm-activeLine {
    background: rgba(99, 102, 241, 0.05);
}

/* ---- Response Panel (Right) ---- */
.response-panel {
    flex: 0 0 40%;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.response-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    height: 45px;
}

.response-header h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.response-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-primary);
    border-radius: 6px;
    padding: 2px;
}

.response-tab {
    padding: 0.3rem 0.6rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.response-tab:hover { color: var(--text-secondary); }
.response-tab.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.response-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* ---- Welcome State ---- */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    background: var(--accent-gradient);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.2);
}

.welcome-state h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.welcome-state p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    max-width: 300px;
    margin-bottom: 1.5rem;
}

.template-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.template-chip {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.template-chip:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

/* ---- Analysis Cards ---- */
.analysis-section {
    margin-bottom: 1.25rem;
}

.analysis-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.analysis-card h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.suitability-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.25rem;
}

.suitability-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.suitability-fill.high { background: var(--success); }
.suitability-fill.medium { background: var(--warning); }
.suitability-fill.low { background: var(--error); }

/* ---- Paper References ---- */
.paper-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.paper-item:last-child { border-bottom: none; }

.paper-icon {
    color: var(--accent-primary);
    font-size: 0.75rem;
    margin-top: 0.15rem;
    flex-shrink: 0;
}

.paper-title {
    font-size: 0.8rem;
    color: var(--text-primary);
}

.paper-title a {
    color: var(--accent-primary);
    text-decoration: none;
}

.paper-title a:hover { text-decoration: underline; }

.paper-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* ---- Suggestions ---- */
.suggestion-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.suggestion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.4rem;
}

.suggestion-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
}

.impact-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-weight: 500;
    text-transform: uppercase;
}

.impact-badge.high {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.impact-badge.medium {
    background: rgba(234, 179, 8, 0.15);
    color: var(--warning);
}

.impact-badge.low {
    background: rgba(160, 160, 176, 0.15);
    color: var(--text-secondary);
}

.suggestion-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.suggestion-code {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
    overflow-x: auto;
    white-space: pre;
    position: relative;
}

.btn-copy {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.65rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-copy:hover {
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

/* ---- Chat ---- */
.chat-view {
    display: none;
    flex-direction: column;
    height: 100%;
}

.chat-view.active { display: flex; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.chat-message {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.75rem;
}

.chat-message.user { justify-content: flex-end; }

.chat-avatar {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-message.assistant .chat-avatar {
    background: var(--accent-gradient);
    color: white;
}

.chat-message.user .chat-avatar {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    order: 1;
}

.chat-bubble {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.6;
}

.chat-message.assistant .chat-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.chat-message.user .chat-bubble {
    background: var(--accent-primary);
    color: white;
}

.chat-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    outline: none;
    resize: none;
}

.chat-input:focus {
    border-color: var(--accent-primary);
}

.btn-send {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-send:hover { transform: translateY(-1px); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- LLM Response (markdown-style) ---- */
.llm-response {
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.llm-response h1, .llm-response h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem;
    color: var(--text-primary);
}

.llm-response h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0.75rem 0 0.35rem;
}

.llm-response p { margin-bottom: 0.5rem; }

.llm-response code {
    background: var(--code-bg);
    padding: 0.15rem 0.35rem;
    border-radius: 3px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.llm-response pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.75rem;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.llm-response pre code {
    background: none;
    padding: 0;
}

.llm-response ul, .llm-response ol {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
}

.llm-response li { margin-bottom: 0.25rem; }

.llm-response strong { color: var(--text-primary); }

.llm-response a {
    color: var(--accent-primary);
    text-decoration: none;
}

.llm-response a:hover { text-decoration: underline; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .nathan-main {
        flex-direction: column;
    }

    .editor-panel {
        flex: 0 0 50%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .response-panel { flex: 0 0 50%; }
}

@media (max-width: 600px) {
    .editor-panel { flex: 0 0 45%; }
    .response-panel { flex: 0 0 55%; }

    .language-tabs { gap: 0; }
    .language-tab { padding: 0.3rem 0.5rem; font-size: 0.7rem; }

    .header-link { display: none; }
}

/* ---- Privacy Notice (inline) ---- */
.privacy-notice {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.5rem;
    max-width: 600px;
    margin: 0 auto 1.25rem;
    padding: 0.6rem 1rem;
    background: rgba(34, 211, 238, 0.05);
    border: 1px solid rgba(34, 211, 238, 0.15);
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.6;
    text-align: left;
}

.privacy-notice svg {
    flex-shrink: 0;
    margin-top: 0.2rem;
    color: var(--nathan-accent);
}

.privacy-notice a {
    color: var(--nathan-accent);
    text-decoration: none;
}

.privacy-notice a:hover {
    text-decoration: underline;
}

/* ---- Privacy Section (footer) ---- */
.privacy-section {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 3rem 1.5rem;
}

.privacy-content {
    max-width: 800px;
    margin: 0 auto;
}

.privacy-content h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.privacy-content > p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 1.25rem;
}

.privacy-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.privacy-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}

.privacy-card h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.75rem;
}

.privacy-card ul {
    list-style: none;
    padding: 0;
}

.privacy-card li {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0.25rem 0;
    padding-left: 1rem;
    position: relative;
    line-height: 1.5;
}

.privacy-card li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.6rem;
    width: 4px;
    height: 4px;
    border-radius: 50%;
}

/* "removed" items get red dots, "preserved" get green */
.privacy-card:first-child li::before { background: var(--error); }
.privacy-card:last-child li::before { background: var(--success); }

.privacy-card code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    color: var(--nathan-accent);
}

.privacy-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.privacy-note code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    background: var(--bg-tertiary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    color: var(--nathan-accent);
}

@media (max-width: 600px) {
    .privacy-grid { grid-template-columns: 1fr; }
}
