/* --------------------------------------------------
   🔭 Inner Lens — Design System & Stylesheet
   -------------------------------------------------- */

:root {
    /* Color Palette */
    --bg-main: #080b11;
    --bg-panel: rgba(17, 25, 40, 0.75);
    --bg-header: rgba(13, 18, 30, 0.85);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(16, 185, 129, 0.5);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    /* Interactive states */
    --primary-color: #10b981;
    --primary-hover: #059669;
    --primary-glow: rgba(16, 185, 129, 0.35);
    
    --secondary-color: #374151;
    --secondary-hover: #4b5563;
    
    /* IFS Entity Colors */
    --color-self: #1abc9c;
    --color-manager: #2ecc71;
    --color-exil: #e67e22;
    --color-firefighter: #c0392b;
    
    /* IFS Background Tones (10% opacity) */
    --bg-self: rgba(26, 188, 156, 0.1);
    --bg-manager: rgba(46, 204, 113, 0.1);
    --bg-exil: rgba(230, 126, 34, 0.1);
    --bg-firefighter: rgba(192, 57, 43, 0.1);

    /* Jung Entity Colors */
    --color-ego: #3498db;
    --color-persona: #9b59b6;
    --color-shadow: #34495e;
    --color-animaanimus: #e74c3c;
    --color-self-jung: #f1c40f;
    
    /* Jung Background Tones (10% opacity) */
    --bg-ego: rgba(52, 152, 219, 0.1);
    --bg-persona: rgba(155, 89, 182, 0.1);
    --bg-shadow: rgba(52, 73, 94, 0.15);
    --bg-animaanimus: rgba(231, 76, 60, 0.1);
    --bg-self-jung: rgba(241, 196, 15, 0.1);
    
    /* Shamanism Entity Colors */
    --color-syd: #2ecc71;
    --color-vast: #e67e22;
    --color-norr: #9b59b6;
    --color-ost: #f1c40f;
    --color-moderjord: #1abc9c;
    --color-faderhimmel: #3498db;
    
    /* Shamanism Background Tones (10% opacity) */
    --bg-syd: rgba(46, 204, 113, 0.1);
    --bg-vast: rgba(230, 126, 34, 0.1);
    --bg-norr: rgba(155, 89, 182, 0.1);
    --bg-ost: rgba(241, 196, 15, 0.1);
    --bg-moderjord: rgba(26, 188, 156, 0.1);
    --bg-faderhimmel: rgba(52, 152, 219, 0.1);
    
    /* Layout */
    --header-height: 64px;
}

/* Jung Override for shared variables (Self) */
body.lens-jung {
    --color-self: var(--color-self-jung);
    --bg-self: var(--bg-self-jung);
}

/* Reset & Global */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-header);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

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

.header-logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #fff 40%, #10b981 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.25);
    border-radius: 9999px;
    font-weight: 500;
}

.version-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
    border-radius: 9999px;
    font-weight: 500;
}

.header-nav {
    display: flex;
    gap: 16px;
}

.nav-link {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
}

.nav-link.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Layout Grid */
.app-layout {
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
    display: grid;
    grid-template-columns: 380px 1fr 450px;
    overflow: hidden;
}

@media (max-width: 1200px) {
    .app-layout {
        grid-template-columns: 340px 1fr 380px;
    }
}

@media (max-width: 1024px) {
    .app-layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: auto;
    }
}

/* Panel Structure */
.panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-panel);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.panel:last-child {
    border-right: none;
}

@media (max-width: 1024px) {
    .panel {
        height: 600px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}

.panel-header {
    height: 52px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.panel-icon {
    font-size: 1.1rem;
}

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.panel-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.15);
}

/* Forms & Inputs */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

textarea {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 12px;
    font-family: inherit;
    font-size: 0.85rem;
    resize: none;
    transition: all 0.25s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
    background-color: rgba(0, 0, 0, 0.35);
}

.panel-input textarea {
    height: 280px;
}

.row-group {
    flex-direction: row;
    align-items: flex-end;
    gap: 12px;
}

.select-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

