/* ================================================================
   Personaut PDK — Chat Interface Stylesheet
   Design Language: personaut.ai (light, warm, purple accents)
   ================================================================ */

/* ── Chat Layout ── */
.chat-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl);
    gap: var(--space-md);
    min-height: calc(100vh - 60px);
}

.chat-header {
    margin-bottom: var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.chat-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ── LLM Status Badge ── */
.llm-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.72rem;
    padding: 0.25rem 0.85rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    letter-spacing: 0.02em;
    vertical-align: middle;
    margin-left: var(--space-sm);
}

.llm-badge.active {
    background: rgba(0, 184, 148, 0.1);
    color: var(--success);
    border: 1px solid rgba(0, 184, 148, 0.25);
}

.llm-badge.fallback {
    background: rgba(253, 203, 110, 0.15);
    color: #e17055;
    border: 1px solid rgba(253, 203, 110, 0.3);
}

/* ── Token Totals Badge ── */
.token-total-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    padding: 0.2rem 0.65rem;
    border-radius: var(--radius-full);
    margin-left: 0.75rem;
    background: var(--accent-light);
    border: 1px solid rgba(108, 92, 231, 0.12);
    font-family: var(--font-mono);
    vertical-align: middle;
}

.token-total-badge .label {
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.6rem;
}

.token-total-badge .val {
    color: var(--text-primary);
    font-weight: 700;
}

.token-total-badge .sep {
    color: var(--bg-tertiary);
    margin: 0 0.1rem;
}

.token-total-badge .prompt {
    color: var(--info);
}

.token-total-badge .completion {
    color: var(--success);
}

/* ── Chat Container ── */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 400px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(108, 92, 231, 0.08);
}

/* ── Messages Area ── */
.messages {
    flex: 1;
    padding: var(--space-lg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: linear-gradient(180deg, rgba(108, 92, 231, 0.02), transparent);
}

.message {
    max-width: 70%;
    padding: 0.85rem 1.15rem;
    border-radius: var(--radius-lg);
    animation: msgFadeIn 0.35s ease;
    line-height: 1.5;
    font-size: 0.95rem;
}

@keyframes msgFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    background: var(--accent-gradient);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 12px rgba(108, 92, 231, 0.2);
}

.message.received {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.message-sender {
    font-size: 0.72rem;
    color: rgba(0, 0, 0, 0.4);
    margin-bottom: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.message.sent .message-sender {
    color: rgba(255, 255, 255, 0.65);
}

/* ── Token Badge on Messages ── */
.token-badge {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.35rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    font-size: 0.65rem;
    font-family: var(--font-mono);
}

.token-badge .token-item {
    color: var(--text-muted);
}

.token-badge .token-item.prompt {
    color: var(--info);
}

.token-badge .token-item.completion {
    color: var(--success);
}

/* ── Activation Info Badges ── */
.activation-info {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.4rem;
    padding-top: 0.35rem;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
}

.act-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.6rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
    cursor: default;
    transition: opacity 0.2s;
    font-weight: 600;
}

.act-badge:hover {
    opacity: 0.75;
}

.act-mask {
    background: rgba(108, 92, 231, 0.1);
    color: var(--accent);
    border: 1px solid rgba(108, 92, 231, 0.2);
}

.act-trigger {
    background: rgba(253, 203, 110, 0.12);
    color: #e17055;
    border: 1px solid rgba(253, 203, 110, 0.25);
}

.act-memory {
    background: rgba(116, 185, 255, 0.1);
    color: var(--info);
    border: 1px solid rgba(116, 185, 255, 0.2);
}

/* ── Typing Indicator ── */
.typing {
    display: inline-flex;
    gap: 4px;
}

.typing span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 0.6s infinite alternate;
}

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

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

@keyframes typingBounce {
    to {
        transform: translateY(-6px);
        opacity: 0.3;
    }
}

/* ── Input Area ── */
.input-area {
    display: flex;
    gap: 0.5rem;
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-top: 1px solid rgba(108, 92, 231, 0.08);
}

.input-area input {
    flex: 1;
    padding: 0.8rem 1.15rem;
    border-radius: var(--radius-pill);
    border: 2px solid transparent;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-family);
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-area input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}

.input-area .btn {
    border-radius: var(--radius-pill);
}

/* ── Session Grid ── */
.session-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-md);
}

.session-card {
    text-decoration: none;
    color: var(--text-primary);
}

.session-card h3 {
    margin-bottom: var(--space-sm);
    font-size: 1.1rem;
}

