* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Modern Fluent UI Color Scheme */
    --sidebar-bg: linear-gradient(145deg, #1e1e1e 0%, #2d2d30 100%);
    --main-bg: linear-gradient(145deg, #252526 0%, #2d2d30 100%);
    --hover-bg: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.12);
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #969696;
    --accent-blue: #0078d4;
    --accent-blue-hover: #106ebe;
    --accent-green: #00bcf2;
    --accent-hover: #1ba1e2;
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.12);
    --message-bg-user: rgba(0, 120, 212, 0.15);
    --message-bg-assistant: rgba(255, 255, 255, 0.05);
    
    /* Modern effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.25);
    --blur-bg: rgba(255, 255, 255, 0.05);
    --blur-amount: 10px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

body {
    font-family: "Segoe UI Variable", "Segoe UI", -apple-system, BlinkMacSystemFont, "Roboto", "Helvetica Neue", sans-serif;
    background: var(--main-bg);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    backdrop-filter: blur(var(--blur-amount));
    /* Touch optimization */
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text selection in content areas */
.message-content,
#messageInput,
#systemPrompt {
    -webkit-user-select: text;
    user-select: text;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Modern Fluent Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    backdrop-filter: blur(var(--blur-amount));
    box-shadow: var(--shadow-md);
    position: relative;
}

.sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--blur-bg);
    backdrop-filter: blur(var(--blur-amount));
    border-radius: 0;
    pointer-events: none;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(var(--blur-amount));
    position: relative;
}

.sidebar-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--blur-bg);
    backdrop-filter: blur(var(--blur-amount));
    pointer-events: none;
}

.sidebar-icons {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: 16px 8px;
    backdrop-filter: blur(var(--blur-amount));
}

.sidebar-icons-top {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-icons-bottom {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
}

.sidebar.collapsed .sidebar-icons {
    display: flex;
}

.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .conversation-list,
.sidebar.collapsed .sidebar-footer {
    display: none;
}

.icon-btn {
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    backdrop-filter: blur(var(--blur-amount));
}

.icon-btn:hover {
    background: var(--hover-bg);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px) scale(1.05);
}

.icon-btn:active {
    transform: translateY(0) scale(1);
    box-shadow: none;
}

/* Character icon specific hover - no rotation */
#charactersIconBtn:hover svg {
    transform: scale(1.1);
}

/* Settings icon rotation in collapsed mode */
#settingsIconBtn:hover svg {
    transform: rotate(90deg);
}

.icon-btn.active {
    background: var(--accent-blue);
    color: white;
    box-shadow: var(--shadow-md);
}

/* Modern Fluent Tooltip */
.icon-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: var(--blur-bg);
    backdrop-filter: blur(var(--blur-amount));
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-left: 12px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    z-index: 1000;
}

.icon-btn:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(4px);
}

.new-chat-btn {
    width: 100%;
    padding: 14px 16px;
    background: var(--blur-bg);
    backdrop-filter: blur(var(--blur-amount));
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.new-chat-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-green) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.new-chat-btn:hover {
    background: var(--hover-bg);
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.new-chat-btn:hover::before {
    opacity: 0.15;
}

.new-chat-btn svg {
    transition: transform 0.3s ease;
}

.new-chat-btn:hover svg {
    transform: rotate(90deg);
}

.new-chat-btn:hover {
    background: var(--hover-bg);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    padding: 12px;
    margin-bottom: 2px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s;
    position: relative;
}

.conversation-item:hover {
    background: var(--hover-bg);
}

.conversation-item.active {
    background: var(--hover-bg);
}

.conversation-item-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
}

.delete-conversation-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.conversation-item:hover .delete-conversation-btn {
    opacity: 1;
}

.delete-conversation-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid transparent;
    backdrop-filter: blur(var(--blur-amount));
    position: relative;
    transition: border-color 0.3s ease;
}

.sidebar:not(.collapsed) .sidebar-footer {
    border-top-color: var(--border-color);
}

.sidebar-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--blur-bg);
    backdrop-filter: blur(var(--blur-amount));
    pointer-events: none;
}

.settings-btn {
    width: 100%;
    padding: 14px 16px;
    background: var(--blur-bg);
    backdrop-filter: blur(var(--blur-amount));
    border: 1px solid transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: var(--radius-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.settings-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--accent-blue) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.settings-btn:hover::before {
    opacity: 0.1;
}

.settings-btn svg {
    transition: transform 0.3s ease;
}

/* Only rotate settings icon, not characters icon */
.settings-btn:hover svg {
    transform: none;
}

#settingsBtn:hover svg {
    transform: rotate(90deg);
}

/* Character button subtle hover effect */
#charactersBtn:hover svg {
    transform: scale(1.1);
}

/* Improved hover states with smooth transitions */
.settings-btn:hover {
    background: var(--hover-bg);
    border-color: rgba(0, 120, 212, 0.3);
    box-shadow: 0 4px 20px rgba(0, 120, 212, 0.2);
    transform: translateY(-2px);
}

.settings-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 10px rgba(0, 120, 212, 0.1);
}