select {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.25s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239ca3af'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
    padding-right: 36px;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

select option {
    background-color: #111827;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #059669 100%);
    color: #fff;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: var(--secondary-color);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: var(--secondary-hover);
    color: #fff;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.btn-xs {
    padding: 4px 8px;
    font-size: 0.7rem;
    border-radius: 4px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Quick Examples */
.quick-examples {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.example-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Disclaimer */
.disclaimer {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.disclaimer-icon {
    font-size: 1rem;
    color: #f59e0b;
    margin-top: 1px;
}

.disclaimer p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Panel 2: Graphical View specific */
.panel-graphical {
    background-color: rgba(8, 11, 17, 0.95);
}

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

.graph-wrapper {
    position: relative;
    padding: 0;
    overflow: hidden;
}

#cy {
    width: 100%;
    height: 100%;
    background-color: #05070a;
}

/* Floating Legend */
.graph-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(13, 18, 30, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    backdrop-filter: blur(12px);
    width: 220px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 10;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

.graph-legend h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 4px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
}

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

.legend-text {
    color: var(--text-primary);
}

/* Floating Tooltip */
.graph-tooltip {
    position: absolute;
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    backdrop-filter: blur(12px);
    max-width: 240px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 20;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.graph-tooltip h4 {
    font-size: 0.85rem;
    color: #fff;
    margin-bottom: 2px;
}

.tooltip-type {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 6px;
}

.graph-tooltip p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

/* Panel 3: Interpretation & Dialogue specific */
.panel-interpretation {
    border-left: 1px solid var(--border-color);
}

.interpretation-flow {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Welcome Box */
.welcome-box {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
}

.welcome-lead {
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
}

.welcome-box p:not(.welcome-lead) {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Interpretation Displays */
.interpretation-display {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.summary-card {
    background: rgba(16, 185, 129, 0.05);
    border-left: 3px solid var(--primary-color);
    padding: 12px 16px;
    border-radius: 0 8px 8px 0;
    font-size: 0.85rem;
    font-style: italic;
    color: #e5e7eb;
    line-height: 1.45;
}

.interpretation-text {
    font-size: 0.88rem;
    line-height: 1.6;
    color: #d1d5db;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.interpretation-text p {
    margin-bottom: 2px;
}

/* Dynamic Part tags in interpretation text */
.part-tag {
    display: inline-flex;
    align-items: center;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: transform 0.15s ease;
    cursor: help;
}

.part-tag:hover {
    transform: scale(1.05);
}

.part-tag[data-type="Self"] {
    background-color: var(--bg-self);
    border-color: rgba(26, 188, 156, 0.4);
    color: var(--color-self);
}

.part-tag[data-type="Manager"] {
    background-color: var(--bg-manager);
    border-color: rgba(46, 204, 113, 0.4);
    color: var(--color-manager);
}

.part-tag[data-type="Exil"] {
    background-color: var(--bg-exil);
    border-color: rgba(230, 126, 34, 0.4);
    color: var(--color-exil);
}

.part-tag[data-type="Firefighter"] {
    background-color: var(--bg-firefighter);
    border-color: rgba(192, 57, 43, 0.4);
    color: var(--color-firefighter);
}

.part-tag[data-type="Ego"] {
    background-color: var(--bg-ego);
    border-color: rgba(52, 152, 219, 0.4);
    color: var(--color-ego);
}

.part-tag[data-type="Persona"] {
    background-color: var(--bg-persona);
    border-color: rgba(155, 89, 182, 0.4);
    color: var(--color-persona);
}

.part-tag[data-type="Shadow"] {
    background-color: var(--bg-shadow);
    border-color: rgba(52, 73, 94, 0.4);
    color: var(--color-shadow);
}

.part-tag[data-type="AnimaAnimus"] {
    background-color: var(--bg-animaanimus);
    border-color: rgba(231, 76, 60, 0.4);
    color: var(--color-animaanimus);
}

.part-tag[data-type="Syd"] {
    background-color: var(--bg-syd);
    border-color: rgba(46, 204, 113, 0.4);
    color: var(--color-syd);
}

.part-tag[data-type="Väst"] {
    background-color: var(--bg-vast);
    border-color: rgba(230, 126, 34, 0.4);
    color: var(--color-vast);
}

.part-tag[data-type="Norr"] {
    background-color: var(--bg-norr);
    border-color: rgba(155, 89, 182, 0.4);
    color: var(--color-norr);
}

.part-tag[data-type="Öst"] {
    background-color: var(--bg-ost);
    border-color: rgba(241, 196, 15, 0.4);
    color: var(--color-ost);
}

.part-tag[data-type="ModerJord"] {
    background-color: var(--bg-moderjord);
    border-color: rgba(26, 188, 156, 0.4);
    color: var(--color-moderjord);
}

.part-tag[data-type="FaderHimmel"] {
    background-color: var(--bg-faderhimmel);
    border-color: rgba(52, 152, 219, 0.4);
    color: var(--color-faderhimmel);
}


/* Follow-up dialogue styling */
.followup-section {
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.followup-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.followup-icon {
    font-size: 1rem;
}

.followup-header h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.followup-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.followup-form textarea {
    height: 80px;
    font-size: 0.82rem;
}

.followup-form button {
    align-self: flex-end;
}

/* Spinners & Shimmers */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Shimmer Overlay for Graphs/Text loading */
.shimmer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 11, 17, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    z-index: 100;
}

.shimmer-overlay p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.05em;
}

.pulse-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0) 70%);
    border: 2px solid var(--primary-color);
    animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        transform: scale(1.1);
        opacity: 1;
        box-shadow: 0 0 20px 8px rgba(16, 185, 129, 0.2);
    }
    100% {
        transform: scale(0.8);
        opacity: 0.5;
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
}

/* Skeleton Loading Lines */
.shimmer-line {
    width: 100%;
    height: 14px;
    background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);
    background-size: 200% 100%;
    animation: shimmer-swipe 1.5s infinite;
    border-radius: 4px;
}

.header-shimmer {
    height: 20px;
    width: 60%;
    margin-bottom: 12px;
}

.body-shimmer-1 { width: 95%; }
.body-shimmer-2 { width: 90%; }
.body-shimmer-3 { width: 85%; }

@keyframes shimmer-swipe {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Custom error message styles */
.error-box {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    padding: 12px 16px;
    color: #f87171;
    font-size: 0.8rem;
    line-height: 1.4;
    margin-top: 10px;
}

/* --- Chat Bubbles & Layout --- */

#chat-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

/* Chat bubble common styling */
.chat-message {
    max-width: 85%;
    padding: 14px 16px;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.55;
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: bubble-fade-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes bubble-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Message (Right aligned, colored) */
.chat-message.user {
    align-self: flex-end;
    background-color: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #e6fffa;
    border-bottom-right-radius: 2px;
}

.chat-message.user p {
    margin: 0;
}

/* Assistant Message (Left aligned, glassmorphic dark) */
.chat-message.assistant {
    align-self: flex-start;
    background-color: rgba(255, 255, 255, 0.015);
    border: 1px solid var(--border-color);
    color: #d1d5db;
    border-bottom-left-radius: 2px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.chat-message.assistant p {
    margin-bottom: 0;
}

/* Pinned footer layout for followup */
.panel-interpretation .panel-footer.followup-section {
    border-top: 1px solid var(--border-color);
    padding: 14px 20px;
    background: rgba(8, 11, 17, 0.95);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.panel-interpretation .followup-form {
    display: flex;
    gap: 12px;
    flex-direction: row;
    align-items: flex-end;
}

.panel-interpretation .followup-form textarea {
    height: 42px;
    padding: 10px 16px;
    font-size: 0.85rem;
    border-radius: 21px;
    flex-grow: 1;
    resize: none;
    line-height: 1.4;
    transition: all 0.25s ease;
    background-color: rgba(0, 0, 0, 0.35);
}

.panel-interpretation .followup-form textarea:focus {
    box-shadow: 0 0 0 3px var(--primary-glow);
    background-color: rgba(0, 0, 0, 0.45);
}

.panel-interpretation .followup-form button {
    height: 42px;
    border-radius: 21px;
    padding: 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
