/* =============================================================
   Local LLM Web —— 全局样式（DeepSeek 风格，原创设计）
   ============================================================= */
:root {
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --sidebar-bg: #f7f8fa;
  --border: #e5e6eb;
  --text: #1f2329;
  --text-secondary: #4e5969;
  --text-muted: #86909c;
  --accent: #4d6bfe;
  --accent-soft: #eef1ff;
  --accent-hover: #3a56e0;
  --danger: #f53f3f;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(31, 35, 41, 0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.65;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =============================================================
   认证页（登录 / 注册）
   ============================================================= */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(160deg, #f7f8fa 0%, #eef1ff 100%);
}
.auth-card {
  width: 360px; max-width: 92vw; background: var(--bg);
  border-radius: 16px; box-shadow: var(--shadow); padding: 36px 32px;
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.brand-logo {
  display: inline-block; width: 1.5em; height: 1.5em;
  vertical-align: -0.3em; margin-bottom: 4px;
}
.auth-brand .brand-logo {
  display: block; width: 56px; height: 56px;
  margin: 0 auto 10px; filter: drop-shadow(0 4px 10px rgba(56, 189, 248, .35));
}
.auth-brand h1 { font-size: 22px; margin: 6px 0 2px; }
.brand-sub { color: var(--text-muted); font-size: 13px; margin: 0; }
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.auth-form input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; transition: border .15s;
}
.auth-form input:focus { border-color: var(--accent); }
.form-error {
  background: #fff1f0; color: var(--danger); border: 1px solid #ffccc7;
  border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 8px;
}
.form-error--success {
  background: #f6ffed; color: var(--success, #389e0d); border-color: #b7eb8f;
}
.btn-primary {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 10px 16px; font-size: 15px; cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.auth-form .btn-primary { margin-top: 18px; }
.auth-foot { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 20px; }

/* 注册/登录页 —— 方式切换标签页 */
.auth-tabs {
  display: flex; gap: 4px; background: #f2f3f5;
  border-radius: 10px; padding: 4px; margin-bottom: 18px;
}
.auth-tab {
  flex: 1; padding: 8px 0; border: none; background: transparent;
  border-radius: 8px; font-size: 14px; color: var(--text-secondary);
  cursor: pointer; transition: all .15s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active { background: #fff; color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.auth-panel { display: none; }
.auth-panel.active { display: flex; }
.req-star { color: var(--danger); margin-left: 2px; }
.sms-code-row { display: flex; gap: 8px; align-items: center; }
.sms-code-row input { flex: 1; }
.btn-secondary {
  background: #fff; color: var(--accent); border: 1px solid var(--accent);
  border-radius: 8px; padding: 9px 12px; font-size: 13px; cursor: pointer;
  white-space: nowrap; transition: all .15s;
}
.btn-secondary:hover { background: var(--accent); color: #fff; }
.btn-secondary:disabled { opacity: .6; cursor: not-allowed; }

/* =============================================================
   聊天页布局
   ============================================================= */
.chat-page { overflow: hidden; }
.app { display: flex; height: 100vh; }

.sidebar {
  width: 260px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 30;
}
.sidebar-head { padding: 14px 14px 10px; }
.brand { font-size: 16px; font-weight: 600; padding: 6px 4px 12px; color: var(--text); }
.brand .brand-logo { width: 24px; height: 24px; vertical-align: -5px; margin-right: 8px; }
.btn-new-chat {
  width: 100%; padding: 9px 0; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; cursor: pointer; font-size: 14px;
  color: var(--text); transition: all .15s;
}
.btn-new-chat:hover { border-color: var(--accent); color: var(--accent); }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px; margin-bottom: 2px; border-radius: 8px;
  cursor: pointer; color: var(--text-secondary); font-size: 14px;
}
.chat-item:hover { background: #eef0f3; }
.chat-item.active { background: var(--accent-soft); color: var(--accent); }
.chat-item .title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item .ops { display: none; gap: 4px; flex-shrink: 0; margin-left: 6px; }
.chat-item:hover .ops { display: flex; }
.chat-item .ops button {
  border: none; background: transparent; cursor: pointer; color: var(--text-muted);
  font-size: 13px; padding: 2px 4px; border-radius: 4px;
}
.chat-item .ops button:hover { color: var(--accent); background: #fff; }
.chat-item .ops .del:hover { color: var(--danger); }

.sidebar-foot {
  padding: 10px 14px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.model-badge {
  font-size: 12px; color: var(--text-muted); background: #fff;
  border: 1px solid var(--border); border-radius: 20px; padding: 4px 10px;
  align-self: flex-start;
}
.user-box { display: flex; align-items: center; justify-content: space-between; }
.user-name { font-size: 14px; font-weight: 500; color: var(--text-secondary); }
.btn-ghost {
  border: 1px solid var(--border); background: #fff; color: var(--text-secondary);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }

.sidebar-mask { display: none; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 52px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 16px; flex-shrink: 0;
}
.icon-btn {
  border: none; background: transparent; font-size: 18px; cursor: pointer;
  color: var(--text-secondary); display: none;
}
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-model { margin-left: auto; font-size: 12px; color: var(--text-muted); }

/* ---- 消息区 ---- */
.messages { flex: 1; overflow-y: auto; padding: 24px 0 8px; }
.msg-row { max-width: 780px; margin: 0 auto; padding: 12px 20px; }
.msg-user { text-align: right; }
.msg-body { display: inline-block; max-width: 100%; text-align: left; }
.msg-user .bubble {
  background: var(--accent-soft); border-radius: 12px 12px 4px 12px;
  padding: 10px 14px; white-space: pre-wrap; word-break: break-word;
}
.msg-assistant { text-align: left; }
.msg-assistant .bubble { padding: 4px 2px; width: 100%; }

/* 思考内容 */
.think-block {
  margin: 6px 0 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-soft); overflow: hidden;
}
.think-head {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px;
  font-size: 12px; color: var(--text-muted); cursor: pointer; user-select: none;
}
.think-head .arrow { font-size: 10px; transition: transform .15s; }
.think-block.collapsed .think-head .arrow { transform: rotate(-90deg); }
.think-body {
  padding: 2px 12px 10px; color: #6b7280; font-size: 13px; line-height: 1.7;
  border-top: 1px dashed var(--border); white-space: pre-wrap; word-break: break-word;
}
.think-block.collapsed .think-body { display: none; }

/* Markdown 内容 */
.md-body { word-break: break-word; line-height: 1.7; }
.md-body p { margin: 8px 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: 14px 0 8px; line-height: 1.35; }
.md-body ul, .md-body ol { margin: 8px 0; padding-left: 24px; }
.md-body pre {
  background: #1e1e1e; color: #d4d4d4; border-radius: 8px;
  padding: 12px; overflow-x: auto; position: relative; margin: 10px 0;
}
.md-body code { font-family: Consolas, "Courier New", monospace; font-size: 13px; }
.md-body :not(pre) > code {
  background: #f2f3f5; padding: 2px 6px; border-radius: 4px; font-size: 13px;
}
.md-body pre code { background: transparent; padding: 0; }
.md-body blockquote {
  border-left: 3px solid var(--accent); margin: 8px 0; padding: 2px 12px;
  color: var(--text-secondary); background: var(--bg-soft);
}
.md-body a { color: var(--accent); }
.md-body table { border-collapse: collapse; margin: 10px 0; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 6px 12px; }
.md-body img { max-width: 100%; border-radius: 6px; }
.copy-btn {
  position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.12);
  color: #ccc; border: none; border-radius: 4px; font-size: 11px; padding: 3px 8px;
  cursor: pointer; opacity: 0; transition: opacity .15s;
}
.md-body pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,.25); color: #fff; }

/* 状态提示 */
.assistant-status { color: var(--text-muted); font-size: 13px; padding: 4px 2px; }
.assistant-error {
  color: var(--danger); font-size: 13px; padding: 4px 2px;
  background: #fff1f0; border-radius: 8px; padding: 8px 12px; margin: 4px 0;
}
.empty-tip { text-align: center; padding-top: 18vh; color: var(--text-muted); }
.empty-logo {
  display: block; width: 68px; height: 68px;
  margin: 0 auto 12px; filter: drop-shadow(0 6px 14px rgba(56, 189, 248, .3));
}
.empty-tip p { margin: 6px 0; }
.empty-sub { font-size: 13px; }

/* ---- 输入区 ---- */
.input-area { padding: 12px 20px 18px; flex-shrink: 0; }
.input-box {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px;
  background: #fff; box-shadow: var(--shadow);
}
.input-box:focus-within { border-color: var(--accent); }
#prompt {
  flex: 1; border: none; outline: none; resize: none; font-size: 15px;
  font-family: inherit; line-height: 1.5; max-height: 180px; padding: 6px 2px;
  background: transparent; color: var(--text);
}
.input-box .btn-primary { flex-shrink: 0; }
.btn-stop {
  flex-shrink: 0; background: #fff; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 8px; padding: 10px 16px;
  font-size: 14px; cursor: pointer;
}
.btn-stop:hover { background: var(--danger); color: #fff; }
.input-hint { text-align: center; color: var(--text-muted); font-size: 12px; margin: 8px 0 0; }
.queue-tip {
  max-width: 780px; margin: 0 auto 8px; background: #fffbe6;
  border: 1px solid #ffe58f; color: #874d00; border-radius: 8px;
  padding: 8px 14px; font-size: 13px;
}

/* ---- 响应式 ---- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35);
    z-index: 20; opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .sidebar-mask.show { opacity: 1; pointer-events: auto; }
  .icon-btn { display: block; }
  .msg-row { padding: 10px 12px; }
  .input-area { padding: 8px 12px 14px; }
  .topbar-model { display: none; }
}

/* =============================================================
   管理后台
   ============================================================= */
.admin-entry {
  display: block; font-size: 13px; color: var(--accent);
  padding: 6px 10px; border: 1px dashed var(--accent);
  border-radius: 8px; text-align: center; margin-bottom: 4px;
}
.admin-entry:hover { background: var(--accent-soft); text-decoration: none; }

.admin-app { min-height: 100vh; display: flex; flex-direction: column; }
.admin-topbar {
  height: 52px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--bg); flex-shrink: 0;
}
.admin-brand { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.admin-brand .brand-logo { width: 24px; height: 24px; vertical-align: -5px; margin-right: 8px; }
.admin-badge {
  font-size: 11px; color: var(--accent); background: var(--accent-soft);
  border-radius: 12px; padding: 2px 8px; font-weight: 500;
}
.admin-top-nav { display: flex; align-items: center; gap: 10px; }
.admin-user { font-size: 13px; color: var(--text-secondary); }
.btn-ghost.danger { color: var(--danger); border-color: #ffccc7; }
.btn-ghost.danger:hover { background: var(--danger); color: #fff; }

.admin-body { flex: 1; display: flex; min-height: 0; }
.admin-side {
  width: 170px; flex-shrink: 0; background: var(--bg-soft);
  border-right: 1px solid var(--border); padding: 12px 10px;
  display: flex; flex-direction: column; gap: 4px;
}
.admin-nav-item {
  border: none; background: transparent; text-align: left; cursor: pointer;
  padding: 10px 12px; border-radius: 8px; font-size: 14px;
  color: var(--text-secondary); transition: all .15s;
}
.admin-nav-item:hover { background: #eef0f3; color: var(--text); }
.admin-nav-item.active { background: var(--accent); color: #fff; font-weight: 600; }

.admin-main { flex: 1; overflow-y: auto; padding: 20px 24px; min-width: 0; }
.admin-view { display: none; }
.admin-view.active { display: block; }
.view-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.view-head h2 { margin: 0; font-size: 19px; }
.view-meta { font-size: 12px; color: var(--text-muted); }

/* 统计卡片 */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.stat-value { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* 信息卡片 */
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.info-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.info-card h3 {
  margin: 0 0 10px; font-size: 14px; color: var(--text-secondary);
  border-bottom: 1px solid var(--border); padding-bottom: 8px;
}
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; font-size: 13px; }
.kv-key { color: var(--text-muted); flex-shrink: 0; }
.kv-val { text-align: right; word-break: break-all; }
.bar { height: 8px; border-radius: 4px; background: #eef0f3; overflow: hidden; width: 100%; margin: 4px 0; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; }

/* 表格 */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th { background: var(--bg-soft); font-weight: 600; color: var(--text-secondary); }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #fafbfc; }
.td-user { font-weight: 500; }
.td-title { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-ops { display: flex; gap: 6px; }

.btn-mini {
  border: 1px solid var(--border); background: #fff; color: var(--text-secondary);
  border-radius: 6px; padding: 3px 9px; font-size: 12px; cursor: pointer;
}
.btn-mini:hover { border-color: var(--accent); color: var(--accent); }
.btn-mini.ok { color: var(--accent); border-color: #c3cdfe; }
.btn-mini.ok:hover { background: var(--accent-soft); }
.btn-mini.warn { color: #d48806; border-color: #ffe58f; }
.btn-mini.warn:hover { background: #fffbe6; }
.btn-mini.danger { color: var(--danger); border-color: #ffccc7; }
.btn-mini.danger:hover { background: var(--danger); color: #fff; }

.pill {
  display: inline-block; font-size: 12px; border-radius: 10px; padding: 2px 10px;
  background: #f2f3f5; color: var(--text-secondary);
}
.pill-ok { background: #e8f7ec; color: #2e8b57; }
.pill-off { background: #f2f3f5; color: var(--text-muted); }
.pill-admin { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill-queued { background: #fff7e6; color: #d48806; }
.pill-active { background: var(--accent-soft); color: var(--accent); }
.pill-done { background: #e8f7ec; color: #2e8b57; }
.pill-cancelled { background: #f2f3f5; color: var(--text-muted); }
.pill-error { background: #fff1f0; color: var(--danger); }

.table-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 30px 0; }
.err-tip {
  color: var(--danger); font-weight: 700; cursor: help;
}

/* 消息查看弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-mask.open { display: flex; }
.modal {
  background: var(--bg); border-radius: 14px; width: min(720px, 94vw);
  max-height: 82vh; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.modal-close {
  border: none; background: transparent; font-size: 22px; cursor: pointer;
  color: var(--text-muted); line-height: 1;
}
.modal-close:hover { color: var(--danger); }
.modal-body { overflow-y: auto; padding: 14px 18px; }
.msg-card {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  margin-bottom: 10px; background: #fafbfc;
}
.msg-card-user { border-left: 3px solid var(--accent); }
.msg-card-head { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.msg-reasoning {
  background: var(--bg-soft); border-radius: 8px; margin-bottom: 8px; font-size: 13px;
}
.msg-reasoning summary { padding: 6px 10px; cursor: pointer; color: var(--text-muted); font-size: 12px; }
.msg-reasoning pre { margin: 0; padding: 0 10px 8px; white-space: pre-wrap; word-break: break-word; color: #6b7280; font-size: 12px; }
.msg-content { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 13px; font-family: inherit; }

/* 日志 */
.log-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.log-select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--text);
}
.log-lines { width: 90px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.log-auto { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.log-viewer {
  background: #0f1115; color: #d7dae0; border-radius: 10px; padding: 14px 16px;
  font-family: Consolas, "Courier New", monospace; font-size: 12px; line-height: 1.55;
  overflow: auto; max-height: 70vh; white-space: pre-wrap; word-break: break-all;
}

@media (max-width: 720px) {
  .admin-side { width: 62px; padding: 10px 6px; }
  .admin-nav-item { padding: 10px 4px; font-size: 12px; text-align: center; }
  .admin-main { padding: 14px 12px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
