/* =============================================
   FANUC VC 智能助手 —— 工程风格主题
   深色为默认值；浅色通过 <html data-theme="light"> 覆盖
   全部颜色走 CSS 变量，切换主题不需要重载页面
   ============================================= */

:root {
    --bg:           #0e1116;
    --bg-side:      #131820;
    --bg-elev:      #1a2029;
    --bg-hover:     #212936;
    --bg-input:     #0b0e13;

    --border:       #262d38;
    --border-soft:  #1e242e;

    --text:         #e3e8ef;
    --text-dim:     #98a2b3;
    --text-mute:    #667085;

    --accent:       #3b82f6;
    --accent-hover: #2f6fd8;
    --accent-soft:  rgba(59, 130, 246, 0.13);
    --accent-text:  #ffffff;

    --danger:       #ef4444;
    --danger-soft:  rgba(239, 68, 68, 0.12);
    --ok:           #22c55e;

    --radius:       6px;
    --radius-lg:    8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
            "PingFang SC", "Hiragino Sans GB", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-theme="light"] {
    --bg:           #f6f7f9;
    --bg-side:      #ffffff;
    --bg-elev:      #ffffff;
    --bg-hover:     #eceff3;
    --bg-input:     #ffffff;

    --border:       #d5dae1;
    --border-soft:  #e6e9ee;

    --text:         #1a2029;
    --text-dim:     #5a6472;
    --text-mute:    #8a929e;

    --accent:       #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft:  rgba(37, 99, 235, 0.09);
    --accent-text:  #ffffff;

    --danger:       #dc2626;
    --danger-soft:  rgba(220, 38, 38, 0.09);
    --ok:           #16a34a;
}

/* ---------- 基础 ---------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { font-weight: 600; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: content-box; }

/* ---------- 侧边栏 ---------- */

.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    display: flex;
    flex-direction: column;
    background: var(--bg-side);
    border-right: 1px solid var(--border);
    z-index: 100;
    transition: transform .22s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text);
}

.logo-emoji {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px; height: 24px;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-text);
    font-size: 12px;
    font-weight: 700;
}

.close-sidebar {
    display: none;
    width: 30px; height: 30px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text-dim);
}
.close-sidebar:hover { background: var(--bg-hover); color: var(--text); }

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    transition: background .15s, border-color .15s;
}
.new-chat-btn:hover { background: var(--bg-hover); border-color: var(--text-mute); }

.chat-history { display: flex; flex-direction: column; gap: 2px; }

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 8px 8px 10px;
    border-radius: var(--radius);
    border-left: 2px solid transparent;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.chat-history-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-history-item.active {
    background: var(--accent-soft);
    border-left-color: var(--accent);
    color: var(--text);
}
.chat-history-item i { font-size: 12px; flex-shrink: 0; opacity: .8; }
.chat-history-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.delete-conv {
    flex-shrink: 0;
    width: 22px; height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-mute);
    opacity: 0;
    transition: opacity .12s, background .12s, color .12s;
}
.chat-history-item:hover .delete-conv { opacity: 1; }
.delete-conv:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- 知识库 ---------- */

.knowledge-section {
    margin-top: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.knowledge-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 11px;
    background: var(--bg-elev);
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}
.knowledge-header:hover { color: var(--text); }
.knowledge-toggle-icon {
    font-size: 9px;
    color: var(--text-mute);
    transition: transform .2s;
}
.knowledge-toggle-icon.open { transform: rotate(90deg); }

.knowledge-body {
    padding: 10px;
    border-top: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.upload-btn {
    width: 100%;
    height: 32px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 12px;
    transition: border-color .15s, color .15s;
}
.upload-btn:hover { border-color: var(--accent); color: var(--accent); }

.knowledge-files { display: flex; flex-direction: column; gap: 4px; }

.knowledge-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 7px;
    border-radius: 5px;
    background: var(--bg-elev);
    border: 1px solid var(--border-soft);
}
.file-icon { font-size: 12px; color: var(--accent); flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name {
    font-size: 12px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-meta { font-size: 10.5px; color: var(--text-mute); font-family: var(--font-mono); }
.file-delete {
    flex-shrink: 0;
    width: 20px; height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-mute);
}
.file-delete:hover { background: var(--danger-soft); color: var(--danger); }

.knowledge-status {
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-mute);
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
}

.sidebar-footer-info {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: var(--text-mute);
}

/* ---------- 主区域 ---------- */

.main-content {
    margin-left: 260px;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 52px;
    padding: 0 16px;
    background: var(--bg-side);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.menu-toggle {
    display: none;
    width: 32px; height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text-dim);
}
.menu-toggle:hover { background: var(--bg-hover); color: var(--text); }

.header-title {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 1;
    min-width: 0;
}
.header-title h1 {
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.header-emoji {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    border-radius: 5px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    flex-shrink: 0;
}

.header-actions { display: flex; align-items: center; gap: 6px; }

.action-btn {
    width: 32px; height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text-dim);
    font-size: 14px;
    transition: background .12s, color .12s;
}
.action-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- 聊天区 ---------- */

.chat-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    scroll-behavior: smooth;
}