.session-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.session-card--new {
    border: 2px dashed var(--accent) !important;
    text-align: center;
    background: var(--accent-light) !important;
}

.session-card--new:hover {
    background: rgba(108, 92, 231, 0.12) !important;
}

/* ── Form Group (chat-specific) ── */
.fg {
    margin-bottom: var(--space-lg);
}

.fg label {
    display: block;
    margin-bottom: var(--space-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.fg select,
.fg input,
.fg textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 2px solid var(--bg-tertiary);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-family);
    font-weight: 500;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.fg select:focus,
.fg input:focus,
.fg textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}

/* ── Collapsible Panels ── */
.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(108, 92, 231, 0.08);
    margin-bottom: 0.5rem;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.6s ease;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.panel-header:hover {
    background: rgba(108, 92, 231, 0.04);
}

.panel-header h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
    margin: 0;
    background: none;
    -webkit-text-fill-color: var(--text-secondary);
}

.panel-toggle {
    color: var(--text-muted);
    font-size: 0.75rem;
    transition: transform 0.2s;
}

.panel-body {
    padding: 0 1rem 1rem;
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.panel-body.collapsed {
    display: none;
}

/* ── Radar Chart ── */
.radar-canvas-wrap {
    flex: 0 0 auto;
}

.radar-legend {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding-top: 0.5rem;
}

.radar-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
}

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

.radar-legend-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.radar-legend-value {
    color: var(--text-primary);
    font-weight: 700;
    font-family: var(--font-mono);
    margin-left: auto;
}

.radar-emotions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.25rem;
}

.radar-emotion-chip {
    font-size: 0.68rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-full);
    background: var(--accent-light);
    border: 1px solid rgba(108, 92, 231, 0.12);
    color: var(--text-secondary);
    font-weight: 500;
}

.radar-emotion-chip .intensity {
    color: var(--accent);
    font-weight: 700;
}

/* ── Active Emotions Section Label ── */
.emotions-section-label {
    margin-top: 0.5rem;
    border-top: 1px solid var(--bg-tertiary);
    padding-top: 0.5rem;
}

.section-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

/* ── Item Lists (Memories, Masks, Triggers) ── */
.item-list {
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 0.6rem;
}

.item-list::-webkit-scrollbar {
    width: 4px;
}

.item-list::-webkit-scrollbar-track {
    background: transparent;
}

.item-list::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

/* Memory Items */
.memory-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    background: rgba(108, 92, 231, 0.04);
    margin-bottom: 0.35rem;
    border: 1px solid rgba(108, 92, 231, 0.08);
    transition: border-color 0.2s;
}

.memory-item:hover {
    border-color: rgba(108, 92, 231, 0.2);
}

.memory-item .item-content {
    flex: 1;
    min-width: 0;
}

.memory-item .item-text {
    font-size: 0.82rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.memory-item .item-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.memory-item .item-meta .salience-high {
    color: var(--warning);
}

.memory-item .item-meta .salience-mid {
    color: var(--accent);
}

.memory-item .item-meta .salience-low {
    color: var(--text-muted);
}

.memory-item .item-meta .emo-tags {
    color: var(--info);
}

/* Mask Items */
.mask-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
    background: rgba(116, 185, 255, 0.04);
    margin-bottom: 0.4rem;
    border: 1px solid rgba(116, 185, 255, 0.1);
    transition: border-color 0.2s;
}

.mask-item:hover {
    border-color: rgba(116, 185, 255, 0.25);
}

.mask-item .item-content {
    flex: 1;
    min-width: 0;
}

.mask-item .mask-name {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

.mask-item .mask-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
    line-height: 1.3;
}

.mask-item .mask-triggers-text {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* Trigger Items */
.trigger-item {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-sm);
    background: rgba(253, 203, 110, 0.04);
    margin-bottom: 0.4rem;
    border: 1px solid rgba(253, 203, 110, 0.1);
    transition: border-color 0.2s;
}

.trigger-item:hover {
    border-color: rgba(253, 203, 110, 0.2);
}

.trigger-item .item-content {
    flex: 1;
    min-width: 0;
}

.trigger-item .trigger-desc {
    font-size: 0.82rem;
    color: var(--text-primary);
}

