/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a1a;
    --bg-input: #1e1e1e;
    --bg-hover: #242424;
    --border: #2a2a2a;
    --border-focus: #444;
    --text-primary: #f0f0f0;
    --text-secondary: #999;
    --text-muted: #666;
    --accent: #4f8ff7;
    --accent-hover: #3a7ae0;
    --accent-subtle: rgba(79, 143, 247, 0.1);
    --success: #34d399;
    --success-bg: rgba(52, 211, 153, 0.1);
    --warning: #fbbf24;
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, 0.1);
    --radius: 8px;
    --radius-lg: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

/* Layout */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.nav {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    letter-spacing: -0.02em;
}

.nav-brand span { color: var(--text-muted); font-weight: 400; }

.nav-logo {
    height: 20px;
    width: auto;
    vertical-align: middle;
}

.nav-links { display: flex; gap: 0.25rem; }

.nav-links a {
    color: var(--text-secondary);
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    font-size: 0.875rem;
    transition: all 0.15s;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--text-primary);
    background: var(--bg-hover);
}

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

.nav-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.nav-user img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

.container-wide {
    max-width: 1200px;
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.card + .card { margin-top: 1rem; }

/* Forms */
label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

input, textarea, select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.625rem 0.875rem;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.875rem;
    transition: border-color 0.15s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--border-focus);
}

textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
}

textarea.notes-input {
    min-height: 240px;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group { margin-bottom: 1rem; }

/* Tag Input */
.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 40px;
    cursor: text;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 0.1875rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8125rem;
}

.tag button {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    opacity: 0.7;
}

.tag button:hover { opacity: 1; }

.tag-input {
    border: none;
    background: none;
    padding: 0.1875rem;
    min-width: 80px;
    flex: 1;
}

.tag-input:focus { outline: none; }

/* People chips */
.people-section { margin-bottom: 1rem; }
.people-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.person-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    padding: 0.25rem 0.625rem;
    border-radius: 20px;
    font-size: 0.8125rem;
    margin: 0.125rem;
}

.person-chip.internal { border-color: var(--accent); background: var(--accent-subtle); }
.person-chip.external { border-color: var(--border); }

.person-chip select {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0;
    width: auto;
    min-width: 70px;
    background-image: none;
}

.person-chip button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 0.875rem;
}

/* Action Items */
.action-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-input);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}

.action-item input[type="text"] {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0;
}

.action-item input[type="text"]:focus { border: none; }

.action-item select {
    width: 140px;
    background: transparent;
    border: none;
    font-size: 0.8125rem;
    padding: 0;
    background-image: none;
}

.action-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.125rem;
    padding: 0;
}

.action-remove:hover { color: var(--danger); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

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

.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger);
    color: #fff;
}

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

.btn-group { display: flex; gap: 0.5rem; }

/* Metadata panel (after extraction) */
.metadata-panel {
    display: none;
    animation: fadeIn 0.2s ease;
}

