* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f9f9f9;
    --bg-tertiary: #f4f4f4;
    --text-primary: #000000;
    --text-secondary: #333333;
    --text-tertiary: #666666;
    --text-muted: #999999;
    --border-primary: #e5e5e5;
    --border-secondary: #d1d1d1;
    --border-hover: #d5d5d5;
    --button-bg: #000000;
    --button-hover: #333333;
    --button-text: #ffffff;
    --message-user-bg: #f4f4f4;
    --message-assistant-bg: #ffffff;
    --message-assistant-border: #e5e5e5;
    --sidebar-bg: #f9f9f9;
    --chat-item-hover: #efefef;
    --chat-item-active: #e5e5e5;
    --code-bg: #1e1e1e;
    --code-header-bg: #2d2d2d;
    --code-border: #3e3e3e;
    --code-text: #d4d4d4;
    --overlay-bg: rgba(0, 0, 0, 0.5);
}

body.dark-mode {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2a2a2a;
    --bg-tertiary: #333333;
    --text-primary: #ffffff;
    --text-secondary: #e5e5e5;
    --text-tertiary: #cccccc;
    --text-muted: #999999;
    --border-primary: #3a3a3a;
    --border-secondary: #4a4a4a;
    --border-hover: #5a5a5a;
    --button-bg: #ffffff;
    --button-hover: #e5e5e5;
    --button-text: #000000;
    --message-user-bg: #2a2a2a;
    --message-assistant-bg: #242424;
    --message-assistant-border: #3a3a3a;
    --sidebar-bg: #222222;
    --chat-item-hover: #2e2e2e;
    --chat-item-active: #353535;
    --code-bg: #0d0d0d;
    --code-header-bg: #1a1a1a;
    --code-border: #2a2a2a;
    --code-text: #d4d4d4;
    --overlay-bg: rgba(0, 0, 0, 0.7);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    transition: background 0.3s, color 0.3s;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-primary);
}

.new-chat-btn {
    width: 100%;
    padding: 10px 16px;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

.new-chat-btn:hover {
    background: var(--button-hover);
}

.new-chat-btn .btn-icon {
    filter: brightness(0) invert(1);
}

body.dark-mode .new-chat-btn .btn-icon {
    filter: brightness(0);
}

.btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-icon.hidden {
    display: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-primary);
    text-align: center;
}

.disclaimer {
    color: var(--text-muted);
    font-size: 12px;
    text-decoration: none;
    transition: color 0.2s;
    cursor: pointer;
    display: inline-block;
}

.disclaimer:hover {
    color: var(--text-tertiary);
}

.chat-item {
    padding: 12px 16px;
    margin-bottom: 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.chat-item:hover {
    background: var(--chat-item-hover);
}

.chat-item.active {
    background: var(--chat-item-active);
}

.chat-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-chat-btn {
    opacity: 0;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-item:hover .delete-chat-btn {
    opacity: 1;
}

.delete-chat-btn:hover {
    background: #ff4444;
}

.delete-chat-btn img {
    width: 14px;
    height: 14px;
    filter: brightness(0);
}

body.dark-mode .delete-chat-btn img {
    filter: brightness(0) invert(1);
}

.delete-chat-btn:hover img {
    filter: brightness(0) invert(1);
}

.sidebar-toggle {
    position: fixed;
    top: 16px;
    left: 16px;
    width: 40px;
    height: 40px;
    background: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: var(--bg-secondary);
}

.sidebar-toggle img {
    width: 20px;
    height: 20px;
}

body.dark-mode .sidebar-toggle img {
    filter: brightness(0) invert(1);
}

.sidebar.open ~ .sidebar-toggle {
    left: 276px;
    z-index: 101;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 98;
}

.sidebar.open ~ .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-height: 100vh;
    max-width: 768px;
    margin: 0 auto;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.top-controls {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 50;
    display: flex;
    gap: 8px;
    align-items: center;
}

.mode-dropdown {
    padding: 8px 12px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

.mode-dropdown:hover {
    border-color: var(--border-secondary);
}

.mode-dropdown:focus {
    border-color: var(--button-bg);
}

.theme-toggle {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-secondary);
}

.theme-icon {
    width: 20px;
    height: 20px;
}

body.dark-mode .theme-icon {
    filter: brightness(0) invert(1);
}

/* Empty State */
.empty-state {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.empty-state.hidden {
    opacity: 0;
}

.empty-title {
    font-size: 28px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 20px;
    position: relative;
}

.input-container {
    border-top: 1px solid var(--border-primary);
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: var(--bg-primary);
}

.input-container.centered {
    position: absolute;
    bottom: 45%;
    left: 50%;
    transform: translate(-50%, 50%);
    border: none;
    max-width: 600px;
    width: calc(100% - 40px);
}

.input-container.animating-down {
    animation: slideDown 0.5s ease forwards;
}

@keyframes slideDown {
    from {
        position: absolute;
        bottom: 45%;
        left: 50%;
        transform: translate(-50%, 50%);
    }
    to {
        position: relative;
        bottom: 0;
        left: 0;
        transform: translate(0, 0);
    }
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    max-width: 100%;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-secondary);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
    outline: none;
    height: 48px;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden;
    line-height: 1.5;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

#messageInput:focus {
    border-color: var(--button-bg);
}

#messageInput::placeholder {
    color: var(--text-muted);
}

/* Hide scrollbar when empty */
#messageInput:empty,
#messageInput:placeholder-shown {
    overflow-y: hidden;
}

