:root {
    --bg-deep: #0a0a0f;
    --bg-surface: #12121a;
    --bg-card: #1a1a25;
    --bg-hover: #22222f;
    --text-primary: #e8e8ed;
    --text-secondary: #a0a0b0;
    --text-muted: #606070;
    --accent: #6c63ff;
    --accent-hover: #5a52e0;
    --accent-cyan: #00d4ff;
    --success: #4caf50;
    --error: #ff5252;
    --border: #2a2a35;
    --radius: 8px;
}

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

body {
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    min-height: 100vh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.header-left h1 {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--accent-cyan);
}

.tagline {
    font-size: 0.8rem;
    color: var(--text-muted);
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 24px;
}

/* Login prompt */
#login-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60vh;
    gap: 16px;
}

#login-prompt h2 {
    font-size: 1.6rem;
    color: var(--text-primary);
    font-weight: 600;
}

#login-prompt p {
    color: var(--text-secondary);
    font-size: 1rem;
    max-width: 400px;
    line-height: 1.5;
}

.login-prompt-buttons {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.login-prompt-buttons .ar-btn {
    font-size: 1.05rem;
    padding: 12px 32px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s;
}

.login-prompt-buttons .ar-btn-primary {
    background: var(--accent);
    color: white;
    border: none;
}

.login-prompt-buttons .ar-btn-primary:hover {
    background: var(--accent-hover);
}

.login-prompt-buttons .ar-btn-secondary {
    background: transparent;
    color: var(--accent-cyan);
    border: 1px solid var(--accent-cyan);
}

.login-prompt-buttons .ar-btn-secondary:hover {
    background: rgba(0, 212, 255, 0.1);
}

/* Search section */
#search-section {
    margin-bottom: 40px;
}

.search-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#idea-input {
    flex: 1;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 12px 16px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    transition: border-color 0.2s;
}

#idea-input:focus {
    outline: none;
    border-color: var(--accent);
}

#idea-input::placeholder {
    color: var(--text-muted);
}

#submit-btn {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 12px 24px;
    font-size: 0.95rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
    height: fit-content;
}

#submit-btn:hover {
    background: var(--accent-hover);
}

#submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#progress-container {
    margin-top: 12px;
}

/* Results */
#results-section {
    margin-bottom: 32px;
    padding: 16px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Ideas heading */
#my-ideas-heading {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-weight: 500;
}

/* Graph container */
#ideas-graph-container {
    width: 100%;
    height: 70vh;
    min-height: 400px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

#ideas-graph-container {
    position: relative;
}

#graph-zoom-reset {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s, color 0.2s;
}

#graph-zoom-reset:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Graph nodes (ForceGraph component handles base styles via fg- prefix) */

/* Parent picker modal */
.parent-picker-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    max-width: 400px;
    width: 100%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.parent-picker-content h3 {
    margin-bottom: 10px;
    color: var(--accent-cyan);
    font-size: 0.9rem;
}

#parent-picker-search {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 0.85rem;
    font-family: inherit;
    margin-bottom: 8px;
    width: 100%;
}

#parent-picker-search:focus {
    outline: none;
    border-color: var(--accent);
}

#parent-picker-search::placeholder {
    color: var(--text-muted);
}

.parent-picker-list {
    overflow-y: auto;
    max-height: 50vh;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.parent-picker-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-primary);
    background: var(--bg-card);
    transition: background 0.15s;
    border: none;
    text-align: left;
    width: 100%;
    font-family: inherit;
}

.parent-picker-item:hover {
    background: var(--bg-hover);
}

.parent-picker-empty {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
    padding: 12px 0;
    text-align: center;
}

/* Lightbox parent actions */
.lightbox-parent-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.lightbox-parent-actions:empty {
    display: none;
}

