:root {
    --sidebar-width: 280px;
    --transition-speed: 0.3s;
    --accent-rgb: 100, 116, 139;
    --glass-bg: var(--bg-glass);
    --glass-border: var(--border-glass);
}

.chat-layout {
    display: flex;
    height: calc(100vh - 260px);
    max-width: 1400px;
    margin: 0 auto;
    gap: 1.5rem;
    position: relative;
    padding: 0 1rem;
}

.history-sidebar {
    width: var(--sidebar-width);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    backdrop-filter: blur(16px);
    box-shadow: 0 8px 32px var(--shadow-glass);
}

.history-sidebar.hidden {
    width: 0;
    margin-left: calc(var(--sidebar-width) * -1);
    opacity: 0;
    pointer-events: none;
}

.history-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.history-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-header span {
    font-weight: 700;
    font-size: 1.1rem;
}

.history-search {
    background: rgba(128, 128, 128, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
    color: inherit;
    font-size: 0.8rem;
    outline: none;
    margin-right: 0.2rem;
    transition: border-color 0.2s;
}

.history-search:focus {
    border-color: var(--accent);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.history-item {
    padding: 0.7rem;
    border-radius: 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.history-item:hover {
    background: rgba(128, 128, 128, 0.1);
    border-color: var(--glass-border);
}

.history-item.active {
    background: rgba(var(--accent-rgb), 0.2);
    border-color: var(--accent);
}

.history-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    flex: 1;
}

.history-item-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-item:hover .history-actions {
    opacity: 1;
}

.btn-icon-small {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    transition: all 0.2s;
}

.btn-icon-small:hover {
    background: rgba(128, 128, 128, 0.1);
    color: var(--accent);
}

.btn-icon-small.del:hover {
    color: #fca5a5;
}

.btn-new-chat-sidebar {
    margin: 1rem;
    padding: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--accent);
    color: #fff;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.theme-dark .btn-new-chat-sidebar {
    color: #0f172a;
}

.btn-new-chat-sidebar:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.chat-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
    position: relative;
    height: 100%;
}

.chat-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    flex-shrink: 0;
}

.chat-info h2 {
    margin: 0 0 0.4rem 0;
    font-size: 1.3rem;
    font-weight: 700;
}

.chat-info .sub {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.8rem;
}

.pill {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-glass);
    border: 1px solid var(--glass-border);
}

.pill-success {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.4);
}

.pill-danger {
    background: #ef4444;
    color: #fff !important;
    border: 1px solid #b91c1c;
    font-weight: 700;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
    animation: pulse-danger 3s 3;
}

@keyframes pulse-danger {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.session-warning {
    color: #fca5a5;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-thread {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    min-height: 0;
}

.msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: msgAppear 0.3s ease-out forwards;
}

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

.msg.user {
    align-self: flex-end;
    align-items: flex-end;
}

.msg.assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.msg-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    display: flex;
    gap: 0.8rem;
}

.bubble {
    padding: 0.8rem 1.2rem;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.6;
    box-shadow: 0 4px 15px var(--shadow-glass);
}

.msg.user .bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.theme-dark .msg.user .bubble {
    color: #0f172a;
}

.msg.assistant .bubble {
    background: var(--bg-glass);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
    backdrop-filter: blur(8px);
}

.composer-wrapper {
    position: relative;
    width: 100%;
    max-width: 850px;
    margin: 0 auto;
    align-self: center;
    flex-shrink: 0;
}

.composer-container {
    background: var(--bg-glass);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 0.75rem;
    backdrop-filter: blur(20px);
    box-shadow: 0 10px 40px var(--shadow-glass);
    transition: all 0.3s ease;
}

.composer-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 10px 40px var(--shadow-glass), 0 0 0 1px var(--accent);
}

.sys-prompt-overlay {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-glass);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1rem;
    margin-bottom: 1rem;
    backdrop-filter: blur(20px);
    display: none;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 10;
    animation: slideUp 0.2s ease-out;
    box-shadow: 0 -10px 30px var(--shadow-glass);
}

#system-prompt {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    max-height: 30vh;
    resize: vertical;
}

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

.sys-prompt-overlay.active {
    display: flex;
}

.sys-prompt-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-glass);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 1.5rem;
    max-width: 500px;
    width: 90%;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 50px var(--shadow-glass);
    animation: modalAppear 0.2s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}

.prompt-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.prompt-chip {
    font-size: 0.8rem;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(128, 128, 128, 0.05);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.prompt-chip:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    transform: translateY(-2px);
}

.theme-dark .prompt-chip:hover {
    color: #0f172a;
}

.composer-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--glass-border);
    gap: 1rem;
}

.controls-left {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    align-items: flex-start;
}

.footer-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#algorithm-select {
    flex: 0 0 auto;
    width: auto;
}

#model-select {
    flex: 1;
    min-width: 0;
}

.chat-empty {
    text-align: center;
    margin-top: 20vh;
    opacity: 0.4;
    font-style: italic;
}

.kbd {
    padding: 2px 5px;
    background: rgba(128, 128, 128, 0.1);
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.75rem;
}

.local-history-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.3rem 0.7rem;
    border-radius: 10px;
    background: rgba(128, 128, 128, 0.05);
    border: 1px solid var(--glass-border);
}

.input-stats {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 4px;
    padding-right: 0.5rem;
}
.modal-input {
    width: 100%;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

.theme-dark .modal-input:focus {
    box-shadow: 0 0 0 2px rgba(99, 179, 237, 0.3);
}

@media (max-width: 768px) {
    .chat-layout {
        padding: 0 0.5rem;
    }

    .history-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 200;
        margin: 0;
        border-radius: 0;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .history-sidebar.hidden {
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }

    .history-item-name {
        font-size: 0.8rem;
    }

    .composer-wrapper {
        max-width: 100%;
        padding: 0 0.25rem;
    }

    .modal-content {
        width: 95%;
        padding: 1.25rem;
    }
}
