:root {
    --bg-primary: #f0e6f6;
    --bg-secondary: #e8dff0;
    --bg-tertiary: #f7f2fa;
    --accent-primary: #667eea;
    --accent-secondary: #764ba2;
    --accent-tertiary: #c054d4;
    --accent-glow: rgba(118,75,162,0.15);
    --text-primary: #2d2640;
    --text-secondary: #6b4f8a;
    --border-color: rgba(118,75,162,0.25);
    --header-min-height: 58px;
    --header-padding-vertical: 14px;
    --header-padding-horizontal: 20px;
    --header-line-height: 1.25;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 50%, var(--bg-tertiary) 100%);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
}

.chat-panel {
    width: 30%;
    background: linear-gradient(180deg, rgba(255,255,255,0.92) 0%, rgba(240,230,246,0.95) 100%);
    box-shadow: 0 0 30px rgba(118,75,162,0.1), inset 0 0 60px rgba(240,230,246,0.3);
    padding: 20px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    position: relative;
    transition: margin-left 0.3s ease, border-right-color 0.3s ease;
}

.chat-header {
    font-size: 24px;
    min-height: var(--header-min-height);
    padding: var(--header-padding-vertical) var(--header-padding-horizontal);
    line-height: var(--header-line-height);
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 50%, var(--accent-tertiary) 100%);
    color: #fff;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(102,126,234,0.3);
    text-shadow: 0 2px 10px rgba(0,0,0,0.15);
    letter-spacing: 2px;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    margin-top: 15px;
    background: rgba(255,255,255,0.6);
    border-radius: 15px;
    border: 1px solid rgba(118,75,162,0.15);
    box-shadow: inset 0 0 30px rgba(240,230,246,0.4);
}

.chat-message {
    margin-bottom: 15px;
    padding: 12px 15px;
    background: linear-gradient(135deg, rgba(102,126,234,0.08) 0%, rgba(118,75,162,0.08) 100%);
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(118,75,162,0.1);
    border: 1px solid rgba(118,75,162,0.1);
    backdrop-filter: blur(5px);
}

.chat-message p {
    margin-bottom: 5px;
    line-height: 1.5;
}

.chat-message p strong {
    font-weight: 600;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-tertiary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.chat-message p code {
    background: var(--accent-glow);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
    color: var(--accent-secondary);
    border: 1px solid rgba(118,75,162,0.2);
}

.link-group {
    display: flex;
    justify-content: space-between;
    margin: 15px 0;
    padding: 10px;
    background: rgba(255,255,255,0.4);
    border-radius: 10px;
    border: 1px solid rgba(118,75,162,0.15);
}

.link-group a {
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 15px;
    border-radius: 8px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.link-group a:hover {
    background: linear-gradient(135deg, rgba(102,126,234,0.15) 0%, rgba(118,75,162,0.15) 100%);
    border-color: rgba(118,75,162,0.3);
    box-shadow: 0 0 15px var(--accent-glow);
    color: var(--accent-secondary);
}

form {
    display: flex;
    flex-direction: row;
    width: 100%;
    gap: 10px;
    align-items: center;
}

.chat-input {
    padding: 14px 18px;
    border: 1px solid var(--border-color);
    border-radius: 25px;
    flex-grow: 1;
    font-size: 14px;
    background: rgba(255,255,255,0.8);
    color: var(--text-primary);
    box-shadow: inset 0 2px 10px rgba(118,75,162,0.05), 0 0 20px rgba(118,75,162,0.05);
    transition: all 0.3s ease;
}

.chat-input:focus {
    outline: none;
    border-color: rgba(118,75,162,0.5);
    box-shadow: inset 0 2px 10px rgba(118,75,162,0.05), 0 0 25px rgba(118,75,162,0.15);
}

.chat-input::placeholder {
    color: rgba(118,75,162,0.4);
}

.chat-submit {
    padding: 14px 20px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 50%, var(--accent-tertiary) 100%);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    letter-spacing: 1px;
    box-shadow: 0 4px 20px rgba(102,126,234,0.3);
    white-space: nowrap;
}

.chat-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(102,126,234,0.5);
}

.chat-submit:active {
    transform: translateY(0);
}

.viewer-panel {
    flex: 1;
    min-width: 0;
    padding: 20px 20px 20px 44px;
    background: linear-gradient(135deg, rgba(232,223,240,0.9) 0%, rgba(247,242,250,0.95) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 60px rgba(118,75,162,0.05);
    position: relative;
    overflow: hidden;
}

.viewer-panel::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at center, rgba(102,126,234,0.04) 0%, transparent 70%);
    animation: nebula-pulse 8s ease-in-out infinite;
    pointer-events: none;
}

@keyframes nebula-pulse {
    0%,100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

.viewer-panel.full-viewer {
    padding: 0;
}

.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(240,230,246,0.9);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-tertiary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(240,230,246,0.6);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--accent-primary) 0%, var(--accent-secondary) 50%, var(--accent-tertiary) 100%);
    border-radius: 10px;
    border: 2px solid rgba(240,230,246,0.6);
    box-shadow: 0 0 10px var(--accent-glow);
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--accent-tertiary) 0%, var(--accent-secondary) 50%, var(--accent-primary) 100%);
    box-shadow: 0 0 15px rgba(192,84,212,0.3);
}

::-webkit-scrollbar-corner {
    background: rgba(240,230,246,0.6);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--accent-secondary) rgba(240,230,246,0.6);
}

