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

:root {
    --color-primary:       #2DD4BF;
    --color-primary-dark:  #14B8A6;
    --color-primary-light: rgba(45,212,191,0.1);
    --color-accent:        #38BDF8;
    --color-bg:            #0F0F0F;
    --color-surface:       #1A1A1A;
    --color-surface-elevated: #242424;
    --color-text:          #ECECEC;
    --color-text-secondary:#A0A0A0;
    --color-text-muted:    #6B6B6B;
    --color-user-bubble:   linear-gradient(135deg, #007C8A 0%, #009AA8 100%);
    --color-user-text:     #FFFFFF;
    --color-border:        #2A2A2A;
    --color-border-light:  #222222;
    --font-family:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-size-base:      16px;
    --font-size-sm:        14px;
    --font-size-xs:        12px;
    --radius-bubble:       20px;
    --radius-lg:           24px;
    --radius-input:        24px;
    --radius-btn:          12px;
    --shadow-xs:           0 1px 2px rgba(0,0,0,0.2);
    --shadow-sm:           0 1px 3px rgba(0,0,0,0.3);
    --shadow-md:           0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg:           0 8px 30px rgba(0,0,0,0.5);
    --header-height:       56px;
    --content-max-width:   768px;
    --transition:          0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast:     0.15s ease;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
    position: relative;
    background: var(--color-bg);
}

.chat-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 24px;
    background: var(--color-surface);
    color: var(--color-text);
    flex-shrink: 0;
    border-bottom: 1px solid var(--color-border);
}

.chat-header__brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header__logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, #007C8A, #009AA8);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
    color: #fff;
    flex-shrink: 0;
}

.chat-header__title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--color-text);
}

.chat-header__subtitle {
    font-size: var(--font-size-xs);
    font-weight: 400;
    color: var(--color-text-muted);
    letter-spacing: 0.01em;
}

#reset {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-btn);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

#reset:hover {
    background: var(--color-surface-elevated);
    border-color: #3A3A3A;
    color: var(--color-text);
}

#reset:active {
    transform: scale(0.97);
}

.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.08) transparent;
}

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

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.15);
}

.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: var(--content-max-width);
    margin: 0 auto;
    animation: messageIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.message__bubble {
    padding: 14px 20px;
    border-radius: var(--radius-bubble);
    font-size: var(--font-size-base);
    line-height: 1.7;
    word-break: break-word;
    overflow-wrap: break-word;
}

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

.message--user {
    align-items: flex-end;
}

.message--user .message__bubble {
    background: var(--color-user-bubble);
    color: var(--color-user-text);
    border-bottom-right-radius: 6px;
    box-shadow: 0 2px 12px rgba(0,124,138,0.3);
    max-width: 85%;
}

.message--assistant {
    align-items: flex-start;
}

.message--assistant .message__bubble {
    background-color: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    border-bottom-left-radius: 6px;
}

.message--error {
    align-items: flex-start;
}

.message--error .message__bubble {
    background-color: rgba(185,28,28,0.12);
    color: #FCA5A5;
    border: 1px solid rgba(185,28,28,0.25);
    border-bottom-left-radius: 6px;
}

.message--typing {
    align-items: flex-start;
}

.message--typing .message__bubble {
    background-color: var(--color-surface);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    border-bottom-left-radius: 6px;
    padding: 16px 22px;
}

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

.typing-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-primary);
    opacity: 0.35;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

.chat-input-area {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 24px 20px;
    background: linear-gradient(to top, var(--color-bg) 60%, transparent);
    gap: 6px;
}

.token-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 11px;
    color: var(--color-text-muted);
    letter-spacing: 0.02em;
    opacity: 0.6;
}

.chat-input-area__inner {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    width: 100%;
    max-width: var(--content-max-width);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-input);
    padding: 6px 6px 6px 18px;
    box-shadow: var(--shadow-md);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-area__inner:focus-within {
    border-color: rgba(45,212,191,0.4);
    box-shadow: var(--shadow-md), 0 0 0 3px rgba(45,212,191,0.06);
}

#prompt {
    flex: 1 1 auto;
    resize: none;
    overflow-y: auto;
    max-height: 200px;
    min-height: 44px;
    padding: 10px 0;
    border: none;
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: transparent;
    line-height: 1.5;
    outline: none;
    scrollbar-width: thin;
}

