/* ===== AI创作平台 · 管理后台 样式 ===== */
/* 浅色主题 / 蓝色重点 / 白色卡片 / 极简侧栏 / 无外部依赖 */
:root {
  --bg: #f4f6fb;
  --bg-soft: #eef2f9;
  --card: #ffffff;
  --card-2: #fbfcfe;
  --border: #e4e9f2;
  --border-strong: #d4dbe8;
  --text: #1f2733;
  --text-2: #5b6677;
  --text-3: #657185;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --primary-50: #eef4ff;
  --primary-100: #dbe7ff;
  --success: #15763d;
  --success-bg: #e8f6ed;
  --warning: #8b5607;
  --warning-bg: #fcf1de;
  --danger: #dc2626;
  --danger-bg: #fdeaea;
  --info: #0891b2;
  --info-bg: #e3f5f9;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
  --shadow-lg: 0 10px 40px rgba(16,24,40,.16);
  --sidebar-w: 224px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden], dialog:not([open]) { display: none !important; }
dialog.drawer[open] { display: flex; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; font-size: inherit; }

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; min-height: 38px;
  border: 1px solid var(--border-strong);
  background: #fff; color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer;
  font-weight: 500; transition: background .15s, border-color .15s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger { color: var(--danger); border-color: var(--danger-bg); background: var(--danger-bg); }
