/* 吾微 AI 智能体平台 · 员工工作台 —— 品牌视觉（橄榄绿主色） */
:root {
  --brand: #717D28;
  --brand-dark: #5a6620;
  --brand-light: #eef1dd;
  --teal: #62B4B4;
  --yellow: #FFD400;
  --coral: #D65856;
  --ink: #282C16;
  --ink-2: #5c6146;
  --ink-3: #9a9e85;
  --bg: #f6f7f1;
  --card: #ffffff;
  --line: #e6e8da;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(40, 44, 22, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

#app { display: flex; min-height: 100vh; }

/* ============ 桌面侧边栏 ============ */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 20px 18px 14px; border-bottom: 1px solid var(--line); }
.brand img { width: 150px; height: auto; display: block; }
.brand-sub { margin-top: 8px; font-size: 12px; color: var(--ink-3); letter-spacing: 0.5px; }

#sideNav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-group { padding: 10px 18px 4px; font-size: 12px; color: var(--ink-3); }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  margin: 2px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 14px;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--brand-light); }
.nav-item.active { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; }
.nav-item .ico { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-user {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-2);
}
.sidebar-user .name { font-weight: 600; color: var(--ink); }
.sidebar-user .org { color: var(--ink-3); font-size: 12px; margin-top: 2px; }

/* ============ 移动端顶栏/底栏 ============ */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  z-index: 20;
}
.topbar img { height: 26px; width: auto; }
.topbar-title { font-size: 14px; font-weight: 600; color: var(--brand-dark); }

.tabbar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  font-size: 11px;
  color: var(--ink-3);
  text-decoration: none;
}
.tabbar a.active { color: var(--brand-dark); font-weight: 600; }
.tabbar .ico { width: 20px; height: 20px; }

/* ============ 主视图 ============ */
.view { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1080px; }

.page-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.page-desc { font-size: 13px; color: var(--ink-3); margin-bottom: 20px; }

/* 统计卡 */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--brand-dark); }
.stat-card .lbl { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* 智能体卡片墙 */
.section-title { font-size: 15px; font-weight: 600; margin: 6px 0 12px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.agent-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agent-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(40, 44, 22, 0.1); border-color: var(--brand); }
.agent-card .avatar {
  width: 42px; height: 42px;
  border-radius: 10px;
  background: var(--brand-light);
  color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700;
}
.agent-card .name { font-size: 15px; font-weight: 600; }
.agent-card .desc {
  font-size: 12px; color: var(--ink-3); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 36px;
}
.agent-card .go { font-size: 12px; color: var(--brand-dark); font-weight: 600; }

/* 空状态 / 加载 */
.empty {
  text-align: center; color: var(--ink-3); padding: 60px 20px;
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty .big { font-size: 34px; margin-bottom: 10px; }
.loading { text-align: center; color: var(--ink-3); padding: 40px; font-size: 13px; }

/* ============ 对话页 ============ */
.chat-wrap {
  display: flex; flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: calc(100vh - 120px);
  min-height: 420px;
  overflow: hidden;
}
.chat-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.chat-head .avatar {
  width: 36px; height: 36px; border-radius: 9px;
  background: var(--brand-light); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.chat-head .meta .name { font-weight: 600; font-size: 15px; }
.chat-head .meta .desc { font-size: 12px; color: var(--ink-3); }
.chat-head .back { margin-left: auto; font-size: 13px; color: var(--brand-dark); text-decoration: none; }

.chat-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; background: #fafbf6; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot.error { border-color: var(--coral); color: var(--coral); }
.msg .ops { margin-top: 6px; display: flex; gap: 10px; }
.msg .ops button {
  border: none; background: none; font-size: 12px; color: var(--teal); padding: 0;
}
.msg .meta { margin-top: 6px; font-size: 11px; color: var(--ink-3); }
.typing { display: inline-flex; gap: 4px; align-items: center; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.chat-input { border-top: 1px solid var(--line); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-end; background: #fff; }
.chat-input textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; line-height: 1.5; max-height: 120px; outline: none;
}
.chat-input textarea:focus { border-color: var(--brand); }
.btn {
  border: none; border-radius: 10px; padding: 10px 20px; font-size: 14px; font-weight: 600;
  background: var(--brand); color: #fff; transition: background 0.15s;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { background: var(--ink-3); cursor: not-allowed; }
.btn.ghost { background: var(--brand-light); color: var(--brand-dark); }
.btn.ghost:hover { background: #e2e7cc; }

/* ============ 历史记录 ============ */
.run-item {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.run-item .row1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.run-item .agent-name { font-weight: 600; font-size: 14px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.badge.ok { background: var(--brand-light); color: var(--brand-dark); }
.badge.fail { background: #fbe7e6; color: var(--coral); }
.run-item .time { margin-left: auto; font-size: 12px; color: var(--ink-3); }
.run-item .input-line { margin-top: 8px; font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-item .kv { margin-top: 6px; font-size: 12px; color: var(--ink-3); }
.run-item .detail { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 13px; line-height: 1.6; }
.run-item .detail h5 { font-size: 12px; color: var(--ink-3); margin: 6px 0 4px; }
.run-item .detail .box { background: #fafbf6; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; }
.run-item .toggle { margin-top: 8px; border: none; background: none; color: var(--teal); font-size: 12px; padding: 0; }

.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.filter-bar select {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px;
  background: #fff; color: var(--ink); outline: none;
}

/* ============ 我的 ============ */
.profile-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.profile-card .row { display: flex; padding: 8px 0; font-size: 14px; }
.profile-card .row .k { width: 90px; color: var(--ink-3); flex-shrink: 0; }
.form-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.form-card h3 { font-size: 15px; margin-bottom: 14px; }
.form-item { margin-bottom: 12px; }
.form-item label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.form-item input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; outline: none;
}
.form-item input:focus { border-color: var(--brand); }

/* ============ 登录页 ============ */
.login-wrap {
  min-height: 100vh; width: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #f3f5e4 0%, #e9efe0 45%, #ddebdc 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 16px; padding: 34px 30px;
  box-shadow: 0 10px 40px rgba(40, 44, 22, 0.12);
}
.login-card img { width: 170px; display: block; margin: 0 auto 6px; }
.login-card .slogan { text-align: center; font-size: 13px; color: var(--ink-3); margin-bottom: 26px; }
.login-card .form-item input { padding: 12px 14px; }
.login-card .btn { width: 100%; padding: 12px; margin-top: 6px; }
.login-tip { margin-top: 14px; font-size: 12px; color: var(--ink-3); text-align: center; line-height: 1.6; }

/* Toast */
body.guest .view { padding: 0; max-width: none; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: rgba(40, 44, 22, 0.92); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 24px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s; z-index: 99; max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 响应式：移动端 ============ */
@media (max-width: 899px) {
  #app { flex-direction: column; }
  .sidebar { display: none !important; }
  .topbar { display: flex; }
  .tabbar { display: flex; }
  .view { padding: 66px 14px 84px; max-width: none; }
  .page-title { font-size: 18px; }
  .chat-wrap { height: calc(100dvh - 52px - 60px); border-radius: 0; border: none; box-shadow: none; margin: -14px; }
  .msg { max-width: 88%; }
  .agent-grid { grid-template-columns: 1fr 1fr; }
  .agent-card .desc { -webkit-line-clamp: 3; min-height: 54px; }
}
@media (max-width: 420px) {
  .agent-grid { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(3, 1fr); }
  .stat-card { padding: 12px; }
  .stat-card .num { font-size: 20px; }
}
