/* 叨叨英语管理后台 —— 视觉升级(W1 之后的样式基线,供 W3-W5 内容 CRUD / 看板 / 运维页直接复用)。
   设计取向:密度 + 可扫读的内部工具,不是儿童向 App —— 不用 App 的 Baloo 2 圆体,
   只借用 App 的品牌色(theme.ts)做"看一眼就是叨叨英语"的强关联;中性色刻意调暖,
   避免落回冷灰。CSP 无 unsafe-inline,所有样式必须落在这个文件里的类上,
   模板里禁止 style="..." 与 <style> 块。 */

:root {
  /* 品牌色(与 app/src/theme.ts 的 mint/mintDark 同值) */
  --accent: #33c4b8;
  --accent-dark: #1fa89c;
  --accent-bg: #e3f6f4;

  /* 危险色(珊瑚橙红系,取 theme.ts 的 dangerDeep/dangerBg,比 CTA 用的 coral 更沉,
     适合按钮/文字对比度) */
  --danger: #b23a1b;
  --danger-dark: #8f2e15;
  --danger-bg: #fdebe5;
  --danger-line: #f3c9bb;

  /* 语义色:成功 / 警示,取 theme.ts 的 success 系与暖黄系 */
  --success: #0e8a5f;
  --success-bg: #eaf7f1;
  --warning: #92600a;
  --warning-bg: #fbf0da;

  /* 中性色 —— 暖调,不用纯冷灰。ink/sub 取 theme.ts 原值(App 气泡正文/次要文字),
     背景与描边在此基础上单独调过明度,兼顾大面积后台数据的可读性(不照搬 App 大面积米白底)。 */
  --bg: #f5f2ed;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --ink: #2b2119;
  --ink-soft: #4a3d32;
  --sub: #8a7b6e;
  --faint: #c4b39c;
  --line: #e7ddcd;
  --line-soft: #f0e9dc;

  /* 侧边栏:暗色，与内容区形成分区，同时用品牌色标出当前页 */
  --sidebar-bg: #241c15;
  --sidebar-fg: #efe7da;
  --sidebar-fg-muted: #a8988320;
  --sidebar-muted: #b9a791;
  --sidebar-line: #3a2f24;
  --sidebar-active-bg: rgba(51, 196, 184, 0.16);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 2px rgba(43, 33, 25, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, "PingFang SC",
        "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

a { color: var(--accent-dark); }
a:hover { color: var(--accent); }

h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }

.muted { color: var(--sub); font-size: 13px; }
.inline { display: inline; }

/* ---------- 登录流程:独立居中卡片,不带侧边栏(未登录不该看到导航) ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-shell .card {
  width: 100%;
  max-width: 380px;
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}

.auth-brand .auth-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex: none;
}

/* ---------- 已登录:左侧固定分组侧边栏 + 内容区 ---------- */

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

.sidebar {
  flex: none;
  width: 216px;
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--sidebar-line);
}

.sidebar-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #17221f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  flex: none;
}

.sidebar-brand-text { line-height: 1.3; }
.sidebar-brand-title { font-weight: 700; font-size: 14px; color: #fff; }
.sidebar-brand-sub { font-size: 11px; color: var(--sidebar-muted); }

.sidebar-nav { padding: 12px 10px; flex: 1; }

.nav-group + .nav-group { margin-top: 18px; }

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  margin: 0 0 6px;
  padding: 0 10px;
}

.nav-link {
  display: block;
  padding: 8px 10px;
  margin: 2px 0;
  border-radius: var(--radius-sm);
  color: var(--sidebar-fg);
  text-decoration: none;
  font-size: 13.5px;
  border-left: 3px solid transparent;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.nav-link.current {
  background: var(--sidebar-active-bg);
  border-left-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.nav-placeholder {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--sidebar-muted);
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar .who { margin-left: auto; color: var(--sub); font-size: 13px; }

main { flex: 1; max-width: 1100px; width: 100%; margin: 0 auto; padding: 24px; }
.auth-shell main { padding: 0; }

/* ---------- 页头:标题 + 说明 + 右侧操作区(W3-W5 直接复用) ---------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header-text { min-width: 0; }
.page-header .page-desc { margin: 4px 0 0; }
.page-header-actions { display: flex; gap: 8px; flex: none; }

/* ---------- 卡片 / 分区 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card.error h1 { color: var(--danger); }

/* ---------- 表格:紧凑、表头弱化、hover 高亮、数字右对齐 ---------- */

table { width: 100%; border-collapse: collapse; }

table th, table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13.5px;
  vertical-align: middle;
}

table th {
  color: var(--sub);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table tbody tr:hover { background: var(--surface-2); }

table td.num, table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty-state {
  padding: 28px 8px;
  text-align: center;
  color: var(--sub);
  font-size: 13.5px;
}

/* ---------- 状态徽章:语义色(中性 / 成功 / 警示 / 危险) ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--line-soft); color: var(--ink-soft); }

/* ---------- 表单:label + 输入 + 帮助文字 + 字段级错误 ---------- */

label { display: block; margin: 12px 0 4px; font-weight: 500; font-size: 13px; color: var(--ink-soft); }
label:first-child { margin-top: 0; }

input[type=text], input[type=password], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}

input[type=text]:focus, input[type=password]:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.help-text { color: var(--sub); font-size: 12px; margin: 4px 0 0; }
.field-error { color: var(--danger); font-size: 13px; margin: 6px 0 0; }

.form-actions { margin-top: 14px; }

/* ---------- 按钮:三级(主要 / 次要 / 危险) ---------- */

button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #0f2422;
}

