@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap');

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

body {
    font-family: "Montserrat", sans-serif;
    background: #f7f7f8;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    background: #ffffff;
    padding: 16px 24px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.logo {
    font-size: 20px;
    font-weight: 600;
    color: #202123;
}

.subtitle {
    font-size: 12px;
    color: #6e6e80;
    margin-top: 2px;
}

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

.mode-selection {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
}

.mode-selection h1 {
    font-size: 32px;
    margin-bottom: 32px;
    color: #202123;
}

/* General Chat Card - SMALLER SIZE */
.general-chat-home {
    margin-bottom: 28px;
    width: 100%;
    max-width: 500px; /* Reduced from 600px */
}

.general-chat-card {
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6c 100%);
    border: none;
    border-radius: 14px;
    padding: 24px; /* Reduced from 32px */
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    box-shadow: 0 4px 20px rgba(16, 163, 127, 0.2);
}

.general-chat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(16, 163, 127, 0.3);
}

.chat-icon {
    font-size: 40px; /* Reduced from 48px */
    color: white;
    margin-bottom: 12px;
}

.general-chat-card h3 {
    font-size: 20px; /* Reduced from 24px */
    color: white;
    margin-bottom: 6px;
}

.general-chat-card p {
    font-size: 14px; /* Reduced from 15px */
    color: rgba(255, 255, 255, 0.9);
}

/* OR DIVIDER - NO LINES */
.or-divider {
    font-size: 14px;
    color: #6e6e80;
    margin-bottom: 24px;
    text-align: center;
}

.mode-cards {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 900px;
}

.mode-card {
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 12px;
    padding: 24px;
    width: 260px;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-card:hover {
    border-color: #10a37f;
    box-shadow: 0 4px 12px rgba(16, 163, 127, 0.1);
    transform: translateY(-2px);
}

.mode-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: #202123;
}

.mode-card p {
    font-size: 14px;
    color: #6e6e80;
    margin-bottom: 0;
}

.mode-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.sub-selection {
    flex: 1;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    overflow-y: auto;
}

.sub-selection.active {
    display: flex;
}

.back-btn {
    align-self: flex-start;
    margin-bottom: 20px;
    padding: 8px 16px;
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: #202123;
}

.back-btn:hover {
    background: #f7f7f8;
}

.sub-selection h2 {
    font-size: 28px;
    margin-bottom: 24px;
    color: #202123;
}

.selection-box {
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    max-width: 500px;
    margin: 20px 0px;
}

.selection-box label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: #202123;
}

