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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.app-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    width: 98%;
    max-width: 1600px;
    height: 95vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    padding: 12px 15px;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.header-text {
    flex: 1;
    text-align: center;
}

header h1 {
    font-size: 1.4rem;
    margin-bottom: 3px;
}

header p {
    opacity: 0.9;
    font-size: 0.85rem;
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
}

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

.toggle-btn.active {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.8);
}

.session-info {
    margin-top: 6px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: monospace;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.session-info.hidden {
    display: none;
}

.new-session-link,
.sessions-list-link {
    color: white;
    text-decoration: none;
    margin-left: 15px;
    padding: 5px 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    font-size: 0.85rem;
    transition: background 0.3s ease;
}

.new-session-link:hover,
.sessions-list-link:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Main content - 2 колонки */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Ліва колонка - Профілі симулятора */
.simulator-column {
    width: 420px;
    min-width: 420px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f8f9fa;
    border-right: 2px solid #e0e0e0;
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
    flex-shrink: 0;
    opacity: 1;
}

.simulator-column.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}

.profile-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 1px solid #dee2e6;
    transition: flex 0.3s ease;
}

.profile-section.collapsed {
    flex: 0 0 auto;
}

.profile-section:last-child {
    border-bottom: none;
}

.profile-header {
    padding: 12px 15px;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
}

.profile-header:hover {
    background: #dee2e6;
}

.profile-header h4 {
    margin: 0;
    font-size: 1rem;
    color: #495057;
}

.profile-header::after {
    content: '▼';
    font-size: 0.8rem;
    color: #6c757d;
    transition: transform 0.3s ease;
}

.profile-section.collapsed .profile-header::after {
    transform: rotate(-90deg);
}

.profile-select {
    margin: 10px 15px;
    padding: 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
    font-size: 0.9rem;
    cursor: pointer;
}

.profile-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: #495057;
    white-space: pre-wrap;
    transition: opacity 0.3s ease, padding 0.3s ease;
    opacity: 1;
}

.profile-section.collapsed .profile-select,
.profile-section.collapsed .profile-content,
.profile-section.collapsed .demographics-form {
    display: none;
}

.loading-text {
    color: #6c757d;
    font-style: italic;
}

.demographics-section {
    flex: 0 0 auto;
}

.demographics-form {
    padding: 15px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
}

.form-group {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    color: #495057;
}

.form-control {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
    font-size: 0.85rem;
    cursor: pointer;
}

/* Центральна колонка - Чат */
.chat-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 2px solid #e0e0e0;
}

/* Права колонка - JSON дані */
.data-column {
    width: 420px;
    min-width: 420px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f8f9fa;
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
    flex-shrink: 0;
    opacity: 1;
}

.data-column.collapsed {
    width: 0;
    min-width: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}

/* Панель мотивації */
.motivation-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-bottom: 2px solid #dee2e6;
    transition: flex 0.3s ease;
}

.motivation-panel.collapsed {
    flex: 0 0 auto;
}

/* Панель оцінених віх */
.milestones-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: flex 0.3s ease;
}

.milestones-panel.collapsed {
    flex: 0 0 auto;
}

/* Контент мотивації */
.motivation-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Список віх */
.milestones-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.empty-message {
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 20px;
    margin: 0;
}

/* Елементи мотивації */
.motivation-item {
    margin-bottom: 10px;
    padding: 8px 10px;
    background: white;
    border-left: 3px solid #4facfe;
    border-radius: 4px;
}

.motivation-item:last-child {
    margin-bottom: 0;
}

.motivation-label {
    font-weight: 600;
    color: #4facfe;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.motivation-value {
    color: #212529;
    line-height: 1.4;
    font-size: 0.85rem;
}

/* Елемент віхи */
.milestone-item {
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
    font-size: 0.85rem;
}

.milestone-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.milestone-category {
    font-weight: 600;
    color: #495057;
    font-size: 0.8rem;
}

.milestone-age {
    color: #6c757d;
    font-size: 0.75rem;
}

