:root {
    --bg: #0b1020;
    --bg-soft: #11182b;
    --surface: rgba(20, 29, 49, 0.78);
    --surface-strong: #17223a;
    --surface-user: #3267d6;
    --text: #eef4ff;
    --muted: #8f9bb3;
    --accent: #79a8ff;
    --accent-strong: #4f82ef;
    --border: rgba(164, 190, 255, 0.14);
    --radius: 18px;
    --shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background: var(--bg);
}

body {
    min-height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    color: var(--text);
    background:
        radial-gradient(circle at 10% 0%, rgba(78, 121, 230, 0.22), transparent 34%),
        radial-gradient(circle at 100% 100%, rgba(106, 71, 190, 0.16), transparent 32%),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
}

body::before {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    content: "";
    opacity: 0.25;
    background-image: linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.app-header {
    width: min(100%, 1100px);
    margin: 0 auto;
    padding: 24px 34px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.brand,
.connection-status {
    display: flex;
    align-items: center;
}

.brand {
    gap: 12px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(151, 186, 255, 0.32);
    border-radius: 13px;
    color: white;
    background: linear-gradient(145deg, #76a7ff, #6652c8);
    box-shadow: 0 8px 24px rgba(80, 119, 235, 0.3);
    font-size: 22px;
}

.brand strong,
.brand span {
    display: block;
}

.brand strong {
    letter-spacing: -0.02em;
    font-size: 16px;
}

.brand span {
    color: var(--muted);
    font-size: 12px;
}

.connection-status {
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.035);
    font-size: 12px;
}

.status-dot {
    width: 7px;
    height: 7px;
    display: block;
    border-radius: 50%;
    background: #55d895;
    box-shadow: 0 0 12px #55d895;
}

#chat-window {
    width: min(100%, 1100px);
    min-height: 0;
    flex: 1;
    margin: 0 auto;
    padding: 28px 34px 44px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    overflow-y: auto;
    scroll-behavior: smooth;
    animation: fadeIn 0.45s ease-out;
}

#chat-window::-webkit-scrollbar {
    width: 8px;
}

#chat-window::-webkit-scrollbar-thumb {
    border-radius: 99px;
    background: rgba(150, 174, 224, 0.24);
}

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

.message {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    animation: messageIn 0.28s ease-out both;
}

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

.avatar {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    font-size: 19px;
}

.content {
    width: fit-content;
    max-width: min(780px, calc(100% - 50px));
    padding: 17px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.ai-message .content {
    border-top-left-radius: 6px;
}

.user-message {
    justify-content: flex-end;
}

.user-message .avatar {
    order: 2;
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.13);
}