/* Focus states for accessibility */
.settings-btn:focus {
    outline: 2px solid rgba(0, 120, 212, 0.5);
    outline-offset: 2px;
}

/* Main Container */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--main-bg);
}

/* Header */
.header {
    background: var(--main-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Improved touch target */
    min-width: 44px;
    min-height: 44px;
}

.sidebar-toggle:hover {
    background: var(--hover-bg);
}

.header-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Dropdown */
.dropdown {
    position: relative;
}

.dropdown-trigger {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    /* Improved touch target */
    min-height: 44px;
}

.dropdown-trigger:hover {
    background: var(--hover-bg);
}

.dropdown-content {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--main-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    min-width: 180px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin-top: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
}

.dropdown-content.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 14px;
    color: var(--text-primary);
}

.dropdown-item:hover {
    background: var(--hover-bg);
}

.dropdown-item.selected {
    background: var(--accent-green);
    color: white;
}

/* Chat Container */
.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    /* Mobile keyboard handling */
    height: 100%;
}

.welcome-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    max-width: 600px;
    width: 100%;
    padding: 40px 24px;
}

.welcome-screen h2 {
    font-size: 48px;
    font-weight: 300;
    margin-bottom: 20px;
    color: var(--text-primary);
    line-height: 1.2;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 32px;
}

.messages {
    padding: 32px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.message {
    margin-bottom: 32px;
    animation: slideIn 0.4s cubic-bezier(0.2, 0, 0, 1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--accent-green);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--hover-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.message-role {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.message-content {
    padding-left: 48px;
    line-height: 1.6;
    font-size: 15px;
    color: var(--text-primary);
}

.message-content p {
    margin-bottom: 16px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul, .message-content ol {
    margin-left: 24px;
    margin-bottom: 16px;
}

.message-content li {
    margin-bottom: 6px;
}

.message-content h1, .message-content h2, .message-content h3 {
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 600;
}

.message-content h1 {
    font-size: 24px;
    color: var(--text-primary);
}

.message-content h2 {
    font-size: 20px;
    color: var(--text-primary);
}

.message-content h3 {
    font-size: 18px;
    color: var(--text-primary);
}

.message-content pre {
    background: var(--message-bg-user);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin-bottom: 16px;
    font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
    font-size: 14px;
}

.message-content code {
    font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
    font-size: 14px;
}

.message-content :not(pre) > code {
    background: var(--hover-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: var(--accent-green);
    border: 1px solid var(--border-color);
}

.message-content blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 20px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-style: italic;
}

.message-content a {
    color: var(--accent-green);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
    font-size: 14px;
    border-radius: 8px;
    overflow: hidden;
}

.message-content table th,
.message-content table td {
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    text-align: left;
}

.message-content table th {
    background: var(--hover-bg);
    font-weight: 600;
    color: var(--text-primary);
}

.message-content table tr:nth-child(even) {
    background: var(--hover-bg);
}

/* Input Container */
.input-container {
    padding: 24px;
    background: transparent;
}

.input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 4px;
    transition: all 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--accent-green);
}

#messageInput {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
    outline: none;
    line-height: 1.5;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    padding: 8px;
    background: var(--accent-green);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    /* Improved touch target */
    min-width: 44px;
    min-height: 44px;
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--main-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.close-modal-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.close-modal-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 100px);
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.setting-group select,
.setting-group textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s ease;
}

.setting-group select:focus,
.setting-group textarea:focus {
    outline: none;
    border-color: var(--accent-green);
}

.setting-group textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.5;
}

.setting-group small {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.4;
}

/* Loading animation */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 16px 0;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    30% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive Design */

/* Tablet and small desktop */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: 240px;
    }
    
    .messages {
        padding: 24px;
    }
    
    .welcome-screen h1 {
        font-size: 40px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        z-index: 1000;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 260px; /* Maintain full width when hidden */
    }
    
    /* Mobile sidebar backdrop */
    .sidebar::after {
        content: '';
        position: fixed;
        top: 0;
        left: 260px;
        width: calc(100vw - 260px);
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        pointer-events: none;
    }
    
    .sidebar:not(.collapsed)::after {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
    
    .main-container {
        margin-left: 0;
        width: 100vw;
    }
    
    .messages {
        padding: 20px 16px;
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    .message-content {
        padding-left: 0;
        margin-top: 8px;
        font-size: 15px;
        line-height: 1.5;
    }

    .message-header {
        margin-bottom: 8px;
        gap: 12px;
    }
    
    .message {
        margin-bottom: 24px;
    }
    
    /* Improve code blocks on mobile */
    .message-content pre {
        font-size: 13px;
        padding: 12px;
        overflow-x: auto;
        border-radius: 6px;
    }
    
    .message-content :not(pre) > code {
        font-size: 12px;
        padding: 1px 4px;
    }
    
    /* Improve tables on mobile */
    .message-content table {
        font-size: 12px;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .message-content table th,
    .message-content table td {
        padding: 8px 12px;
    }
    
    .input-container {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom)); /* Handle iOS safe area */
    }
    
    .input-wrapper {
        gap: 8px;
        padding: 6px;
    }
    
    #messageInput {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 14px 16px;
        min-height: 44px; /* Better touch target */
    }
    
    .send-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    
    .welcome-screen {
        padding: 24px 16px;
    }
    
    .welcome-screen h1 {
        font-size: 32px;
    }
    
    /* Hide character indicator on mobile to save space */
    .current-character {
        display: none;
    }
}