#prompt::placeholder {
    color: var(--color-text-muted);
}

#prompt:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#send {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #007C8A 0%, #009AA8 100%);
    color: var(--color-surface);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: none;
}

#send:hover:not(:disabled) {
    transform: scale(1.06);
    box-shadow: 0 2px 14px rgba(0,124,138,0.5);
}

#send:active:not(:disabled) {
    transform: scale(0.94);
}

#send:disabled {
    background: #3A3A3A;
    cursor: not-allowed;
    opacity: 0.5;
}

#send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.message--assistant .message__bubble h1,
.message--assistant .message__bubble h2,
.message--assistant .message__bubble h3,
.message--assistant .message__bubble h4,
.message--assistant .message__bubble h5,
.message--assistant .message__bubble h6 {
    margin-top: 1em;
    margin-bottom: 0.4em;
    font-weight: 700;
    line-height: 1.35;
    color: var(--color-text);
}

.message--assistant .message__bubble h1 { font-size: 1.25em; }
.message--assistant .message__bubble h2 { font-size: 1.15em; }
.message--assistant .message__bubble h3 { font-size: 1.05em; }

.message--assistant .message__bubble p {
    margin-bottom: 0.65em;
}

.message--assistant .message__bubble p:last-child {
    margin-bottom: 0;
}

.message--assistant .message__bubble ul,
.message--assistant .message__bubble ol {
    padding-left: 1.5em;
    margin-bottom: 0.65em;
}

.message--assistant .message__bubble li {
    margin-bottom: 0.25em;
}

.message--assistant .message__bubble code {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
    font-size: 0.875em;
    background-color: rgba(45,212,191,0.08);
    color: var(--color-primary);
    padding: 2px 7px;
    border-radius: 6px;
}

.message--assistant .message__bubble pre {
    margin: 0.75em 0;
    border-radius: 12px;
    overflow-x: auto;
    background-color: #0A0A0A;
    border: 1px solid var(--color-border);
}

.message--assistant .message__bubble pre code {
    display: block;
    padding: 16px 18px;
    font-size: 0.85em;
    background: transparent;
    color: #D4D4D8;
    line-height: 1.65;
    white-space: pre;
}

.message--assistant .message__bubble blockquote {
    border-left: 3px solid var(--color-primary);
    padding: 6px 16px;
    margin: 0.75em 0;
    color: var(--color-text-secondary);
    font-style: italic;
    background: var(--color-primary-light);
    border-radius: 0 10px 10px 0;
}

.message--assistant .message__bubble strong {
    font-weight: 700;
}

.message--assistant .message__bubble em {
    font-style: italic;
}

.message--assistant .message__bubble a {
    color: var(--color-primary);
    text-decoration: none;
    border-bottom: 1px solid rgba(45,212,191,0.25);
    transition: border-color var(--transition);
}

.message--assistant .message__bubble a:hover {
    border-bottom-color: var(--color-primary);
}

.message--assistant .message__bubble hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1em 0;
}

.message--assistant .message__bubble table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin-bottom: 0.65em;
    border-radius: 10px;
    overflow: hidden;
}

.message--assistant .message__bubble th,
.message--assistant .message__bubble td {
    border: 1px solid var(--color-border);
    padding: 10px 14px;
    text-align: left;
}

.message--assistant .message__bubble th {
    background-color: rgba(45,212,191,0.08);
    font-weight: 600;
    color: var(--color-primary);
}

@media (max-width: 768px) {
    .chat-header {
        padding: 0 16px;
    }

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

    .chat-input-area {
        padding: 10px 16px 18px;
    }

    .message--user .message__bubble {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .chat-header__subtitle {
        display: none;
    }

    .chat-messages {
        padding: 16px 12px;
        gap: 14px;
    }

    .message__bubble {
        padding: 12px 16px;
        font-size: 15px;
    }

    .chat-input-area {
        padding: 8px 12px 14px;
    }

    .chat-input-area__inner {
        padding: 4px 4px 4px 14px;
        border-radius: 20px;
    }

    #prompt {
        min-height: 40px;
        font-size: 15px;
    }

    #send {
        width: 36px;
        height: 36px;
    }

    #send svg {
        width: 16px;
        height: 16px;
    }

    .message--user .message__bubble {
        max-width: 94%;
    }
}
