/* ===== AI CHAT STYLES - REDESIGNED ===== */
/* Adapted Japanese Minimalism for Chat Interface */
/* Dense spacing for conversation flow, clean styling */

/* ===== SPACING SYSTEM (CHAT-SPECIFIC) ===== */
:root {
    --chat-space-xs: 4px;   /* Tight element spacing */
    --chat-space-sm: 8px;   /* Message spacing */
    --chat-space-md: 12px;  /* Bubble padding */
    --chat-space-lg: 16px;  /* Section padding */
    
    --chat-border-radius: 8px;
    --chat-transition: 150ms cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* ===== AI GUIDE SECTION (IN PANELS) ===== */
.ai-guide-section {
    margin-bottom: 2rem;
    padding: 1.25rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--chat-border-radius);
    text-align: center;
}

.ai-guide-hint {
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.ai-guide-button {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--gold-start);
    color: white;
    border: none;
    border-radius: var(--chat-border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--chat-transition);
}

.ai-guide-button:hover {
    opacity: 0.9;
}

.ai-guide-button:active {
    transform: scale(0.98);
}

.ai-guide-count {
    font-size: 0.875rem;
    opacity: 0.9;
}

/* Button states */
.ai-guide-button.limited {
    background: #FF8C00;
}

.ai-guide-button.exhausted {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.6;
}

.ai-guide-button.exhausted:hover {
    transform: none;
}

/* ===== JOURNEY PROGRESS INDICATORS ===== */
.journey-progress-container {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--chat-border-radius);
}

.journey-progress-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.journey-progress-stages {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.journey-stage {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--chat-border-radius);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    transition: all var(--chat-transition);
    opacity: 0.4;
}

.journey-stage.active {
    opacity: 1;
    border-color: var(--gold-start);
    background: rgba(212, 175, 55, 0.1);
}

.journey-stage.active .stage-label {
    color: var(--gold-start);
    font-weight: 600;
}

.journey-stage.completed {
    opacity: 1;
    border-color: var(--gold-start);
    background: rgba(212, 175, 55, 0.05);
}

.journey-stage.completed .stage-hourglass {
    display: none;
}

.journey-stage.completed::before {
    content: '✓';
    font-size: 1.2rem;
    color: var(--gold-start);
    font-weight: bold;
    margin-right: 0.15rem;
}

.journey-stage.completed .stage-label {
    color: var(--text-secondary);
    opacity: 0.7;
}

.stage-hourglass {
    font-size: 1rem;
}

.stage-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.stage-arrow {
    color: var(--text-secondary);
    opacity: 0.2;
    font-size: 0.875rem;
}

.journey-stage.completed + .stage-arrow {
    opacity: 0.8;
    color: var(--gold-start);
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .journey-progress-stages {
        flex-direction: column;
        align-items: stretch;
    }
    
    .stage-arrow {
        transform: rotate(90deg);
        align-self: center;
    }
    
    .journey-stage {
        width: 100%;
        justify-content: flex-start;
    }
}

/* ===== INTENTION PROMPT ===== */
.intention-prompt {
    margin: 1rem 0;
    padding: 1rem;
    background: rgba(212, 175, 55, 0.05);
    border: 1px solid var(--gold-start);
    border-radius: var(--chat-border-radius);
    text-align: center;
}

.intention-prompt p {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

/* ===== INTENTION STATUS BANNER (AI CHAT MODAL) ===== */
.intention-status-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: rgba(212, 175, 55, 0.08);
    border-bottom: 1px solid var(--border-color);
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.banner-icon {
    color: var(--gold-start);
    font-size: 1.125rem;
}

.banner-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.knowledge-bank-access-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--chat-border-radius);
    cursor: pointer;
    transition: all var(--chat-transition);
    font-size: 0.875rem;
}

.knowledge-bank-access-btn:hover {
    border-color: var(--gold-start);
}

.ai-premium-badge {
    font-size: 0.75rem;
    color: var(--gold-start);
    padding: 0.25rem 0.5rem;
    background: rgba(212, 175, 55, 0.1);
    border-radius: 1rem;
    border: 1px solid var(--gold-start);
    font-weight: 600;
    letter-spacing: 0.025em;
}

#message-counter.premium {
    background: rgba(212, 175, 55, 0.1);
    border-color: var(--gold-start);
}

/* ===== AI CHAT MODAL ===== */
#ai-chat-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 1rem;
}

.ai-chat-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== CHAT HEADER ===== */
.ai-chat-header {
    padding: var(--chat-space-lg);
    border-bottom: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 32px 1fr 32px;
    gap: var(--chat-space-md);
    align-items: center;
    position: relative;
}

/* Sun icon in header (left corner) */
.ai-header-sun {
    grid-column: 1;
    justify-self: start;
    align-self: center;
}

