* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #f1f5f9; color: #1e293b; font-size: 14px;
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: #fff; border-bottom: 1px solid #e2e8f0;
}
header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.status { padding: 3px 10px; border-radius: 12px; font-size: 12px; }
.status.running { background: #dcfce7; color: #166534; }
.status.stopped { background: #fee2e2; color: #991b1b; }
button {
  padding: 6px 12px; border: 1px solid #cbd5e1; background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
button:hover { background: #f8fafc; }
button.primary { background: #2563eb; color: #fff; border-color: #2563eb; }
button.primary:hover { background: #1d4ed8; }

main { padding: 14px; }

/* ========== 仪表盘 ========== */
.dashboard {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 14px;
  align-items: start;
}
.dash-left, .dash-right {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 14px; min-height: calc(100vh - 90px);
  display: flex; flex-direction: column;
}
.dash-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid #e2e8f0;
}
.dash-header h2 { font-size: 15px; margin: 0; font-weight: 600; flex: 1; }
.dash-task-list {
  display: flex; flex-direction: column; gap: 10px;
  overflow: auto; flex: 1;
}
.task-empty { color: #94a3b8; font-size: 13px; padding: 8px 0; }
.task-item {
  display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px;
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 10px 12px; cursor: pointer; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.task-item:hover { background: #f1f5f9; }
.task-item.active { border-color: #2563eb; background: #eff6ff; }
.task-item.paused { opacity: 0.75; }
.task-item.paused-closed { opacity: 0.7; border-color: #f59e0b; background: #fffbeb; }
.task-item.triggered { border-color: #22c55e; background: #f0fdf4; }
.task-main { flex: 1; min-width: 0; }
.task-name { font-weight: 600; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-rules {
  color: #475569; font-size: 12px; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-meta {
  color: #64748b; font-size: 11px; margin-top: 4px;
  display: flex; gap: 10px; flex-wrap: wrap;
}
.task-time { color: #2563eb; }
.task-status {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #e2e8f0; color: #475569; white-space: nowrap;
}
.task-item.triggered .task-status { background: #dcfce7; color: #166534; }
.task-item.paused .task-status { background: #fee2e2; color: #991b1b; }
.task-item.paused-closed .task-status { background: #fef3c7; color: #92400e; }
.task-actions { display: flex; gap: 4px; margin-top: 2px; }
.task-actions .mini-btn { margin-left: 0; padding: 2px 6px; font-size: 11px; }
.task-tag { display: inline-block; background: #2563eb; color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 4px; margin-bottom: 3px; }

/* 任务列表顶部全局设置摘要 */
.global-settings-bar {
  display: flex; align-items: center; gap: 12px;
  background: #f1f5f9; border: 1px dashed #cbd5e1; border-radius: 8px;
  padding: 8px 12px; font-size: 12px; color: #475569; margin-bottom: 10px;
}
.global-settings-bar span { display: flex; align-items: center; gap: 4px; }
.global-settings-bar .mini-btn { margin-left: auto; padding: 2px 8px; font-size: 11px; }

/* 右侧消息队列 */
.alert-queue {
  display: flex; flex-direction: column; gap: 12px;
  overflow: auto; flex: 1;
}
.queue-empty { color: #94a3b8; font-size: 13px; padding: 8px 0; }
.queue-group {
  border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc;
  padding: 10px 12px;
}
.queue-group-title {
  font-weight: 600; font-size: 13px; color: #1e293b;
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
}
.queue-items { display: flex; flex-direction: column; gap: 8px; }
.queue-item {
  background: #fff; border-left: 3px solid #2563eb;
  border-radius: 4px; padding: 6px 10px; font-size: 12px;
}
.queue-head { color: #334155; }
.queue-cond { color: #1d4ed8; margin-top: 2px; }
.queue-meta { color: #64748b; font-size: 11px; margin-top: 2px; }

/* ========== 编辑器 ========== */
.editor { display: flex; flex-direction: column; gap: 14px; }
.editor-head {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 12px 16px;
}
.editor-head h2 { font-size: 16px; margin: 0; font-weight: 600; flex: 1; }
.back-btn { background: #f1f5f9; }
.editor-actions { display: flex; gap: 8px; }
.editor-body {
  display: grid; grid-template-columns: 1fr 1.4fr 1fr;
  gap: 14px; align-items: start;
}
.editor-col { display: flex; flex-direction: column; gap: 14px; }
.editor-main { min-width: 0; }
.editor-preview { position: sticky; top: 14px; }

.panel {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 10px;
  padding: 14px;
}
.panel h2 { font-size: 14px; margin: 4px 0 10px; font-weight: 600; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.panel h2 small { color: #94a3b8; font-weight: 400; font-size: 12px; }
.mini { font-size: 12px; font-weight: 400; color: #475569; display: inline-flex; align-items: center; gap: 3px; margin-left: 6px; }
.mini-btn { font-size: 12px; padding: 3px 9px; margin-left: 6px; border: 1px solid #cbd5e1; background: #fff; border-radius: 6px; cursor: pointer; }
.mini-btn:hover { background: #f8fafc; }
.row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.row input, .row select { padding: 6px; border: 1px solid #cbd5e1; border-radius: 6px; }

.autocomplete-wrap { position: relative; }
.search-box { position: relative; flex: 1; min-width: 160px; }
#kw { width: 100%; }
.dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 260px; overflow: auto; background: #fff;
  border: 1px solid #cbd5e1; border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08); z-index: 50;
}
.dropdown.hidden { display: none; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
}
.dropdown-item:hover, .dropdown-item.active { background: #eff6ff; }
.dropdown-item .code { color: #64748b; }
.dropdown-item .ex { margin-left: auto; color: #94a3b8; font-size: 11px; }
.dropdown-empty { padding: 10px; color: #94a3b8; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; min-height: 26px; }
.chips .empty-tip { color: #94a3b8; font-size: 12px; padding: 4px 0; }
.chip {
  background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe;
  padding: 3px 8px; border-radius: 12px; font-size: 12px;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip .code { color: #3b82f6; }
.chip .x { cursor: pointer; color: #64748b; font-weight: 700; padding: 0 2px; }
.chip .x:hover { color: #ef4444; }
.sel-summary { font-size: 13px; color: #2563eb; margin-top: 2px; }

/* 周期独立配置面板 */
.period-settings { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.period-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 10px; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
}
.period-row.active { background: #eff6ff; border-color: #bfdbfe; }
.period-row label { font-size: 13px; font-weight: 600; }
.period-mode-row {
  background: #f0f9ff; border: 1px dashed #bae6fd; border-radius: 8px;
  padding: 8px 10px; margin-bottom: 10px; font-size: 13px;
}
.period-mode-row label { font-weight: 400; margin-right: 10px; }
.period-mode { font-size: 12px; color: #475569; }
.period-mode label { font-weight: 400; }
.period-mode input { margin-right: 2px; }
.sub-mode { font-size: 12px; color: #7c3aed; background: #f5f3ff; padding: 2px 6px; border-radius: 4px; }
.sub-mode label { font-weight: 400; margin-right: 6px; }
.sub-mode input { margin-right: 2px; }
.period-body {
  margin-left: 24px; padding: 10px; background: #fff; border: 1px solid #e2e8f0;
  border-radius: 8px; display: flex; flex-direction: column; gap: 10px;
}
.ind-card {
  border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px; background: #fff;
}
.ind-top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.ind-top .ind-name { font-weight: 600; font-size: 13px; }
.ind-mode { font-size: 12px; color: #475569; }
.ind-mode label { font-weight: 400; margin-right: 6px; }
.ind-mode input { margin-right: 2px; }
.ind-params { font-size: 12px; color: #475569; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ind-params input[type=number] { padding: 3px; border: 1px solid #cbd5e1; border-radius: 4px; }
.ind-params label { white-space: nowrap; }

.push-card, .ref-card {
  background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 10px; margin-bottom: 10px;
}
.push-card .row, .ref-card .row { margin-bottom: 8px; }
.push-card .row:last-child, .ref-card .row:last-child { margin-bottom: 0; }
.push-card .hint, .ref-card .hint { font-size: 12px; color: #64748b; }
.hidden { display: none !important; }
h2.collapsible { cursor: pointer; user-select: none; }
h2.collapsible::before { content: '▸'; display: inline-block; margin-right: 6px; color: #94a3b8; transition: transform .2s; }
h2.collapsible.open::before { transform: rotate(90deg); }

.ref-items { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.ref-item {
  border: 1px solid #e2e8f0; border-radius: 8px; background: #fff;
}
.ref-item-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: #f8fafc; border-radius: 8px; user-select: none;
}
.ref-item-head .name { flex: 1; font-weight: 600; font-size: 13px; }
.ref-item-head input[type=checkbox] { cursor: pointer; }
.ref-item-body {
  padding: 10px; border-top: 1px solid #e2e8f0;
  display: flex; flex-direction: column; gap: 10px;
}

.alerts { max-height: 180px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.alert {
  border-left: 3px solid #2563eb; background: #eff6ff; padding: 6px 10px;
  border-radius: 4px; font-size: 13px;
}
.alert .meta { color: #64748b; font-size: 11px; }
.alert .cond { color: #1d4ed8; }
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 8px 16px; border-radius: 6px;
  opacity: 0; transition: opacity .3s; pointer-events: none; font-size: 13px;
}
#toast.show { opacity: 1; }

/* 预览图数据源信息 + 数据不足提示 */
.chart-info { font-size: 11px; color: #64748b; margin: 6px 4px 0; }
.chart-warn {
  font-size: 12px; line-height: 1.5; color: #92400e;
  background: #fffbeb; border: 1px solid #fde68a; border-radius: 6px;
  padding: 7px 10px; margin: 6px 4px 0;
}
.chart-warn.hidden { display: none; }

/* 消息队列「更多/清空」按钮 */
.queue-group-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.queue-group-title .queue-pin {
  flex-shrink: 0; font-size: 13px; margin-right: 2px;
}
.queue-group-title span:nth-of-type(2) {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.queue-title-actions {
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0;
}
.queue-group.pinned {
  border-color: #2563eb;
  background: #eff6ff;
}
.queue-group-title .queue-pin-btn { margin-left: 0; }
.queue-group-title .queue-pin-btn.pinned {
  background: #dbeafe; border-color: #2563eb; color: #1d4ed8;
}
.queue-group-title .queue-more { margin-left: 0; }
.queue-group-title .queue-clear {
  color: #dc2626; border-color: #fecaca; background: #fef2f2;
}
.queue-group-title .queue-clear:hover {
  background: #fee2e2;
}

/* 任务消息详情弹窗 */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none !important; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45);
}
.modal-content {
  position: relative; background: #fff; border-radius: 12px;
  width: 90%; max-width: 560px; max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0,0,0,.15);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid #e2e8f0;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-close {
  background: transparent; border: none; font-size: 22px; color: #64748b;
  line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: #1e293b; }
.modal-body {
  flex: 1; overflow: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.modal-foot {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px 16px; border-top: 1px solid #e2e8f0;
}
.modal-foot .mini-btn { margin-left: 0; }
.modal-foot span { font-size: 13px; color: #475569; min-width: 50px; text-align: center; }

/* 小屏适配 */
@media (max-width: 1200px) {
  .dashboard { grid-template-columns: 1fr; }
  .editor-body { grid-template-columns: 1fr; }
  .editor-preview { position: static; }
}

/* ===== 工具类 ===== */
.hidden { display: none !important; }

/* 未登录时隐藏顶部操作区与账号菜单 */
body.logged-out header { display: none; }

/* ===== 登录 / 注册 门禁 ===== */
.auth-gate {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  padding: 16px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 16px; padding: 28px 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.auth-card h2 { margin: 0 0 6px; font-size: 20px; text-align: center; color: #0f172a; }
.auth-sub { margin: 0 0 18px; text-align: center; font-size: 13px; color: #64748b; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tabs button {
  flex: 1; padding: 8px; border: 1px solid #e2e8f0; background: #f8fafc;
  border-radius: 8px; cursor: pointer; font-size: 14px; color: #475569;
}
.auth-tabs button.active { background: #1e3a8a; color: #fff; border-color: #1e3a8a; }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  width: 100%; padding: 11px 12px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 14px; box-sizing: border-box;
}
.auth-form .primary { padding: 11px; font-size: 15px; }
.auth-err { color: #dc2626; font-size: 13px; min-height: 16px; text-align: center; }

/* ===== 账号菜单 ===== */
.account-menu { position: relative; }
.acc-name {
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.3);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.acc-dropdown {
  position: absolute; right: 0; top: 110%; background: #fff; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px; min-width: 130px; z-index: 50;
  display: flex; flex-direction: column; gap: 2px;
}
.acc-dropdown button {
  text-align: left; background: transparent; border: none; padding: 9px 10px;
  border-radius: 7px; cursor: pointer; font-size: 13px; color: #334155;
}
.acc-dropdown button:hover { background: #f1f5f9; }

/* ===== 管理后台 ===== */
.admin-panel { padding: 16px 20px; }
.admin-panel .dash-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.admin-users { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; font-size: 13px; }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #eef2f7; white-space: nowrap; }
.admin-table th { background: #f1f5f9; color: #334155; font-weight: 600; }
.admin-table tr:hover td { background: #f8fafc; }
.admin-task { padding: 8px 10px; border: 1px solid #eef2f7; border-radius: 8px; margin-bottom: 8px; font-size: 13px; color: #334155; }
.admin-detail { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.admin-detail > .dash-header, .admin-detail > .modal-body {
  background: #fff; border-radius: 12px; width: 92%; max-width: 560px; max-height: 84vh;
}
.admin-detail > .dash-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid #e2e8f0; }
.admin-detail > .dash-header h3 { margin: 0; font-size: 15px; }
.admin-detail > .modal-body { overflow: auto; padding: 14px 16px; }
.admin-detail .kv { font-size: 13px; color: #475569; margin-bottom: 6px; }
.admin-detail h4 { margin: 14px 0 8px; font-size: 14px; color: #1e293b; }
.login-hist { font-size: 12px; color: #64748b; display: flex; flex-direction: column; gap: 3px; }
.mini-btn.danger { color: #dc2626; border-color: #fecaca; }

/* ===== 手机端底部导航 ===== */
.bottom-nav { display: none; }
@media (max-width: 768px) {
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
    background: #fff; border-top: 1px solid #e2e8f0; box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  }
  .nav-btn {
    flex: 1; padding: 12px 4px; background: transparent; border: none; cursor: pointer;
    font-size: 13px; color: #475569; border-top: 2px solid transparent;
  }
  .nav-btn:active, .nav-btn:hover { color: #1e3a8a; }
  body { padding-bottom: 56px; }
  header h1 { font-size: 16px; }
  .head-actions { flex-wrap: wrap; gap: 6px; }
  .head-actions button { padding: 6px 10px; font-size: 12px; }
  .editor-head, .dash-header { flex-wrap: wrap; }
  .task-card { flex-direction: column; align-items: flex-start; }
}

