:root {
  --bg: #f3f0ea;
  --card: #fffdf8;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e0d5;
  --accent: #0f766e;
  --danger: #b91c1c;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--ui-font-ui);
  color: var(--ink);
  background:
    radial-gradient(900px 400px at 10% -10%, #d9f3ef 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 0%, #f5e6d3 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
}
#app { max-width: 960px; margin: 0 auto; padding: 24px 16px 48px; }
.hidden { display: none !important; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(28, 25, 23, 0.04);
}
.login-card { max-width: min(420px, 100%); margin: 12vh auto 0; }
h1 { margin: 0 0 6px; font-size: 1.6rem; letter-spacing: 0.02em; }
.sub, .hint, .err { color: var(--muted); font-size: 0.92rem; }
.err { color: var(--danger); min-height: 1.2em; }
label { display: block; margin: 12px 0; font-size: 0.9rem; }
.captcha-box { margin: 12px 0; }
.captcha-box > label { margin: 0 0 6px; display: block; font-size: 0.9rem; }
.captcha-line {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.captcha-line input { margin-top: 0; flex: 1; width: auto; }
.captcha-code {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 0 12px;
  border-radius: 10px;
  letter-spacing: 0.28em;
  font-weight: 700;
  font-size: 1.25rem;
  background: #134e4a;
  color: #ecfdf5;
  cursor: pointer;
  user-select: none;
  border: 1px solid #0f766e;
}
button.captcha-refresh {
  width: auto;
  margin-top: 0;
  min-width: 64px;
}
input, select, button, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font: inherit;
  background: #fff;
}
textarea {
  resize: vertical;
  min-height: 64px;
}
button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  margin-top: 14px;
}
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); width: auto; }
.top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.badge {
  display: inline-block; margin-left: 8px; padding: 2px 8px;
  border-radius: 999px; background: #ecfdf5; color: #065f46; font-size: 0.8rem;
}
.badge.off { background: #fef2f2; color: #991b1b; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button {
  width: auto; margin: 0; background: #fff; color: var(--ink); border: 1px solid var(--line);
}
.tabs button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.panel { }
.toolbar { margin: 8px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar button, .card button { width: auto; }
.status-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.status-actions button { margin-top: 0; width: auto; }
button.danger-btn { color: var(--danger); border-color: #fecaca; }
button.danger-btn:hover { background: #fef2f2; }
.forward-toolbar input {
  flex: 1; min-width: 160px; margin: 0; width: auto;
}
.room-table-wrap { max-height: 320px; margin-bottom: 14px; }
.task-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 10px;
}
.task-section .table-wrap { border: none; }
table tbody tr.selected { background: #ecfdf5; }
table tbody tr { cursor: pointer; }
table tbody tr button { cursor: pointer; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #faf7f2; position: sticky; top: 0; z-index: 1; }
.log-terminal {
  margin: 0;
  min-height: 420px;
  max-height: min(70vh, 640px);
  overflow: auto;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #2a2f3a;
  background: #0c0f14;
  color: #d6deeb;
  font-family: var(--ui-font-mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-terminal .log-ok { color: #d6deeb; }
.log-terminal .log-fail { color: #f87171; }
.log-auto { width: auto; margin: 0; font-size: 0.9rem; color: var(--muted); }
.log-auto input { width: auto; margin: 0 6px 0 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row input[type=checkbox] { width: auto; margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.schedule-days-root { margin: 8px 0 12px; overflow-x: auto; }
.schedule-days-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: 8px;
}
.schedule-days-table th,
.schedule-days-table td {
  border: 1px solid var(--line);
  padding: 4px;
  text-align: center;
  white-space: nowrap;
}
.schedule-days-table input[type="time"] { width: 100px; }
.schedule-quick { display: flex; flex-direction: column; gap: 8px; }
.schedule-quick-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
}
.schedule-quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.schedule-quick-actions button { width: auto; }
.captcha img { max-width: 180px; display: block; margin: 10px 0; border-radius: 8px; }
/* 原生 dialog：Esc 关闭、Tab 焦点锁在弹窗内、遮罩由 ::backdrop 提供 */
dialog.modal-dialog {
  width: 100%;
  max-width: none;
  max-height: 100%;
  margin: 0;
  padding: 16px;
  border: none;
  background: transparent;
  color: inherit;
  overflow: visible;
}
dialog.modal-dialog[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 16px 40px rgba(28,25,23,0.18);
}
.modal-card-wide { width: min(640px, 100%); }
.modal-card-messages {
  width: min(720px, 100%);
  max-height: min(92vh, 860px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.modal-card-messages .mx-msg-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}
.modal-card-messages .mx-msg-header h3 { margin: 0; }
.modal-card-messages .mx-msg-header button { width: auto; margin: 0; }
.mx-msg-load-top {
  padding: 8px 14px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.mx-msg-list {
  flex: 1;
  min-height: 420px;
  max-height: min(78vh, 720px);
  overflow: auto;
  padding: 14px 16px 18px;
  background: #faf7f2;
}
.mx-msg-item {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(28, 25, 23, 0.03);
}
.mx-msg-time {
  font-size: 0.8rem;
  color: #78716c;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.mx-msg-content {
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.mx-msg-body {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.mx-msg-body .mx-msg-content { flex: 1; min-width: 0; }
.mx-msg-body .mx-resend-btn {
  flex: none;
  width: auto;
  margin: 0;
  padding: 4px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}
.mx-msg-content img.mx-msg-img {
  display: block;
  max-width: min(100%, 320px);
  max-height: 240px;
  margin: 6px 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: contain;
  background: #f8fafc;
}
.mx-rooms-wrap { max-height: min(70vh, 560px); }
.mx-rooms-wrap tbody tr { cursor: default; }
.mx-rooms-wrap tbody tr:hover { background: #faf7f2; }
.modal-card h3 { margin: 0 0 8px; }
.modal-card button { width: 100%; }
@media (max-width: 640px) {
  .row2 { grid-template-columns: 1fr; }
  .room-table-wrap { max-height: 240px; }
}

/* —— 状态卡（B：信息架构） —— */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 24px rgba(28, 25, 23, 0.04);
}
.stat-label { color: var(--muted); font-size: 0.82rem; letter-spacing: 0.04em; }
.stat-value { font-size: 1.08rem; line-height: 1.35; word-break: break-word; }
.stat-card-wide { grid-column: 1 / -1; }
.offline-line { margin: 10px 0 0; }

/* —— 转发设置：房间 / 任务分栏 —— */
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 16px;
  align-items: start;
}
.split-col { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 1024px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}

/* —— 分页条 —— */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.pager-actions { display: flex; align-items: center; gap: 8px; }
.pager-size {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-family: var(--ui-font-ui);
  font-size: 0.88rem;
}
.pager button { white-space: nowrap; flex: 0 0 auto; }
.pager button:disabled { opacity: 0.45; cursor: not-allowed; }

/* —— 可排序表头 —— */
th.th-sortable { cursor: pointer; user-select: none; }
th.th-sortable:hover { color: var(--accent); }
th[data-sort-dir="asc"]::after { content: " ▲"; font-size: 0.7em; }
th[data-sort-dir="desc"]::after { content: " ▼"; font-size: 0.7em; }

/* —— 手机端：表格卡片化 —— */
@media (max-width: 640px) {
  .card-table thead { display: none; }
  .card-table, .card-table tbody, .card-table tr, .card-table td { display: block; width: 100%; }
  .card-table tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  .card-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: none;
    padding: 4px 0;
    white-space: normal;
  }
  .card-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.82rem;
    flex: 0 0 auto;
  }
  .card-table td:empty { display: none; }
  .room-table-wrap { max-height: none; }
  .stat-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* —— 暗色：跟随系统 —— */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1216;
    --card: #151c22;
    --ink: #e6edf3;
    --muted: #9aa7b4;
    --line: #26313b;
    --accent: #2dd4bf;
    --danger: #f87171;
  }
  body {
    background:
      radial-gradient(900px 400px at 10% -10%, rgba(13, 148, 136, 0.18) 0%, transparent 55%),
      radial-gradient(700px 360px at 100% 0%, rgba(180, 83, 9, 0.14) 0%, transparent 50%),
      var(--bg);
  }
  .card, .stat-card { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
  .log-terminal { background: #070b0e; color: #cfd8e3; }
}
/* —— 暗色补充：门户里写死浅色的容器 —— */
@media (prefers-color-scheme: dark) {
  input, select, textarea {
    background: #101a22;
    color: var(--ink);
    border: 1px solid var(--line);
  }
  .tabs button {
    background: #16202a;
    color: var(--ink);
    border: 1px solid var(--line);
  }
  .tabs button.active { background: var(--accent); color: #04211d; border-color: var(--accent); }
  .table-wrap { background: #111a22; }
  th { background: #16202a; }
  table tbody tr.selected { background: rgba(45, 212, 191, 0.12); }
  .mx-rooms-wrap tbody tr:hover { background: #16202a; }
  .modal-card { background: #16202a; border: 1px solid var(--line); }
  .modal-card-messages .mx-msg-header { background: #16202a; }
  .chat-bubble, .mx-msg-item { background: #101a22; }
}

/* —— 表格不换行（分栏后列更窄）；手机端卡片化时不再限制 —— */
@media (min-width: 641px) {
  .card-table th, .card-table td { white-space: nowrap; }
  .card-table td:first-child { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
  .room-table-wrap { max-height: 62vh; }
}
/* 分栏后表格更紧凑，避免任务表横向溢出 */
.split .card-table th,
.split .card-table td { padding: 8px 10px; }
.split .card-table button { padding: 5px 9px; font-size: 0.84rem; width: auto; }
.split .card-table td:first-child { max-width: 180px; }
/* 手机端防横向溢出 */
@media (max-width: 640px) {
  html, body { overflow-x: hidden; }
  #app { padding: 16px 12px 32px; max-width: 100%; }
  .toolbar input, .forward-toolbar input { flex: 1 1 100%; min-width: 0; width: 100%; }
  .status-actions { flex-wrap: wrap; }
  .card-table tr { width: 100%; }
  .card-table td { width: 100%; min-width: 0; }
  .split .card-table td:first-child { max-width: none; }
  .pager { font-size: 0.85rem; }
}