/* Restart button (center) */
#ai-new-conversation-btn {
    grid-column: 2;
    justify-self: center;
}

/* Close button (right corner) */
.ai-chat-header .ai-close-btn {
    grid-column: 3;
    justify-self: end;
}

/* Progress and meta sections span full width below main header */
.ai-chat-header .ai-chat-progress {
    grid-column: 1 / -1;
    padding: 0.75rem 0;
    text-align: center;
}

.ai-chat-header .ai-chat-meta {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ai-chat-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color var(--chat-transition);
    padding: 0;
    line-height: 1;
}

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

/* ===== MESSAGES AREA ===== */
#ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--chat-space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--chat-space-sm); /* Tight spacing: 8px between messages */
}

/* ===== MESSAGE STRUCTURE ===== */
.ai-message {
    display: flex;
    gap: var(--chat-space-sm);
    align-items: flex-start;
}

.ai-message.user {
    flex-direction: row-reverse;
}

/* ===== AVATARS (SIMPLIFIED) ===== */
.ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gold-start);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    color: white;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    color: white;
}

/* ===== MESSAGE BUBBLES ===== */
.ai-message-bubble {
    background: var(--bg-primary);
    padding: var(--chat-space-md); /* 12px padding */
    border-radius: var(--chat-border-radius);
    max-width: 70%;
    word-wrap: break-word;
    border: 1px solid var(--border-color);
}

.ai-message.user .ai-message-bubble {
    background: rgba(212, 175, 55, 0.08);
    border-color: rgba(212, 175, 55, 0.2);
    text-align: right;
}

.ai-message-bubble p {
    margin: 0 0 0.5rem 0;
    line-height: 1.5;
    font-size: 0.9375rem;
}

.ai-message-bubble p:last-child {
    margin-bottom: 0;
}

.ai-message-bubble.pending {
    opacity: 0.7;
}

.pending-icon {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    opacity: 0.6;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* ===== INPUT AREA - FLOATING PILL DESIGN ===== */
.ai-input-area {
    padding: var(--chat-space-lg);
    padding-bottom: calc(var(--chat-space-lg) + var(--chat-space-md));
}

.ai-input-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--chat-space-md);
    padding: 0 var(--chat-space-xs);
}

.ai-new-conversation-btn {
    padding: var(--chat-space-xs) var(--chat-space-md);
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all var(--chat-transition);
}

.ai-new-conversation-btn:hover {
    border-color: var(--gold-start);
    color: var(--gold-start);
}

/* FLOATING PILL - Modern chat input container */
.chat-input-pill {
    display: flex;
    align-items: flex-end;
    gap: var(--chat-space-sm);
    background: var(--bg-secondary);
    border-radius: 30px;
    padding: var(--chat-space-xs);
    box-shadow: 0 2px 12px var(--shadow-light);
    transition: box-shadow var(--chat-transition);
}

.chat-input-pill:focus-within {
    box-shadow: 0 4px 16px var(--shadow-medium);
}

#ai-input {
    flex: 1;
    padding: var(--chat-space-md);
    padding-left: calc(var(--chat-space-md) + var(--chat-space-xs));
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9375rem;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    min-height: 20px;
}

#ai-input:focus {
    outline: none;
}

/* Send button as icon-only circle inside pill */
#ai-send-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    padding: 0;
    background: var(--gold-start);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--chat-transition);
    flex-shrink: 0;
}

#ai-send-btn:hover {
    background: var(--gold-end);
    transform: scale(1.05);
}

#ai-send-btn:active {
    transform: scale(0.95);
}

#ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: scale(1);
}

#ai-send-btn svg {
    display: block;
}

/* ===== CHARACTER COUNT ===== */
.ai-char-count {
    position: absolute;
    bottom: var(--chat-space-xs);
    right: var(--chat-space-lg);
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.ai-char-count.warning {
    color: #ff6b6b;
}

/* ===== LOADING STATE ===== */
#ai-loading {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 1rem;
}

.ai-loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.ai-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-color);
    border-top-color: var(--gold-start);
    border-radius: 50%;
    animation: ai-spin 0.8s linear infinite;
}

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

/* ===== UPGRADE PROMPT ===== */
#ai-upgrade-prompt {
    text-align: center;
    padding: 1rem;
    background: rgba(212, 175, 55, 0.05);
    border-radius: var(--chat-border-radius);
    margin: 1rem var(--chat-space-lg);
}

#ai-upgrade-prompt p {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* ===== PROGRESS TEXT ===== */
.ai-chat-progress {
    padding: 0.75rem var(--chat-space-lg);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

#ai-progress-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===== MESSAGE COUNTER ===== */
.message-counter-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--chat-border-radius);
}

