/* ============================================================
   Sunkoon 品牌主题样式
   品牌橙: #F35509  / 米白: #FDFFF4  — 商务・简洁・专业
   ============================================================ */
:root {
  --brand: #F35509;
  --brand-dark: #C73E00;
  --brand-soft: #FFF0E5;
  --bg: #FDFFF4;
  --bg-card: #FFFFFF;
  --bg-subtle: #F6F8EE;
  --text: #232323;
  --text-muted: #8A8F7E;
  --border: #E8EAD9;
  --shadow: 0 8px 30px rgba(60, 50, 20, 0.08);
  --radius: 14px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
}

button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

/* ---------- 视图 ---------- */
.view { display: none; height: 100%; }
.view.active { display: block; }

/* ---------- 品牌 ---------- */
.brand-logo-img {
  height: 52px;
  width: auto;
  max-width: 240px;
  object-fit: contain;
}
.brand-logo-img-sm {
  height: 34px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
}

/* ============================================================
   登录页
   ============================================================ */
.login-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 380px;
  max-width: 96vw;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px 28px;
}
.brand { text-align: center; margin-bottom: 28px; }
.brand-tagline {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 2px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-subtle);
  font-size: 15px;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(243, 85, 9, 0.12);
  background: #fff;
}
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 14px;
  transition: all .2s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-block { width: 100%; display: block; }
.login-msg {
  margin-top: 14px;
  text-align: center;
  color: #D33;
  font-size: 13px;
  min-height: 18px;
}
.login-footer {
  margin-top: 26px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ============================================================
   聊天页
   ============================================================ */
.app-shell {
  display: flex;
  height: 100%;
}
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--border); }
.btn-new-chat {
  margin: 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  padding: 10px;
}
.btn-new-chat:hover { background: var(--brand-dark); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 10px; }
.conv-item {
  position: relative;
  padding: 10px 30px 10px 12px;
  border-radius: 10px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background .15s;
}
.conv-item:hover { background: var(--bg-subtle); }
.conv-item.active { background: var(--brand-soft); }
.conv-title {
  display: block;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-meta { font-size: 11px; color: var(--text-muted); }
.conv-del {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  opacity: 0;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: #D33; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  margin-bottom: 6px;
  text-align: left;
}
.btn-ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn-logout:hover { border-color: #D33; color: #D33; }
.btn-block { width: 100%; }

/* 主区 */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.icon-btn {
  border: none;
  background: none;
  font-size: 18px;
  color: var(--text-muted);
  display: none;
}
.chat-title {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-user { display: flex; align-items: center; gap: 8px; }
.user-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}
.user-name { font-size: 14px; color: var(--text-muted); }

/* 聊天区 */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 8%;
  scroll-behavior: smooth;
}
.welcome { text-align: center; margin-top: 12vh; }
.welcome-logo {
  width: 220px;
  height: auto;
  margin: 0 auto 18px;
  opacity: 1;
}
.welcome h2 { font-size: 24px; margin-bottom: 8px; }
.welcome p { color: var(--text-muted); margin-bottom: 28px; }
.suggests {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  max-width: 640px;
  margin: 0 auto;
}
.suggest-chip {
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 14px;
  transition: all .2s;
}
.suggest-chip:hover {
  border-color: var(--brand);
  color: var(--brand);
  box-shadow: var(--shadow);
}

/* 消息气泡 */
.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
  max-width: 860px;
}
.msg-user { flex-direction: row-reverse; margin-left: auto; }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}
.avatar-ai { background: var(--brand-soft); color: var(--brand); }
.avatar-user { background: var(--text); color: #fff; }
.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.7;
  font-size: 14.5px;
  word-break: break-word;
}
.msg-user .bubble {
  background: var(--brand);
  color: #fff;
  border-top-right-radius: 4px;
}
.msg-ai .bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  min-width: 60px;
}
.bubble strong { font-weight: 600; }
.bubble code {
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
}
.typing { color: var(--text-muted); }
.err { color: #D33; }
/* 回答中断/失败后的重试提示 */
.retry-note {
  margin-top: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.retry-btn {
  border: 1px solid var(--brand);
  background: transparent;
  color: var(--brand);
  font-size: 13px;
  padding: 2px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}
.retry-btn:hover { background: var(--brand); color: #fff; }

/* 输入栏 */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 8%;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-input-bar textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  resize: none;
  max-height: 160px;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg-subtle);
  transition: border-color .2s, box-shadow .2s;
}
.chat-input-bar textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(243, 85, 9, 0.12);
  background: #fff;
}
.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--brand-dark); }

