html,
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #0f0f0f;
    color: #e1e5e9;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}

body.keyboard-lock {
    position: fixed;
    inset: 0;
    width: 100%;
    height: var(--app-height, 100dvh);
}

body {
    min-height: var(--app-height, 100dvh);
}

.chat-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.header {
    background-color: #1a1a1a;
    padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
    border-bottom: 1px solid #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    color: #e1e5e9;
    line-height: 1.2;
}

h2 {
    margin: 4px 0 0 0;
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    color: #e1e5e9;
}

.chat-container {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1 1 auto;
    padding: 20px;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
}

.typing-indicator {
    display: flex;
    align-items: center;
    margin: 0 0 20px 0;
    font-style: italic;
    color: #666;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #666;
    animation: bounce 1.4s infinite ease-in-out;
    margin: 0 2px;
}

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

@keyframes bounce {
    0%, 80%, 100% {
        opacity: 0.5;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

.input-container {
    background-color: #1a1a1a;
    padding: 20px;
    border-top: 1px solid #333;
}

.selector-row {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.selector {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: #cbd5f5;
}

.selector span {
    font-weight: 600;
    letter-spacing: 0.02em;
}

.selector select {
    background-color: #2b2b2b;
    color: #e1e5e9;
    border: 1px solid #555;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 14px;
    min-width: 140px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #555;
    border-radius: 12px;
    background-color: #333;
    color: #e1e5e9;
    font-size: 16px;
    line-height: 1.4;
    outline: none;
    box-sizing: border-box;
    resize: none;
    min-height: 20px;
    max-height: 150px;
    font-family: inherit;
}

#message-input::placeholder {
    color: #999;
}

#message-input:focus {
    border-color: #0066cc;
    box-shadow: 0 0 0 2px rgba(0, 102, 204, 0.3);
}

#send-button {
    padding: 12px 20px;
    background-color: #0066cc;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    white-space: nowrap;
}

#send-button:hover {
    background-color: #0052a3;
}

#send-button:disabled {
    background-color: #666;
    cursor: not-allowed;
}

.message {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;
}

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

.message.bot {
    justify-content: flex-start;
}

.message.professor {
    justify-content: flex-start;
}

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

.message {
    display: flex;
    margin-bottom: 16px;
    align-items: flex-start;
    animation: fadeIn 0.3s ease-in;
}

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

.message.bot {
    justify-content: flex-start;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    position: relative;
}

.typing-layer {
    position: absolute;
    inset: 0;
    padding: inherit;
}

.ghost-text {
    visibility: hidden;
    display: block;
}

.message.user .message-content {
    background-color: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.bot .message-content {
    background-color: #374151;
    color: #e1e5e9;
    border-bottom-left-radius: 4px;
}

.message.professor .message-content {
    background-color: #1f2937;
    border-left: 3px solid #38bdf8;
}

.message.persona .message-content {
    background-color: #312e81;
    border-right: 3px solid #f97316;
}

.action {
    font-style: italic;
    color: #9ca3af;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 768px) {
    .chat-messages {
        padding: 10px;
    }
    .input-container {
        padding: 10px;
    }
    .message-content {
        max-width: 85%;
        font-size: 14px;
    }
    .header {
        padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
    }
    h1 {
        font-size: 18px;
    }
    h2 {
        font-size: 14px;
    }
}
