/* ============================
   Smart Customer Service - Styles
   ============================ */

:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --text: #1e293b;
    --text-light: #64748b;
    --text-sidebar: #cbd5e1;
    --border: #e2e8f0;
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-lg: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ============================
   Layout
   ============================ */

.app-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100vh;
}

/* ============================
   Sidebar
   ============================ */

.sidebar {
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    overflow: hidden;
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
}

.subtitle {
    font-size: 12px;
    color: var(--text-sidebar);
    opacity: 0.7;
    margin-top: 2px;
}

.sidebar-section h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.6;
    margin-bottom: 10px;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.session-item {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-item:hover {
    background: var(--bg-sidebar-hover);
}

.session-item.active {
    background: var(--primary);
    color: #fff;
}

.empty-state {
    font-size: 13px;
    opacity: 0.5;
    text-align: center;
    padding: 20px;
}

.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 12px;
    font-size: 12px;
}

.sidebar-link, .nav-link {
    color: var(--text-sidebar);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
}

.sidebar-link:hover, .nav-link:hover {
    opacity: 1;
    color: #fff;
    background: var(--bg-sidebar-hover);
}

/* ============================
   Chat Area
   ============================ */

.chat-area {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    font-size: 22px;
    color: var(--text);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
    margin-bottom: 24px;
}

.suggestions {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.suggestion-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    transition: all 0.2s;
}

.suggestion-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef2ff;
}

/* Messages */
.message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--primary);
    color: #fff;
}

.message.assistant .message-avatar {
    background: #f1f5f9;
    color: var(--text);
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

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

.message.assistant .message-bubble {
    background: #f1f5f9;
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.message-source {
    font-size: 11px;
    margin-top: 4px;
    opacity: 0.6;
}

.message.user .message-source {
    text-align: right;
    color: rgba(255,255,255,0.7);
}

.message.assistant .message-source {
    color: var(--text-light);
}

.message-timestamp {
    font-size: 11px;
    margin-top: 2px;
    opacity: 0.5;
}

.message.user .message-timestamp {
    text-align: right;
}

/* Thinking indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #f1f5f9;
    border-radius: 12px;
    align-self: flex-start;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary-light);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); }
    40% { transform: scale(1); }
}

/* ============================
   Input Area
   ============================ */

/* ============================
   Confirm card */
.confirm-card {
    background: var(--bg-card); border: 2px solid var(--primary); border-radius: var(--radius-lg);
    padding: 16px 20px; margin: 12px 0; animation: fadeIn 0.3s ease;
    max-width: 100%;
}
.confirm-card h4 { font-size: 14px; margin-bottom: 12px; color: var(--primary); }
.confirm-card .field { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.confirm-card .field label { min-width: 70px; font-size: 13px; color: var(--text-light); padding-top: 6px; }
.confirm-card .field input {
    flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 13px; font-family: inherit; outline: none; transition: border-color 0.2s;
}
.confirm-card .field input:focus { border-color: var(--primary); }
.confirm-card .actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }

.chat-input-area {
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

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

.input-wrapper textarea {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    max-height: 120px;
    line-height: 1.5;
}

.input-wrapper textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.btn-send {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 2px;
}

.char-count {
    font-size: 12px;
    color: var(--text-light);
}

/* ============================
   Action Buttons (Upload + Generate)
   ============================ */

.action-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 18px;
    transition: all 0.2s;
    user-select: none;
}

.action-btn:hover {
    border-color: var(--primary);
    background: #eef2ff;
    transform: scale(1.08);
}

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

.upload-btn {
    color: var(--primary);
    border-style: dashed;
}

.gen-btn {
    color: var(--success);
    border-color: var(--border);
}

/* Toggle Switch */
.mode-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-light);
}

.toggle-slider {
    width: 36px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 10px;
    position: relative;
    transition: background 0.3s;
}