.milestone-essence {
    color: #212529;
    line-height: 1.3;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.milestone-scores {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-left: auto;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: default;
}

.score-value {
    font-weight: 600;
    color: #495057;
}

.score-separator {
    color: #ced4da;
    margin: 0 2px;
    font-weight: 300;
}

.total-percentage {
    font-weight: 600;
}

.overall-score {
    font-size: 0.85rem;
}

.milestone-evidence {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #e9ecef;
    font-size: 0.75rem;
    color: #6c757d;
    font-style: italic;
    line-height: 1.4;
}

.milestone-red-flags {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid #ffeaa7;
    font-size: 0.75rem;
    color: #856404;
    font-style: italic;
    line-height: 1.4;
    background: #fff9e6;
    padding: 6px 8px;
    border-radius: 4px;
}

.data-header {
    padding: 15px 20px;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s ease;
}

.data-header:hover {
    background: #dee2e6;
}

.data-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #495057;
}

.data-header::after {
    content: '▼';
    font-size: 0.8rem;
    color: #6c757d;
    transition: transform 0.3s ease;
}

.motivation-panel.collapsed .data-header::after,
.milestones-panel.collapsed .data-header::after {
    transform: rotate(-90deg);
}

.motivation-panel.collapsed .motivation-content,
.milestones-panel.collapsed .milestones-list {
    display: none;
}


.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Не дозволяємо виходити за межі */
    min-height: 0; /* Важливо для Firefox */
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f8f9fa;
    min-height: 0; /* Важливо для Firefox */
}

.message {
    margin-bottom: 15px;
    display: flex;
    animation: fadeIn 0.3s ease-in;
}

.message p {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
}

.bot-message {
    justify-content: flex-start;
    flex-direction: column;
    align-items: flex-start;
}

.bot-message p,
.bot-message .message-content {
    background: #e3f2fd;
    color: #1976d2;
    border-bottom-left-radius: 5px;
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
}

.message-metadata {
    font-size: 0.75rem;
    color: #666;
    opacity: 0.7;
    margin-top: 4px;
    margin-left: 12px;
    font-style: italic;
}

/* Стилі для Markdown елементів у повідомленнях бота */
.bot-message .message-content h1,
.bot-message .message-content h2,
.bot-message .message-content h3,
.bot-message .message-content h4,
.bot-message .message-content h5,
.bot-message .message-content h6 {
    color: #1565c0;
    margin: 8px 0 4px 0;
    font-weight: 600;
}

.bot-message .message-content h1 { font-size: 1.4em; }
.bot-message .message-content h2 { font-size: 1.3em; }
.bot-message .message-content h3 { font-size: 1.2em; }
.bot-message .message-content h4 { font-size: 1.1em; }

.bot-message .message-content p {
    margin: 6px 0;
    padding: 0;
    background: none;
    color: inherit;
    border-radius: 0;
    max-width: none;
}

.bot-message .message-content strong {
    font-weight: 700;
    color: #0d47a1;
}

.bot-message .message-content em {
    font-style: italic;
    color: #1565c0;
}

.bot-message .message-content ul,
.bot-message .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bot-message .message-content li {
    margin: 2px 0;
}

.bot-message .message-content blockquote {
    border-left: 4px solid #4facfe;
    margin: 8px 0;
    padding: 4px 0 4px 12px;
    background: rgba(79, 172, 254, 0.1);
    border-radius: 0 4px 4px 0;
}

.bot-message .message-content code {
    background: rgba(79, 172, 254, 0.1);
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.bot-message .message-content pre {
    background: rgba(79, 172, 254, 0.1);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0;
}

.bot-message .message-content pre code {
    background: none;
    padding: 0;
}

.user-message {
    justify-content: flex-end;
}

.user-message p {
    background: #4facfe;
    color: white;
    border-bottom-right-radius: 5px;
}

.chat-input-wrapper {
    flex: 0 0 auto; /* Не розтягується, фіксована висота */
    background: white;
    border-top: 1px solid #e0e0e0;
    position: relative;
}

.input-loader {
    padding: 8px 20px;
    background: #f0f8ff;
    border-bottom: 1px solid #4facfe;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #1976d2;
    animation: fadeIn 0.2s ease-in;
}

.input-loader.hidden {
    display: none;
}

.input-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e3f2fd;
    border-top: 2px solid #4facfe;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.chat-input {
    padding: 20px;
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.input-controls {
    flex: 1;
    position: relative;
    display: flex;
    gap: 8px;
}

.input-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.button-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 150px;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    outline: none;
    font-size: 16px;
    transition: border-color 0.3s ease;
    resize: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.4;
}