.selection-box select {
    width: 100%;
    padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.scheme-list {
    display: none;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 500px;
}

.scheme-list.active {
    display: flex;
}

.scheme-item {
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.scheme-item:hover {
    border-color: #10a37f;
    background: #f7fff7;
}

.scheme-item h4 {
    font-size: 16px;
    color: #202123;
    margin-bottom: 4px;
}

.scheme-item p {
    font-size: 13px;
    color: #6e6e80;
}

.option-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 500px;
}

.chat-interface {
    flex: 1;
    display: none;
    flex-direction: column;
    background: white;
    min-height: 0;
    overflow: hidden;
}

.chat-interface.active {
    display: flex;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-title {
    font-size: 16px;
    font-weight: 500;
    color: #202123;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 70%;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.ai {
    align-self: flex-start;
}

.message-content {
    background: #f7f7f8;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
    color: #202123;
    word-wrap: break-word;
}

.message.user .message-content {
    background: #10a37f;
    color: white;
}

/* LOADING DOTS ANIMATION */
.loading-dots {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 20px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: #10a37f;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

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

/* Markdown styles for AI messages */
.message.ai .message-content h1,
.message.ai .message-content h2,
.message.ai .message-content h3 {
    margin-top: 12px;
    margin-bottom: 8px;
    font-weight: 600;
}

.message.ai .message-content h1 { font-size: 20px; }
.message.ai .message-content h2 { font-size: 18px; }
.message.ai .message-content h3 { font-size: 16px; }

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

.message.ai .message-content li {
    margin: 4px 0;
}

.message.ai .message-content p {
    margin: 8px 0;
}

.message.ai .message-content code {
    background: #e5e5e5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.message.ai .message-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message.ai .message-content pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.message.ai .message-content strong {
    font-weight: 600;
}

.message.ai .message-content em {
    font-style: italic;
}

.input-area {
    padding: 16px 24px;
    border-top: 1px solid #e5e5e5;
    background: white;
    flex-shrink: 0;
}

.input-container {
    display: flex;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
}

.input-container input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    font-size: 15px;
    outline: none;
}

.input-container input:focus {
    border-color: #10a37f;
}

.input-container input:disabled {
    background: #f7f7f8;
    cursor: not-allowed;
}

.input-container button {
    padding: 12px 24px;
    background: #10a37f;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.input-container button:hover:not(:disabled) {
    background: #0d8c6c;
}

.input-container button:disabled {
    background: #e5e5e5;
    color: #6e6e80;
    cursor: not-allowed;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #6e6e80;
}

@media (max-width: 768px) {
    .mode-cards {
        flex-direction: column;
        align-items: center;
    }

    .message {
        max-width: 85%;
    }
    
    .general-chat-home {
        max-width: 90%;
    }
}

/* RESPONSIVE DESIGN FOR MOBILE */


@media (max-width: 768px) {
    /* Header */
    .header {
        padding: 12px 16px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background-color: #fff;
        border-bottom: 1px solid #e0e0e0;
    }

    .logo {
        font-size: 18px;
    }

    .subtitle {
        font-size: 11px;
    }

    /* Mode Selection */
    .mode-selection {
        padding: 24px 16px;
        padding-top: 80px; /* Account for fixed header */
    }

    .mode-selection h1 {
        font-size: 26px;
        margin-bottom: 24px;
    }

    /* Ask NEGen Card */
    .general-chat-home {
        max-width: 95%;
    }

    .general-chat-card {
        padding: 20px;
        border-radius: 12px;
    }

    .chat-icon {
        font-size: 36px;
        margin-bottom: 10px;
    }

    .general-chat-card h3 {
        font-size: 18px;
    }

    .general-chat-card p {
        font-size: 13px;
    }

    /* Divider */
    .or-divider {
        font-size: 13px;
        margin-bottom: 20px;
    }

    /* Mode Cards */
    .mode-cards {
        flex-direction: column;
        align-items: center;
        gap: 16px;
    }

    .mode-card {
        width: 100%;
        max-width: 350px;
        padding: 20px;
    }

    .mode-card h3 {
        font-size: 17px;
    }

    .mode-card p {
        font-size: 13px;
    }

    .mode-icon {
        font-size: 28px;
    }

    /* Sub-selection */
    .sub-selection {
        padding: 24px 16px;
        padding-top: 80px; /* Account for fixed header */
    }

    .sub-selection h2 {
        font-size: 24px;
        margin-bottom: 20px;
    }

    .back-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* Selection Box */
    .selection-box {
        padding: 16px;
        max-width: 100%;
    }

    .selection-box label {
        font-size: 13px;
    }

    .selection-box select {
        padding: 10px;
        font-size: 13px;
    }

    /* Scheme List */
    .scheme-list {
        max-width: 100%;
        gap: 12px;
    }

    .scheme-item {
        padding: 14px;
    }

    .scheme-item h4 {
        font-size: 15px;
    }

    .scheme-item p {
        font-size: 12px;
    }

    /* Chat Interface Container */
    .chat-container {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height for mobile browsers */
        overflow: hidden;
    }

    /* Chat Header */
    .chat-header {
        padding: 14px 16px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        background-color: #fff;
        border-bottom: 1px solid #e0e0e0;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .chat-title {
        font-size: 15px;
    }

    /* Disclaimer */
    .disclaimer {
        margin: 12px 16px;
        margin-top: 70px; /* Account for fixed header */
        padding: 10px;
        font-size: 12px;
        background-color: #fff3cd;
        border-radius: 8px;
    }

    /* Chat Messages - FIXED SCROLLING */
    .chat-messages {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 16px;
        padding-top: 120px; /* Account for fixed header + disclaimer */
        padding-bottom: 90px; /* Account for fixed input area */
        gap: 12px;
        display: flex;
        flex-direction: column;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        height: calc(100vh - 140px);
        height: calc(100dvh - 140px);
    }

    .message {
        max-width: 85%;
        flex-shrink: 0;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 14px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Markdown in messages */
    .message.ai .message-content h1 { font-size: 18px; }
    .message.ai .message-content h2 { font-size: 16px; }
    .message.ai .message-content h3 { font-size: 15px; }

    .message.ai .message-content code {
        font-size: 12px;
    }

    /* Input Area - FIXED WITH CONSISTENT BUTTON COLOR */
    .input-area {
        padding: 12px 16px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #ffffff;
        border-top: 1px solid #e0e0e0;
        z-index: 101;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        /* Prevent iOS Safari from hiding the input area */
        padding-bottom: env(safe-area-inset-bottom, 12px);
    }

    .input-container {
        gap: 8px;
        display: flex;
        align-items: center;
        max-width: 100%;
    }

    .input-container input {
        padding: 12px 14px;
        font-size: 15px;
        flex: 1;
        border: 1px solid #ddd;
        border-radius: 8px;
        outline: none;
        background-color: #ffffff;
    }

    .input-container input:focus {
        border-color: #007bff;
        box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
    }

    /* CONSISTENT SEND BUTTON STYLING */
    .input-container button,
    .input-container button[type="submit"],
    .send-button,
    button.send-btn {
        padding: 12px 20px !important;
        font-size: 15px !important;
        border: none !important;
        border-radius: 8px !important;
        background-color: #007bff !important;
        color: #ffffff !important;
        cursor: pointer;
        white-space: nowrap;
        min-width: 70px;
        font-weight: 500;
        transition: background-color 0.2s ease;
        -webkit-appearance: none;
        appearance: none;
    }

    /* Button hover state (for devices that support hover) */
    @media (hover: hover) {
        .input-container button:hover,
        .input-container button[type="submit"]:hover,
        .send-button:hover,
        button.send-btn:hover {
            background-color: #0069d9 !important;
        }
    }

    /* Button active/pressed state */
    .input-container button:active,
    .input-container button[type="submit"]:active,
    .send-button:active,
    button.send-btn:active {
        background-color: #0056b3 !important;
        transform: scale(0.98);
    }

    /* Disabled button state */
    .input-container button:disabled,
    .input-container button[type="submit"]:disabled,
    .send-button:disabled,
    button.send-btn:disabled {
        background-color: #6c757d !important;
        opacity: 0.6;
        cursor: not-allowed;
    }

    /* Loading dots */
    .loading-dots {
        padding: 10px 16px;
    }

    .loading-dots span {
        width: 7px;
        height: 7px;
    }

    .loading {
        padding: 16px;
        font-size: 13px;
    }

    /* Prevent body scroll when chat is open */
    body.chat-active {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }

    /* End Chat button styling */
    .end-chat-btn,
    button[onclick*="endChat"] {
        padding: 8px 16px;
        font-size: 14px;
        background-color: #dc3545;
        color: white;
        border: none;
        border-radius: 6px;
        cursor: pointer;
    }

    .end-chat-btn:active {
        background-color: #c82333;
    }
}

/* Extra Small Phones (below 480px) */
@media (max-width: 480px) {
    .mode-selection h1 {
        font-size: 22px;
    }

    .general-chat-card h3 {
        font-size: 16px;
    }

    .general-chat-card p {
        font-size: 12px;
    }

    .mode-card {
        max-width: 100%;
        padding: 18px;
    }

    .message {
        max-width: 90%;
    }

    .chat-messages {
        padding: 12px;
        padding-top: 110px;
        padding-bottom: 85px;
    }

    .input-area {
        padding: 10px 12px;
        padding-bottom: env(safe-area-inset-bottom, 10px);
    }

    .input-container input {
        padding: 11px 12px;
        font-size: 14px;
    }

    .input-container button,
    .send-button,
    button.send-btn {
        padding: 11px 16px !important;
        font-size: 14px !important;
        min-width: 60px;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-messages {
        padding-top: 80px;
        padding-bottom: 75px;
    }

    .disclaimer {
        margin-top: 60px;
        padding: 8px;
        font-size: 11px;
    }
}

/* Fix for iOS Safari address bar */
@supports (-webkit-touch-callout: none) {
    .chat-messages {
        height: -webkit-fill-available;
    }

    .chat-container {
        height: -webkit-fill-available;
    }
}