/* 提示 toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translate(-50%, -80px);
  background: #D33;
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 200;   /* toast 层 */
  transition: transform .35s;
  font-size: 14px;
}
.toast.show { transform: translate(-50%, 0); }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;   /* 弹窗层 */
}
.modal {
  width: 420px;
  max-width: 92vw;
  max-height: 86vh;
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-close { border: none; background: none; font-size: 16px; color: var(--text-muted); }
.modal-body { padding: 20px; overflow-y: auto; }
.usage-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.usage-card {
  background: var(--bg-subtle);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
}
.u-num { font-size: 28px; font-weight: 700; color: var(--brand); }
.u-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   管理后台
   ============================================================ */
.admin-body { height: 100%; }
.admin-shell { display: flex; height: 100%; }
.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #1d1d1a;
  color: #eee;
  display: flex;
  flex-direction: column;
  padding-top: 18px;
}
.admin-sidebar .brand { padding: 0 18px 16px; }
.admin-sidebar img { filter: none; }
.admin-sidebar .brand-logo-img-sm {
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
}
.admin-nav { flex: 1; padding: 8px; }
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: none;
  background: none;
  color: #c9c9c2;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 4px;
  transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; }
.admin-sidebar-foot { padding: 12px; }
.admin-sidebar-foot .btn-ghost { border-color: #3a3a35; color: #c9c9c2; }
.admin-sidebar-foot .btn-ghost:hover { border-color: var(--brand); color: #fff; }
.admin-main { flex: 1; overflow-y: auto; padding: 24px 28px; }
.admin-tab { max-width: 1100px; }
.tab-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.tab-head h2 { font-size: 20px; }
.tab-actions { display: flex; gap: 10px; align-items: center; }

/* 表格 */
.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.table th, .table td {
  padding: 11px 14px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.table th { background: var(--bg-subtle); font-weight: 600; color: var(--text-muted); }
.table tr:last-child td { border-bottom: none; }
.table .muted { color: var(--text-muted); font-size: 12px; }
.ops { white-space: nowrap; }
.btn-mini {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  margin-right: 4px;
}
.btn-mini:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger:hover { border-color: #D33; color: #D33; }
.btn-warn { border-color: var(--brand); color: var(--brand); }
.btn-ok { border-color: #2a9d3f; color: #2a9d3f; }
.empty { text-align: center; color: var(--text-muted); padding: 30px !important; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
}
.badge-ok { background: #e5f7e9; color: #2a9d3f; }
.badge-err { background: #fdeaea; color: #D33; }
.badge-admin { background: var(--brand-soft); color: var(--brand-dark); }
.badge-user { background: var(--brand-soft); color: var(--brand-dark); }
.badge-ai { background: var(--bg-subtle); color: var(--text-muted); }

/* 统计卡片 */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-val { font-size: 26px; font-weight: 700; color: var(--brand); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.chart-box {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.chart-box h3 { font-size: 15px; margin-bottom: 14px; }
.daily-chart {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  min-height: 160px;
  padding: 10px 4px 0;
}
.bar-col { display: flex; flex-direction: column; align-items: center; flex: 1; }
.bar {
  width: 32px;
  background: linear-gradient(180deg, var(--brand), var(--brand-soft));
  border-radius: 6px 6px 0 0;
  min-height: 2px;
}
.bar-val { font-size: 12px; font-weight: 600; margin-top: 4px; color: var(--text-muted); }
.bar-date { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* 对话记录 */
.msg-list { display: flex; flex-direction: column; gap: 10px; }
.msg-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.msg-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.msg-item-body {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow-y: auto;
}
.muted { color: var(--text-muted); font-size: 12px; }

/* select */
select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  font-size: 13px;
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 500;
    transform: translateX(-100%);
    transition: transform .25s;
    box-shadow: 0 0 40px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: block; }
  /* 手机端遮罩：侧栏打开时覆盖主区，点击关闭 */
  .sidebar-mask {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 499;  /* 低于侧栏 500，盖住主区 */
  }
  .chat-body, .chat-input-bar { padding-left: 4%; padding-right: 4%; }
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; flex-direction: row; align-items: center; height: 56px; padding-top: 0; }
  .admin-sidebar .brand { padding: 0 12px; }
  .admin-nav { display: flex; padding: 8px; }
  .nav-item { padding: 8px 12px; margin-bottom: 0; }
  .admin-sidebar-foot { display: none; }
  .admin-main { padding: 16px; }
}

/* 无障碍：用户偏好减少动画时，关闭过渡与位移 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .toast { transform: translate(-50%, 0); }
  .sidebar { transform: none; }
}