.metadata-panel.visible { display: block; }

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

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.1875rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-investor { background: #2d1f5e; color: #a78bfa; }
.badge-customer { background: #1e3a2f; color: #34d399; }
.badge-bd { background: #2d2a1f; color: #fbbf24; }
.badge-internal { background: #1e2d3a; color: #60a5fa; }
/* Checkbox in tables */
.notes-table input[type="checkbox"] { cursor: pointer; }
.notes-table tr:has(input[type="checkbox"]:checked) td { opacity: 0.5; }

.badge-competitive { background: #3a1e2d; color: #f472b6; }
.badge-other { background: #2a2a2a; color: #999; }

/* Notes list */
.notes-table {
    width: 100%;
    border-collapse: collapse;
}

.notes-table th {
    text-align: left;
    padding: 0.625rem 0.875rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.notes-table td {
    padding: 0.875rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    vertical-align: top;
}

.notes-table tr:hover td { background: var(--bg-hover); }

.notes-table .note-summary {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

.notes-table .note-company {
    font-weight: 500;
}

.notes-table .note-date {
    color: var(--text-muted);
    font-size: 0.8125rem;
    white-space: nowrap;
}

.notes-table .note-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.mini-tag {
    font-size: 0.6875rem;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    background: var(--bg-hover);
    color: var(--text-secondary);
}

/* Filters bar */
.filters-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.filters-bar input, .filters-bar select {
    width: auto;
    min-width: 160px;
}

/* Suggestions dropdown */
.suggestions-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 0.25rem;
    z-index: 50;
    max-height: 280px;
    overflow-y: auto;
}

.suggestion-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--bg-hover); }

/* Ask / RAG */
.ask-input-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.ask-input-row input {
    flex: 1;
}

.answer-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

/* Markdown rendering in answer cards */
.answer-card.markdown-body { white-space: normal; }
.answer-card.markdown-body h1, .answer-card.markdown-body h2, .answer-card.markdown-body h3 {
    color: var(--text-primary); margin: 1rem 0 0.5rem; font-weight: 600;
}
.answer-card.markdown-body h1 { font-size: 1.25rem; }
.answer-card.markdown-body h2 { font-size: 1.125rem; }
.answer-card.markdown-body h3 { font-size: 1rem; }
.answer-card.markdown-body p { margin: 0.5rem 0; }
.answer-card.markdown-body ul, .answer-card.markdown-body ol {
    margin: 0.5rem 0; padding-left: 1.5rem;
}
.answer-card.markdown-body li { margin: 0.25rem 0; }
.answer-card.markdown-body strong { color: var(--text-primary); }
.answer-card.markdown-body code {
    background: var(--bg-hover); padding: 0.125rem 0.375rem; border-radius: 3px;
    font-family: var(--font-mono); font-size: 0.8125rem;
}
.answer-card.markdown-body blockquote {
    border-left: 3px solid var(--accent); padding-left: 1rem; margin: 0.75rem 0;
    color: var(--text-secondary); font-style: italic;
}
.answer-card.markdown-body hr {
    border: none; border-top: 1px solid var(--border); margin: 1rem 0;
}

.answer-card .source-tag {
    display: inline-block;
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    margin: 0.125rem;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border) 50%, var(--bg-hover) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.skeleton-row {
    display: flex;
    gap: 1rem;
    padding: 0.875rem;
    border-bottom: 1px solid var(--border);
    align-items: center;
}

.skeleton-line {
    height: 14px;
    border-radius: 4px;
}

.skeleton-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-card {
    text-align: center;
    padding: 3rem;
    max-width: 400px;
    width: 100%;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.875rem;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    background: #fff;
    color: #333;
    border: 1px solid #ddd;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-google:hover {
    background: #f5f5f5;
    border-color: #ccc;
}

.btn-google svg { width: 20px; height: 20px; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    z-index: 1000;
    animation: slideUp 0.2s ease;
}

.toast-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.toast-error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Note detail modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
}

.modal-close {
    float: right;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
}

/* Hamburger button — hidden on desktop */
.hamburger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    flex-direction: column;
    gap: 4px;
}
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 1px;
    transition: all 0.2s;
}

/* Mobile menu — hidden on desktop */
.mobile-menu {
    display: none;
    flex-direction: column;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
}
.mobile-menu.open { display: flex; }
.mobile-menu a {
    color: var(--text-secondary);
    padding: 0.75rem 0.5rem;
    font-size: 0.9375rem;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
}
.mobile-menu a:last-child { border-bottom: none; }
.mobile-menu a.active { color: var(--text-primary); }
.mobile-menu a:hover { color: var(--text-primary); }

/* Responsive — mobile */
@media (max-width: 768px) {
    .container { padding: 1rem; }
    .container-wide { max-width: 100%; }
    .form-row { grid-template-columns: 1fr; }

    /* Nav: show hamburger, hide desktop links */
    .nav {
        padding: 0 0.75rem;
        height: 48px;
    }
    .nav-brand { font-size: 0.875rem; }
    .nav-links { display: none; }
    .nav-user { display: none; }
    .hamburger { display: flex; }

    /* Filters */
    .filters-bar { flex-direction: column; gap: 0.5rem; }
    .filters-bar input, .filters-bar select { width: 100%; min-width: 0; }

    /* Tables: make scrollable and hide less important columns */
    .notes-table { display: block; overflow-x: auto; }
    .notes-table th:nth-child(4),
    .notes-table td:nth-child(4),
    .notes-table th:nth-child(5),
    .notes-table td:nth-child(5) { display: none; }
    .notes-table th, .notes-table td { padding: 0.625rem 0.5rem; font-size: 0.8125rem; }

    /* Modal: full width on mobile */
    .modal {
        width: 95%;
        max-height: 90vh;
        padding: 1.25rem;
        margin: 1rem;
    }

    /* Ask input */
    .ask-input-row { flex-direction: column; }
    .ask-input-row input { width: 100%; }

    /* Answer card */
    .answer-card { padding: 1rem; font-size: 0.875rem; }

    /* Login */
    .login-card { padding: 2rem 1.5rem; }

    /* Analytics */
    .card canvas { max-height: 220px; }

    /* Page header */
    .page-header h1 { font-size: 1.25rem; }

    /* Buttons */
    .btn-lg { padding: 0.625rem 1.25rem; font-size: 0.875rem; }

    /* Toast */
    .toast { left: 1rem; right: 1rem; bottom: 1rem; text-align: center; }

    /* Action items table: hide less important columns */
    .notes-table th:nth-child(5),
    .notes-table td:nth-child(5),
    .notes-table th:nth-child(6),
    .notes-table td:nth-child(6) { display: none; }
}

/* Analytics grid on mobile */
@media (max-width: 768px) {
    #stats-summary { grid-template-columns: repeat(2, 1fr) !important; }
    #pipeline-summary { grid-template-columns: repeat(3, 1fr) !important; }
    .analytics-grid { grid-template-columns: 1fr !important; }
}