.toggle-slider::after {
    content: '';
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.mode-label input:checked + .toggle-slider {
    background: var(--primary);
}

.mode-label input:checked + .toggle-slider::after {
    transform: translateX(16px);
}

/* ============================
   Knowledge Base Panel
   ============================ */

.kb-panel {
    background: var(--bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

.panel-header h2 {
    font-size: 16px;
    margin-bottom: 12px;
}

.panel-tabs {
    display: flex;
    gap: 4px;
    background: #f1f5f9;
    border-radius: 6px;
    padding: 2px;
}

.tab-btn {
    flex: 1;
    padding: 6px 12px;
    border: none;
    background: transparent;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-light);
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--bg-card);
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow);
}

.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-content.active {
    display: block;
}

.tab-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* QA List */
.qa-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.qa-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
}

.qa-item .qa-question {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.qa-item .qa-answer {
    font-size: 12px;
    color: var(--text-light);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.qa-item .qa-meta {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    font-size: 11px;
}

.qa-item .qa-category {
    background: #eef2ff;
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Document list */
.doc-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
}

.doc-item .doc-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.doc-item .doc-meta {
    font-size: 11px;
    color: var(--text-light);
    display: flex;
    gap: 12px;
}

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    margin-bottom: 12px;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: #eef2ff;
}

.upload-area p {
    font-size: 14px;
    color: var(--text-light);
}

.upload-area small {
    font-size: 11px;
    color: var(--text-light);
    opacity: 0.7;
}

/* Loading */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 13px;
}

/* ============================
   Modal
   ============================ */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal[hidden] {
    display: none !important;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 500px;
    max-width: 90vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 4px;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* ============================
   Buttons
   ============================ */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    color: var(--error);
    background: none;
    padding: 2px 8px;
    font-size: 12px;
}

.btn-danger:hover {
    background: #fef2f2;
}

/* ============================
   Order Form
   ============================ */
.order-form {
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin: 0 20px 12px;
    animation: fadeIn 0.3s ease;
    flex-shrink: 0;
}
.order-form .form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.order-form .form-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--primary);
}
.order-form .upload-hint {
    font-size: 12px;
    color: var(--primary);
    background: #ede9fe;
    padding: 4px 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}
.order-form .upload-hint:hover {
    background: #ddd6fe;
}
.order-form .field {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: flex-start;
}
.order-form .field label {
    min-width: 76px;
    font-size: 13px;
    color: var(--text-light);
    padding-top: 7px;
    flex-shrink: 0;
}
.order-form .field label.required::after {
    content: ' *';
    color: var(--error);
}
.order-form .field input {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: #f8fafc;
}
.order-form .field input:focus {
    border-color: var(--primary);
    background: #fff;
}
.order-form .pickup-options {
    display: flex;
    gap: 20px;
    padding: 5px 0;
}
.order-form .pickup-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    min-width: auto !important;
    padding-top: 0 !important;
}
.order-form .pickup-label input[type="radio"] {
    width: auto;
    margin: 0;
}
.order-form .datetime-group {
    display: flex;
    gap: 8px;
    flex: 1;
}
.order-form .datetime-group input {
    flex: 1;
}
.order-form .form-actions {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}
.order-form .form-actions .btn-block {
    flex: 1;
    padding: 10px;
    font-size: 15px;
}
.order-form .form-actions .btn-secondary {
    padding: 10px 18px;
    font-size: 14px;
    flex-shrink: 0;
}

/* ============================
   Scrollbar
   ============================ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================
   Responsive
   ============================ */

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 200px 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }
    .sidebar {
        display: none;
    }
    .action-btn {
        width: 44px;
        height: 44px;
        border-radius: 12px;
    }
    .chat-input-area {
        padding: 10px 12px 14px;
    }
    .chat-messages {
        padding: 12px 16px;
    }
}

/* 移动端底部导航栏（替代侧边栏） */
.mobile-bottom-nav {
    display: none;
}
@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        align-items: center;
        justify-content: space-around;
        padding: 8px 12px;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
    }
    .mobile-bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        text-decoration: none;
        color: var(--text-light);
        font-size: 11px;
        padding: 6px 16px;
        border-radius: 8px;
        transition: all 0.2s;
    }
    .mobile-bottom-nav a:hover,
    .mobile-bottom-nav a:active {
        color: var(--primary);
        background: #eef2ff;
    }
    .mobile-bottom-nav a .nav-icon {
        font-size: 20px;
    }
}
