/* ═══════════════════════════════════════════════════════════════════════════════
 * Einblick Nexus PWA — Chat View Styles
 * ═══════════════════════════════════════════════════════════════════════════════
 * AMOLED-first conversational interface. CEO ↔ JANO.
 * Uses design tokens from tokens.css.
 * ═══════════════════════════════════════════════════════════════════════════════ */


/* ─── Layout ──────────────────────────────────────────────────────────────── */

.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}


/* ─── Session Header ─────────────────────────────────────────────────────── */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    min-height: 44px;
}

.chat-header__info {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    min-width: 0;
}

.chat-header__agent-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--accent-green);
    flex-shrink: 0;
    box-shadow: 0 0 6px var(--accent-green);
    animation: pulse-dot 2s ease-in-out infinite;
}

.chat-header__label {
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header__label strong {
    color: var(--text-primary);
    font-weight: var(--fw-semibold);
}

.chat-header__new-btn {
    background: none;
    border: 1px solid var(--border-medium);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-family: var(--font-sans);
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    white-space: nowrap;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
    gap: var(--sp-1);
}

.chat-header__new-btn:hover {
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.chat-header__new-btn:active {
    background: var(--bg-hover);
    transform: scale(0.96);
}


/* ─── Agent Selector Bar ──────────────────────────────────────────────────── */

.chat-agent-bar {
    display: flex;
    gap: var(--sp-1);
    padding: var(--sp-2) var(--sp-3);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.chat-agent-bar::-webkit-scrollbar {
    display: none;
}

.chat-agent-chip {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    border: 1.5px solid var(--border-subtle);
    background: transparent;
    color: var(--text-tertiary);
    font-size: var(--fs-xs);
    font-family: var(--font-sans);
    font-weight: var(--fw-medium);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 30px;
    transition: all var(--duration-fast) var(--ease-out);
}

.chat-agent-chip:hover {
    border-color: var(--chip-color, var(--accent-blue));
    color: var(--chip-color, var(--accent-blue));
    background: color-mix(in srgb, var(--chip-color, var(--accent-blue)) 8%, transparent);
}

.chat-agent-chip.active {
    border-color: var(--chip-color, var(--accent-blue));
    color: var(--chip-color, var(--accent-blue));
    background: color-mix(in srgb, var(--chip-color, var(--accent-blue)) 12%, transparent);
    font-weight: var(--fw-semibold);
    box-shadow: 0 0 8px color-mix(in srgb, var(--chip-color, var(--accent-blue)) 20%, transparent);
}

.chat-agent-chip:active {
    transform: scale(0.95);
}


/* ─── Messages Container ─────────────────────────────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--sp-4) var(--sp-4) var(--sp-2);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* Subtle fade at the top when scrolled */
.chat-messages::before {
    content: '';
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(to bottom, var(--bg-primary), transparent);
    pointer-events: none;
    z-index: 1;
    flex-shrink: 0;
    margin-bottom: -24px;
}


/* ─── Chat Bubbles ────────────────────────────────────────────────────────── */

.chat-bubble {
    max-width: 85%;
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius-lg);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    word-wrap: break-word;
    overflow-wrap: break-word;
    animation: bubble-appear var(--duration-normal) var(--ease-out) both;
    position: relative;
}

/* CEO Bubble — right-aligned, accent gradient */
.chat-bubble--ceo {
    align-self: flex-end;
    background: linear-gradient(135deg, hsl(220, 80%, 48%), hsl(230, 70%, 38%));
    color: #FFFFFF;
    border-bottom-right-radius: var(--sp-1);
    margin-left: 15%;
}

/* JANO Bubble — left-aligned, dark surface */
.chat-bubble--jano,
.chat-bubble--agent {
    align-self: flex-start;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: var(--sp-1);
    margin-right: 10%;
}


/* ─── Agent Tag ───────────────────────────────────────────────────────────── */

.chat-bubble__agent-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--accent-purple);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--sp-1);
    font-family: var(--font-mono);
}

.chat-bubble__agent-tag::before {
    content: '⬡';
    font-size: 0.6em;
    opacity: 0.7;
}


/* ─── Message Content (Markdown Rendering) ────────────────────────────────── */

.chat-bubble__content {
    line-height: var(--lh-normal);
}

.chat-bubble__content p {
    margin-bottom: var(--sp-2);
}

.chat-bubble__content p:last-child {
    margin-bottom: 0;
}

.chat-bubble__content strong {
    font-weight: var(--fw-semibold);
    color: inherit;
}

.chat-bubble__content em {
    font-style: italic;
    opacity: 0.9;
}

.chat-bubble__content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-bubble--ceo .chat-bubble__content code {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.1);
}

.chat-bubble__content pre {
    margin: var(--sp-2) 0;
    padding: var(--sp-3);
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.6;
}

.chat-bubble--ceo .chat-bubble__content pre {
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.1);
}

.chat-bubble__content pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
}

.chat-bubble__content ul,
.chat-bubble__content ol {
    margin: var(--sp-1) 0;
    padding-left: var(--sp-5);
}

.chat-bubble__content li {
    margin-bottom: 2px;
}

.chat-bubble__content a {
    color: var(--accent-blue);
    text-decoration: none;
    border-bottom: 1px solid rgba(68, 138, 255, 0.3);
    transition: border-color var(--duration-fast);
}

.chat-bubble__content a:hover {
    border-bottom-color: var(--accent-blue);
}


/* ─── Timestamp ───────────────────────────────────────────────────────────── */

.chat-bubble__time {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    margin-top: var(--sp-1);
    text-align: right;
}

.chat-bubble--ceo .chat-bubble__time {
    color: rgba(255, 255, 255, 0.45);
}