/* ---- Chat Toggle ---- */
.chat-toggle {
    position: fixed;
    left: 30%;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 80px;
    background: rgba(240,230,246,0.95);
    border: none;
    border-left: 1px solid var(--border-color);
    border-radius: 0 12px 12px 0;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: left 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
}

.chat-toggle:hover {
    background: rgba(255,255,255,1);
    box-shadow: 0 0 20px var(--accent-glow), inset 0 0 15px rgba(118,75,162,0.1);
}

.chat-toggle-dots {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-toggle-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: transform 0.3s ease;
}

.chat-toggle:hover .chat-toggle-dot {
    transform: scale(1.4);
}

body.chat-collapsed .chat-panel {
    margin-left: -30%;
    border-right-color: transparent;
}

body.chat-collapsed .chat-toggle {
    left: 0;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.modal-overlay.show { display: flex; }

.modal-content {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.modal-header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    padding: 16px 20px;
    font-size: 18px;
    font-weight: 600;
}

.modal-body { padding: 20px; }

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.modal-footer-right { display: flex; gap: 10px; margin-left: auto; }

/* ---- Form elements ---- */
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.form-input:focus { border-color: var(--accent-primary); }
.form-input:read-only { opacity: 0.7; cursor: not-allowed; }
.form-input::placeholder { color: var(--text-secondary); opacity: 0.7; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.checkbox-label span { font-size: 14px; color: var(--text-primary); }

/* ---- Modal buttons ---- */
.modal-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.modal-btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.modal-btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.modal-btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.modal-btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.modal-btn-danger { background: #dc3545; color: white; }

.modal-btn-danger:hover {
    background: #c82333;
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

/* ---- Brainstorm icon button (inside input) ---- */
.chat-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.chat-input-wrapper .chat-input {
    width: 100%;
    padding-left: 36px;
    padding-right: 36px;
}

.brainstorm-icon-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.brainstorm-icon-btn:hover {
    color: var(--accent-primary);
    background: var(--accent-glow);
}

.light-mode .brainstorm-icon-btn {
    color: var(--text-secondary);
}

.light-mode .brainstorm-icon-btn:hover {
    color: var(--accent-primary);
}

/* ---- Brainstorm modal (full-window variant) ---- */
.brainstorm-modal .modal-content {
    max-width: none;
    width: calc(100% - 80px);
    height: calc(100% - 80px);
    display: flex;
    flex-direction: column;
}

.brainstorm-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.brainstorm-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.brainstorm-close-btn:hover { opacity: 1; }

.brainstorm-messages {
    flex: 1;
    overflow-y: auto;
    scrollbar-gutter: stable;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.brainstorm-message {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 85%;
    word-wrap: break-word;
}

.brainstorm-user {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    align-self: flex-end;
}

.brainstorm-assistant {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    align-self: flex-start;
}

.brainstorm-input-row {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.brainstorm-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.brainstorm-input:focus { border-color: var(--accent-primary); }
.brainstorm-input::placeholder { color: var(--text-secondary); opacity: 0.7; }

.brainstorm-send-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.brainstorm-send-btn:hover {
    filter: brightness(1.1);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.brainstorm-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.brainstorm-assistant p { margin: 4px 0; }
.brainstorm-assistant pre { background: var(--bg-tertiary); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 8px 0; }
.brainstorm-assistant code { font-size: 13px; }
.brainstorm-assistant ul, .brainstorm-assistant ol { margin: 4px 0; padding-left: 20px; }

.brainstorm-build-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

.brainstorm-build-btn {
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.brainstorm-build-btn:hover {
    filter: brightness(1.15);
    box-shadow: 0 2px 10px var(--accent-glow);
}

.brainstorm-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.brainstorm-suggestion-chip {
    padding: 5px 12px;
    font-size: 12px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.4;
}

.brainstorm-suggestion-chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-glow);
}

.brainstorm-suggestion-chip:disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.brainstorm-thinking {
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 14px;
    font-style: italic;
}

/* ---- Save Line ---- */
.save-line {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0 15px;
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.7;
}

.save-line::before,
.save-line::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color), transparent);
}

.save-line-label {
    white-space: nowrap;
    letter-spacing: 0.5px;
}

/* ---- Shared page rules ---- */
#loadingOverlay { position: absolute; }
.chat-submit:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.chat-input:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Attach button (left side of input) ---- */
.attach-btn {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    z-index: 2;
}
.attach-btn:hover {
    color: var(--accent-primary);
    background: var(--accent-glow);
}
.light-mode .attach-btn {
    color: var(--text-secondary);
}
.light-mode .attach-btn:hover {
    color: var(--accent-primary);
}

/* ---- Attach popup menu ---- */
.attach-menu {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    overflow: hidden;
    z-index: 100;
    min-width: 160px;
}
.attach-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
}
.attach-menu-item:hover {
    background: var(--accent-glow);
}

/* ---- Attachment pills ---- */
.attachment-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 4px;
    min-height: 0;
}
.attachment-pills:empty { display: none; }
.attachment-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 8px;
    max-width: 180px;
}
.attachment-pill-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    line-height: 1;
}
.attachment-pill-remove:hover {
    color: #ff6b6b;
}

/* ---- Screenshot overlay ---- */
.screenshot-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.15);
    cursor: crosshair;
    z-index: 1000;
}
.screenshot-rect {
    display: none;
    position: absolute;
    border: 2px solid red;
    background: rgba(255,0,0,0.05);
    pointer-events: none;
}