.trigger-item .trigger-keywords {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.trigger-item .trigger-response {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* ── Mini Badges / Chips ── */
.badge-always-on {
    font-size: 0.55rem;
    background: var(--success);
    color: white;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-type {
    font-size: 0.55rem;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-type--emotional {
    background: rgba(108, 92, 231, 0.15);
    color: var(--accent);
}

.badge-type--situational {
    background: rgba(253, 203, 110, 0.2);
    color: #e17055;
}

.badge-toggle {
    cursor: pointer;
    font-size: 0.6rem;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    transition: all 0.2s;
}

.badge-toggle--on {
    background: rgba(0, 184, 148, 0.1);
    color: var(--success);
    border: 1px solid rgba(0, 184, 148, 0.2);
}

.badge-toggle--off {
    background: rgba(225, 112, 85, 0.1);
    color: var(--error);
    border: 1px solid rgba(225, 112, 85, 0.2);
}

/* Emotion Modification Chips */
.mod-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.3rem;
}

.mod-chip {
    font-size: 0.6rem;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.mod-chip--positive {
    background: rgba(0, 184, 148, 0.08);
    color: var(--success);
    border: 1px solid rgba(0, 184, 148, 0.15);
}

.mod-chip--negative {
    background: rgba(225, 112, 85, 0.08);
    color: var(--error);
    border: 1px solid rgba(225, 112, 85, 0.15);
}

/* Rule Chips */
.rule-chip {
    font-size: 0.6rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(253, 203, 110, 0.08);
    color: #e17055;
    border: 1px solid rgba(253, 203, 110, 0.15);
    font-weight: 600;
}

.rule-match-mode {
    font-size: 0.55rem;
    color: var(--text-muted);
}

/* ── Delete Buttons ── */
.btn-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.72rem;
    padding: 2px 6px;
    flex-shrink: 0;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-delete:hover {
    color: var(--error);
    background: rgba(225, 112, 85, 0.08);
}

/* ── Panel Forms ── */
.panel-form {
    border-top: 1px solid var(--bg-tertiary);
    padding-top: 0.5rem;
}

.panel-form .section-label {
    margin-bottom: 0.35rem;
}

.panel-form-row {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.3rem;
}

.panel-input {
    flex: 1;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid rgba(108, 92, 231, 0.15);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.78rem;
    font-family: var(--font-family);
    font-weight: 500;
    transition: border-color 0.2s;
}

.panel-input:focus {
    outline: none;
    border-color: var(--accent);
}

.panel-input--mask {
    border-color: rgba(116, 185, 255, 0.2);
}

.panel-input--trigger {
    border-color: rgba(253, 203, 110, 0.2);
}

.panel-input--full {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 0.25rem;
}

.panel-textarea {
    width: 100%;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid rgba(108, 92, 231, 0.15);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.78rem;
    font-family: var(--font-family);
    font-weight: 500;
    resize: vertical;
    min-height: 42px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.panel-textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.panel-select {
    padding: 0.35rem 0.55rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid rgba(108, 92, 231, 0.15);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: var(--font-family);
    font-weight: 500;
    transition: border-color 0.2s;
}

.panel-select:focus {
    outline: none;
    border-color: var(--accent);
}

.panel-btn {
    padding: 0.35rem 0.85rem;
    font-size: 0.75rem;
    border-radius: var(--radius-pill);
    border: none;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-family);
    transition: all 0.2s;
    white-space: nowrap;
}

.panel-btn--accent {
    background: var(--accent-gradient);
    color: white;
}

.panel-btn--accent:hover {
    box-shadow: 0 2px 12px rgba(108, 92, 231, 0.3);
}

.panel-btn--blue {
    background: linear-gradient(135deg, var(--info), #0984e3);
    color: white;
}

.panel-btn--blue:hover {
    box-shadow: 0 2px 12px rgba(116, 185, 255, 0.3);
}

.panel-btn--amber {
    background: linear-gradient(135deg, #fdcb6e, #e17055);
    color: white;
}

.panel-btn--amber:hover {
    box-shadow: 0 2px 12px rgba(253, 203, 110, 0.3);
}

/* ── Salience Slider ── */
.salience-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.35rem;
}

.salience-row label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 600;
}

.salience-row input[type="range"] {
    flex: 1;
    accent-color: var(--accent);
}

.salience-display {
    font-size: 0.7rem;
    color: var(--accent);
    min-width: 2.2em;
    text-align: right;
    font-family: var(--font-mono);
    font-weight: 600;
}

/* ── Speaker Profile Preview ── */
.profile-preview {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ── Count Badge ── */
.count-badge {
    font-size: 0.7rem;
    opacity: 0.6;
}

/* ── Empty Panel State ── */
.empty-panel {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 0.8rem 0;
    font-weight: 500;
}

/* ── Error Message in Chat ── */
.error-message {
    color: var(--error);
    font-style: italic;
}