.btn-parent-action {
    background: transparent;
    color: var(--accent-cyan);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2px 8px;
    font-size: 0.7rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.btn-parent-action:hover {
    background: rgba(0, 212, 255, 0.1);
    border-color: var(--accent-cyan);
}

.btn-unlink {
    color: var(--text-muted);
}

.btn-unlink:hover {
    color: var(--error);
    border-color: var(--error);
    background: rgba(255, 82, 82, 0.1);
}

/* Graph empty state */
.graph-empty {
    fill: var(--text-muted);
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.version-badge {
    background: var(--accent);
    color: white;
    padding: 1px 6px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
}

/* Modal / lightbox */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    overscroll-behavior: contain;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 100%;
    position: relative;
}

.modal-content h3 {
    margin-bottom: 12px;
    color: var(--accent-cyan);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* Lightbox layout now handled by InfographicModal component */

/* Message styles (rendered inside modal) */
.msg {
    margin-bottom: 10px;
}

.msg-user {
    display: flex;
    justify-content: flex-end;
}

.msg-assistant {
    display: flex;
    justify-content: flex-start;
}

.msg-bubble {
    max-width: 100%;
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    line-height: 1.3;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-bubble-user {
    background: var(--accent, #6c63ff);
    color: white;
    border-bottom-right-radius: 4px;
}

.msg-bubble-assistant {
    background: var(--bg-card, #1a1a1a);
    color: var(--text-secondary, #ccc);
    border-bottom-left-radius: 4px;
}

.conversation-image {
    max-width: 120px;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid var(--border, #222);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.conversation-image:hover {
    border-color: var(--accent, #6c63ff);
}

.conversation-turn {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border, #222);
}

.conversation-turn:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.retry-btn {
    background: var(--accent, #6c63ff);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 3px 10px;
    margin-left: 8px;
    cursor: pointer;
    font-size: 0.8rem;
}

.retry-btn:hover {
    background: var(--accent-hover, #5a54d4);
}

.classify-debug {
    font-size: 0.7rem;
    color: var(--text-muted, #888);
    margin-top: 4px;
}
.classify-debug summary {
    cursor: pointer;
    opacity: 0.6;
}
.classify-debug summary:hover {
    opacity: 1;
}
.classify-prompt {
    margin: 6px 0 0;
    padding: 8px;
    background: var(--bg-main, #0a0a0a);
    border: 1px solid var(--border, #222);
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.7rem;
    max-height: 200px;
    overflow-y: auto;
}

/* Buttons */
.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: transparent;
    color: var(--accent-cyan);
    border: 1px solid var(--accent-cyan);
    border-radius: var(--radius);
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: rgba(0, 212, 255, 0.1);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: var(--radius);
    transition: color 0.2s;
}

.btn-ghost:hover {
    color: var(--text-primary);
}

.btn-small {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-danger:hover {
    color: var(--error);
}

/* Auth area */
#auth-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

#auth-area .user-email,
#auth-area .ar-user-email {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

#auth-area button {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.85rem;
}

#auth-area button:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* Image overlay now handled by InfographicModal component */

/* Modal close button (X) — used in confirm modal and lightbox */
.modal-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
}

.modal-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}


/* Breadcrumb + children nav now rendered inline by InfographicModal nav slot */

.breadcrumb-link {
    color: var(--accent-cyan, #00d4ff);
    text-decoration: none;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
}

.breadcrumb-link:hover {
    text-decoration: underline;
}

.breadcrumb-sep {
    color: var(--text-muted, #888);
    flex-shrink: 0;
}

.breadcrumb-current {
    color: var(--text-secondary, #ccc);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
    border-top: 1px solid var(--border);
}

/* Children/branches inline-styled in nav slot */

/* Recent node highlight (3 most recent when search empty) — extends ForceGraph fg- classes */
.fg-recent .fg-node-bg {
    stroke: var(--accent) !important;
    stroke-width: 3 !important;
    animation: pulse-stroke 2s ease-in-out infinite;
}

@keyframes pulse-stroke {
    0%, 100% { stroke-opacity: 0.6; }
    50% { stroke-opacity: 1; }
}

/* Reorganize button */
#reorg-btn {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    font-size: 0.8rem;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s, color 0.2s;
}

#reorg-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

#reorg-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#reorg-progress-container {
    margin-top: 8px;
}

/* Reorg debug panel */
#reorg-debug {
    margin-top: 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.reorg-debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.reorg-debug-header:hover {
    background: var(--bg-hover);
}

.reorg-debug-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-cyan);
}

.reorg-debug-summary {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.reorg-debug-body {
    padding: 12px 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.reorg-section {
    margin-bottom: 16px;
}

.reorg-section:last-child {
    margin-bottom: 0;
}

.reorg-section-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.reorg-pre {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 0.75rem;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-secondary);
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.5;
}

.reorg-changes-list {
    list-style: none;
    padding: 0;
}

.reorg-changes-list li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.reorg-changes-list li:last-child {
    border-bottom: none;
}

.reorg-action-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-right: 6px;
}

.reorg-action-badge.reparent {
    background: rgba(108, 99, 255, 0.2);
    color: var(--accent);
}

.reorg-action-badge.link {
    background: rgba(0, 212, 255, 0.2);
    color: var(--accent-cyan);
}

.reorg-none {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

/* Toast notifications */
.toast-notification {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--accent-cyan);
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 0.85rem;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}

.toast-notification.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Header nav link */
.header-nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: color 0.2s, border-color 0.2s;
}

.header-nav-link:hover {
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
}

/* Activity log panel */
#activity-log-section {
    margin-top: 16px;
}

#activity-log-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.activity-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.activity-log-header:hover {
    background: var(--bg-hover);
}

.activity-log-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-cyan);
}

.activity-log-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.activity-log-controls {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

.activity-log-controls select {
    background: var(--bg-deep);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 5px 10px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
}

#activity-log-entries {
    max-height: 60vh;
    overflow-y: auto;
    padding: 8px 16px;
}

.activity-entry {
    border-bottom: 1px solid var(--border);
    padding: 6px 0;
}

.activity-entry:last-child {
    border-bottom: none;
}

.activity-entry summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 4px 0;
    list-style: none;
}

.activity-entry summary::-webkit-details-marker {
    display: none;
}

.activity-entry summary::before {
    content: '\25b6';
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform 0.15s;
    flex-shrink: 0;
}

.activity-entry[open] summary::before {
    transform: rotate(90deg);
}

.activity-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

.activity-badge.similarity_check { background: rgba(0, 212, 255, 0.15); color: var(--accent-cyan); }
.activity-badge.auto_parent { background: rgba(108, 99, 255, 0.2); color: var(--accent); }
.activity-badge.create_idea { background: rgba(76, 175, 80, 0.2); color: var(--success); }
.activity-badge.classify_followup { background: rgba(255, 193, 7, 0.2); color: #ffc107; }
.activity-badge.update_idea { background: rgba(0, 212, 255, 0.15); color: var(--accent-cyan); }
.activity-badge.branch_idea { background: rgba(108, 99, 255, 0.2); color: var(--accent); }
.activity-badge.delete_idea { background: rgba(255, 82, 82, 0.2); color: var(--error); }
.activity-badge.retry_image { background: rgba(255, 193, 7, 0.2); color: #ffc107; }
.activity-badge.reorganize { background: rgba(108, 99, 255, 0.2); color: var(--accent); }
.activity-badge.image_gen_complete { background: rgba(76, 175, 80, 0.2); color: var(--success); }
.activity-badge.set_parent { background: rgba(76, 175, 80, 0.2); color: var(--success); }
.activity-badge.unset_parent { background: rgba(255, 82, 82, 0.2); color: var(--error); }

.activity-idea-link {
    color: var(--accent-cyan);
    text-decoration: none;
    cursor: pointer;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
}

.activity-idea-link:hover {
    text-decoration: underline;
}

.activity-snippet {
    color: var(--text-muted);
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.activity-time {
    color: var(--text-muted);
    font-size: 0.7rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.activity-detail {
    padding: 8px 0 4px 18px;
}

.activity-detail pre {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 0.72rem;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-secondary);
    max-height: 300px;
    overflow-y: auto;
    margin: 4px 0;
    line-height: 1.4;
}

.activity-detail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 6px;
}

.activity-duration {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.activity-log-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.activity-log-pagination button {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.activity-log-pagination button:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.activity-log-pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 600px) {
    .search-container {
        flex-direction: column;
    }
    #submit-btn {
        width: 100%;
    }
    #ideas-graph-container {
        height: 50vh;
        min-height: 300px;
    }
    /* Lightbox mobile handled by InfographicModal component */
    /* Full width textarea on mobile */
    #idea-input {
        text-align: center;
        width: 100%;
    }
    /* Prevent mobile viewport zoom on input focus */
    #idea-input {
        font-size: 16px;
    }
    header {
        padding: 12px 16px;
    }
    .tagline {
        display: none;
    }
    main {
        padding: 20px 16px;
    }
}
