:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --line: #e3e8ef;
  --ink: #1c2430;
  --ink-2: #5a6572;
  --ink-3: #8b95a3;
  --brand: #2f6fed;
  --brand-soft: #e8f0fe;
  --ok: #1e9e6a;
  --warn: #d97706;
  --bad: #d64545;
  --chip: #eef2f7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07);
  font-size: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.55;
}
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select { font: inherit; }
a { color: var(--brand); }

/* ---------------- 登录屏 ---------------- */
#auth {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #eaf1fd 0%, var(--bg) 60%);
}
.auth-card {
  width: 400px; max-width: calc(100vw - 32px); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px 32px 26px;
  box-shadow: 0 10px 40px rgba(31, 58, 131, .10);
}
/* 品牌区：麦吉优 logo + M² 母体 */
.brand-head { text-align: center; margin-bottom: 14px; }
.brand-logo { width: 148px; max-width: 70%; display: block; margin: 0 auto 8px; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: .5px; }
.brand-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; letter-spacing: .3px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card .sub { color: var(--ink-2); font-size: 12.5px; margin-bottom: 18px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--chip);
  padding: 4px; border-radius: 10px; }
.auth-tabs button { flex: 1; padding: 7px 0; border-radius: 8px; color: var(--ink-2); font-size: 13px; }
.auth-tabs button.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fbfcfe; outline: none;
}
.field input:focus { border-color: var(--brand); background: #fff; }
.field .with-btn { display: flex; gap: 8px; }
.field .with-btn input { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border-radius: 9px; padding: 9px 16px;
  font-weight: 600;
}
.btn:hover { filter: brightness(.95); }
.btn.ghost { background: var(--panel); color: var(--brand); border: 1px solid var(--brand); }
.btn.mini { padding: 6px 10px; font-size: 12.5px; font-weight: 500; }
.btn.block { width: 100%; margin-top: 6px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.auth-msg { min-height: 20px; font-size: 12.5px; margin-top: 10px; }
.auth-msg.err { color: var(--bad); }
.auth-msg.ok { color: var(--ok); }
.dev-code { margin-top: 6px; font-size: 12.5px; color: var(--warn); }
.auth-foot { margin-top: 14px; font-size: 12px; color: var(--ink-3); line-height: 1.6; }
.auth-foot .copyright, .copyright {
  margin-top: 10px; font-size: 11px; color: var(--ink-3); text-align: center;
  letter-spacing: .2px;
}

/* ---------------- 主框架 ---------------- */
#app { display: none; height: 100vh; flex-direction: column; }
#app.on { display: flex; }
.topbar {
  height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex: none;
}
.topbar .logo { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.topbar .logo span { color: var(--brand); }
.topbar-logo { height: 26px; width: auto; display: block; }
.logo-text { white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .me { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); }
.role-pill {
  background: var(--brand-soft); color: var(--brand); border-radius: 999px;
  padding: 2px 10px; font-size: 12px; font-weight: 600;
}
.role-pill.viewer { background: #fdeef0; color: var(--bad); }
.role-pill.operator { background: #e7f6ee; color: var(--ok); }
.role-pill.manager { background: #fff3e2; color: var(--warn); }
.body-row { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 168px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  padding: 10px 8px; display: flex; flex-direction: column; gap: 2px;
}
.sidebar button {
  display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 9px;
  color: var(--ink-2); font-size: 13.5px; text-align: left;
}
.sidebar button:hover { background: var(--chip); }
.sidebar button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sidebar .ic { width: 18px; text-align: center; flex: none; }
.side-foot { margin-top: auto; padding: 10px 6px 4px; border-top: 1px solid var(--line); }
.side-powered { font-size: 11px; color: var(--ink-2); text-align: center; }
.side-powered b { color: var(--brand); }
.side-copyright {
  margin-top: 4px; font-size: 10px; color: var(--ink-3); text-align: center; line-height: 1.5;
}
.main { flex: 1; min-width: 0; overflow: auto; padding: 18px 22px; }

/* ---------------- 聊天 ---------------- */
.chat-wrap { display: flex; flex-direction: column; height: 100%; gap: 10px; }
.chat-head {
  display: flex; align-items: center; gap: 10px; flex: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 9px 14px;
}
.chat-head select { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #fbfcfe; max-width: 300px; }
.chat-head .hint { color: var(--ink-3); font-size: 12px; }
.chat-head .right { margin-left: auto; }
.msgs {
  flex: 1; min-height: 0; overflow-y: auto; padding: 6px 2px 6px 6px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg { max-width: 86%; display: flex; flex-direction: column; gap: 5px; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg .who { font-size: 11.5px; color: var(--ink-3); padding: 0 4px; }
.msg .bubble {
  padding: 10px 14px; border-radius: 14px; background: var(--panel);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--brand); border-color: var(--brand); color: #fff; }
.msg.assistant .bubble { width: 100%; }
.msg .bubble.md h1 { font-size: 17px; margin: 10px 0 6px; }
.msg .bubble.md h2 { font-size: 15.5px; margin: 10px 0 5px; }
.msg .bubble.md h3 { font-size: 14.5px; margin: 8px 0 4px; }
.msg .bubble.md h4 { font-size: 13.5px; margin: 6px 0 3px; color: var(--ink-2); }
.msg .bubble.md p { margin: 4px 0; }
.msg .bubble.md ul, .msg .bubble.md ol { padding-left: 20px; margin: 4px 0; }
.msg .bubble.md code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.msg .bubble.md pre { background: #f0f3f8; padding: 8px 10px; border-radius: 8px; overflow-x: auto; margin: 6px 0; }
.msg .bubble.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--ink-2); margin: 6px 0; }
.msg .bubble.md table { border-collapse: collapse; margin: 6px 0; font-size: 12.5px; }
.msg .bubble.md th, .msg .bubble.md td { border: 1px solid var(--line); padding: 4px 8px; }
.msg .bubble.md hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.msg.user .bubble code { background: rgba(255,255,255,.2); color: #fff; }
.msg .att-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--chip);
  border-radius: 8px; padding: 4px 10px; font-size: 12.5px; color: var(--ink-2);
}
.att-chip .x { color: var(--ink-3); font-size: 14px; }
.att-chip .x:hover { color: var(--bad); }
.msg .typing { color: var(--ink-3); font-size: 12.5px; padding: 0 4px; }
.dots::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.composer {
  flex: none; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.composer .staged { display: flex; flex-wrap: wrap; gap: 6px; }
.composer .row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; font: inherit; color: var(--ink);
  background: transparent; max-height: 130px; min-height: 22px; line-height: 1.5;
  padding: 4px 2px;
}
.composer .clip, .composer .send {
  flex: none; width: 38px; height: 38px; border-radius: 10px; display: flex;
  align-items: center; justify-content: center; font-size: 17px;
}
.composer .clip { background: var(--chip); color: var(--ink-2); }
.composer .clip:hover { background: #e2e9f2; }
.composer .send { background: var(--brand); color: #fff; font-size: 15px; }
.composer .send:disabled { opacity: .5; }
.composer .note { font-size: 11.5px; color: var(--ink-3); }

/* ---------------- 通用面板 ---------------- */
.page { max-width: 1080px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.page-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.page-head h2 { font-size: 17px; }
.page-head .desc { color: var(--ink-2); font-size: 12.5px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe;
}
.toolbar input[type=text] { width: 220px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th { text-align: left; color: var(--ink-2); font-weight: 600; font-size: 12px;
  padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid td { padding: 7px 8px; border-bottom: 1px solid #eef1f6; vertical-align: top; }
table.grid tr:hover td { background: #fafbfd; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 11.5px;
  background: var(--chip); color: var(--ink-2); }
.badge.high { background: #e7f6ee; color: var(--ok); }
.badge.partial { background: #fff3e2; color: var(--warn); }
.badge.noise, .badge.conflict { background: #fdeef0; color: var(--bad); }
.badge.viewer { background: #fdeef0; color: var(--bad); }
.badge.operator { background: #e7f6ee; color: var(--ok); }
.badge.manager { background: #fff3e2; color: var(--warn); }
.badge.admin { background: var(--brand-soft); color: var(--brand); }
.pager { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 6px 0; }
.pager button { padding: 5px 12px; border-radius: 7px; background: var(--chip); color: var(--ink-2); }
.pager button.cur { background: var(--brand); color: #fff; }
.pager button:disabled { opacity: .4; }
.empty { text-align: center; color: var(--ink-3); padding: 26px 0; font-size: 13px; }

/* ---------------- 报告 ---------------- */
.report-list { display: flex; flex-direction: column; gap: 8px; }
.report-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  cursor: pointer; background: #fbfcfe;
}
.report-item:hover { border-color: var(--brand); background: #fff; }
.report-item .t { display: flex; align-items: center; gap: 8px; }
.report-item .t .name { font-weight: 600; font-size: 13.5px; }
.report-item .t .date { margin-left: auto; color: var(--ink-3); font-size: 12px; }
.report-item .pv { color: var(--ink-2); font-size: 12px; margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-view h2 { font-size: 16px; margin-bottom: 8px; }
.report-view .md { border-top: 1px solid var(--line); padding-top: 10px; }
.md h1 { font-size: 18px; margin: 12px 0 8px; }
.md h2 { font-size: 16px; margin: 12px 0 6px; }
.md h3 { font-size: 14.5px; margin: 10px 0 5px; }
.md h4 { font-size: 13.5px; margin: 8px 0 4px; color: var(--ink-2); }
.md p { margin: 5px 0; }
.md ul, .md ol { padding-left: 22px; margin: 5px 0; }
.md code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.md pre { background: #f0f3f8; padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--ink-2); margin: 8px 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; }
.md hr { border: none; border-top: 1px solid var(--line); margin: 10px 0; }

/* ---------------- 可视化 ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat .k { color: var(--ink-2); font-size: 12px; }
.stat .v { font-size: 21px; font-weight: 700; margin-top: 2px; }
.stat .s { color: var(--ink-3); font-size: 11.5px; }
.viz-exh { margin-top: 4px; }
.viz-exh h3 { font-size: 14.5px; margin-bottom: 6px; }
.viz-exh .meta { color: var(--ink-3); font-size: 12px; margin-bottom: 8px; }
.chart-row { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.chart-row .cap { font-size: 12.5px; color: var(--ink-2); }
.chart-row .cap b { color: var(--ink); }
.forecast-line { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 2px; }
.forecast-day { background: #f7f0ff; border: 1px dashed #b9a3e6; color: #5b3fa8;
  border-radius: 8px; padding: 4px 10px; font-size: 12px; }
.chart { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; }
.evo-note { font-size: 12.5px; color: var(--ink-2); white-space: pre-wrap;
  max-height: 260px; overflow-y: auto; background: #fbfcfe; border-radius: 8px; padding: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
/* 目标展倒计时徽标 */
.cd { display: inline-block; border-radius: 999px; padding: 2px 10px;
  font-size: 11.5px; font-weight: 600; vertical-align: middle; margin-left: 6px; }
.cd.up { background: var(--brand-soft); color: var(--brand); }
.cd.live { background: #e7f6ee; color: var(--ok); }
.cd.done { background: var(--chip); color: var(--ink-3); }

/* ---------------- 管理台 ---------------- */
.admin-sec h3 { font-size: 14.5px; margin-bottom: 8px; }
.exh-picker { display: flex; flex-wrap: wrap; gap: 6px; max-width: 360px; }
.exh-pick { border: 1px solid var(--line); border-radius: 7px; padding: 3px 9px;
  font-size: 12px; color: var(--ink-2); cursor: pointer; }
.exh-pick.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.inline-edit { display: flex; gap: 6px; align-items: center; }
.inline-edit input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; width: 130px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1c2430; color: #fff; border-radius: 9px; padding: 9px 18px; font-size: 13px;
  opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 99;
}
.toast.on { opacity: .96; }
.toast.err { background: var(--bad); }

/* ---------------- 响应式 ---------------- */
/* PC 宽屏：内容区更宽，充分利用横向空间 */
@media (min-width: 1400px) {
  .page { max-width: 1280px; }
  .main { padding: 20px 30px; }
  .two-col { gap: 16px; }
}
/* 平板 / 小屏电脑 */
@media (max-width: 960px) {
  .main { padding: 14px; }
  .page { max-width: 100%; }
  .toolbar input[type=text] { width: 150px; }
}
/* 手机端：侧边导航改为底部标签栏，顶部压缩，内容满宽 */
@media (max-width: 720px) {
  .topbar { height: 46px; padding: 0 12px; gap: 8px; }
  .topbar-logo { height: 20px; }
  .logo-text { font-size: 12.5px; white-space: normal; line-height: 1.25; }
  .topbar .me { gap: 6px; font-size: 12px; }
  .role-pill, .topbar .btn, .topbar .me > span:first-child { white-space: nowrap; }
  .role-pill { padding: 2px 7px; }
  .body-row { display: block; }
  /* 手机端聊天：输入框沉底，消息区占满剩余高度 */
  .main {
    display: flex; flex-direction: column;
    height: calc(100vh - 46px);   /* 减掉顶栏；底部导航是 fixed，用 padding 让位 */
  }
  .main > * { width: 100%; }
  .chat-wrap { flex: 1; min-height: 0; }
  .chat-wrap .msgs { flex: 1; }
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    width: auto; flex-direction: row; justify-content: space-around;
    border-right: none; border-top: 1px solid var(--line);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); gap: 0;
    box-shadow: 0 -2px 10px rgba(16, 24, 40, .06);
  }
  .sidebar button {
    flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px;
    font-size: 11px; border-radius: 8px;
  }
  .sidebar .ic { width: auto; font-size: 17px; }
  .side-foot { display: none; }
  .main { padding: 12px 10px calc(64px + env(safe-area-inset-bottom)); overflow-x: hidden; }
  .page { gap: 10px; }
  .page-head .desc { width: 100%; }
  .auth-card { padding: 22px 18px 20px; border-radius: 12px; }
  .brand-logo { width: 118px; }
  .msg { max-width: 95%; }
  .chat-wrap { gap: 8px; }
  .chat-head { flex-wrap: wrap; padding: 8px 10px; }
  .chat-head .hint { display: none; }
  .chat-head select { max-width: 60vw; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; gap: 10px; }
  .toolbar input[type=text] { width: 100%; }
  .inline-edit { flex-wrap: wrap; }
  .inline-edit input { width: 110px; }
  .exh-picker { max-width: 100%; }
  .card { padding: 12px; }
  /* 宽表格在手机上横向滚动，不撑破布局 */
  .card { overflow-x: auto; }
  .toast { bottom: calc(70px + env(safe-area-inset-bottom)); width: max-content; max-width: 88vw; }
}