button:hover, .btn:hover { background: var(--accent-dark); color: #fff; }

button.btn-secondary, .btn-secondary {
  background: var(--surface);
  color: var(--ink-soft);
  border-color: var(--line);
}

button.btn-secondary:hover, .btn-secondary:hover {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--faint);
}

button.danger, .btn-danger {
  background: var(--danger);
  color: #fff;
}

button.danger:hover, .btn-danger:hover { background: var(--danger-dark); }

button.btn-sm, .btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ---------- 危险区:破坏性动作(封号 / 注销)单独分区,视觉上与补偿性动作分开 ---------- */

.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.actions-grid .action {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-2);
}

.actions-grid .action h3 { margin-top: 0; }

.action-section { margin-bottom: 20px; }
.action-section:last-child { margin-bottom: 0; }

.action-section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--sub);
  text-transform: uppercase;
  margin: 0 0 10px;
}

.danger-zone {
  border: 1px solid var(--danger-line);
  background: var(--danger-bg);
  border-radius: var(--radius);
  padding: 16px;
}

.danger-zone .action-section-title { color: var(--danger); }

.danger-zone .actions-grid .action {
  background: var(--surface);
  border-color: var(--danger-line);
}

/* ---------- 二次确认(details/summary,纯原生行为,无 JS) ---------- */

details.confirm summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-size: 13.5px;
  font-weight: 600;
  list-style: none;
}

details.confirm summary::-webkit-details-marker { display: none; }
details.confirm summary::before { content: "▸ "; }
details.confirm[open] summary::before { content: "▾ "; }

details.confirm .confirm-body {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

/* ---------- 分页 ---------- */

.pagination { display: flex; gap: 14px; align-items: center; margin: 4px 0 0; }
.pagination a { font-weight: 600; }

/* ---------- 页内子导航(如工单状态筛选)——用 tab 样式呈现 ---------- */

.tabs { display: flex; gap: 4px; margin: 10px 0 4px; flex-wrap: wrap; }

.tabs a {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--sub);
  text-decoration: none;
}

.tabs a:hover { background: var(--surface-2); color: var(--ink); }
.tabs a.current { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }

/* ---------- 搜索 / 过滤条 ---------- */

.search-form { display: flex; gap: 8px; margin-bottom: 4px; }
.search-form input[type=text] { flex: 1; }
.search-form button { flex: none; }

.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.filter-grid p { grid-column: 1 / -1; margin: 12px 0 0; }

/* ---------- 长文本(用户可控)——只管排版换行,不承担任何转义/安全职责,
   内容始终由 Jinja autoescape 负责。 ---------- */

.ticket-content { white-space: pre-wrap; word-break: break-word; }

/* ---------- JSON 展示(审计 detail):等宽字体、限高可滚 ---------- */

.detail-json {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  max-height: 160px;
  overflow: auto;
}

/* 内容运营:多对多归属的多选框网格(scenes ↔ categories)。
   CSP 无 unsafe-inline,所以这类布局只能落在这里,模板里不能写 style=。 */
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
                 gap: 6px 14px; margin: 6px 0 2px; }
.checkbox-item { display: flex; align-items: center; gap: 6px; margin: 0;
                 font-weight: 400; font-size: 14px; }
/* JSON 编辑框用等宽字体,不然大括号和缩进对不齐,没法看 */
.json-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* ---------- 数据看板 ---------- */

/* h2 全局是 margin-top:0(表单页里紧跟着卡片标题,那样才对),但看板/限流这类
   一页里有五六个并列段落的地方,不给上边距就会挤成一坨。所以按段落包一层。
   (类名带 dash- 前缀是历史原因 —— 先在看板上做的,运维页直接复用。) */
.dash-section { margin-top: 30px; }
.dash-section h3 { margin-top: 22px; }
/* 一段里有多个子表(限流按 name 分组)时,表和下一个 h3 之间也要留白 */
.dash-section table + h3, .dash-section p + h3 { margin-top: 22px; }
.dash-section > h2 { padding-bottom: 8px; border-bottom: 1px solid var(--line-soft); }

/* KPI 表:数字才是主角,列头退成小字灰。普通明细表(星星来源/等级分布)不加这个类。 */
.kpi td { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; padding-top: 10px; }
.kpi th { font-size: 12px; font-weight: 500; color: var(--sub); }
.kpi .kpi-unit { font-size: 13px; font-weight: 400; color: var(--sub); margin-left: 2px; }

/* ---------- 运维页 ---------- */

/* 动作成功后的回执。用绿底而不是纯文字:302 回来后页面整体没变化,
   不给个明显的色块,人会以为「点了没反应」而重复点击。 */
.flash-ok { color: var(--success); background: var(--success-bg);
            border: 1px solid var(--success); border-radius: var(--radius-sm);
            padding: 8px 12px; margin: 0 0 12px; font-size: 13px; }

/* session_id / pc_id / 限流 key 这类机读串:等宽 + 小一号,不然长串会把表格撑歪 */
.mono-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
             font-size: 12px; color: var(--ink-soft); word-break: break-all; }

/* 并排的几个二次确认块 */
.action-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