#message-counter {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===== MESSAGE EDITING BUTTONS ===== */
.message-actions {
    margin-top: var(--chat-space-xs);
    display: flex;
    gap: var(--chat-space-xs);
    flex-wrap: wrap;
}

.message-action-btn {
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: all var(--chat-transition);
}

.message-action-btn:hover {
    border-color: var(--gold-start);
    color: var(--text-primary);
}

.message-action-btn:active {
    transform: scale(0.98);
}

.message-action-btn.delete {
    color: #FF6B6B;
    border-color: #FF6B6B;
}

.message-action-btn.delete:hover {
    background: #FF6B6B;
    color: white;
}

.message-action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ===== COMMITMENT SUN BADGE ===== */
.sun-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: var(--gold-start);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
    z-index: 10;
}

.sun-badge.loading {
    animation: rotate 2s linear infinite;
}

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

.sun-badge.pulse {
    animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* ===== PENDING MESSAGE ACTION BUTTONS ===== */
.btn-ai-action {
    background: var(--gold-start);
    color: white;
    border: none;
    cursor: pointer;
    transition: opacity var(--chat-transition);
    padding: 0.5rem 1rem;
    border-radius: var(--chat-border-radius);
    font-weight: 600;
}

.btn-ai-action:hover {
    opacity: 0.9;
}

.btn-ai-action:active {
    transform: scale(0.98);
}

.btn-ai-cancel {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--chat-transition);
    padding: 0.5rem 1rem;
    border-radius: var(--chat-border-radius);
}

.btn-ai-cancel:hover {
    border-color: var(--text-secondary);
}

/* ===== JOURNEY SECTION SWITCHER ===== */
.journey-section-switcher {
    margin-bottom: 1.5rem;
}

.section-switch-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(212, 175, 55, 0.05);
    border: 1px solid rgba(212, 175, 55, 0.15);
    border-radius: var(--chat-border-radius);
    cursor: pointer;
    transition: all var(--chat-transition);
}

.section-switch-banner:hover {
    background: rgba(212, 175, 55, 0.1);
    border-color: rgba(212, 175, 55, 0.3);
}

.switch-text {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
}

.switch-arrow {
    font-size: 1rem;
    color: var(--gold-start);
}

.section-notification-badge {
    width: 8px;
    height: 8px;
    background: var(--gold-start);
    border-radius: 50%;
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* ===== JOURNEY SECTIONS ===== */
.journey-section {
    display: none;
}

.journey-section.active {
    display: block;
}

/* ===== AI SECTION INLINE STYLES ===== */
.ai-chat-header-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--chat-border-radius);
    margin-bottom: 1rem;
}

.ai-message-counter {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

#ai-messages-inline {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1rem;
    padding: 0.5rem;
}

/* ===== AUTOCOMPLETE DROPDOWN ===== */
.autocomplete-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--chat-border-radius);
    margin-bottom: 50px;
    max-height: 65vh;
    overflow-y: auto;
    z-index: 10002;
}

[data-theme="midnight"] .autocomplete-dropdown,
[data-theme="desert"] .autocomplete-dropdown {
    background-color: var(--bg-secondary);
}

.autocomplete-item {
    padding: 12px 15px;
    cursor: pointer;
    transition: background-color var(--chat-transition);
    border-bottom: 1px solid var(--border-color);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background-color: var(--bg-primary);
}

.autocomplete-item strong {
    color: var(--gold-start);
    font-weight: 600;
}

.autocomplete-item small {
    color: var(--text-secondary);
    display: block;
    margin-top: 4px;
    font-size: 0.85em;
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 768px) {
    .ai-chat-content {
        width: 95%;
        max-height: 90vh;
        border-radius: 8px;
    }
    
    .ai-message-bubble {
        max-width: 85%;
    }
    
    .ai-guide-section {
        padding: 0.75rem;
    }
    
    .ai-guide-button {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    .ai-chat-progress {
        display: none;
    }
    
    .intention-status-banner {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
    
    .knowledge-bank-access-btn {
        width: 100%;
        justify-content: center;
    }
    
    .ai-chat-header {
        padding: var(--chat-space-md);
    }
    
    #ai-messages {
        padding: var(--chat-space-md);
    }
    
    .ai-input-container {
        padding: var(--chat-space-md);
    }
}

/* ===== THEME-SPECIFIC ===== */
[data-theme="midnight"] .message-action-btn {
    color: #FFFFFF;
}

[data-theme="midnight"] .message-action-btn:hover {
    color: #FFFFFF;
}

[data-theme="midnight"] .message-action-btn.delete {
    color: #FF6B6B;
}

[data-theme="midnight"] .message-action-btn.delete:hover {
    color: white;
}

/* ===== UTILITY ===== */
.hidden {
    display: none;
}