/**
 * AI Backend Frontend
 * 现代极简设计 + 完整功能
 * 2025-12-13
 */

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

html, body {
    width: 100%;
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #ffffff;
    color: #1f2937;
    overflow: hidden;
}

/* ==================== 主容器 ==================== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
}

/* ==================== 顶部状态栏 ==================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    background: #ffffff;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #1f2937;
}

.logo-text {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b7280;
}

.pulse {
    position: relative;
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    animation: pulse 2s infinite;
}

.pulse.error {
    background: #ef4444;
    animation: none;
}

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

.divider {
    width: 1px;
    height: 16px;
    background: #e5e7eb;
}

.latency {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
    color: #6b7280;
}

.icon {
    width: 12px;
    height: 12px;
    stroke: #9ca3af;
}

/* ==================== 快速标签栏 ==================== */
.quick-tags {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.quick-tags::-webkit-scrollbar {
    display: none;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    background: #ffffff;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    flex-shrink: 0;
}

.tag-icon {
    font-size: 13px;
}

/* ==================== 主消息区 ==================== */
.main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    padding: 0;
}

.messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
    overflow-y: auto;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: auto;
    gap: 8px;
    text-align: center;
}

.placeholder-text {
    font-size: 16px;
    font-weight: 500;
    color: #374151;
}

.placeholder-hint {
    font-size: 13px;
    color: #9ca3af;
}

/* 消息气泡 */
.message {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
    max-width: 90%;
    animation: slideIn 0.3s ease-out;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 100%;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #0066ff;
    color: white;
}

.message.assistant .message-avatar {
    background: #f3f4f6;
    color: #6b7280;
}

.message-content {
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-content {
    background: #0066ff;
    color: white;
}

.message.assistant .message-content {
    background: #f3f4f6;
    color: #1f2937;
}

.message.system .message-content {
    background: transparent;
    color: #9ca3af;
    font-size: 12px;
}

/* ==================== 输入区域 ==================== */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 12px 16px;
    background: #ffffff;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

/* 档位选择按钮 */
.tier-selector {
    display: flex;
    gap: 6px;
}

.tier-btn {
    flex: 1;
    padding: 8px 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.tier-btn:hover {
    background: #f3f4f6;
}

.tier-btn.active {
    background: #1f2937;
    color: white;
    border-color: #1f2937;
}

/* 搜索组 */
.search-group {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 8px 12px;
    transition: all 0.2s;
}

.search-group:focus-within {
    background: #ffffff;
    border-color: #d1d5db;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.search-icon {
    width: 16px;
    height: 16px;
    stroke: #d1d5db;
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    background: transparent;
    border: none;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    font-weight: 400;
    line-height: 1.5;
}

.search-input::placeholder {
    color: #d1d5db;
}

.send-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1f2937;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.send-btn:hover {
    background: #374151;
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.send-btn svg {
    width: 16px;
    height: 16px;
}

/* 错误提示 */
.error-hint {
    font-size: 12px;
    color: #ef4444;
    padding: 0 4px;
    min-height: 16px;
}

/* ==================== 底部状态抽屉 ==================== */
.drawer {
    max-height: 40%;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: max-height 0.3s ease;
}

.drawer-handle {
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    flex-shrink: 0;
}

.drawer-handle::before {
    content: '';
    width: 32px;
    height: 3px;
    background: #d1d5db;
    border-radius: 2px;
}

.drawer-section {
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
}

.drawer-section:last-child {
    border-bottom: none;
}

.drawer-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #9ca3af;
    margin-bottom: 8px;
}

/* 供应商网格 */
.providers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
}

.provider-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    cursor: default;
    transition: all 0.2s;
}

.provider-tag.healthy {
    border-color: #d1fce7;
    background: #f0fdf4;
    color: #059669;
}

.provider-tag.unhealthy {
    border-color: #fecaca;
    background: #fef2f2;
    color: #dc2626;
}

.provider-tag.disabled {
    border-color: #e5e7eb;
    background: #f9fafb;
    color: #9ca3af;
}