#sendBtn {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--button-bg);
    color: var(--button-text);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
    position: relative;
}

#sendBtn:hover {
    background: var(--button-hover);
}

#sendBtn:active {
    background: var(--button-bg);
}

#sendBtn .btn-icon {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1);
}

body.dark-mode #sendBtn .btn-icon {
    filter: brightness(0);
}

#sendBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Message styles */
.message {
    margin-bottom: 32px;
    padding: 12px 16px;
    border-radius: 8px;
    max-width: 80%;
    line-height: 1.6;
    animation: fadeIn 0.3s ease-in;
    opacity: 0;
    animation-fill-mode: forwards;
    position: relative;
    padding-bottom: 40px; /* hard coded, we need better way to add spacing on mobile this is a yikes, TODO */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background: var(--message-user-bg);
    margin-left: auto;
}

.message-actions {
    position: absolute;
    bottom: 8px;
    right: 16px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions,
.message.actions-visible .message-actions {
    opacity: 1;
}

.message-action-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border-primary);
    border-radius: 6px;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

.message-action-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--border-secondary);
}

.message-action-btn img {
    width: 14px;
    height: 14px;
    opacity: 0.7;
}

body.dark-mode .message-action-btn img {
    filter: brightness(0) invert(1);
}

.message-action-btn:hover img {
    opacity: 1;
}

.message.assistant {
    background: var(--message-assistant-bg);
    border: 1px solid var(--message-assistant-border);
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.message.assistant .avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    object-fit:contain;
}

.message.assistant .avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.message.assistant .content {
    flex: 1;
    min-width: 0;
}

.message.assistant .content div {
    white-space: pre-wrap;
}

.message.assistant.complete {
    border-color: var(--border-hover);
    transition: border-color 0.3s ease;
}

.typing-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--button-bg);
    border-radius: 50%;
    animation: blink 1.4s infinite;
    margin-left: 2px;
}

@keyframes blink {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

.codeblock-wrapper {
    margin: 12px 0;
    position: relative;
    animation: fadeIn 0.3s ease-in;
}

.codeblock {
    background: var(--code-bg);
    border-radius: 8px;
    overflow: hidden;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

.codeblock-header {
    background: var(--code-header-bg);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--code-border);
}

.codeblock-language {
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
}

.copy-button {
    background: var(--code-border);
    color: var(--button-text);
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.copy-button:hover {
    background: var(--border-secondary);
}

.copy-button.copied {
    background: #419f44;
}

.copy-icon {
    width: 16px;
    height: 16px;
    filter: brightness(0) invert(1);
}

.copy-icon.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.codeblock-content {
    padding: 16px;
    overflow-x: auto;
    color: var(--code-text);
    font-size: 14px;
    line-height: 1.6;
}

.codeblock-content pre {
    margin: 0;
    white-space: pre;
}

.code-keyword {
    color: #c586c0;
}

.code-function {
    color: #dcdcaa;
}

.code-string {
    color: #ce9178;
}

.code-number {
    color: #b5cea8;
}

.code-operator {
    color: #d4d4d4;
}

.code-bracket {
    color: #ffd700;
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        max-width: 300px;
    }
    
    .sidebar.open ~ .sidebar-toggle {
        left: 310px;
    }
    
    .sidebar.open ~ .chat-container {
        margin-left: 0;
    }
    
    .messages-area {
        padding: 16px;
    }
    
    .input-container {
        padding: 12px 16px;
    }
    
    #messageInput {
        font-size: 16px;
    }
    
    .empty-title {
        font-size: 24px;
        padding: 0 20px;
    }
    
    .message .message-actions {
        opacity: 0;
    }
    
    .message.actions-visible .message-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 480px) {
    .sidebar {
        max-width: 280px;
    }
    
    .sidebar-toggle {
        top: 12px;
        left: 12px;
        width: 36px;
        height: 36px;
    }
    
    .sidebar.open ~ .sidebar-toggle {
        left: 290px;
    }
    
    .messages-area {
        padding: 12px;
        padding-bottom: 80px;
    }
    
    .input-container {
        padding: 10px 12px;
        padding-bottom: 80px;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .input-wrapper {
        gap: 8px;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    #messageInput {
        padding: 10px 12px;
        height: 48px;
        flex: 1;
        min-width: 0;
        font-size: 16px;
        box-sizing: border-box;
    }
    
    #sendBtn {
        width: 48px;
        min-width: 48px;
        height: 48px;
        min-height: 48px;
        flex-shrink: 0;
        box-sizing: border-box;
    }
    
    .empty-title {
        font-size: 20px;
    }
}