.user-message .content {
    border: 0;
    border-top-right-radius: 6px;
    color: white;
    background: linear-gradient(135deg, var(--surface-user), #4f55c9);
    box-shadow: 0 14px 36px rgba(52, 91, 211, 0.22);
}

.welcome-message .content {
    background: linear-gradient(135deg, rgba(37, 52, 84, 0.9), rgba(24, 33, 58, 0.86));
}

.message-body {
    min-width: 0;
}

.message-body > :first-child {
    margin-top: 0;
}

.message-body > :last-child {
    margin-bottom: 0;
}

.message-body p,
.assistant-response p {
    margin: 0 0 12px;
}

.assistant-response {
    min-width: 0;
    overflow-wrap: anywhere;
}

.assistant-response h1,
.assistant-response h2,
.assistant-response h3,
.assistant-response h4,
.assistant-response h5,
.assistant-response h6 {
    margin: 20px 0 8px;
    color: #f8fbff;
    line-height: 1.25;
    letter-spacing: -0.025em;
}

.assistant-response h1 { font-size: 1.65rem; }
.assistant-response h2 { font-size: 1.4rem; }
.assistant-response h3 { font-size: 1.2rem; }
.assistant-response h4,
.assistant-response h5,
.assistant-response h6 { font-size: 1rem; }

.assistant-response strong {
    color: #dce8ff;
    font-weight: 750;
}

.assistant-response em {
    color: #b9d2ff;
}

.assistant-response del {
    color: #a0aabe;
}

.assistant-response mark {
    padding: 1px 4px;
    border-radius: 4px;
    color: #1a2440;
    background: #f2d77b;
}

.assistant-response ul,
.assistant-response ol {
    margin: 10px 0 14px 22px;
}

.assistant-response li {
    margin: 4px 0;
    padding-left: 3px;
}

.task-item {
    list-style: none;
    margin-left: -20px !important;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.task-item input {
    width: 15px;
    height: 15px;
    margin-top: 5px;
    accent-color: var(--accent-strong);
}

.assistant-response blockquote {
    margin: 14px 0;
    padding: 10px 15px;
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    color: #c4d0e7;
    background: rgba(121, 168, 255, 0.08);
}

.assistant-response blockquote p:last-child {
    margin-bottom: 0;
}

.assistant-response hr {
    margin: 20px 0;
    border: 0;
    border-top: 1px solid var(--border);
}

.assistant-response a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.assistant-response img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 12px 0;
    border-radius: 10px;
}

.assistant-response code,
.thought-content code {
    padding: 2px 6px;
    border: 1px solid rgba(164, 190, 255, 0.12);
    border-radius: 5px;
    color: #d7e7ff;
    background: rgba(0, 0, 0, 0.25);
    font-family: "Cascadia Code", Consolas, monospace;
    font-size: 0.9em;
}

.assistant-response pre,
.thought-content pre {
    max-width: 100%;
    margin: 14px 0;
    padding: 15px 16px;
    overflow-x: auto;
    border: 1px solid rgba(164, 190, 255, 0.14);
    border-radius: 11px;
    background: #080d18;
}

.assistant-response pre code,
.thought-content pre code {
    padding: 0;
    border: 0;
    color: #d9e5ff;
    background: transparent;
    font-size: 0.86rem;
    line-height: 1.6;
}

.table-wrap {
    max-width: 100%;
    margin: 14px 0;
    overflow-x: auto;
}

.assistant-response table {
    width: 100%;
    min-width: 420px;
    border-collapse: collapse;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.assistant-response th,
.assistant-response td {
    padding: 9px 11px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.assistant-response th {
    color: #dce8ff;
    background: rgba(121, 168, 255, 0.1);
    font-weight: 700;
}

.assistant-response tr:last-child td {
    border-bottom: 0;
}

.thought-process {
    margin-bottom: 14px;
    border: 1px solid rgba(121, 168, 255, 0.18);
    border-radius: 12px;
    overflow: hidden;
    background: rgba(79, 130, 239, 0.08);
}

.thought-process summary {
    min-height: 42px;
    padding: 10px 13px;
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    list-style: none;
    color: #c5d8ff;
    font-size: 13px;
    font-weight: 700;
}

.thought-process summary::-webkit-details-marker {
    display: none;
}

.thought-process summary::after {
    margin-left: auto;
    content: "⌄";
    color: var(--muted);
    font-size: 18px;
    transition: transform 0.2s ease;
}

.thought-process[open] summary::after {
    transform: rotate(180deg);
}

.thought-icon {
    color: #9bbdff;
    font-size: 16px;
}

.thought-hint {
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
}

.thought-content {
    padding: 0 15px 14px;
    color: #aebbd3;
    font-size: 13px;
}

.mcp-activity-list {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.mcp-activity {
    padding: 10px 12px;
    border: 1px solid rgba(121, 168, 255, 0.18);
    border-radius: 11px;
    background: rgba(121, 168, 255, 0.07);
}

.mcp-activity.success {
    border-color: rgba(85, 216, 149, 0.22);
    background: rgba(85, 216, 149, 0.06);
}

.mcp-activity.failure {
    border-color: rgba(255, 138, 128, 0.25);
    background: rgba(255, 138, 128, 0.06);
}

.mcp-activity-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #dce8ff;
    font-size: 13px;
}

.mcp-activity-icon {
    width: 19px;
    height: 19px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--accent);
    background: rgba(121, 168, 255, 0.13);
    font-size: 12px;
}

.mcp-activity.success .mcp-activity-icon {
    color: #72e0a8;
    background: rgba(85, 216, 149, 0.14);
}

.mcp-activity.failure .mcp-activity-icon {
    color: #ffaaa4;
    background: rgba(255, 138, 128, 0.14);
}

.mcp-activity-status {
    margin-left: auto;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
}

.loading-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 4px;
    vertical-align: middle;
}

.loading-dots i {
    width: 4px;
    height: 4px;
    display: block;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.28;
    animation: loadingDot 1.1s infinite ease-in-out;
}

.loading-dots i:nth-child(2) { animation-delay: 0.16s; }
.loading-dots i:nth-child(3) { animation-delay: 0.32s; }

@keyframes loadingDot {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-2px); }
}

