/* CSS Variables for theming */
:root {
    --bg-primary: #1e1e2e;
    --bg-secondary: #2a2a3e;
    --bg-cell: #252535;
    --bg-input: #1a1a28;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b0;
    --text-muted: #6c6c7c;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --border: #3a3a4e;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header and toolbar */
#header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
}

#header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--accent);
    letter-spacing: -0.02em;
}

#toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

#toolbar button {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-cell);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: var(--font-sans);
}

#toolbar button:hover {
    background: var(--accent);
    border-color: var(--accent);
}

#toolbar button:active {
    transform: scale(0.98);
}

#toolbar .icon {
    font-size: 0.9rem;
}

#toolbar .spacer {
    flex: 1;
}

/* Main notebook area */
#notebook {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

#cells-container {
    max-width: 900px;
    margin: 0 auto;
}

/* Cell structure */
.cell {
    background: var(--bg-cell);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.cell:hover {
    border-color: #4a4a5e;
}

.cell.focused {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}

.cell.running {
    border-color: var(--warning);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

.cell.error {
    border-color: var(--error);
}

/* Cell toolbar */
.cell-toolbar {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 0.25rem;
}

.cell-number {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-right: auto;
    padding: 0 0.25rem;
}

.cell-toolbar button {
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.1s;
}

.cell-toolbar button:hover {
    background: var(--bg-cell);
    color: var(--text-primary);
}

.cell-toolbar .btn-run {
    color: var(--success);
}

.cell-toolbar .btn-run:hover {
    background: rgba(16, 185, 129, 0.15);
}

.cell-toolbar .btn-delete:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
}

/* Code input area */
.cell-input {
    position: relative;
    display: flex;
}

.cell-input .line-numbers {
    width: 3rem;
    padding: 0.75rem 0.5rem;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-muted);
    background: var(--bg-secondary);
    user-select: none;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.cell-input textarea {
    flex: 1;
    min-height: 80px;
    padding: 0.75rem;
    background: var(--bg-input);
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    overflow: hidden;
}

.cell-input textarea::placeholder {
    color: var(--text-muted);
}

/* Output area */
.cell-output {
    padding: 0.75rem 1rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.cell-output:empty {
    display: none;
}

.cell-output .result {
    color: var(--success);
}

.cell-output .result::before {
    content: '=> ';
    color: var(--text-muted);
}

.cell-output .print {
    color: var(--text-primary);
}

.cell-output .error {
    color: var(--error);
}

.cell-output .error::before {
    content: 'Error: ';
    font-weight: 600;
}

/* Status bar */
#status-bar {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Modal styles */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem 2rem;
    max-width: 650px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--accent);
    font-size: 1.5rem;
}

.modal-content h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    color: var(--text-primary);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.modal-content ul {
    margin-left: 1.25rem;
    color: var(--text-secondary);
}

.modal-content li {
    margin-bottom: 0.25rem;
}

.modal-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 0.5rem;
}

.modal-content td {
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.modal-content td:first-child {
    font-family: var(--font-mono);
    color: var(--accent);
    white-space: nowrap;
    font-size: 0.875rem;
}

.modal-content td:last-child {
    color: var(--text-secondary);
}

.modal-content pre {
    background: var(--bg-input);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin-top: 0.5rem;
}

.modal-content code {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.modal-content button {
    margin-top: 1.25rem;
    padding: 0.6rem 1.25rem;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s;
}

.modal-content button:hover {
    background: var(--accent-hover);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

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

::-webkit-scrollbar-thumb:hover {
    background: #4a4a5e;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #header {
        padding: 0.5rem;
    }

    #header h1 {
        font-size: 1.1rem;
    }

    #toolbar button {
        padding: 0.35rem 0.5rem;
        font-size: 0.8rem;
    }

    #toolbar button span:not(.icon) {
        display: none;
    }

    #notebook {
        padding: 0.75rem;
    }

    .modal-content {
        margin: 1rem;
        padding: 1rem;
    }
}
