* {
    box-sizing: border-box;
}

html {
    font-size: 15px;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: #0f0f0f;
    color: #e0e0e0;
    display: flex;
    height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* SIDEBAR */
.sidebar {
    width: 240px;
    background: #111;
    border-right: 1px solid #222;
}

/* MAIN */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* CHAT */
.chat {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

/* MESSAGE */
.msg {
    display: flex;
    margin: 8px 0;
    align-items: flex-end;
    gap: 8px;
}

.user { justify-content: flex-end; }
.bot { justify-content: flex-start; }

/* BUBBLE */
.bubble {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: 12px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

.user .bubble {
    background: #2563eb;
    color: white;
    border-radius: 12px 4px 12px 12px;
}

.bot .bubble {
    background: #1f1f1f;
    border: 1px solid #333;
    color: #e0e0e0;
    border-radius: 4px 12px 12px 12px;
}

/* INPUT FIX (QUAN TRỌNG) */
.input-box {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 16px 10px;
    border-top: 1px solid #222;
    background: #0f0f0f;
    position: sticky;
    bottom: 0;
}

.input-row {
    display: flex;
    gap: 10px;
}

.model-bar {
    display: flex;
    align-items: center;
}

.model-bar select {
    background: #1a1a1a;
    color: #bbb;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    max-width: 240px;
    transition: border-color 0.2s;
}

.model-bar select:focus {
    border-color: #555;
}

.model-bar select option,
.model-bar select optgroup {
    background: #1a1a1a;
    color: #ddd;
}

.model-bar select optgroup {
    color: #888;
    font-style: normal;
    font-size: 11px;
}

.btn-export {
    margin-left: auto;
    background: none;
    border: 1px solid #333;
    color: #888;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.btn-export:hover {
    background: #1a1a1a;
    color: #e0e0e0;
    border-color: #555;
}

/* textarea KHÔNG bị co, tự động mở rộng */
textarea {
    flex: 1;
    min-width: 0;
    min-height: 42px;
    max-height: 200px;
    padding: 10px 14px;
    background: #1a1a1a;
    border: 1px solid #333;
    color: #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    line-height: 1.4;
}

textarea:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea::placeholder {
    color: #666;
}

/* button KHÔNG bị méo trên mobile */
button {
    flex-shrink: 0;
    padding: 10px 18px;
    background: #2563eb;
    border: none;
    color: white;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
}

button:hover {
    background: #1d4ed8;
}

button:active {
    background: #1e40af;
}

/* MOBILE FIX */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    body {
        font-size: 13px;
    }

    .sidebar {
        display: none;
    }

    .bubble {
        max-width: 80%;
        padding: 9px 12px;
        font-size: 13px;
    }

    .chat {
        padding: 12px 12px;
    }

    .input-box {
        padding: 6px 10px 8px;
        gap: 4px;
    }

    .input-row {
        gap: 6px;
    }

    textarea {
        padding: 9px 12px;
        font-size: 13px;
    }

    button {
        padding: 9px 14px;
        font-size: 13px;
        white-space: nowrap;
    }
}

.bubble.loading {
    padding: 6px 12px;
}

.typing-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* chữ */
.typing-text {
    font-size: 12px;
    color: #888;
    animation: fadeText 1.5s infinite;
}

/* fade nhẹ chữ */
@keyframes fadeText {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Scrollbar styling */
.chat::-webkit-scrollbar {
    width: 6px;
}

.chat::-webkit-scrollbar-track {
    background: transparent;
}

.chat::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

.chat::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* dots container */
.typing-dots {
    display: flex;
    gap: 4px;
}

/* dots */
.typing-dots i {
    width: 6px;
    height: 6px;
    background: #888;
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.2s infinite ease-in-out;
}

/* delay từng dot */
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }

/* animation kiểu “nhảy” */
@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.5);
        opacity: 0.3;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.bot .bubble {
    line-height: 1.6;
    font-size: 15px;
}

/* paragraph spacing */
.bot .bubble p {
    margin: 6px 0;
}

/* bold text */
.bot .bubble b {
    color: #ffffff;
}

/* code block */
.bot .bubble code {
    background: #111;
    padding: 2px 6px;
    border-radius: 6px;
    color: #fbbf24;
    font-family: monospace;
}

/* bullet list */
.bot .bubble ul {
    padding-left: 18px;
    margin: 6px 0;
}

.bot .bubble li {
    margin: 4px 0;
}

/* quote */
.bot .bubble blockquote {
    border-left: 3px solid #ffffff;
    padding-left: 10px;
    color: #aaa;
    margin: 6px 0;
    font-style: italic;
}

/* Token & cost usage */
.usage-info {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #333;
    font-size: 11px;
    color: #888;
    user-select: none;
}

.usage-model {
    color: #f59e0b;
}

.usage-tokens {
    color: #6b9eff;
}

.usage-sep {
    color: #555;
}

.usage-cost {
    color: #6b9eff;
}

.usage-cost.free {
    color: #4ade80;
}

.usage-estimated {
    color: #f59e0b;
}

.est-tier-btn {
    cursor: pointer;
    color: #888;
    font-size: 10px;
    transition: color 0.2s;
    user-select: none;
}

.est-tier-btn:hover {
    color: #f59e0b;
}

.est-tier-name {
    color: #f59e0b;
    border-bottom: 1px dashed #666;
}

.est-cost-value {
    color: #f59e0b;
}