.file-attachment {
    margin-top: 10px;
    padding: 9px;
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid rgba(121, 168, 255, 0.16);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.15);
}

.file-attachment-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: rgba(121, 168, 255, 0.12);
    font-size: 16px;
}

.file-attachment-info {
    min-width: 0;
    flex: 1;
}

.file-attachment-info strong,
.file-attachment-info span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-attachment-info strong {
    color: #dce8ff;
    font-size: 12px;
}

.file-attachment-info span {
    color: var(--muted);
    font-size: 10px;
}

.file-attachment a {
    padding: 5px 7px;
    border-radius: 6px;
    color: var(--accent);
    background: rgba(121, 168, 255, 0.09);
    font-size: 11px;
    text-decoration: none;
    white-space: nowrap;
}

.file-attachment a:hover {
    background: rgba(121, 168, 255, 0.18);
}

.mcp-activity-provider {
    margin: 3px 0 0 27px;
    color: var(--muted);
    font-size: 11px;
}

.mcp-activity-details {
    margin: 8px 0 0 27px;
    color: var(--muted);
    font-size: 11px;
}

.mcp-activity-details summary {
    cursor: pointer;
}

.mcp-activity-details pre {
    margin: 7px 0 0;
    padding: 9px;
    max-height: 220px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: #b9c8e4;
    background: rgba(0, 0, 0, 0.2);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: 11px/1.5 "Cascadia Code", Consolas, monospace;
}

.thought-content p {
    margin-bottom: 9px;
}

.error-message {
    color: #ffaaa4;
    line-height: 1.5;
}

#input-container {
    padding: 18px 34px 24px;
    border-top: 1px solid var(--border);
    background: rgba(10, 15, 29, 0.72);
    box-shadow: 0 -18px 45px rgba(0, 0, 0, 0.18);
    backdrop-filter: blur(22px);
}

#chat-form {
    width: min(100%, 850px);
    margin: 0 auto;
    padding: 6px 7px 6px 10px;
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid rgba(164, 190, 255, 0.2);
    border-radius: 17px;
    background: rgba(24, 34, 57, 0.88);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

#user-input {
    min-width: 0;
    flex: 1;
    padding: 11px 7px;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font: inherit;
    font-size: 15px;
}

#user-input::placeholder {
    color: #7e8aa3;
}

#user-input:focus {
    outline: none;
}

button {
    border: 0;
    color: white;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

button:focus-visible,
#user-input:focus-visible {
    outline: 3px solid rgba(121, 168, 255, 0.35);
    outline-offset: 2px;
}

.microphone-btn,
.send-btn {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(121, 168, 255, 0.12);
    font-size: 15px;
}

.microphone-btn:hover,
.send-btn:hover {
    background: rgba(121, 168, 255, 0.25);
    transform: translateY(-1px);
}

.microphone-btn.recording {
    color: white;
    background: #de765f;
    box-shadow: 0 0 0 5px rgba(222, 118, 95, 0.12);
}

.send-btn {
    background: linear-gradient(135deg, var(--accent-strong), #645dcc);
    box-shadow: 0 6px 16px rgba(79, 130, 239, 0.28);
}

@media (max-width: 700px) {
    .app-header {
        padding: 17px 18px 8px;
    }

    #chat-window {
        padding: 22px 18px 32px;
    }

    #input-container {
        padding: 12px 14px 17px;
    }

    .connection-status {
        padding: 7px;
    }

    .connection-status span:last-child {
        display: none;
    }

    .content {
        max-width: calc(100% - 47px);
        padding: 14px 15px;
    }

    .thought-hint {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
