* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #1877f2;
    --primary-dark: #166fe5;
    --primary-light: #e7f3ff;
    --bg: #ffffff;
    --bg-secondary: #f0f2f5;
    --white: #fff;
    --text: #1c1e21;
    --text-secondary: #65676b;
    --text-muted: #8a8d91;
    --border: #e4e6eb;
    --success: #38a169;
    --success-light: #c6f6d5;
}

html, body {
    height: 100%;
}

body {
    font-family: 'Tiro Bangla', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Header - minimal like ChatGPT */
.header {
    padding: 0.875rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header svg {
    width: 24px;
    height: 24px;
    color: var(--primary);
}

.header h1 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.header-actions {
    position: absolute;
    right: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.new-chat-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
}

.new-chat-btn svg {
    width: 20px;
    height: 20px;
}

/* Main Layout */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
    height: calc(100vh - 57px); /* Subtract header height */
    height: calc(100dvh - 57px);
    overflow: hidden;
}

.chat {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 0;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.chat > * {
    max-width: 48rem;
    margin-left: auto;
    margin-right: auto;
}

/* Welcome - centered like ChatGPT */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    padding: 2rem 1rem;
}

.welcome-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.welcome-icon svg {
    width: 28px;
    height: 28px;
    color: white;
}

.welcome h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2rem;
}

.examples {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    max-width: 600px;
}

.example {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.875rem;
    color: var(--text);
}

.example:hover {
    background: var(--bg-secondary);
    border-color: var(--primary);
}

/* Messages */
.message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message.user > div {
    background: var(--primary);
    color: white;
    padding: 0.875rem 1rem;
    border-radius: 1.25rem;
    border-bottom-right-radius: 0.25rem;
    max-width: 85%;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.message.assistant {
    padding: 0;
}

/* Answer */
.answer {
    line-height: 1.7;
    color: var(--text);
    font-size: 0.9375rem;
}

.answer p { margin-bottom: 0.75rem; }
.answer strong { color: var(--primary); font-weight: 600; }
.answer em { font-style: italic; }
.answer ul, .answer ol { margin: 0.5rem 0 0.75rem 1.25rem; }
.answer li { margin-bottom: 0.375rem; }

.answer h2, .answer h3, .answer h4 {
    margin: 1rem 0 0.5rem 0;
    font-weight: 600;
    color: var(--text);
}
.answer h2 { font-size: 1.125rem; }
.answer h3 { font-size: 1rem; }
.answer h4 { font-size: 0.9375rem; }

.answer hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

/* Tables (rendered by marked.js) */
.answer table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.8125rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.answer th,
.answer td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.answer th:last-child,
.answer td:last-child {
    border-right: none;
}

.answer th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text);
}

.answer tr:last-child td {
    border-bottom: none;
}

.answer tr:hover td {
    background: var(--bg-secondary);
}

/* Code blocks */
.answer code {
    background: var(--bg-secondary);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.875em;
}

.answer pre {
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.75rem 0;
}

.answer pre code {
    background: none;
    padding: 0;
}

/* Blockquotes */
.answer blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 1rem;
    margin: 0.75rem 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* Links */
.answer a {
    color: var(--primary);
    text-decoration: none;
}

.answer a:hover {
    text-decoration: underline;
}

/* Sources */
.sources {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.sources-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 500;
}

.source {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    padding: 0.25rem 0.625rem;
    border-radius: 6px;
    font-size: 0.75rem;
    margin: 0.25rem 0.375rem 0.25rem 0;
    font-weight: 500;
}

/* Lawyer CTA */
.lawyer-cta {
    margin-top: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, #f0fff4 0%, #e6fffa 100%);
    border: 1px solid var(--success);
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.cta-content { flex: 1; min-width: 0; }

.cta-content h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: #276749;
    margin-bottom: 0.125rem;
}

.cta-content p {
    font-size: 0.8125rem;
    color: #2f855a;
    line-height: 1.4;
}

.cta-button {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--success);
    color: white;
    padding: 0.625rem 1rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
    transition: all 0.15s;
    flex-shrink: 0;
}

.cta-button:hover {
    background: #2f855a;
}

.cta-button svg {
    width: 14px;
    height: 14px;
}

/* Input Area - ChatGPT style, fixed at bottom */
.input-area {
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    background: var(--bg);
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    max-width: 48rem;
    margin: 0 auto;
    width: 100%;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 0.25rem 0.25rem 0.25rem 0;
    transition: all 0.15s ease;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.15);
    background: var(--bg);
}

#input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1rem;
    line-height: 1.5;
    padding: 0.75rem 0 0.75rem 1.25rem;
    outline: none;
    min-width: 0;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    font-family: inherit;
    overflow-y: auto;
}

#input::placeholder {
    color: var(--text-muted);
}

#btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#btn svg {
    width: 18px;
    height: 18px;
}

#btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

#btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Loading State */
.loading-state {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.25rem 0;
}

.loading-text {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Typing Indicator */
.typing {
    display: inline-flex;
    gap: 4px;
}

.typing span {
    width: 6px;
    height: 6px;
    background: var(--primary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.typing span:nth-child(1) { animation-delay: -0.32s; }
.typing 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; }
}

/* Desktop */
@media (min-width: 640px) {
    .header {
        padding: 1rem 1.5rem;
    }

    .chat {
        padding: 1.5rem 2rem;
    }

    .chat > * {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .welcome h2 {
        font-size: 1.75rem;
    }

    .message.user > div {
        max-width: 70%;
    }

    .input-area {
        padding: 1rem 2rem 1.5rem;
    }

    .input-wrapper {
        border-radius: 1.75rem;
        padding: 0.375rem 0.375rem 0.375rem 0;
    }

    #input {
        padding: 0.875rem 0 0.875rem 1.5rem;
    }

    #btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .lawyer-cta {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }

    .cta-button {
        width: 100%;
        justify-content: center;
    }

    .message.user > div {
        max-width: 90%;
    }

    .examples {
        flex-direction: column;
        width: 100%;
    }

    .example {
        width: 100%;
        text-align: left;
    }
}
