.chat-page {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
}

.chat-shell {
    display: flex;
    gap: 1.25rem;
    width: 100%;
    height: calc(100vh - 170px);
    min-height: 560px;
}

.chat-sidebar {
    flex: 0 0 300px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.sidebar-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    margin-bottom: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.material-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.material-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    text-align: left;
    width: 100%;
    transition: background-color 0.15s, border-color 0.15s;
}

.material-item:hover {
    background: var(--bg-light);
}

.material-item.active {
    background: var(--mark-soft);
    border-color: rgba(255, 210, 63, 0.55);
}

.material-icon {
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--bg-light);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.material-item.active .material-icon {
    background: var(--primary-color);
    color: var(--primary-ink);
}

.material-meta {
    min-width: 0;
    flex: 1;
}

.material-title {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.material-sub {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.1rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
}

.status-dot.completed { background: #2ecc71; }
.status-dot.pending, .status-dot.processing { background: #f5a623; animation: pulse-dot 1.4s infinite; }
.status-dot.failed { background: #e74c3c; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

.empty-materials {
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 0.75rem;
    text-align: center;
    border: 1px dashed var(--border-color);
    border-radius: 10px;
}

.upload-zone {
    display: flex;
    flex-direction: column;
    border: 1.5px dashed var(--border-color);
    border-radius: 12px;
    padding: 1rem 0.75rem;
    text-align: center;
    background: var(--bg-light);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
    position: relative;
}

.upload-zone:hover,
.upload-zone.is-dragging {
    border-color: var(--primary-color);
    background: var(--mark-soft);
}

.upload-zone-icon {
    font-size: 1.15rem;
    margin-bottom: 0.3rem;
}

.upload-zone-text {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-main);
}

.upload-zone-hint {
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.upload-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.field-error {
    color: #e74c3c;
    font-size: 0.72rem;
    font-weight: 500;
    margin-top: 0.5rem;
    display: flex;
    align-items: flex-start;
    gap: 0.3rem;
}

.upload-loading-indicator {
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    align-items: center;
    gap: 0.4rem;
}

.progress-notice {
    background: var(--mark-soft);
    color: var(--text-main);
    padding: 0.65rem 0.8rem;
    border-radius: 10px;
    font-size: 0.78rem;
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.stalled-notice {
    background: rgba(231, 76, 60, 0.1);
    color: #c0392b;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-top: 0.5rem;
    line-height: 1.45;
}

.alert-success {
    background: rgba(46, 204, 113, 0.12);
    color: #219150;
    padding: 0.65rem 0.8rem;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 500;
}

.chat-main {
    flex: 1;
    min-width: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.chat-header {
    padding: 0.9rem 1.35rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-blue));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex: 0 0 auto;
}

.chat-header-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.chat-header-focus {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    flex: 0 0 auto;
}

.icon-btn:hover {
    background: var(--bg-light);
    color: var(--text-main);
}

.chat-messages {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    scroll-behavior: smooth;
}

.msg-row {
    display: flex;
    gap: 0.6rem;
    max-width: 100%;
}

.msg-row.from-user {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    margin-top: 2px;
}

.msg-avatar.assistant {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-blue));
}

.msg-avatar.user {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}

.msg-bubble {
    max-width: min(74%, 620px);
    padding: 0.75rem 1rem;
    border-radius: 14px;
    line-height: 1.55;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

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

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

.typing-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
    padding: 0.2rem 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
    gap: 0.4rem;
}

.empty-chat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-blue));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-chat h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
}

.empty-chat p {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 380px;
    line-height: 1.5;
}

.suggestion-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 0.85rem;
}

.suggestion-chip {
    font-size: 0.78rem;
    font-weight: 500;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-main);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;
}

.suggestion-chip:hover {
    border-color: var(--primary-color);
    background: var(--mark-soft);
}

.chat-composer {
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.composer-bar {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 0.5rem 0.6rem 0.5rem 0.9rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-bar:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--mark-soft);
}

.composer-textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    line-height: 1.5;
    max-height: 160px;
    padding: 0.4rem 0;
}

.composer-textarea::placeholder {
    color: var(--text-secondary);
}

.composer-attach {
    position: relative;
    flex: 0 0 auto;
}

.composer-attach .upload-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.composer-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: var(--primary-ink);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
    transition: background-color 0.15s, transform 0.1s;
}

.composer-send:hover {
    background: var(--primary-hover);
}

.composer-send:active {
    transform: scale(0.94);
}

.composer-send:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.composer-hint {
    font-size: 0.68rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 0.55rem;
}

@media (max-width: 860px) {
    .chat-shell {
        flex-direction: column;
        height: auto;
    }
    .chat-sidebar {
        flex: none;
        width: 100%;
        max-height: 260px;
    }
    .chat-main {
        min-height: 560px;
    }
}
