/* --- Base & Variables ---- */
:root {
    /* Light Theme Colors */
    --bg-card: #ffffff;
    --text-light-primary: #333;
    --text-light-secondary: #555;
    --text-on-gradient: #ffffff;

    /* Primary Colors */
    --primary-color: #4a69bd;
    --primary-dark: #1e3799;
    --secondary-color: #6a89cc;

    /* Accent Colors */
    --accent-color: #34e89e;
    --accent-color-rgb: 0, 119, 255;
    --accent-light: #e0f8f0;

    /* Supporting Colors */
    --border-light: #e0e0e0;
    --success-color: #38a169;
    --error-color: #d9534f;
    --info-color: var(--secondary-color);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #4a69bd, #6a89cc);
    --gradient-accent: linear-gradient(to right, #34e89e, #07e07f);

    /* Fonts */
    --font-primary: 'Poppins', sans-serif;

    /* Shadows */
    --shadow-medium: 0 6px 20px rgba(0, 0, 0, 0.1);
    --shadow-subtle: 0 2px 5px rgba(0,0,0,0.05);
}

/* --- Basic Reset & Body --- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }

body.light-theme {
    font-family: var(--font-primary);
    color: var(--text-light-primary);
    background-color: var(--bg-light-primary);
    line-height: 1.7;
}

/* --- Container --- */
.container { max-width: 1140px; margin: 0 auto; padding: 0 20px; }

/* --- Chat Section --- */
.chat-section {
    padding: 60px 0;
    background-color: var(--bg-light-secondary);
}
.chat-container { display: flex; flex-direction: column; align-items: center; }

/* --- Chat Window Structure --- */
.chat-window {
    background-color: var(--bg-card);
    color: var(--text-light-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-medium);
    overflow: hidden;
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    height: 75vh;
    min-height: 550px;
    max-height: 75vh;
    border: 1px solid var(--border-light);
    position: relative;
}

/* --- Chat Header --- */
.chat-header {
    background: var(--bg-light-primary);
    color: var(--text-light-primary);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}
.header-info { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.header-info i { color: var(--primary-color); }

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background-color: #ccc;
    display: inline-block;
    margin-left: 10px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.status-dot.online {
    background-color: var(--success-color);
    box-shadow: 0 0 8px rgba(56, 161, 105, 0.5);
}

/* --- Form Structure --- */
#analysisForm {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* --- Chat Display (Messages Area) --- */
.chat-display {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 18px;
    background-color: #fcfdff;
    min-height: 0;
    max-height: calc(100% - 0px);
    position: relative;
    z-index: 1;
}

/* --- Message Styling --- */
.message {
    display: flex;
    align-items: flex-end;
    max-width: 85%;
    gap: 12px;
    width: 100%;
}
.message p {
    padding: 12px 18px;
    border-radius: 18px;
    margin: 0;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: var(--shadow-subtle);
}
.message .avatar {
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-align: center;
}

/* Bot messages */
.message.bot {
    align-self: flex-start;
}
.message.bot p {
    background-color: #e8eaf6;
    color: var(--text-light-primary);
    border-bottom-left-radius: 5px;
}
.message.bot .avatar {
    background: var(--gradient-primary);
    color: white;
}

/* Placeholder message */
.message.placeholder p {
    background-color: transparent;
    color: #aaa;
    font-style: italic;
    font-size: 0.9rem;
    box-shadow: none;
}

/* Analysis update messages */
.message.analysis-update p {
    background-color: #e0e0e0;
    color: #555;
    font-style: italic;
    font-size: 0.9em;
}

/* --- Chat Input Area --- */
.chat-input-area {
    display: flex;
    flex-direction: column;
    padding: 15px 20px;
    border-top: 1px solid var(--border-light);
    background-color: var(--bg-light-primary);
    gap: 15px;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 10;
}

#userInput {
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 12px 15px;
    font-family: var(--font-primary);
    font-size: 1rem;
    resize: none;
    min-height: 60px;
    max-height: 160px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    line-height: 1.5;
    background-color: #fff;
    color: var(--text-light-primary);
}
#userInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(107, 70, 193, 0.1);
}
#userInput::placeholder {
    color: #a0aec0;
    opacity: 1;
}

