/* =================================================================
   AnythingAdder Web Editor 2.0 — Node Graph & Full UI Stylesheet
   ================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---- CSS Variables ---- */
:root {
    --bg-deep: #0a0c10;
    --bg-base: #0f1117;
    --bg-panel: #161b26;
    --bg-card: #1c2232;
    --bg-hover: #222b3e;
    --border: #252d3d;
    --border-light: #2e3a52;

    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-pink: #ec4899;
    --accent-orange: #f97316;

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #475569;

    --glow-blue: 0 0 20px rgba(59, 130, 246, 0.4);
    --glow-green: 0 0 20px rgba(16, 185, 129, 0.4);

    --node-dialogue: #1e3a5f;
    --node-dialogue-border: #3b82f6;
    --node-choice: #1a3a2a;
    --node-choice-border: #10b981;
    --node-command: #3a2a10;
    --node-command-border: #f97316;
    --node-condition: #3a1a1a;
    --node-condition-border: #ef4444;
    --node-camera: #2a1a3a;
    --node-camera-border: #8b5cf6;
    --node-delay: #1a2a3a;
    --node-delay-border: #06b6d4;
    --node-quest: #3a2a1a;
    --node-quest-border: #f59e0b;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-deep);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ---- Top Bar ---- */
.topbar {
    height: 52px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-right: 16px;
}

.topbar-brand h1 {
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, #3b82f6, #06b6d4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.version-badge {
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: 0.5px;
}

.tab-bar {
    display: flex;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

.tab-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.tab-btn.active {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    border-bottom: 2px solid var(--accent-blue);
}

.topbar-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* ---- Main Layout ---- */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ---- Left Sidebar ---- */
.sidebar-left {
    width: 240px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-section {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-section h4 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.node-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: grab;
    user-select: none;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
}

.node-palette-item:hover { background: var(--bg-hover); }
.node-palette-item:active { cursor: grabbing; }

.node-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.dot-dialogue { background: var(--node-dialogue-border); }
.dot-choice { background: var(--node-choice-border); }
.dot-command { background: var(--node-command-border); }
.dot-condition { background: var(--node-condition-border); }
.dot-camera { background: var(--node-camera-border); }
.dot-delay { background: var(--node-delay-border); }
.dot-quest { background: var(--node-quest-border); }

/* ---- Graph Canvas ---- */
.graph-canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.02) 0%, transparent 70%),
        linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
    background-size: 100% 100%, 28px 28px, 28px 28px;
}

#graph-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.graph-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
    z-index: 2;
}

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

/* ---- Graph Nodes ---- */
.graph-node {
    position: absolute;
    min-width: 200px;
    max-width: 260px;
    border-radius: var(--radius-lg);
    border: 1.5px solid;
    cursor: move;
    user-select: none;
    transition: box-shadow 0.2s;
    z-index: 3;
}

.graph-node:hover { z-index: 10; box-shadow: 0 8px 32px rgba(0,0,0,0.6); }
.graph-node.selected { z-index: 20; }

.graph-node.type-DIALOGUE { background: var(--node-dialogue); border-color: var(--node-dialogue-border); }
.graph-node.selected.type-DIALOGUE { box-shadow: 0 0 0 2px var(--node-dialogue-border), var(--glow-blue); }

.graph-node.type-CHOICE { background: var(--node-choice); border-color: var(--node-choice-border); }
.graph-node.selected.type-CHOICE { box-shadow: 0 0 0 2px var(--node-choice-border), var(--glow-green); }

