:root {
    --bg-color: #FAFAF8;
    --text-color: #1A1A1A;
    --muted: #F5F3F0;
    --muted-foreground: #6B6B6B;
    --accent: #ef6427;
    --accent-secondary: #f27f4d;
    --border: #E8E4DF;
    --card: #FFFFFF;
    --sidebar-width: 280px;
}

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

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Source Sans 3', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior: none;
}

body {
    display: flex;
    flex-direction: row;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 400;
    margin: 0;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.45);
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

#sidebar {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background-color: var(--bg-color);
    flex-shrink: 0;
    height: 100%;
    height: 100dvh;
    z-index: 500;
}

.sidebar-header {
    height: 70px;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.btn-outline {
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--text-color);
    color: var(--text-color);
    padding: 0.65rem 1rem;
    font-family: 'Source Sans 3', sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.04em;
    border-radius: 6px;
    cursor: pointer;
    transition: all 180ms ease-out;
}

.btn-outline:hover {
    background-color: var(--muted);
    border-color: var(--accent);
    color: var(--accent);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0;
    -webkit-overflow-scrolling: touch;
}

.chat-item {
    padding: 0.85rem 1.5rem;
    cursor: pointer;
    font-family: 'Source Sans 3', sans-serif;
    font-size: 0.875rem;
    color: var(--muted-foreground);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    user-select: none;
    transition: all 180ms ease-out;
    border-left: 3px solid transparent;
}

.chat-item:hover {
    background-color: var(--muted);
    color: var(--text-color);
}

.chat-item.active {
    color: var(--text-color);
    background-color: var(--card);
    border-left-color: var(--accent);
    font-weight: 600;
}

#main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
}

header {
    height: 70px;
    padding: 0 1.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    background-color: var(--bg-color);
    z-index: 10;
}

.chat-title {
    font-size: 1.5rem;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.4rem;
    margin-right: 0.75rem;
    color: var(--text-color);
    border-radius: 6px;
    line-height: 1;
}

.sidebar-toggle:active {
    background-color: var(--muted);
}

#chat-container {
    flex: 1 1 0%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0;
    scroll-behavior: smooth;
}

.message-wrapper {
    padding: 1.75rem 2rem;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    width: 100%;
    max-width: 56rem;
}

.message-wrapper.user {
    background-color: var(--card);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.message-role {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.message-content {
    font-size: 1rem;
    color: var(--text-color);
    word-break: break-word;
    overflow-wrap: break-word;
}

.message-content p {
    margin-top: 0;
    margin-bottom: 1.25rem;
}

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

.message-content pre {
    background-color: #1A1A1A;
    color: #F5F3F0;
    padding: 1.25rem;
    overflow-x: auto;
    border-radius: 6px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.message-content code {
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.875rem;
    background-color: var(--muted);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}

.message-content pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
}

.message-content h1, .message-content h2, .message-content h3 {
    font-family: 'Playfair Display', Georgia, serif;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    color: var(--text-color);
}

.message-content ul, .message-content ol {
    margin-bottom: 1.25rem;
    padding-left: 1.75rem;
}

.message-content li {
    margin-bottom: 0.4rem;
}

.input-container {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 1.25rem 1.75rem;
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    position: sticky;
    bottom: 0;
    z-index: 20;
}

.input-wrapper {
    max-width: 56rem;
    width: 100%;
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    background-color: var(--card);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
    overflow: hidden;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(239, 100, 39, 0.25);
}

input[type="text"] {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    padding: 0.9rem 1.25rem;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: var(--text-color);
    box-sizing: border-box;
}

input[type="text"]::placeholder {
    color: var(--muted-foreground);
    opacity: 0.7;
}

.btn-primary {
    flex-shrink: 0;
    background-color: var(--accent);
    color: #FFFFFF;
    border: none;
    padding: 0.9rem 1.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    letter-spacing: 0.03em;
    cursor: pointer;
    font-family: 'Source Sans 3', sans-serif;
    border-radius: 0;
    transition: background-color 180ms ease-out;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
}

.btn-primary:hover {
    background-color: var(--accent-secondary);
}

.btn-primary:active {
    background-color: #d8541c;
}

.btn-primary:disabled {
    background-color: #c4bebb;
    cursor: not-allowed;
}

.thinking {
    font-style: italic;
    color: var(--muted-foreground);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

.modal {
    display: none; 
    position: fixed; 
    z-index: 1000; 
    inset: 0;
    background-color: rgba(0,0,0,0.55); 
    align-items: center; 
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--card);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    max-width: 380px;
    width: 100%;
    text-align: center;
    border: 1px solid var(--border);
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
    margin-bottom: 0.75rem;
    font-size: 1.4rem;
    color: var(--text-color);
}

#captcha-text {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent);
    margin: 0.75rem 0 1.25rem 0;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.modal-content input {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.85rem;
    font-size: 16px;
    text-align: center;
    outline: none;
    font-family: inherit;
}

.modal-content input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(239, 100, 39, 0.2);
}

.modal-content .btn-primary {
    border-radius: 6px;
    width: 100%;
}

.error-msg {
    color: #d32f2f;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    min-height: 1.2rem;
}

@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        height: 100%;
        height: 100dvh;
        width: 82vw;
        max-width: 300px;
        z-index: 500;
        transition: left 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        border-right: 1px solid var(--border);
        box-shadow: 4px 0 20px rgba(0,0,0,0.18);
    }

    #sidebar.show-mobile {
        left: 0;
    }

    .sidebar-toggle {
        display: flex;
    }

    header {
        height: 56px;
        padding: 0 1rem;
    }

    .chat-title {
        font-size: 1.15rem;
        font-weight: 600;
    }

    #chat-container {
        padding: 0.75rem 0;
    }

    .message-wrapper {
        padding: 1rem 1rem;
    }

    .message-role {
        font-size: 0.7rem;
        margin-bottom: 0.5rem;
    }

    .message-content {
        font-size: 0.95rem;
        line-height: 1.55;
    }

    .message-content pre {
        padding: 0.85rem;
        font-size: 0.8rem;
        margin-bottom: 1rem;
    }

    .input-container {
        padding: 0.5rem 0.75rem;
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
        background-color: var(--bg-color);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.03);
    }

    .input-wrapper {
        border-radius: 8px;
    }

    input[type="text"] {
        padding: 0.7rem 0.85rem;
        font-size: 16px;
        min-height: 42px;
    }

    .btn-primary {
        padding: 0 1.1rem;
        font-size: 0.85rem;
        min-height: 42px;
    }

    .modal-content {
        padding: 1.5rem;
        border-radius: 10px;
    }
}