.provider-tag::before {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
}

.provider-tag.skeleton {
    background: #e5e7eb;
    border: none;
    color: transparent;
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* 优先级列表 */
.priority-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.priority-item {
    display: flex;
    gap: 10px;
    padding: 8px;
    background: white;
    border-radius: 8px;
    border-left: 2px solid #1f2937;
    font-size: 12px;
}

.priority-rank {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1f2937;
    color: white;
    border-radius: 4px;
    font-weight: 600;
    font-size: 10px;
    flex-shrink: 0;
}

.priority-details {
    flex: 1;
}

.priority-name {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 2px;
}

.priority-desc {
    font-size: 11px;
    color: #9ca3af;
}

.priority-cost {
    font-weight: 600;
    padding: 2px 6px;
    background: #f3f4f6;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
}

/* ==================== 响应式设计 ==================== */
@media (max-width: 480px) {
    .header {
        padding: 10px 12px;
    }

    .quick-tags {
        padding: 6px 12px;
        gap: 6px;
    }

    .tag {
        padding: 5px 10px;
        font-size: 11px;
    }

    .messages {
        padding: 12px;
    }

    .message {
        max-width: 95%;
    }

    .input-section {
        padding: 10px 10px 12px;
        gap: 6px;
    }

    .providers-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    }

    .priority-item {
        font-size: 11px;
        padding: 6px;
    }
}

/* ==================== 深色模式支持 ==================== */
@media (prefers-color-scheme: dark) {
    body {
        background: #111827;
        color: #f3f4f6;
    }

    .header {
        background: #1f2937;
        border-color: #374151;
    }

    .logo-dot {
        background: #f3f4f6;
    }

    .logo-text {
        color: #f3f4f6;
    }

    .quick-tags {
        background: #1f2937;
        border-color: #374151;
    }

    .tag {
        background: #111827;
        border-color: #374151;
        color: #d1d5db;
    }

    .main {
        background: #111827;
    }

    .placeholder-text {
        color: #f3f4f6;
    }

    .placeholder-hint {
        color: #9ca3af;
    }

    .message.assistant .message-content {
        background: #374151;
        color: #f3f4f6;
    }

    .input-section {
        background: #1f2937;
        border-color: #374151;
    }

    .tier-btn {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

    .tier-btn:hover {
        background: #4b5563;
    }

    .tier-btn.active {
        background: #f3f4f6;
        color: #111827;
        border-color: #f3f4f6;
    }

    .search-group {
        background: #374151;
        border-color: #4b5563;
        color: #f3f4f6;
    }

    .search-group:focus-within {
        background: #1f2937;
        border-color: #6b7280;
    }

    .search-input {
        color: #f3f4f6;
    }

    .send-btn {
        background: #f3f4f6;
        color: #111827;
    }

    .send-btn:hover {
        background: #e5e7eb;
    }

    .drawer {
        background: #1f2937;
        border-color: #374151;
    }

    .drawer-section {
        border-color: #374151;
    }

    .provider-tag {
        background: #374151;
        border-color: #4b5563;
        color: #d1d5db;
    }

    .provider-tag.healthy {
        background: rgba(16, 185, 129, 0.1);
        border-color: rgba(16, 185, 129, 0.3);
        color: #6ee7b7;
    }

    .provider-tag.unhealthy {
        background: rgba(239, 68, 68, 0.1);
        border-color: rgba(239, 68, 68, 0.3);
        color: #fca5a5;
    }

    .priority-item {
        background: #374151;
        border-color: #f3f4f6;
    }

    .priority-rank {
        background: #f3f4f6;
        color: #111827;
    }

    .priority-name {
        color: #f3f4f6;
    }

    .priority-desc {
        color: #9ca3af;
    }

    .priority-cost {
        background: #4b5563;
    }
}

/* ==================== 打印样式 ==================== */
@media print {
    .input-section,
    .drawer,
    .send-btn {
        display: none;
    }
}