.graph-node.type-COMMAND { background: var(--node-command); border-color: var(--node-command-border); }
.graph-node.type-CONDITION { background: var(--node-condition); border-color: var(--node-condition-border); }
.graph-node.type-CAMERA { background: var(--node-camera); border-color: var(--node-camera-border); }
.graph-node.type-DELAY { background: var(--node-delay); border-color: var(--node-delay-border); }
.graph-node.type-QUEST_STAGE { background: var(--node-quest); border-color: var(--node-quest-border); }
.graph-node.type-END { background: #1a1a2e; border-color: #475569; }

.node-header {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.node-body {
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.node-preview {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
    padding: 6px 8px;
    font-style: italic;
    font-size: 11.5px;
    max-height: 50px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.node-ports {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    align-items: center;
}

.port {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    background: var(--bg-deep);
    cursor: crosshair;
    transition: all 0.15s;
    position: relative;
    z-index: 5;
}

.port:hover { border-color: white; background: white; transform: scale(1.3); }
.port-in { margin-right: auto; }
.port-out { margin-left: auto; }

/* ---- Right Properties Panel ---- */
.sidebar-right {
    width: 280px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.props-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
}

.props-body {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.prop-group { display: flex; flex-direction: column; gap: 4px; }
.prop-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.prop-input, .prop-select, .prop-textarea {
    background: var(--bg-base);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    padding: 8px 10px;
    transition: border-color 0.2s;
    width: 100%;
}

.prop-input:focus, .prop-select:focus, .prop-textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.prop-textarea {
    resize: vertical;
    min-height: 72px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}
.btn-primary:hover { background: #2563eb; transform: translateY(-1px); box-shadow: var(--glow-blue); }

.btn-success {
    background: var(--accent-green);
    color: white;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}
.btn-success:hover { background: #059669; transform: translateY(-1px); }

.btn-danger { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-danger:hover { background: var(--accent-red); color: white; }

.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-light); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: var(--radius); background: transparent; border: none; color: var(--text-secondary); cursor: pointer; }
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ---- Tabs Content ---- */
.tab-content { display: none; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; }

/* ---- Graph Editor Layout ---- */
#tab-graph { display: none; }
#tab-graph.active { display: flex; flex: 1; }

/* ---- Items / Blocks Grid ---- */
.content-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.content-header h2 { font-size: 18px; font-weight: 700; }
.content-header p { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.content-scroll { flex: 1; overflow-y: auto; padding: 20px; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.item-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.item-card.selected {
    border-color: var(--accent-blue) !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4), 0 4px 20px rgba(59, 130, 246, 0.2);
    background: rgba(59, 130, 246, 0.04);
}

.item-card:hover {
    border-color: var(--accent-blue);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.15);
    transform: translateY(-2px);
}

.card-actions {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 6px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.item-card:hover .card-actions {
    opacity: 1.0;
}

.card-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.card-action-btn.edit-btn:hover {
    background: var(--accent-blue);
    color: #ffffff;
    border-color: var(--accent-blue);
    transform: scale(1.1);
}

.card-action-btn.delete-btn:hover {
    background: #ef4444;
    color: #ffffff;
    border-color: #ef4444;
    transform: scale(1.1);
}

.item-card-icon {
    width: 40px;
    height: 40px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-size: 20px;
}

.item-card-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.item-card-meta { font-size: 12px; color: var(--text-muted); }

.item-card-badges { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    letter-spacing: 0.3px;
}

/* ---- Quest & Graph List ---- */
.list-view { display: flex; flex-direction: column; gap: 8px; }

.list-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.list-item:hover {
    border-color: var(--accent-blue);
    background: var(--bg-hover);
}

.list-item-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.list-item-info { flex: 1; }
.list-item-title { font-size: 14px; font-weight: 600; }
.list-item-sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.list-item-actions { display: flex; gap: 6px; }

/* ---- Modal ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.hidden { display: none; }

.modal-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 560px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    animation: modal-appear 0.2s ease;
}

@keyframes modal-appear {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    font-weight: 700;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ---- Minimap ---- */
.graph-minimap {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 180px;
    height: 120px;
    background: rgba(15, 17, 23, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 50;
    overflow: hidden;
}

/* ---- Toolbar ---- */
.graph-toolbar {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px;
    display: flex;
    gap: 4px;
    z-index: 50;
    box-shadow: var(--shadow);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Connection wire SVG ---- */
.node-connection {
    stroke: rgba(148, 163, 184, 0.4);
    stroke-width: 2;
    fill: none;
    filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.3));
}

.node-connection.active { stroke: var(--accent-blue); stroke-width: 2.5; }
.node-connection.preview { stroke: rgba(255,255,255,0.5); stroke-dasharray: 6,4; animation: dash 1s linear infinite; }

@keyframes dash { to { stroke-dashoffset: -20; } }

/* ---- Typewriter Preview ---- */
.typewriter-preview-box {
    background: rgba(0,0,0,0.6);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 500;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.typewriter-preview-box::after {
    content: '|';
    animation: blink 0.7s step-end infinite;
    color: var(--accent-blue);
}

@keyframes blink { 50% { opacity: 0; } }

/* ---- Status bar ---- */
.statusbar {
    height: 24px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 16px;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.statusbar-item { display: flex; align-items: center; gap: 4px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; }
.status-dot.online { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.status-dot.offline { background: var(--accent-red); }

/* ---- 3D viewer tab ---- */
#tab-blocks.active { display: flex; }
.workspace-split { display: flex; gap: 16px; flex: 1; overflow: hidden; }
.viewer-3d-panel {
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.viewer-3d-panel h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
#three-canvas-container { flex: 1; min-height: 200px; border-radius: var(--radius); overflow: hidden; background: #0a0c10; }

/* ---- Cinematic Timeline ---- */
.timeline-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.timeline-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
}

.timeline-track {
    display: flex;
    align-items: center;
    padding: 8px 14px;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    position: relative;
    min-height: 44px;
}

.timeline-keyframe {
    width: 14px;
    height: 14px;
    background: var(--accent-purple);
    border-radius: 50%;
    cursor: pointer;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.1s;
    border: 2px solid rgba(255,255,255,0.2);
}

.timeline-keyframe:hover { transform: translateY(-50%) scale(1.4); }

.timeline-bar {
    flex: 1;
    height: 6px;
    background: var(--bg-deep);
    border-radius: 3px;
    position: relative;
    cursor: pointer;
}

.timeline-progress {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-purple), var(--accent-blue));
    border-radius: 3px;
}

/* ---- Empty State ---- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state i { font-size: 48px; opacity: 0.3; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-secondary); }
.empty-state p { font-size: 13px; max-width: 320px; line-height: 1.6; }

/* ---- Notification Toast ---- */
.toast-container {
    position: fixed;
    bottom: 40px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow);
    animation: toast-in 0.3s ease;
    min-width: 240px;
    font-size: 13px;
}

.toast.success { border-left: 3px solid var(--accent-green); }
.toast.error { border-left: 3px solid var(--accent-red); }
.toast.info { border-left: 3px solid var(--accent-blue); }

@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
