:root {
    --bg-dark: #0a0a0c;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent-color: #4d5c94;
    --accent-bright: #7d91ff;
    --accent-warm: #ffb86c;
    --text-primary: #e0e0e0;
    --text-secondary: #909090;
    --danger: #ff5555;
    --success: #50fa7b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Segoe UI', sans-serif;
}

body {
    background: var(--bg-dark);
    height: 100vh;
    overflow: hidden;
    color: var(--text-primary);
}

button,
textarea {
    font: inherit;
}

.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at center, #1a1a2e 0%, #0a0a0c 100%);
}

.blob {
    position: absolute;
    width: 600px;
    height: 600px;
    background: var(--accent-color);
    filter: blur(120px);
    border-radius: 50%;
    opacity: 0.12;
    animation: move 25s infinite alternate ease-in-out;
}

.blob:nth-child(1) { top: -100px; left: -100px; }
.blob:nth-child(2) { 
    bottom: -100px; 
    right: -100px; 
    background: #2d365e;
    animation-delay: -5s;
}

@keyframes move {
    from { transform: translate(-10%, -10%) scale(1); }
    to { transform: translate(20%, 20%) scale(1.1); }
}

.app-container {
    display: flex;
    height: 100vh;
    padding: 15px;
    gap: 15px;
    animation: app-enter 0.45s ease both;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.16);
}

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