.btn-danger:hover { background: #fbdada; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 18px 18px; }
.section-title { font-size: 15px; font-weight: 650; margin: 0; }
.muted { color: var(--text-2); }
.muted-3 { color: var(--text-3); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg-soft); color: var(--text-2); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge-blue { background: var(--primary-50); color: var(--primary-600); border-color: var(--primary-100); }
.badge-green { background: var(--success-bg); color: var(--success); border-color: #cdead7; }
.badge-amber { background: var(--warning-bg); color: var(--warning); border-color: #f3e0bf; }
.badge-red { background: var(--danger-bg); color: var(--danger); border-color: #f4cccc; }
.badge-gray { background: var(--bg-soft); color: var(--text-3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------- 登录屏 ---------- */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(180deg, #eef3ff 0%, var(--bg) 60%);
}
.login-card { width: 100%; max-width: 380px; }
.login-head { text-align: center; margin-bottom: 22px; }
.login-head .logo {
  width: 46px; height: 46px; border-radius: 12px; background: var(--primary);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; margin-bottom: 12px;
}
.login-head h1 { font-size: 19px; margin: 0 0 4px; }
.login-head p { margin: 0; color: var(--text-2); font-size: 13px; }
.login-error {
  background: var(--danger-bg); color: var(--danger); border: 1px solid #f4cccc;
  padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 14px;
  display: none;
}
.login-error.show { display: block; }

/* ---------- 应用外壳 ---------- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: #fff; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px; padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.sidebar-brand b { font-size: 14.5px; font-weight: 700; line-height: 1.2; }
.sidebar-brand span { display: block; font-size: 11px; color: var(--text-3); font-weight: 500; }
.nav { padding: 10px 10px; flex: 1 1 auto; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: 0; background: transparent; color: var(--text-2);
  border-radius: var(--radius-sm); cursor: pointer; text-align: left; font-weight: 500;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.active { background: var(--primary-50); color: var(--primary-600); font-weight: 650; }
.nav-item svg { flex: 0 0 auto; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 12px; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); }
.health-mini { font-size: 12px; color: var(--text-2); }
.health-mini .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 3px 0; }
.health-mini .row b { font-weight: 600; color: var(--text); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; background: rgba(255,255,255,.86);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 17px; margin: 0; font-weight: 700; }
.hamburger { display: none; }
.topbar .spacer { flex: 1 1 auto; }
.user-chip { display: flex; align-items: center; gap: 9px; }
.user-chip .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary-100);
  color: var(--primary-600); display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.user-chip .meta b { font-size: 13px; display: block; line-height: 1.1; }
.user-chip .meta span { font-size: 11px; color: var(--text-3); }

.content { padding: 22px; max-width: 1320px; width: 100%; margin: 0 auto; }
.page { display: none; }
.page.active { display: block; }

/* ---------- 演示横幅 ---------- */
.demo-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--warning-bg); border: 1px solid #f3e0bf; color: var(--warning);
  padding: 9px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  margin-bottom: 16px;
}
.demo-banner .badge { background: #fff; }

/* ---------- 指标卡 ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.stat .value small { font-size: 14px; color: var(--text-3); font-weight: 600; }
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ---------- 工具栏 / 过滤 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1 1 auto; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.input, .select, textarea.input {
  height: 38px; padding: 8px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: #fff; color: var(--text); font-size: 14px;
  width: 100%; font-family: inherit;
}
textarea.input { height: auto; min-height: 84px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.search-input { min-width: 220px; max-width: 320px; }
.search-input-wrap { position: relative; }
.search-input-wrap .input { padding-left: 34px; }
.search-input-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

/* ---------- 表格 ---------- */
.table-wrap {
  overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; box-shadow: var(--shadow); -webkit-overflow-scrolling: touch;
}
table.grid { border-collapse: collapse; width: 100%; min-width: 720px; }
table.grid th, table.grid td {
  text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border);
  vertical-align: middle; font-size: 13px;
}
table.grid th {
  background: var(--card-2); color: var(--text-2); font-weight: 650; font-size: 12px;
  position: sticky; top: 0; white-space: nowrap;
}
table.grid tbody tr:hover { background: #f8faff; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid td.clickable { cursor: pointer; color: var(--primary-600); font-weight: 600; }
.row-link { background: none; border: 0; color: inherit; cursor: pointer; font: inherit; padding: 0; text-align: left; }
.row-link:hover { text-decoration: underline; color: var(--primary-600); }
td .sub { display: block; font-size: 11px; color: var(--text-3); }

/* ---------- 状态/空/错误 ---------- */
.state { padding: 40px 20px; text-align: center; color: var(--text-2); }
.state .ico { color: var(--text-3); margin-bottom: 10px; }
.state.error .ico { color: var(--danger); }
.state h4 { margin: 0 0 6px; color: var(--text); font-size: 15px; }
.state p { margin: 0 0 14px; font-size: 13px; }
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--primary-100);
  border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---------- dialog / 抽屉 ---------- */
dialog {
  border: 0; background: transparent; padding: 0; color: var(--text);
  max-width: 100vw; max-height: 100vh;
}
dialog::backdrop { background: rgba(17, 24, 39, .42); backdrop-filter: blur(1px); }
dialog[open] { display: block; }
.modal {
  width: 460px; max-width: calc(100vw - 24px); background: #fff;
  border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--card-2); }
.form-row { margin-bottom: 14px; }
.form-row > label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
.form-row .hint { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 12.5px; margin: -6px 0 10px; display: none; }
.form-error.show { display: block; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--text-3); padding: 6px; border-radius: 8px; display: inline-flex; }
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

/* 抽屉（右侧滑出，仍用 dialog 以获得原生 Escape/焦点恢复） */
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 480px;
  max-width: 94vw; margin: 0; background: #fff; box-shadow: var(--shadow-lg);
  border-radius: 0; display: flex; flex-direction: column;
  animation: slidein .2s ease;
}
@keyframes slidein { from { transform: translateX(24px); opacity: .6; } to { transform: translateX(0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer-head .t { min-width: 0; }
.drawer-head h3 { margin: 0 0 4px; font-size: 16px; word-break: break-word; }
.drawer-head .sub { font-size: 12px; color: var(--text-3); }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1 1 auto; }
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 8px 14px; margin: 0 0 16px; }
.kv dt { color: var(--text-2); font-size: 13px; }
.kv dd { margin: 0; font-size: 13px; word-break: break-word; }
.kv dd.unknown { color: var(--warning); font-weight: 600; }
.block-title { font-size: 13px; font-weight: 700; margin: 18px 0 8px; display: flex; align-items: center; gap: 7px; }
pre.io {
  background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 11px 12px; font-family: var(--mono); font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow: auto; margin: 0;
}
.stage {
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 13px; margin-bottom: 10px;
  background: var(--card-2);
}
.stage .stage-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.stage .stage-name { font-weight: 650; font-size: 13px; }
.stage .stage-io { margin-top: 6px; }
.cost-unknown {
  background: var(--warning-bg); border: 1px solid #f3e0bf; color: var(--warning);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12.5px; margin: 6px 0;
}

/* ---------- 系统状态 ---------- */
.health-card .kv { grid-template-columns: 150px 1fr; }
.provider-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

/* ---------- toast ---------- */
#toast-wrap { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: #1f2733; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: toastin .2s ease; max-width: 90vw;
}
.toast.ok { background: #157f3c; }
.toast.err { background: #b91c1c; }
@keyframes toastin { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(17,24,39,.4); z-index: 55; display: none;
  }
  body.nav-open .sidebar-backdrop { display: block; }
  .hamburger { display: inline-flex; }
}
@media (min-width: 901px) { .sidebar-backdrop, .hamburger { display: none !important; } }

@media (max-width: 540px) {
  .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .btn, .icon-btn, .nav-item { min-height: 44px; }
  .content { padding: 14px; }
  .topbar { padding: 10px 14px; }
  .topbar h2 { font-size: 15px; }
  .user-chip .meta { display: none; }
  .search-input { min-width: 140px; max-width: 100%; }
  .toolbar { gap: 8px; }
  .stat .value { font-size: 22px; }
  .drawer { width: 100vw; max-width: 100vw; }
}