.messages {
    max-width: 860px;
    margin: 0 auto;
    padding: 20px 24px 8px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.messages:empty { display: none; }

.message {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.message-avatar {
    flex-shrink: 0;
    width: 28px; height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text-dim);
    margin-top: 1px;
}
.message.user .message-avatar {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.message-content { flex: 1; min-width: 0; }

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 13.5px;
    line-height: 1.72;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
}
.message.user .message-bubble {
    background: var(--accent-soft);
    border-color: transparent;
}

.message-time {
    font-size: 11px;
    color: var(--text-mute);
    font-family: var(--font-mono);
    margin-top: 5px;
    padding: 0 2px;
}

.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.message-images img {
    max-width: 180px;
    max-height: 180px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    object-fit: cover;
    display: block;
}

/* ---------- 欢迎屏 ---------- */

/* JS 里用 style.display = 'flex' 控制显示/隐藏，所以这里必须是 flex 布局 */
.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 640px;
    margin: 0 auto;
    padding: 72px 24px 24px;
    text-align: center;
}

.welcome-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px; height: 48px;
    border-radius: var(--radius-lg);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 20px;
    margin-bottom: 18px;
}

.welcome-screen h2 {
    font-size: 19px;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: .01em;
}

.welcome-screen p {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 26px;
    line-height: 1.7;
}

.suggestion-chips {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 480px;
}

.chip {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    color: var(--text-dim);
    font-size: 12.5px;
    text-align: left;
    transition: background .15s, border-color .15s, color .15s;
}
.chip:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text);
}

/* ---------- 加载指示 ---------- */

.loading-indicator {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 24px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12.5px;
    color: var(--text-mute);
}

.typing-indicator { display: flex; gap: 3px; align-items: center; }
.typing-indicator span {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--text-mute);
    animation: typing 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: .18s; }
.typing-indicator span:nth-child(3) { animation-delay: .36s; }

@keyframes typing {
    0%, 60%, 100% { opacity: .3; transform: translateY(0); }
    30%           { opacity: 1;  transform: translateY(-3px); }
}

/* ---------- 输入区 ---------- */

.input-area {
    flex-shrink: 0;
    padding: 12px 24px 16px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.image-preview-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 860px;
    margin: 0 auto 10px;
}

.image-preview-item { position: relative; }
.image-preview-item img {
    width: 58px; height: 58px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: block;
}
.remove-img {
    position: absolute;
    top: -5px; right: -5px;
    width: 18px; height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    line-height: 1;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 860px;
    margin: 0 auto;
    padding: 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color .15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }

.input-wrapper textarea {
    flex: 1;
    min-width: 0;
    max-height: 160px;
    padding: 7px 4px;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text);
}
.input-wrapper textarea::placeholder { color: var(--text-mute); }

.attach-btn, .web-toggle, .send-btn {
    flex-shrink: 0;
    width: 32px; height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-mute);
    transition: background .12s, color .12s;
}
.attach-btn:hover, .web-toggle:hover { background: var(--bg-hover); color: var(--text); }

.web-toggle.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.send-btn {
    background: var(--accent);
    color: var(--accent-text);
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled {
    background: var(--bg-hover);
    color: var(--text-mute);
    cursor: not-allowed;
}

.disclaimer {
    max-width: 860px;
    margin: 8px auto 0;
    text-align: center;
    font-size: 11px;
    color: var(--text-mute);
}

/* ---------- 设置面板 ---------- */

.settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 200;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 80px 20px 20px;
}
.settings-overlay.active { display: flex; }

.settings-panel {
    width: 100%;
    max-width: 440px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    background: var(--bg-side);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.settings-header h3 { font-size: 14px; font-weight: 600; }

.close-settings {
    width: 28px; height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    color: var(--text-dim);
}
.close-settings:hover { background: var(--bg-hover); color: var(--text); }

.settings-body {
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 主题选择 */

.settings-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-mute);
}

.theme-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.theme-option {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elev);
    text-align: left;
    transition: border-color .15s, background .15s;
}
.theme-option:hover { border-color: var(--text-mute); }
.theme-option.active { border-color: var(--accent); background: var(--accent-soft); }

.theme-preview {
    height: 46px;
    border-radius: 4px;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 8px;
}
/* 缩略图用固定色，不跟随主题变量 */
.theme-preview.dark  { background: #0e1116; }
.theme-preview.light { background: #f6f7f9; }
.theme-preview::before,
.theme-preview::after {
    content: '';
    display: block;
}
.theme-preview::before {
    height: 12px;
    border-bottom: 1px solid var(--border);
}
.theme-preview.dark::before  { background: #131820; }
.theme-preview.light::before { background: #ffffff; }
.theme-preview::after {
    width: 60%;
    height: 8px;
    margin: 8px auto 0;
    border-radius: 2px;
}
.theme-preview.dark::after  { background: #3b82f6; }
.theme-preview.light::after { background: #2563eb; }

.theme-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text);
}
.theme-option.active .theme-name { color: var(--accent); }

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: 40px;
    transform: translate(-50%, 12px);
    max-width: 80vw;
    padding: 10px 16px;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12.5px;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { border-color: var(--ok); color: var(--ok); }
.toast.error   { border-color: var(--danger); color: var(--danger); }
.toast.info    { border-color: var(--border); color: var(--text-dim); }

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .close-sidebar { display: flex; }
    .main-content { margin-left: 0; }
    .menu-toggle { display: flex; }

    .messages { padding: 16px 14px 4px; }
    .loading-indicator { padding: 0 14px 14px; }
    .welcome-screen { padding: 44px 18px 18px; }
    .suggestion-chips { grid-template-columns: 1fr; }
    .input-area { padding: 10px 14px 12px; }
}

@media (max-width: 420px) {
    .settings-overlay { padding: 40px 12px 12px; }
    .settings-panel { max-height: calc(100vh - 60px); }
}
