/* ============================================================
   API Gateway Hub 管理面板样式
   纯 CSS，无外部依赖；浅色主题 + 深色侧栏
   ============================================================ */

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --panel: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
}

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

body {
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.mono { font-family: Consolas, Monaco, monospace; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: 1px solid transparent; border-radius: 8px;
  font-size: 14px; cursor: pointer; transition: .15s; background: var(--panel); color: var(--text);
}
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: rgba(0,0,0,.05); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%); padding: 20px;
}
.login-card {
  width: 380px; background: var(--panel); border-radius: 16px; padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { font-size: 20px; margin-top: 12px; }
.logo-mark {
  width: 52px; height: 52px; margin: 0 auto; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; letter-spacing: 1px;
}
.logo-mark.small { width: 34px; height: 34px; font-size: 11px; border-radius: 9px; margin: 0; }
.login-form label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-muted); }
.login-form input {
  width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.login-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.sso-area { margin-top: 18px; }

/* ---------------- 展示页（未登录默认首页） ---------------- */
.landing-wrap { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); }

.landing-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 28px; background: var(--sidebar); color: #fff;
}
.landing-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }

.landing-hero {
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  color: #fff; text-align: center; padding: 76px 24px 88px;
}
.landing-hero h1 { font-size: 34px; letter-spacing: .5px; }
.landing-sub { margin-top: 12px; font-size: 16px; color: #cbd5e1; }
.landing-welcome { margin-top: 8px; font-size: 14px; color: #94a3b8; }
.landing-welcome:empty { display: none; }
.btn-lg { margin-top: 30px; padding: 12px 40px; font-size: 16px; }
.landing-tip { margin-top: 16px; font-size: 12px; color: #94a3b8; }

.landing-features {
  flex: 1; width: 100%; max-width: 1080px; margin: 0 auto;
  display: grid; gap: 18px; padding: 40px 28px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.feature-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.feature-card h3 { font-size: 15px; margin-bottom: 6px; }
.feature-card p { font-size: 13px; }
.feature-ico {
  width: 36px; height: 36px; margin-bottom: 12px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(37, 99, 235, .12); color: var(--primary); font-size: 18px;
}

.landing-foot {
  text-align: center; padding: 18px; font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ---------------- 分隔线 ---------------- */
.divider { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 12px; margin-bottom: 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------------- 布局 ---------------- */
.app-wrap { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--sidebar); color: #cbd5e1; display: flex;
  flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 10;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08); color: #fff; font-weight: 600;
}
.brand-name { font-size: 14px; }
.nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin-bottom: 2px;
  border-radius: 8px; color: #cbd5e1; text-decoration: none; font-size: 13px;
}
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #64748b;
  padding: 14px 12px 6px;
}
.nav-ico { width: 18px; text-align: center; }
.sidebar-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-name { font-size: 13px; color: #fff; }
.user-role { font-size: 11px; color: #94a3b8; }

.main { flex: 1; margin-left: 220px; display: flex; flex-direction: column; }
.topbar {
  background: var(--panel); padding: 16px 28px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 18px; }
.content { padding: 24px 28px; }
.loading { padding: 40px; text-align: center; color: var(--text-muted); }

/* ---------------- 卡片 & 统计 ---------------- */
.card {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.card h3 { font-size: 15px; margin-bottom: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px;
}
.stat .label { font-size: 12px; color: var(--text-muted); }
.stat .value { font-size: 26px; font-weight: 700; margin: 4px 0; }
.stat .sub { font-size: 12px; color: var(--text-muted); }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: var(--text-muted); font-weight: 600; font-size: 12px; }
tr:hover td { background: #f8fafc; }

/* ---------------- 表单 ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-item label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.form-item input, .form-item select, .form-item textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; outline: none; background: #fff;
}
.form-item input:focus, .form-item select:focus, .form-item textarea:focus { border-color: var(--primary); }
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.filter-bar input, .filter-bar select {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none;
}
.filter-bar .btn { margin-left: auto; }

/* ---------------- 徽章 / 进度条 ---------------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; }
.badge-green { background: #dcfce7; color: var(--success); }
.badge-red { background: #fee2e2; color: var(--danger); }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }
.badge-blue { background: #dbeafe; color: var(--primary); }
.badge-orange { background: #fef3c7; color: var(--warning); }

.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.progress.warn > i { background: var(--warning); }
.progress.danger > i { background: var(--danger); }

/* ---------------- 分段切换 / 配额进度单元格 ---------------- */
.seg { display: inline-flex; gap: 6px; }
.seg .btn.btn-sm { padding: 6px 12px; }
.keys-bar .btn { margin-left: 0; }
.keys-bar .keys-bar-end { margin-left: auto; display: flex; gap: 8px; }
.quota-cell { min-width: 210px; }
.quota-line { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.quota-line .progress { flex: 1; margin-top: 0; }
.quota-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ---------------- 分页 ---------------- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: 13px; }
.pager button { padding: 5px 12px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------------- 模态框 / Toast ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: 560px; max-width: 100%; max-height: 86vh; overflow-y: auto;
  background: var(--panel); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-close { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-lg { width: 1040px; }
.modal-xl { width: 1200px; }

/* 厂商目录：卡片网格，避免左右横向滚动 */
.vendor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.vendor-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.vendor-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.vendor-name { font-weight: 600; }
.vendor-desc { color: var(--text-muted); font-size: 12px; margin: 6px 0; }
.vendor-url { font-size: 12px; word-break: break-all; }

.toast-box { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  padding: 12px 18px; border-radius: 10px; color: #fff; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: slide-in .25s ease;
  max-width: 360px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- 图表 ---------------- */
.chart-box { width: 100%; }
.chart-box svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--text-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* ---------------- 详情 / 其它 ---------------- */
.detail-list { display: grid; grid-template-columns: 140px 1fr; row-gap: 8px; font-size: 13px; }
.detail-list dt { color: var(--text-muted); }
.key-reveal {
  background: #0f172a; color: #4ade80; padding: 12px 14px; border-radius: 8px;
  font-family: Consolas, monospace; font-size: 13px; word-break: break-all; margin: 10px 0;
}
.empty { padding: 30px; text-align: center; color: var(--text-muted); }
.tag-list { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { background: #f1f5f9; border-radius: 6px; padding: 1px 8px; font-size: 12px; color: var(--text-muted); }

/* ---------------- AI 对话 ---------------- */
.chat-wrap {
  display: flex; flex-direction: column; gap: 10px;
  height: calc(100vh - 120px); min-height: 420px;
}
.chat-wrap .card { margin-bottom: 0; }

.chat-hint { font-size: 12px; line-height: 1.6; }
.chat-hint code { background: #f1f5f9; border-radius: 4px; padding: 1px 5px; }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 84%; padding: 10px 14px; border-radius: 12px;
  background: #f1f5f9; color: var(--text); font-size: 14px; line-height: 1.65;
  word-break: break-word; overflow-wrap: anywhere;
}
.chat-msg.user .chat-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant .chat-bubble { border-bottom-left-radius: 4px; }

/* 气泡内的 Markdown 渲染样式 */
.chat-bubble > :first-child { margin-top: 0; }
.chat-bubble > :last-child { margin-bottom: 0; }
.chat-bubble p { margin: 0 0 8px; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3, .chat-bubble h4 {
  margin: 10px 0 6px; font-size: 15px; line-height: 1.4;
}
.chat-bubble ul, .chat-bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble code {
  background: rgba(15,23,42,.08); border-radius: 4px; padding: 1px 5px;
  font-family: Consolas, Monaco, monospace; font-size: 13px; word-break: break-word;
}
.chat-bubble pre.md-code {
  margin: 6px 0 8px; padding: 10px 12px; border-radius: 8px;
  background: #0f172a; color: #e2e8f0; overflow-x: auto;
}
.chat-bubble pre.md-code code { background: none; color: inherit; padding: 0; font-size: 12.5px; white-space: pre; }
.chat-bubble blockquote {
  margin: 6px 0; padding: 2px 12px; border-left: 3px solid var(--border); color: var(--text-muted);
}
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.chat-bubble a { color: var(--primary); text-decoration: underline; }
.chat-bubble table.md-table { border-collapse: collapse; margin: 6px 0 8px; font-size: 13px; display: block; overflow-x: auto; }
.chat-bubble table.md-table th, .chat-bubble table.md-table td {
  border: 1px solid var(--border); padding: 5px 9px; white-space: nowrap;
}
.chat-bubble table.md-table th { background: rgba(15,23,42,.05); font-weight: 600; }
/* 用户气泡为蓝底，代码/链接需要更高的对比度 */
.chat-msg.user .chat-bubble code { background: rgba(255,255,255,.22); }
.chat-msg.user .chat-bubble pre.md-code { background: rgba(0,0,0,.28); color: #fff; }
.chat-msg.user .chat-bubble a { color: #dbeafe; }

/* 输入区：更紧凑 */
.chat-input { padding: 10px 14px; }
.chat-input textarea {
  width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; line-height: 1.55; outline: none;
  resize: none; max-height: 120px; overflow-y: auto;
}
.chat-input textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.chat-input-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 10px; margin-top: 8px; }
.chat-foot-right { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.chat-model-input {
  width: 160px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; outline: none; background: #fff;
}
.chat-model-input:focus { border-color: var(--primary); }
.chat-key-select {
  max-width: 200px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; color: var(--text-muted); background: #fff; outline: none;
}
.chat-key-select:focus { border-color: var(--primary); }

.chat-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chat-quick button {
  padding: 4px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--panel); color: var(--text-muted); font-size: 12px; cursor: pointer; transition: .15s;
}
.chat-quick button:hover { border-color: var(--primary); color: var(--primary); }

@media (max-width: 700px) {
  .chat-wrap { height: auto; }
  .chat-messages { min-height: 320px; }
  .chat-bubble { max-width: 92%; }
  .chat-model-input { width: 120px; }
  .chat-key-select { max-width: 130px; }
}