@keyframes soft-rise {
    from { opacity: 0; transform: translateY(12px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes list-in {
    from { opacity: 0; transform: translateX(-8px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes sheen {
    0% { left: calc(var(--sheen-width, 56px) * -1.6); opacity: 0; }
    14% { opacity: 1; }
    82% { opacity: 1; }
    100% { left: calc(100% + var(--sheen-width, 56px)); opacity: 0; }
}

@keyframes pulse-ring {
    0%, 100% { box-shadow: 0 0 0 0 rgba(125, 145, 255, 0); }
    50% { box-shadow: 0 0 0 5px rgba(125, 145, 255, 0.08); }
}

/* Sidebar */
.sidebar {
    width: 280px;
    display: flex;
    flex-direction: column;
    padding: 15px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.sidebar.hidden {
    width: 0;
    padding: 0;
    margin-right: -15px;
    border: none;
    opacity: 0;
    overflow: hidden;
}

.sidebar-header { margin-bottom: 15px; }

.btn-primary {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    border: none;
    background: var(--accent-color);
    color: white;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary:hover {
    background: #5f70b5;
    box-shadow: 0 8px 24px rgba(77, 92, 148, 0.28);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-item {
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    min-height: 40px;
    overflow: hidden;
    position: relative;
    animation: list-in 0.25s ease both;
    animation-delay: calc(var(--item-index, 0) * 35ms);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.chat-item::after {
    content: '';
    position: absolute;
    top: -40%;
    bottom: -40%;
    left: -72px;
    width: var(--sheen-width, 56px);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
    opacity: 0;
    pointer-events: none;
    transform: skewX(-18deg);
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.055);
    transform: translateX(2px);
}

.chat-item:hover::after {
    animation: sheen 0.75s ease both;
}

.chat-item.active {
    background: rgba(77, 92, 148, 0.2);
    border: 1px solid var(--accent-color);
}

.chat-item-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-delete-btn {
    color: var(--danger);
    opacity: 0.78;
    flex: 0 0 auto;
}

.chat-delete-btn:hover {
    color: #ff7777;
    opacity: 1;
}

/* Main Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
}

.chat-title {
    flex: 1;
    min-width: 0;
    color: var(--text-secondary);
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    margin-left: auto;
    position: relative;
}

.response-mode-select {
    position: relative;
}

.mode-trigger {
    min-width: 116px;
    height: 38px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.045);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    color: var(--text-primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 11px;
    font-size: 13px;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.mode-trigger:hover,
.mode-trigger[aria-expanded='true'] {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(125, 145, 255, 0.35);
    transform: translateY(-1px);
}

.mode-chevron {
    color: var(--text-secondary);
    font-size: 10px;
}

.mode-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 280px;
    padding: 8px;
    z-index: 10;
    background: rgba(14, 16, 26, 0.72);
    backdrop-filter: blur(25px) saturate(135%);
    -webkit-backdrop-filter: blur(25px) saturate(135%);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    animation: soft-rise 0.18s ease both;
}

.mode-menu[hidden] {
    display: none;
}

.mode-option {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 10px;
    text-align: left;
    transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.mode-option:hover,
.mode-option.active {
    background: rgba(77, 92, 148, 0.18);
    border-color: rgba(122, 140, 214, 0.32);
}

.mode-option:hover {
    transform: translateX(2px);
}

.mode-option-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: rgba(99, 114, 183, 0.25);
    color: #b6c2ff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.mode-option-copy {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.mode-option-copy strong {
    font-size: 13px;
    font-weight: 650;
}

.mode-option-copy small {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.35;
}

.btn-icon {
    background: none;
    border: none;
    color: white;
    padding: 10px;
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.2s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-right: 10px;
    scroll-behavior: smooth;
}

/* Messages */
.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    min-width: 60px;
    word-wrap: break-word;
    word-break: break-word;
    animation: soft-rise 0.28s ease both;
}

.message-wrapper.user { align-self: flex-end; }
.message-wrapper.assistant { align-self: flex-start; }
.message-wrapper.streaming {
    max-width: 85%;
    align-items: flex-start;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
    outline: none;
    /* white-space: pre-wrap; */
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.message-bubble:hover {
    border-color: rgba(125, 145, 255, 0.22);
}

.markdown-body p { margin: 0 0 10px; }
.markdown-body p:last-child { margin-bottom: 0; }

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin: 14px 0 8px;
    line-height: 1.25;
    color: #f2f4ff;
}

.markdown-body h1 { font-size: 24px; }
.markdown-body h2 { font-size: 20px; }
.markdown-body h3 { font-size: 17px; }
.markdown-body h4 { font-size: 15px; }

.markdown-body ul,
.markdown-body ol {
    margin: 8px 0 12px 20px;
    padding-left: 10px;
}

.markdown-body li {
    margin: 4px 0;
}

.markdown-body blockquote {
    margin: 12px 0;
    padding: 8px 12px;
    border-left: 3px solid var(--accent-bright);
    background: rgba(125, 145, 255, 0.08);
    color: #c9d0ff;
    border-radius: 8px;
}

.markdown-body a {
    color: #9fb0ff;
    text-decoration: none;
    border-bottom: 1px solid rgba(159, 176, 255, 0.35);
}

.markdown-body a:hover {
    color: white;
    border-bottom-color: white;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 14px 0;
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    overflow: hidden;
    border-radius: 8px;
}

.markdown-body th,
.markdown-body td {
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 10px;
    text-align: left;
}

.markdown-body th {
    background: rgba(125, 145, 255, 0.12);
    color: #f2f4ff;
}

.markdown-body img {
    max-width: 100%;
    border-radius: 10px;
    margin: 10px 0;
}

.markdown-body .katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 0;
}

.message-bubble[contenteditable='true'] {
    background: rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 0 0 2px var(--accent-color);
    min-width: 220px;
}

.user .message-bubble { background: var(--accent-color); }
.assistant .message-bubble { background: rgba(255, 255, 255, 0.05); }

/* Start screen */
.start-screen {
    width: min(860px, 100%);
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 28px 8px;
    animation: soft-rise 0.35s ease both;
}

.start-copy {
    max-width: 620px;
}

.start-kicker {
    color: var(--accent-warm);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.start-copy h1 {
    font-size: clamp(30px, 5vw, 58px);
    line-height: 1.05;
    margin-bottom: 12px;
    color: #f5f6ff;
}

.start-copy p {
    color: var(--text-secondary);
    line-height: 1.55;
}

.start-mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.start-mode-card {
    min-height: 190px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 13px;
    padding: 16px;
    text-align: left;
    position: relative;
    overflow: hidden;
    animation: soft-rise 0.3s ease both;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.start-mode-card::after {
    content: '';
    position: absolute;
    top: -45%;
    bottom: -45%;
    left: -90px;
    width: var(--sheen-width, 64px);
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.14), transparent);
    opacity: 0;
    pointer-events: none;
    transform: skewX(-18deg);
}

.start-mode-card:hover {
    transform: translateY(-3px);
    border-color: rgba(125, 145, 255, 0.38);
    background: rgba(255, 255, 255, 0.055);
}

.start-mode-card:hover::after {
    animation: sheen 0.85s ease both;
}

.start-mode-card.active {
    border-color: rgba(80, 250, 123, 0.36);
    background: rgba(80, 250, 123, 0.06);
}

.start-mode-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(125, 145, 255, 0.16);
    color: #bcc7ff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.start-mode-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.start-mode-body strong {
    font-size: 16px;
}

.start-mode-body small {
    color: var(--text-secondary);
    line-height: 1.4;
}

.start-mode-points {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
    color: #b7bfdc;
    font-size: 12px;
}

.start-mode-points span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.start-mode-points i {
    color: rgba(80, 250, 123, 0.78);
    font-size: 10px;
}

/* Progress Box */
.progress-container {
    padding: 10px 11px;
    margin-bottom: 10px;
    width: min(360px, 100%);
    max-width: 360px;
    align-self: flex-start;
    border-radius: 12px;
    animation: soft-rise 0.24s ease both;
}

.progress-toggle {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 0 8px;
    font-size: 15px;
    font-weight: 650;
}

.progress-toggle i {
    color: var(--text-secondary);
    font-size: 11px;
    transition: transform 0.2s ease;
}

.progress-toggle[aria-expanded='true'] i {
    transform: rotate(180deg);
}

.progress-timeline {
    display: flex;
    flex-direction: column;
}

.progress-step {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    min-width: 0;
}

.progress-container.is-collapsed .progress-step:not(.is-latest) {
    display: none;
}

.progress-container.is-collapsed .progress-step.is-latest .progress-points {
    display: none;
}

.progress-step-line {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.progress-marker {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    font-size: 11px;
}

.progress-marker.ready {
    background: #5665b0;
    color: white;
}

.progress-marker.failed {
    background: rgba(255, 85, 85, 0.18);
    border: 1px solid rgba(255, 85, 85, 0.45);
    color: var(--danger);
}

.progress-marker.processed {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(139, 154, 232, 0.45);
    color: #b6c2ff;
    animation: pulse-ring 1.4s ease infinite;
}

.progress-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(182, 194, 255, 0.25);
    border-top-color: #b6c2ff;
    border-radius: 50%;
    animation: progress-spin 0.8s linear infinite;
}

.progress-mini-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(182, 194, 255, 0.22);
    border-top-color: #b6c2ff;
    border-radius: 50%;
    animation: progress-spin 0.8s linear infinite;
}

@keyframes progress-spin {
    to { transform: rotate(360deg); }
}

.progress-connector {
    width: 2px;
    flex: 1;
    min-height: 20px;
    background: rgba(139, 154, 232, 0.5);
}

.progress-step:last-child .progress-connector,
.progress-container.is-collapsed .progress-connector {
    display: none;
}

.progress-step-body {
    min-width: 0;
    padding: 0 0 13px 2px;
}

.progress-step:last-child .progress-step-body {
    padding-bottom: 0;
}

.progress-step-header {
    min-height: 24px;
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 650;
    min-width: 0;
}

.progress-step-title,
.progress-point-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.progress-value {
    color: var(--text-secondary);
    font-weight: 520;
    flex: 0 0 auto;
    margin-left: auto;
}

.progress-status-edge {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    margin-left: auto;
    transform: translateX(5px);
}

.progress-status-edge.ready {
    color: rgba(80, 250, 123, 0.78);
}

.progress-status-edge.failed {
    color: rgba(255, 85, 85, 0.85);
}

.progress-status-edge.processed {
    color: #b6c2ff;
}

.progress-points {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 5px;
}

.progress-point {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(24px, auto);
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.25;
    min-height: 18px;
}

.progress-point .progress-value,
.progress-point .progress-status-edge {
    justify-self: end;
    margin-left: 0;
}

.message-bubble pre {
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px;
    border-radius: 8px;
    margin: 10px 0;
    overflow-x: auto;
    white-space: pre; 
}

.message-bubble code {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 13px;
}

.message-bubble :not(pre) > code {
    background: rgba(0, 0, 0, 0.35);
    border-radius: 4px;
    padding: 2px 5px;
}

.message-actions {
    display: flex;
    gap: 12px;
    margin-top: 6px;
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    padding: 0 5px;
}

.message-wrapper:hover .message-actions,
.message-bubble[contenteditable='true'] + .message-actions {
    opacity: 1;
    transform: translateY(0);
}

.action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.16s ease, transform 0.16s ease;
}

.action-btn:hover {
    color: white;
    transform: translateY(-1px);
}

.danger-action,
.danger-action:hover {
    color: var(--danger);
}

/* Input Footer */
.chat-footer {
    padding: 12px 16px;
    margin-bottom: 5px;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.chat-footer:focus-within {
    border-color: rgba(125, 145, 255, 0.35);
    background: rgba(255, 255, 255, 0.045);
}

.chat-footer.expanded #message-input {
    min-height: 180px;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    resize: none;
    outline: none;
    padding: 8px 0;
    font-size: 15px;
    max-height: 400px;
    min-height: 24px;
    line-height: 24px;
    overflow-y: hidden;
}

.chat-footer.expanded #message-input,
#message-input.can-scroll {
    overflow-y: auto;
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 4px;
}

.btn-send {
    background: var(--accent-color);
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn-send:hover {
    background: #5f70b5;
    box-shadow: 0 9px 24px rgba(77, 92, 148, 0.34);
    transform: translateY(-1px);
}

.btn-send:active {
    transform: translateY(0) scale(0.98);
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }

@media (max-width: 720px) {
    .app-container {
        padding: 10px;
        gap: 10px;
    }

    .sidebar {
        width: min(260px, 72vw);
    }

    .message-wrapper,
    .message-wrapper.streaming {
        max-width: 96%;
    }

    .start-copy h1 {
        font-size: 34px;
    }

    .mode-menu {
        width: min(280px, calc(100vw - 24px));
    }
}