/* Mobile keyboard optimization */
@media (max-width: 768px) {
    /* Prevent body scroll when input is focused */
    body.input-focused {
        position: fixed;
        width: 100%;
    }
    
    /* Adjust layout when virtual keyboard is open */
    @supports (-webkit-touch-callout: none) {
        /* iOS specific adjustments */
        .input-container {
            padding-bottom: max(16px, env(safe-area-inset-bottom) + env(keyboard-inset-height, 0px));
        }
    }
}
@media (max-width: 600px) {
    .welcome-screen h1 {
        font-size: 28px;
    }
    
    .modal-content {
        width: 92%;
        margin: 16px;
    }
    
    .header-title {
        display: block;
        font-size: 15px;
    }
    
    .dropdown-trigger {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 12px;
    }
    
    .header-left {
        gap: 12px;
    }
    
    .header-title {
        font-size: 14px;
        display: none; /* Hide title on very small screens */
    }
    
    .dropdown-trigger {
        font-size: 12px;
        padding: 6px 8px;
        min-height: 40px;
    }
    
    .welcome-screen h1 {
        font-size: 24px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
    }
    
    .message-content {
        font-size: 14px;
        padding-left: 0;
    }
    
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 20px;
        margin-top: max(20px, env(safe-area-inset-top));
        margin-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .input-container {
        padding: 12px;
    }
    
    .messages {
        padding: 16px 12px;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .header {
        padding: 8px;
    }
    
    .header-left {
        gap: 8px;
    }
    
    .header-title {
        display: none;
    }
    
    .welcome-screen h1 {
        font-size: 20px;
    }
    
    .input-container {
        padding: 8px;
    }
    
    .messages {
        padding: 12px 8px;
    }
    
    .message-content {
        font-size: 13px;
    }
    
    .modal-content {
        width: 98%;
        margin: 8px;
    }
    
    .dropdown-trigger {
        font-size: 11px;
        padding: 4px 6px;
    }
}

/* Mobile keyboard optimization */
@media (max-width: 768px) {
    /* Prevent body scroll when input is focused on mobile */
    body.input-focused {
        position: fixed;
        width: 100%;
    }
}

/* Characters Modal Styles */
.characters-modal {
    max-width: 700px;
    width: 90%;
}

.characters-description {
    color: var(--text-secondary);
    margin-bottom: 24px;
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
}

.character-mode-toggle {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
    text-align: center;
}

.character-mode-toggle h3 {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.mode-description {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.4;
    margin: 0 0 16px 0;
}

.reset-character-btn {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    margin: 0 auto;
}

.reset-character-btn:hover {
    background: var(--hover-bg);
    border-color: var(--accent-green);
    transform: translateY(-1px);
}

.reset-character-btn svg {
    transition: transform 0.3s ease;
}

.reset-character-btn:hover svg {
    transform: rotate(-180deg);
}

.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.character-card {
    background: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.character-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--accent-blue) 0%, var(--accent-green) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.character-card:hover {
    border-color: var(--accent-green);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.character-card:hover::before {
    opacity: 0.1;
}

.character-card.selected {
    border-color: var(--accent-green);
    background: var(--message-bg-user);
}

.character-card.selected::before {
    opacity: 0.15;
}

.character-card[data-character="default"] {
    border-style: dashed;
    opacity: 0.9;
}

.character-card[data-character="default"] .character-icon {
    background: var(--text-muted);
}

.character-card[data-character="default"]:hover .character-icon {
    background: var(--accent-green);
}

.character-card[data-character="default"].selected .character-icon {
    background: var(--accent-green);
}

.character-icon {
    width: 48px;
    height: 48px;
    background: var(--accent-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    font-size: 24px;
    position: relative;
    z-index: 1;
}

.character-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
}

.character-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
    position: relative;
    z-index: 1;
}

.character-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 20px;
    height: 20px;
    background: var(--accent-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
    z-index: 2;
}

.character-card.selected .character-badge {
    opacity: 1;
    transform: scale(1);
}

/* Current character indicator in header */
.current-character {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    margin-left: 16px;
}

.current-character-icon {
    width: 24px;
    height: 24px;
    background: var(--accent-green);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    transition: all 0.3s ease;
    animation: characterPulse 3s ease-in-out infinite;
}

@keyframes characterPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 8px rgba(76, 175, 80, 0);
    }
}

/* Mobile responsiveness for characters modal */
@media (max-width: 768px) {
    .characters-modal {
        width: 95%;
        max-width: none;
    }
    
    .characters-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
        max-height: 300px;
    }
    
    .character-card {
        padding: 16px;
    }
    
    .character-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .character-name {
        font-size: 14px;
    }
    
    .character-description {
        font-size: 12px;
    }
}