:root {
    --bg-color: #0b0c10;
    --chat-bg: #15181e;
    --primary-color: #1e40af; /* Navy Blue */
    --primary-hover: #1e3a8a;
    --text-primary: #ffffff;
    --text-secondary: #9ca3af;
    --msg-bot-bg: #222630;
    --msg-user-bg: var(--primary-color);
    --msg-user-text: #ffffff;
    --border-color: rgba(255, 255, 255, 0.08);
    --input-bg: #1c2028;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    /* Real mobile viewport height (dodges the iOS/Android address-bar jump) */
    height: -webkit-fill-available;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    height: -webkit-fill-available;
    padding: 15px;
    overflow: hidden;
    overscroll-behavior-y: contain;
    background-image: radial-gradient(circle at 50% 0%, #1e222d 0%, var(--bg-color) 60%);
}

.chat-container {
    width: 100%;
    max-width: 440px;
    height: 92vh;
    height: 92dvh;
    max-height: 850px;
    background-color: var(--chat-bg);
    border-radius: 28px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.chat-header {
    padding: 18px 24px;
    padding-top: calc(18px + env(safe-area-inset-top));
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: rgba(21, 24, 30, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10;
    flex-shrink: 0;
}

.profile-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.avatar img {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 0 0 2px var(--chat-bg), 0 0 0 4px var(--primary-color);
}

.header-text h1 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 3px;
    letter-spacing: -0.01em;
}

.status {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 400;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 5px;
}

.message {
    max-width: 85%;
    padding: 13px 18px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    animation: slideUpFade 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    opacity: 0;
    transform: translateY(15px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

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

.message.bot {
    align-self: flex-start;
    background-color: var(--msg-bot-bg);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.message.user {
    align-self: flex-end;
    background-color: var(--msg-user-bg);
    color: var(--msg-user-text);
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

/* Typing Indicator */
.typing-indicator {
    align-self: flex-start;
    background-color: var(--msg-bot-bg);
    padding: 16px 20px;
    border-radius: 20px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

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

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

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

.chat-input-area {
    padding: 20px 24px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    background: rgba(21, 24, 30, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 90px;
    flex-shrink: 0;
}

/* Input Fields */
.input-wrapper {
    display: flex;
    gap: 12px;
    width: 100%;
}

.input-error-msg {
    display: none;
    color: #ef4444;
    font-size: 12px;
    font-weight: 500;
    padding: 0 4px;
}

.input-error-msg.visible {
    display: block;
}

.text-input {
    flex: 1;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 14px 20px;
    border-radius: 26px;
    /* 16px minimum keeps iOS Safari from auto-zooming in on focus */
    font-size: 16px;
    outline: none;
    transition: all 0.3s;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.text-input:focus {
    border-color: var(--primary-color);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1), 0 0 0 3px rgba(30, 64, 175, 0.15);
}

.text-input::placeholder {
    color: #6b7280;
}

.send-btn {
    background-color: var(--primary-color);
    color: var(--msg-user-text);
    border: none;
    width: 50px;
    height: 50px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    touch-action: manipulation;
    font-size: 18px;
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 4px 10px rgba(30, 64, 175, 0.3);
}

.send-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(30, 64, 175, 0.4);
}
.send-btn:active {
    transform: scale(0.95) translateY(0);
}

/* Options/Buttons */
.chat-options-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    gap: 8px;
    margin-top: 4px;
    margin-bottom: 12px;
    animation: fadeIn 0.4s ease forwards;
    padding: 0 4px;
    width: 100%;
}

.chat-option-btn {
    background-color: #ffffff;
    border: 1px solid #e5e7eb;
    color: #1f2937;
    padding: 12px 18px;
    min-height: 44px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    /* flex-shrink 0 would let a long option refuse to shrink and get
       clipped by .chat-container's overflow:hidden on wide screens —
       max-width keeps it inside the card at any viewport size. */
    flex: 0 1 auto;
    max-width: 100%;
    white-space: normal;
    line-height: 1.3;
}

.chat-option-btn:hover {
    background-color: #f9fafb;
    border-color: #d1d5db;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.chat-option-btn:active {
    transform: scale(0.97) translateY(0);
}

/* Success Message */
.success-container {
    text-align: center;
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    background: linear-gradient(145deg, var(--msg-bot-bg), #1a1d24);
    border: 1px solid var(--border-color);
    /* Static, not sliding like the chat bubbles: this is the final
       confirmation, it should just settle in place and stay put. */
    animation: successFadeIn 0.5s ease forwards;
    transform: none;
}

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

.success-icon {
    font-size: 54px;
    color: var(--primary-color);
    text-shadow: 0 0 20px rgba(30, 64, 175, 0.4);
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

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

/* ============================================================
   Mobile: run edge-to-edge like a native chat app instead of a
   floating card, and give thumbs more room on small screens.
   ============================================================ */
@media (max-width: 480px) {
    body {
        padding: 0;
        align-items: stretch;
        background-image: none;
    }

    .chat-container {
        max-width: 100%;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-messages {
        padding: 20px 16px;
    }

    .message {
        max-width: 88%;
        font-size: 15px;
    }

    .chat-header {
        padding: 14px 16px;
        padding-top: calc(14px + env(safe-area-inset-top));
    }

    .chat-input-area {
        padding: 14px 16px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }

    .chat-options-wrapper {
        gap: 10px;
    }

    .chat-option-btn {
        flex: 1 1 auto;
        min-width: 45%;
    }
}