/* Input controls */
.input-controls {
    display: flex;
    gap: 10px;
    width: 100%;
    align-items: center;
    justify-content: center;
}

/* Send button */
.send-button {
    background: var(--gradient-accent);
    color: var(--text-on-gradient);
    border: none;
    border-radius: 8px;
    padding: 0 25px;
    min-width: 150px;
    height: 44px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(var(--accent-color-rgb), 0.15);
}
.send-button i {
    margin-right: 8px;
}
.send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 5px 15px rgba(var(--accent-color-rgb), 0.25);
}
.send-button:active:not(:disabled) {
    transform: scale(0.98);
}
.send-button:disabled {
    background: #dce1e5;
    color: #90a4ae;
    cursor: not-allowed;
    opacity: 0.8;
    box-shadow: none;
}

/* --- Loading Indicator --- */
.loading-bar-container {
    width: 100%;
    height: 5px;
    background-color: var(--accent-light);
    border-radius: 3px;
    margin-bottom: 8px;
    overflow: hidden;
    display: none;
}
.loading-bar {
    height: 100%;
    width: 0;
    background: var(--gradient-accent);
    border-radius: 3px;
    transition: width 0.4s ease-out;
}

/* --- Name Inputs --- */
.name-inputs {
    display: flex;
    gap: 15px;
}
.name-inputs .input-group {
    flex: 1;
}
.name-inputs label {
    display: block;
    font-weight: 600;
    margin-bottom: 5px;
    font-size: 0.9rem;
    color: var(--text-light-secondary);
}
.name-inputs input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    font-family: var(--font-primary);
    font-size: 0.95rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.name-inputs input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(107, 70, 193, 0.1);
}

/* --- Results Page --- */
body.results-page {
    background-color: var(--bg-light-secondary);
}
.results-container {
    max-width: 850px;
    margin: 40px auto;
    padding: 30px;
    background-color: var(--bg-card);
    border-radius: 12px;
    box-shadow: var(--shadow-medium);
    border: 1px solid var(--border-light);
}
.results-header {
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 15px;
    margin-bottom: 25px;
}
.results-header i {
    font-size: 1.8rem;
    color: var(--primary-color);
}
.results-header h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--text-light-primary);
}
.analysis-content {
    line-height: 1.7;
}
.analysis-content h2, .analysis-content h3 {
    color: var(--primary-dark);
    margin-top: 25px;
    margin-bottom: 15px;
}
.analysis-content h2 {
    font-size: 1.4rem;
    padding-bottom: 5px;
    border-bottom: 2px solid var(--accent-light);
}
.analysis-content h3 {
    font-size: 1.2rem;
    color: var(--primary-color);
}
.analysis-content pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
    line-height: 1.6;
    background-color: #f0f2f5;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    margin: 15px 0;
    overflow-x: auto;
    font-family: monospace;
}
.back-link {
    display: inline-block;
    margin-top: 30px;
    padding: 10px 20px;
    background: var(--gradient-primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.3s ease, transform 0.2s ease;
    font-weight: 500;
}
.back-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-subtle);
}

/* --- Responsiveness --- */
@media (max-width: 992px) {
    .chat-window {
        max-width: 90%;
    }
}

@media (max-width: 768px) {
    .chat-section {
        padding: 30px 0;
    }
    .container {
        padding: 0;
    }
    .chat-window {
        max-width: 100%;
        height: 80vh;
        min-height: 450px;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    .chat-display {
        padding: 20px 15px;
        gap: 15px;
    }
    .message {
        max-width: 90%;
    }
    .message p {
        padding: 10px 15px;
    }
    .message .avatar {
        width: 35px;
        height: 35px;
        font-size: 1.3rem;
    }
    .chat-input-area {
        padding: 12px 15px;
        gap: 8px;
    }
    #userInput {
        padding: 10px 15px;
        min-height: 50px;
    }
    .name-inputs {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 576px) {
    .chat-window {
        height: 75vh;
        min-height: 400px;
    }
    .chat-display {
        padding: 15px 10px;
    }
    .message .avatar {
        width: 30px;
        height: 30px;
        font-size: 1.2rem;
    }
    .input-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .send-button {
        width: 100%;
        height: 44px;
        min-width: unset;
    }
    .send-button span {
        display: inline;
    }
}