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

body {
    font-family: var(--global-font);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

.view-active {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    overflow: hidden;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input {
    font-family: inherit;
}

/* -------------------------------------------
   LANDING HEADER
------------------------------------------- */
.landing-header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 5;
}

.landing-header .logo {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    color: var(--primary-color);
}

.user-id {
    background-color: var(--user-id-bg);
    color: var(--user-id-color);
    padding: 6px 12px;
    border-radius: 8px;
    font-family: monospace;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    font-size: 0.85rem;
}

.user-id:hover {
    opacity: 0.85;
}

.user-id:active {
    transform: scale(0.95);
}

/* -------------------------------------------
   LANDING — SPLIT SCREEN
------------------------------------------- */
.landing-split {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* LEFT PANEL */
.landing-left {
    flex: 0 0 50%;
    max-width: 50%;
    overflow-y: auto;
    padding: 48px 48px 80px 48px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: var(--bg-color);
    border-right: 1px solid var(--border-color);
}

.hero {
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.hero-badge {
    background-color: #e0e7ff;
    color: #4338ca;
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 20px;
}

.hero h1 {
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1.1;
    color: #0f172a;
    letter-spacing: -0.02em;
    margin-bottom: 14px;
}

.hero-highlight {
    color: var(--primary-color);
}

.hero p {
    font-size: 1rem;
    color: #64748b;
    margin-bottom: 24px;
    line-height: 1.5;
}

.feature-pills {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.feature-pills span {
    background-color: #f1f5f9;
    color: #475569;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid #e2e8f0;
}

/* Search Container */
.search-container {
    background: white;
    padding: 24px;
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 20px 25px -5px rgba(0, 0, 0, 0.05);
    width: 100%;
    border: 1px solid #f1f5f9;
    margin-bottom: 32px;
}

.search-box label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: #334155;
    margin-bottom: 8px;
}

.search-box input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 16px;
    color: #0f172a;
}

.search-box input:focus {
    border-color: var(--primary-color);
}

.suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.sugg-btn {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #64748b;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    transition: all 0.2s;
    text-align: left;
}

.sugg-btn:hover {
    background-color: #ede9fe;
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.primary-btn-large {
    width: 100%;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 8px;
    font-size: 1.05rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.primary-btn-large:hover {
    filter: brightness(1.1);
}

/* History Cards */
.history-section {
    width: 100%;
    margin-bottom: 40px;
}

.history-label {
    font-size: 0.875rem;
    font-weight: 700;
    color: #64748b;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.history-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.history-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    width: calc(50% - 6px);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.history-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.07);
    border-color: var(--primary-color);
}

.history-title {
    font-weight: 700;
    color: #0f172a;
    font-size: 0.9rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-date {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* RIGHT PANEL */
.landing-right {
    flex: 0 0 50%;
    max-width: 50%;
    background: linear-gradient(145deg, #f8f5ff 0%, #eef2ff 50%, #f0fdf4 100%);
    overflow-y: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 40px;
}

.rp-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 480px;
    width: 100%;
}

.rp-sub {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 12px;
}

.rp-title {
    font-size: 2rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.2;
    margin-bottom: 28px;
}

.rp-highlight {
    color: var(--primary-color);
}

/* Sample Paper */
.rp-paper {
    background: white;
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
    font-family: 'Kalam', cursive;
    font-size: 0.78rem;
    line-height: 1.5;
    border: 1px solid #e2e8f0;
    position: relative;
}

.rp-paper-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px dashed #e2e8f0;
    font-family: 'Outfit', sans-serif;
}

.rp-cols {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

.rp-section {
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    line-height: 1.55;
}

.rp-h {
    font-weight: 700;
    font-size: 0.78rem;
    margin-bottom: 4px;
    text-decoration: underline;
}

.rp-pink {
    background: #fce7f3;
    color: #831843;
}

.rp-pink .rp-h {
    color: #be185d;
}

.rp-blue {
    background: #dbeafe;
    color: #1e3a8a;
}

.rp-blue .rp-h {
    color: #1d4ed8;
}

.rp-purple {
    background: #ede9fe;
    color: #4c1d95;
}

.rp-purple .rp-h {
    color: #7c3aed;
}

.rp-green {
    background: #dcfce7;
    color: #14532d;
}

.rp-green .rp-h {
    color: #16a34a;
}

.rp-orange {
    background: #ffedd5;
    color: #7c2d12;
}

.rp-orange .rp-h {
    color: #ea580c;
}

.rp-bullets {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.rp-bullets span {
    background: white;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

/* -------------------------------------------
   EDITOR VIEW
------------------------------------------- */
.editor-toolbar {
    height: 64px;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    z-index: 10;
    flex-shrink: 0;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.icon-btn,
.icon-btn-small {
    background: none;
    border: none;
    color: var(--text-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.icon-btn {
    padding: 8px 12px;
    font-size: 0.9rem;
}

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

.icon-btn-small {
    padding: 4px;
    font-size: 1.2rem;
    width: 28px;
    height: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn-small:hover {
    background-color: var(--bg-color);
}

.doc-icon {
    color: var(--primary-color);
    display: flex;
    align-items: center;
}

#editor-topic-title {
    font-size: 1rem;
    font-weight: 700;
    color: #0f172a;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.tool-label {
    font-size: 0.75rem;
    color: #64748b;
    margin-right: 8px;
    text-transform: uppercase;
    font-weight: 700;
}

.tool-val {
    font-size: 0.875rem;
    font-weight: 600;
    width: 24px;
    text-align: center;
}

.col-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid transparent;
    background: transparent;
    font-size: 0.875rem;
    font-weight: 600;
    color: #64748b;
}

.col-btn.active {
    background: var(--primary-color);
    color: white;
}

.col-btn:hover:not(.active) {
    background: var(--bg-color);
}

.toggle-group {
    background: #f1f5f9;
    border-radius: 8px;
    padding: 4px;
    gap: 0;
}

.toggle-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toggle-btn.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.font-select {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: white;
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
}

.divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 8px;
}

.export-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: filter 0.2s;
}

.export-btn:hover {
    filter: brightness(1.1);
}

/* Editor Layout */
.editor-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: #f1f5f9;
}

.canvas-container {
    flex: 1;
    overflow: auto;
    position: relative;
    padding: 60px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    cursor: grab;
}

.canvas-container:active {
    cursor: grabbing;
}

.paper-background {
    background-color: #ffffff;
}

.canvas {
    width: 100%;
    max-width: 1200px;
    min-height: 842px;
    padding: 24px 32px;
    border-radius: 2px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    column-count: var(--columns);
    column-gap: 18px;
    transform-origin: top center;
    transition: transform 0.1s ease-out;
}

/* Typography */
.font-handwriting {
    font-family: var(--hw-font) !important;
}

.font-regular {
    font-family: 'Inter', sans-serif !important;
}

/* Sheet Sections */
.sheet-section {
    padding: 2px 4px;
    margin-bottom: 8px;
    break-inside: avoid-column;
    position: relative;
    color: var(--ink-body-blue, #1e3a8a);
    line-height: 1.2;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Section Controls (drag handle + move buttons) */
.section-controls {
    display: none;
    align-items: center;
    gap: 4px;
    position: absolute;
    top: -2px;
    right: 2px;
    z-index: 5;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 4px;
    padding: 1px 3px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.sheet-section:hover .section-controls {
    display: flex;
}

.drag-handle {
    cursor: grab;
    font-size: 14px;
    color: #94a3b8;
    padding: 2px 4px;
    user-select: none;
    line-height: 1;
}

.drag-handle:active {
    cursor: grabbing;
}

.move-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 10px;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 3px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}

.move-btn:hover {
    color: var(--primary-color);
    background: #ede9fe;
}

.move-btn.delete-btn:hover {
    color: #dc2626;
    background: #fee2e2;
}

/* Add Blank Note Button */
.add-note-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    background: rgba(91, 76, 245, 0.08);
    color: var(--primary-color);
    border: 1px dashed var(--primary-color);
    border-radius: 6px;
    font-weight: bold;
    text-align: center;
    break-inside: avoid-column;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.add-note-btn:hover {
    background: rgba(91, 76, 245, 0.18);
}

.section-content {
    outline: none;
}

.sheet-section h4 {
    margin-bottom: 3px;
    font-size: 1.1em;
    text-decoration: underline;
    font-weight: 700;
}

.sheet-section p,
.sheet-section ul {
    margin-bottom: 3px;
}

.sheet-section ul {
    padding-left: 16px;
}

.sheet-section li {
    margin-bottom: 1px;
}

.formula {
    font-family: 'Courier New', monospace;
    padding: 0 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 2px;
    font-size: 0.9em;
    background: rgba(0, 0, 0, 0.03);
}

.example-box {
    margin-top: 4px;
    padding: 4px 8px;
    border-left: 2px solid var(--ink-header-red, #dc2626);
    font-style: italic;
    font-size: 0.85em;
    color: var(--ink-body-black, #1e293b);
    background: rgba(220, 38, 38, 0.04);
    overflow-wrap: break-word;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(244, 246, 248, 0.92);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #cbd5e1;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

#loading-overlay h3 {
    color: #0f172a;
    margin-bottom: 8px;
    font-size: 1.5rem;
}

#loading-overlay p {
    color: #64748b;
}

/* -------------------------------------------
   CHAT ASSISTANT PANEL
------------------------------------------- */
.chat-panel {
    width: 340px;
    min-width: 340px;
    background-color: #ffffff;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.collapsed {
    margin-right: -340px;
    border-left: none;
}

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

.chat-header h3 {
    font-size: 1rem;
    color: #0f172a;
}

/* Prompt Examples */
.chat-examples {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: #fafafa;
    flex-shrink: 0;
}

.chat-examples-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.chat-example-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.78rem;
    color: #475569;
    margin-bottom: 6px;
    transition: border-color 0.2s, color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-example-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8fafc;
}

.message {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.85rem;
    max-width: 90%;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.ai {
    background: #e2e8f0;
    color: #0f172a;
    align-self: flex-start;
    border-top-left-radius: 4px;
}

.message.user {
    background: var(--primary-color);
    color: white;
    align-self: flex-end;
    border-top-right-radius: 4px;
}

/* File Previews */
.chat-files-preview {
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: #f8fafc;
    flex-shrink: 0;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #ede9fe;
    border: 1px solid #c4b5fd;
    border-radius: 20px;
    padding: 4px 10px;
    font-size: 0.75rem;
    color: #5b21b6;
    max-width: 180px;
}

.file-chip-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

.file-chip-remove {
    background: none;
    border: none;
    color: #7c3aed;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.file-chip-remove:hover {
    color: #dc2626;
}

/* Chat Input */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.file-upload-label {
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.file-upload-label:hover {
    background: #f1f5f9;
}

.chat-input-area input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 24px;
    border: 1px solid var(--border-color);
    outline: none;
    font-size: 0.875rem;
}

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

.send-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: filter 0.2s;
}

.send-btn:hover {
    filter: brightness(1.1);
}

/* Floating Chat Button */
.floating-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: white;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 12px 20px;
    border-radius: 30px;
    font-weight: 600;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s;
}

.floating-chat-btn:hover {
    transform: translateY(-2px);
}

/* -------------------------------------------
   TOASTS
------------------------------------------- */
#toast-container {
    position: fixed;
    bottom: 24px;
    left: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background-color: var(--toast-bg);
    color: var(--toast-text);
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideIn 0.3s;
    transition: opacity 0.35s, transform 0.35s;
    max-width: 320px;
}

@keyframes slideIn {
    from {
        transform: translateX(-120%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* -------------------------------------------
   RESPONSIVE
------------------------------------------- */
@media (max-width: 900px) {
    .landing-split {
        flex-direction: column;
    }

    .landing-left,
    .landing-right {
        flex: none;
        max-width: 100%;
        width: 100%;
    }

    .landing-right {
        display: none;
    }

    .rp-cols {
        grid-template-columns: 1fr 1fr;
    }

    .toolbar-center {
        display: none;
    }

    .chat-panel {
        width: 100%;
        min-width: unset;
        margin-right: 0;
    }

    .chat-panel.collapsed {
        margin-right: 0;
        display: none;
    }
}