/* ============================================
   Canvas AI - Fixes & Refinements
   FigJam-style Canvas, Floating UI, No Scrollbars
   ============================================ */

:root {
    /* Colors */
    --bg-primary: #f5f5f5;
    --bg-canvas: #fafafa;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f0;
    --bg-input: rgba(255, 255, 255, 0.9);

    --text-primary: #1a1a1a;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;

    --border-color: #e0e0e0;
    --border-light: #f0f0f0;

    --accent: #1a1a1a;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-canvas);
    color: var(--text-primary);
    overflow: hidden;
    /* Prevent body scroll */
    width: 100vw;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Material Icons */
.material-symbols-rounded {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.material-symbols-rounded.filled {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* ============================================
   Canvas (FigJam Style)
   ============================================ */

#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
    background-color: var(--bg-canvas);
    /* Dot pattern will be handled via background-position updates in JS */
    background-image: radial-gradient(circle, #e0e0e0 1.5px, transparent 1.5px);
    background-size: 24px 24px;
    cursor: grab;
}

#canvas.panning {
    cursor: grabbing;
}

/* The content container transforms (pans/zooms) */
#canvas-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
    /* Will be transformed by JS */
}

/* Blocks Container */
#blocks-container {
    position: absolute;
    top: 0;
    left: 0;
    /* Infinite dimensions logically, managed by JS */
}

/* SVG Connections */
#connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    z-index: 0;
}

.connection-line {
    stroke: #d0d0d0;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
}

.connection-line.branch {
    stroke: #1a73e8;
    stroke-width: 2;
    stroke-dasharray: 6, 4;
    opacity: 0.5;
}

/* ============================================
   UI Overlay (Floating)
   ============================================ */

/* Top Bar */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    padding: 0 var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
    /* Let clicks pass through to canvas */
    z-index: 100;
}

.top-bar>* {
    pointer-events: auto;
    /* Re-enable pointer events for buttons */
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: var(--shadow-sm);
}

.logo .material-symbols-rounded {
    color: #1a73e8;
}

/* Top Actions */
.top-actions {
    display: flex;
    gap: var(--spacing-sm);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    padding: 6px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: var(--shadow-sm);
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

/* ============================================
   Chat Input (Floating Bottom)
   ============================================ */

.chat-input-wrapper {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 700px;
    padding: 0 var(--spacing-lg);
    z-index: 100;
    pointer-events: none;
    /* Let canvas be clickable around it */
}

.chat-input-container {
    background: var(--bg-input);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 28px;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.08),
        0 1px 4px rgba(0, 0, 0, 0.04);
    pointer-events: auto;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
}

.chat-input-container:focus-within {
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.12),
        0 2px 8px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
    border-color: rgba(0, 0, 0, 0.15);
}

#message-input {
    width: 100%;
    border: none;
    background: transparent;
    padding: 16px 24px;
    padding-bottom: 4px;
    font-family: var(--font-family);
    font-size: 15px;
    color: var(--text-primary);
    resize: none;
    max-height: 120px;
}

#message-input:focus {
    outline: none;
}

#message-input::placeholder {
    color: #888;
}

.chat-input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 16px 12px 16px;
}

/* Model Dropdown */
.model-selector-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.model-selector-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary);
}

.model-dropdown-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 12px;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    padding: 8px;
    min-width: 240px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s;
}

.model-dropdown.open .model-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.model-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    border-radius: 12px;
    cursor: pointer;
}

.model-option:hover {
    background: var(--bg-hover);
}

.model-option.active {
    background: rgba(26, 115, 232, 0.08);
}

.model-option .material-symbols-rounded.filled {
    color: #1a73e8;
}

/* Send Button */
.send-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.send-btn:disabled {
    background: #e0e0e0;
    color: #999;
    cursor: not-allowed;
}

/* ============================================
   Nodes / Cards
   ============================================ */

.message-node {
    position: absolute;
    width: 800px;
    z-index: 10;
}

.question-label {
    margin-bottom: 8px;
    margin-left: 4px;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    display: flex;
    align-items: center;
    gap: 6px;
}

.answer-card {
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    /* cursor: grab; Removed because main thread shouldn't have grab cursor by default, handled in JS */
    transition: box-shadow 0.2s;
    user-select: text;
}

/* Allow grab cursor only on draggable items (branches) */
.answer-card.draggable {
    cursor: grab;
}

.answer-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.answer-card.streaming {
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.1);
}

.answer-content {
    font-size: 15px;
    line-height: 1.6;
    color: #222;
    white-space: pre-wrap;
    /* For markdown newlines */
}

/* ============================================
   Branch Tooltip
   ============================================ */

.branch-tooltip {
    position: fixed;
    /* Fixed to viewport */
    z-index: 1000;
}

.branch-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #1a1a1a;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 24px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.1s;
}

.branch-btn:hover {
    transform: scale(1.05);
}

.hidden {
    display: none;
}