/* ─── Thinking Indicator ──────────────────────────────────────────────────── */

.chat-bubble__thinking {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
}

.chat-thinking-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.chat-thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--accent-purple);
    opacity: 0.4;
    animation: thinking-bounce 1.4s ease-in-out infinite;
}

.chat-thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.chat-thinking__label {
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    letter-spacing: 0.02em;
}


/* ─── Quick Actions (empty state) ─────────────────────────────────────────── */

.chat-quick-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-4);
    padding: var(--sp-8) var(--sp-4);
    flex: 1;
    animation: fade-in var(--duration-slow) var(--ease-out);
}

.chat-quick-actions__logo {
    font-size: 2.5rem;
    opacity: 0.3;
    user-select: none;
}

.chat-quick-actions__title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
}

.chat-quick-actions__subtitle {
    font-size: var(--fs-sm);
    color: var(--text-tertiary);
    text-align: center;
    max-width: 280px;
}

.chat-quick-actions__grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--sp-2);
    width: 100%;
    max-width: 320px;
    margin-top: var(--sp-2);
}

.chat-quick-action {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
    min-height: var(--touch-min);
}

.chat-quick-action:hover {
    background: var(--bg-hover);
    border-color: var(--border-medium);
    color: var(--text-primary);
}

.chat-quick-action:active {
    transform: scale(0.97);
    background: var(--bg-active);
}

.chat-quick-action__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}


/* ─── Input Bar ───────────────────────────────────────────────────────────── */

.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-4);
    padding-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    padding: var(--sp-3) var(--sp-4);
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: var(--touch-comfortable);
    line-height: var(--lh-normal);
    transition: border-color var(--duration-fast);
    -webkit-appearance: none;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.chat-input:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(68, 138, 255, 0.15);
}

.chat-send-btn {
    width: var(--touch-comfortable);
    height: var(--touch-comfortable);
    border-radius: var(--radius-full);
    border: none;
    background: linear-gradient(135deg, hsl(220, 80%, 48%), hsl(240, 70%, 42%));
    color: #FFFFFF;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--duration-fast) var(--ease-out);
    box-shadow: 0 2px 8px rgba(68, 138, 255, 0.25);
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(68, 138, 255, 0.35);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Send icon arrow */
.chat-send-btn__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--duration-fast) var(--ease-out);
}

.chat-send-btn:not(:disabled):active .chat-send-btn__icon {
    transform: translateX(2px);
}


/* ─── Day Separator ───────────────────────────────────────────────────────── */

.chat-day-separator {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) 0;
}

.chat-day-separator::before,
.chat-day-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}

.chat-day-separator__label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}


/* ─── Empty State ─────────────────────────────────────────────────────────── */

.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: var(--sp-3);
    padding: var(--sp-8);
    animation: fade-in var(--duration-slow) var(--ease-out);
}

.chat-empty__icon {
    font-size: 3rem;
    opacity: 0.15;
}

.chat-empty__text {
    font-size: var(--fs-sm);
    color: var(--text-tertiary);
    text-align: center;
}


/* ─── Animations ──────────────────────────────────────────────────────────── */

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

@keyframes thinking-bounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 6px var(--accent-green);
    }
    50% {
        opacity: 0.6;
        box-shadow: 0 0 12px var(--accent-green);
    }
}


/* ─── Responsive: Small Screens ───────────────────────────────────────────── */

@media (max-width: 380px) {
    .chat-bubble {
        max-width: 90%;
        padding: var(--sp-2) var(--sp-3);
        font-size: var(--fs-sm);
    }

    .chat-quick-actions__grid {
        grid-template-columns: 1fr;
    }

    .chat-header {
        padding: var(--sp-2) var(--sp-3);
    }
}


/* ─── Code Language Badge ─────────────────────────────────────────────────── */

.chat-bubble__content pre {
    position: relative;
}

.chat-bubble__content pre .code-lang {
    position: absolute;
    top: 0;
    right: 0;
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
    font-weight: var(--fw-medium);
    color: var(--text-tertiary);
    background: var(--bg-surface);
    padding: 2px 8px;
    border-radius: 0 var(--radius-sm) 0 var(--radius-sm);
    border-left: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    text-transform: lowercase;
    letter-spacing: 0.02em;
}


/* ─── Delegation Chain ────────────────────────────────────────────────────── */

.chat-bubble__delegation {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    margin-top: var(--sp-2);
    padding-top: var(--sp-2);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

.chat-bubble__delegation-dot {
    width: 5px;
    height: 5px;
    border-radius: var(--radius-full);
    background: var(--accent-purple);
    opacity: 0.6;
}

.chat-bubble__delegation-agent {
    color: var(--accent-purple);
    font-weight: var(--fw-medium);
}

.chat-bubble__delegation-arrow {
    color: var(--text-tertiary);
    opacity: 0.5;
}


/* ─── Response Metadata Footer ────────────────────────────────────────────── */

.chat-bubble__meta {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    margin-top: var(--sp-2);
    font-size: 10px;
    color: var(--text-tertiary);
    opacity: 0.6;
    font-family: var(--font-mono);
}

.chat-bubble__meta-item {
    display: flex;
    align-items: center;
    gap: 3px;
}


/* ─── Scroll to Bottom FAB ────────────────────────────────────────────────── */

.chat-scroll-fab {
    position: absolute;
    bottom: 80px;
    right: var(--sp-4);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-card);
    transition: all var(--duration-fast) var(--ease-out);
    z-index: var(--z-base);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

.chat-scroll-fab.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.chat-scroll-fab:hover {
    background: var(--bg-hover);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}