#message-input:focus {
    border-color: #4facfe;
}

.voice-btn,
.clear-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    padding: 0;
}

.voice-btn:hover:not(:disabled),
.clear-btn:hover:not(:disabled) {
    background: #f8f9fa;
    border-color: #4facfe;
}

.voice-btn.recording {
    background: #ff4444 !important;
    border-color: #ff4444 !important;
    animation: pulse 1.5s ease-in-out infinite;
    animation-fill-mode: both;
}

.voice-btn.processing {
    background: #ffa500 !important;
    border-color: #ffa500 !important;
    animation: pulse 1.5s ease-in-out infinite;
    animation-fill-mode: both;
}

.voice-btn:disabled,
.clear-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

#send-btn {
    padding: 10px 16px;
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    flex: 1;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

#send-btn .btn-icon,
.auto-response-btn .btn-icon,
.simulator-btn .btn-icon {
    display: none;
}

#send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

#send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.simulator-btn:disabled,
.auto-response-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading {
    position: fixed;
    top: 100px;
    right: 520px;
    background: white;
    padding: 15px 20px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    text-align: center;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
}

.hidden {
    display: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4facfe;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0;
    flex-shrink: 0;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Оверлей для мобільної версії */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.mobile-overlay.active {
    display: block;
}

@media (max-width: 1200px) {
    .data-column {
        width: 400px;
    }
}

@media (max-width: 768px) {
    .app-container {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }

    header {
        padding: 10px;
    }

    .header-content {
        gap: 10px;
    }

    header h1 {
        font-size: 0.85rem;
        margin-bottom: 2px;
    }

    .toggle-btn {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .session-info {
        font-size: 0.7rem;
        padding: 4px 8px;
        margin-top: 4px;
        flex-direction: column;
        gap: 6px;
    }

    .session-info > span {
        display: inline;
        white-space: nowrap;
    }

    .session-links {
        display: flex;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .new-session-link,
    .sessions-list-link {
        font-size: 0.7rem;
        margin-left: 0;
        padding: 3px 6px;
    }

    .main-content {
        position: relative;
    }

    .chat-column {
        border-right: none;
    }

    /* Ліва панель як drawer */
    .simulator-column {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 80%;
        min-width: 0;
        max-width: 90vw;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        margin-left: 0;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .simulator-column.visible {
        transform: translateX(0);
    }

    .simulator-column.collapsed {
        margin-left: 0;
        width: 80%;
        max-width: 80vw;
        opacity: 1;
    }

    .demographics-form {
        grid-template-columns: 1fr;
    }

    /* Права панель як drawer */
    .data-column {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 80%;
        min-width: 0;
        max-width: 80vw;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        margin-right: 0;
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .data-column.visible {
        transform: translateX(0);
    }

    .data-column.collapsed {
        margin-right: 0;
        width: 80%;
        max-width: 90vw;
        opacity: 1;
    }

    .message p,
    .bot-message .message-content {
        max-width: 90%;
    }

    .chat-input {
        padding: 12px;
    }

    #message-input {
        font-size: 14px;
    }

    .button-column {
        min-width: auto;
    }

    #send-btn .btn-text,
    .auto-response-btn .btn-text,
    .simulator-btn .btn-text {
        display: none;
    }

    #send-btn .btn-icon,
    .auto-response-btn .btn-icon,
    .simulator-btn .btn-icon {
        display: inline;
        font-size: 1.2rem;
    }

    #send-btn,
    .auto-response-btn,
    .simulator-btn {
        min-width: 50px;
        padding: 6px !important;
    }
}