/* ==========================================================================
   Collaborative Document, on the shared design system.
   Requires design-tokens.css and ui.css, loaded before this file.

   Selector names are unchanged: collab-doc.js drives the editor, the preview
   and the collaborator list by class. The private indigo palette is gone.

   The editor and the preview keep their own light/dark handling — this app has
   a theme switch of its own, and the tokens describe the chrome around it
   rather than the page being written.
   ========================================================================== */

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

html, body {
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.hidden { display: none !important; }

/* Share Button */
.share-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--brand);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100;
    transition: all 0.3s ease;
}

.share-btn:hover {
    background: var(--brand-strong, #4f46e5);
    transform: translateY(-2px);
}

/* Connection Status */
.connection-status {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 100;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
    animation: pulse 2s infinite;
}

.connection-status.connected .status-dot {
    background: var(--success);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    background: white;
}

/* Header */
.app-header {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

.header-left h1 {
    font-size: 18px;
    color: var(--text);
}

.doc-title {
    flex: 1;
    max-width: 300px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
    color: var(--text);
}

.doc-title:focus {
    outline: none;
    border-color: var(--brand);
}

.room-badge {
    background: var(--surface-3);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.view-mode-toggle {
    display: flex;
    background: var(--surface-3);
    border-radius: 8px;
    padding: 4px;
    gap: 4px;
}

.mode-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: var(--border);
}

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

.theme-toggle button {
    background: var(--surface-3);
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-toggle button:hover {
    background: var(--border);
}

/* Toolbar */
.editor-toolbar {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    gap: 16px;
    align-items: center;
}

.toolbar-group {
    display: flex;
    gap: 4px;
}

.toolbar-btn {
    padding: 8px 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    transition: all 0.2s ease;
}

.toolbar-btn:hover {
    background: var(--surface-3);
    border-color: var(--brand);
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
}

/* Editor Layout */
.editor-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.editor-pane, .preview-pane {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.editor-layout.split .editor-pane,
.editor-layout.split .preview-pane {
    flex: 1;
    border-right: 1px solid var(--border);
}

.editor-layout.split .preview-pane {
    border-right: none;
}

/* CodeMirror Overrides */
.CodeMirror {
    height: 100% !important;
    font-family: 'Courier New', Consolas, monospace;
    font-size: 16px;
    line-height: 1.6;
}

.CodeMirror-lines {
    padding: 20px 0;
}

.CodeMirror-line {
    padding: 0 20px;
}

/* Remote Cursors in Editor */
.remote-cursor {
    position: absolute;
    width: 2px;
    height: 20px;
    z-index: 100;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.remote-cursor-label {
    position: absolute;
    top: -20px;
    left: 2px;
    background: inherit;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    font-family: 'Segoe UI', sans-serif;
}

/* --------------------------------------------------------------------------
   The paper, and the theme that was inside out.

   A mechanical token migration replaced this file's hardcoded colours by
   position rather than by meaning, and `--text` — which is near-white on this
   site — landed everywhere a white *background* had been. The result was the
   preview pane rendering near-white text on white (the app's second headline
   feature, illegible) and a "dark theme" that painted everything pale.

   The preview is paper and says so explicitly, the way the whiteboard's board
   does: it is not derived from the dark palette because it is not part of the
   dark chrome.
   -------------------------------------------------------------------------- */

/* Preview Pane */
.preview-content {
    height: 100%;
    overflow-y: auto;
    padding: 40px;
    background: #ffffff;
    color: #1f2937;          /* ink on paper, not the dark theme's text token */
}

.preview-content.dark {
    background: var(--surface-1);
    color: var(--text);
}

/* Markdown Styling */
.preview-content h1 {
    font-size: 32px;
    margin: 24px 0 16px 0;
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.preview-content h2 {
    font-size: 28px;
    margin: 20px 0 12px 0;
}

.preview-content h3 {
    font-size: 24px;
    margin: 16px 0 10px 0;
}

.preview-content p {
    margin: 12px 0;
    line-height: 1.7;
}

.preview-content code {
    background: var(--surface-3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.preview-content pre {
    background: #f3f4f6;
    color: #111827;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.preview-content pre code {
    background: none;
    color: inherit;
}

.preview-content blockquote {
    border-left: 4px solid var(--brand);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text);
    font-style: italic;
}

.preview-content ul, .preview-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.preview-content li {
    margin: 6px 0;
}

.preview-content a {
    color: var(--brand);
    text-decoration: none;
}

.preview-content a:hover {
    text-decoration: underline;
}

/* Status Bar */
.status-bar {
    background: var(--surface-2);
    border-top: 1px solid var(--border);
    padding: 8px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text);
}

.status-left {
    display: flex;
    gap: 16px;
}

.users-list {
    display: flex;
    gap: 8px;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 12px;
}

.user-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Dark Theme */
body.dark-theme .app-container {
    background: var(--bg);
}

body.dark-theme .app-header,
body.dark-theme .editor-toolbar,
body.dark-theme .status-bar {
    background: var(--surface-1);
    border-color: var(--border);
    color: var(--text);
}

body.dark-theme .doc-title {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

body.dark-theme .toolbar-btn,
body.dark-theme .mode-btn {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}

body.dark-theme .mode-btn.active {
    background: var(--brand);
    color: white;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header-left h1 {
        font-size: 16px;
    }

    .doc-title {
        max-width: 150px;
        font-size: 14px;
    }

    .editor-toolbar {
        overflow-x: auto;
        padding: 8px;
    }

    .toolbar-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .view-mode-toggle {
        flex-direction: column;
    }
}


/* ---- chrome ---------------------------------------------------------------- */
.app-header,
.toolbar,
.editor-toolbar {
    background: var(--surface-1);
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.app-header h1 {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-xl);
    color: var(--text);
}

.room-badge {
    padding: 3px 10px;
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
}

.mode-btn,
.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    color: var(--text-body);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
}

.mode-btn:hover,
.toolbar-btn:hover { background: var(--surface-3); border-color: var(--brand); color: var(--text); }
.mode-btn.active { background: var(--brand-subtle); border-color: var(--brand); color: var(--brand-ink); }
.mode-btn:focus-visible,
.toolbar-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* An icon button holds an icon: padding sized for a text label squeezes an
   <svg>, whose default min-width is its own content, down to a sliver. */
.mode-btn .icon,
.toolbar-btn .icon,
.share-btn .icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
    flex: none;
}

.users-panel {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}

.users-panel h3 {
    display: flex;
    align-items: center;
    font-size: var(--fs-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.users-panel h3 .icon { margin-right: var(--sp-2); flex: none; }

.connection-status {
    color: var(--text-body);
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.status-dot { background: var(--danger); }
.connection-status.connected .status-dot { background: var(--success); }

.share-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    font-weight: 600;
}

.share-btn:hover { background: var(--surface-3); border-color: var(--brand); }

/* CodeMirror sizes itself from its content and pushed the page sideways; it
   scrolls inside its own pane instead. */
.CodeMirror,
.CodeMirror-scroll {
    max-width: 100%;
}
