/* ============================================================
   Nootbook Design System
   A clean, modern CSS foundation with no external dependencies.
   ============================================================ */

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

:root {
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-surface-hover: #f1f3f5;
    --color-border: #e1e4e8;
    --color-text: #1a1a2e;
    --color-text-secondary: #586069;
    --color-text-muted: #8b949e;
    --color-primary: #4f46e5;
    --color-primary-hover: #4338ca;
    --color-primary-light: #eef2ff;
    --color-success: #059669;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-danger-hover: #b91c1c;
    --color-info: #2563eb;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.1);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "Cascadia Code", "Fira Code", monospace;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* ---------- Navbar ---------- */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand a {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--color-text);
}

.logo {
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}

.brand-text {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-user {
    font-size: 14px;
    color: var(--color-text-secondary);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-outline {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-outline:hover { background: var(--color-surface-hover); }

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

.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-full { width: 100%; }

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    opacity: 0.5;
    font-size: 16px;
}
.btn-icon:hover { opacity: 1; background: var(--color-surface-hover); }

.btn-group {
    display: flex;
    gap: 6px;
}

/* ---------- Forms ---------- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--color-text);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: var(--font-sans);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-error {
    color: var(--color-danger);
    font-size: 14px;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #fef2f2;
    border-radius: var(--radius-sm);
}

/* ---------- Auth Pages ---------- */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px);
    padding: 24px;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.auth-card h2 {
    font-size: 24px;
    margin-bottom: 4px;
}

.auth-subtitle {
    color: var(--color-text-secondary);
    margin-bottom: 24px;
}

.auth-form { margin-top: 8px; }

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--color-text-secondary);
}

/* ---------- Hero / Landing ---------- */
.hero {
    max-width: 1000px;
    margin: 0 auto;
    padding: 60px 24px;
    text-align: center;
}

.hero h1 {
    font-size: 48px;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--color-primary), #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 20px;
    color: var(--color-text-secondary);
    max-width: 600px;
    margin: 0 auto 32px;
    line-height: 1.5;
}

.hero-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 60px;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    text-align: left;
}

.feature-card {
    background: var(--color-surface);
    padding: 24px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    transition: box-shadow 0.2s;
}

.feature-card:hover { box-shadow: var(--shadow-md); }

.feature-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.feature-card h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.feature-card p {
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

/* ---------- Dashboard ---------- */
.dashboard {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px;
}

.dashboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.dashboard-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.notebooks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.notebook-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-decoration: none;
    color: var(--color-text);
    transition: all 0.15s;
}

.notebook-card:hover {
    text-decoration: none;
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.notebook-card h3 {
    font-size: 17px;
    margin-bottom: 6px;
}

.notebook-desc {
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notebook-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--color-text-muted);
}

.notebook-date {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 8px;
}

/* ---------- Notebook Workspace ---------- */
.notebook-workspace {
    display: flex;
    height: calc(100vh - 56px);
    overflow: hidden;
}

.sidebar {
    width: 340px;
    min-width: 280px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--color-border);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 700;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
}

.upload-btn {
    cursor: pointer;
}

.item-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.item-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    transition: background 0.1s;
}

.item-card.clickable { cursor: pointer; }
.item-card.clickable:hover, .item-card:hover { background: var(--color-surface-hover); }

.item-card.processing { opacity: 0.7; }

.item-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.item-icon { font-size: 20px; flex-shrink: 0; }

.item-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.item-meta {
    font-size: 12px;
    color: var(--color-text-muted);
}

.status-ready { color: var(--color-success); }
.status-processing { color: var(--color-warning); }
.status-failed { color: var(--color-danger); }
.status-pending { color: var(--color-text-muted); }

.empty-hint, .error-hint {
    font-size: 13px;
    color: var(--color-text-muted);
    padding: 8px 0;
    text-align: center;
}

.error-hint { color: var(--color-danger); }

/* ---------- Main Panel ---------- */
.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

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

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.chat-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

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

.chat-welcome {
    text-align: center;
    padding: 60px 24px;
    color: var(--color-text-secondary);
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.chat-welcome h3 {
    font-size: 20px;
    color: var(--color-text);
    margin-bottom: 8px;
}

/* ---------- Messages ---------- */
.message {
    margin-bottom: 24px;
    max-width: 800px;
}

.message.user {
    margin-left: auto;
}

.message-role {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    color: var(--color-text-muted);
}

.message.user .message-role { text-align: right; }

.message-content {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.7;
}

.message.user .message-content {
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
}

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content ul, .message-content ol { margin: 8px 0; padding-left: 20px; }
.message-content li { margin-bottom: 4px; }
.message-content code {
    background: var(--color-surface-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 13px;
}
.message-content strong { font-weight: 600; }
.message-content h1, .message-content h2, .message-content h3 {
    margin-top: 16px;
    margin-bottom: 8px;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ---------- Sources ---------- */
.sources-section {
    margin-top: 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.sources-header {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    background: var(--color-surface-hover);
    cursor: pointer;
    user-select: none;
}

.sources-header::before { content: "\\25B6  "; font-size: 10px; }
.sources-section.expanded .sources-header::before { content: "\\25BC  "; }

.sources-list {
    display: none;
    padding: 8px;
}

.sources-section.expanded .sources-list { display: block; }

.source-item {
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
}

.source-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 4px;
}

.source-text {
    font-size: 13px;
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.source-score {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ---------- Suggested Questions ---------- */
.suggested-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 24px;
}

.suggestion-chip {
    padding: 6px 14px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    background: var(--color-surface);
    font-size: 13px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.suggestion-chip:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-primary-light);
}

/* ---------- Chat Input ---------- */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

.chat-input-area textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-size: 15px;
    font-family: var(--font-sans);
    line-height: 1.5;
    max-height: 150px;
    background: var(--color-bg);
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

/* ---------- Note View ---------- */
.note-view {
    flex-direction: column;
    height: 100%;
}

.note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    gap: 12px;
}

.note-title-input {
    flex: 1;
    border: none;
    font-size: 18px;
    font-weight: 600;
    background: transparent;
    color: var(--color-text);
    outline: none;
}

.note-actions {
    display: flex;
    gap: 8px;
}

.note-content-input {
    flex: 1;
    border: none;
    padding: 24px;
    font-size: 15px;
    font-family: var(--font-sans);
    line-height: 1.7;
    resize: none;
    background: var(--color-bg);
    color: var(--color-text);
    outline: none;
}

/* ---------- Conversations Panel ---------- */
.conversations-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 320px;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    z-index: 10;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--color-border);
}

.panel-header h3 {
    font-size: 16px;
    font-weight: 600;
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.modal-content {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: 32px;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
}

.modal-content h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ---------- Toast Notifications ---------- */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: white;
    min-width: 250px;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
}

.toast-success { background: var(--color-success); }
.toast-error { background: var(--color-danger); }
.toast-info { background: var(--color-info); }
.toast-warning { background: var(--color-warning); }

@keyframes toast-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---------- Utility States ---------- */
.loading-state, .empty-state, .error-state {
    text-align: center;
    padding: 40px 24px;
    color: var(--color-text-secondary);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--color-text);
    margin-bottom: 8px;
}

.loading-state-sm {
    text-align: center;
    font-size: 13px;
    color: var(--color-text-muted);
    padding: 12px;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .notebook-workspace { flex-direction: column; }
    .sidebar { width: 100%; height: auto; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--color-border); }
    .hero h1 { font-size: 32px; }
    .hero-subtitle { font-size: 16px; }
    .conversations-panel { width: 100%; }
}
