:root {
  --primary: #2e6be6;
  --primary-soft: #eaf1fe;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e4e8ef;
  --text: #1f2733;
  --muted: #7b8794;
  --danger: #e5484d;
  --success: #18a058;
  --warn: #f0a020;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 20px;
  display: grid;
  place-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.state-badge {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-right .btn {
  padding: 6px 14px;
}

.inline-time,
.inline-num {
  width: auto;
}

.login-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 36, 0.45);
  display: grid;
  place-items: center;
  z-index: 999;
}

.login-box {
  width: 320px;
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.2);
}

.login-box h2 {
  margin: 0;
  font-size: 17px;
}

.login-box .hint {
  margin: -6px 0 0;
}

.login-box .btn {
  margin-top: 4px;
}

.layout-inner {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
}

.tabs-nav {
  display: flex;
  gap: 8px;
  padding: 14px 28px 0;
}

.tabs-nav button {
  border: 1px solid transparent;
  background: #fff;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  font: inherit;
  color: #46505c;
}

.tabs-nav button.active {
  background: var(--primary);
  color: #fff;
}

.tab-panel {
  padding: 16px 28px 0;
}

.tab-panel.hidden {
  display: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2 {
  margin: 0 0 14px;
}

.inline-select {
  width: auto;
  min-width: 200px;
  flex: 0 0 auto;
}

.inline-input {
  flex: 1 1 auto;
  min-width: 160px;
}

.station-list,
.route-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.station-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.station-item.current {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.station-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.station-index {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 13px;
}

.station-name {
  font-weight: 600;
}

.station-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.station-ops {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.route-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}

.ops {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn.danger {
  color: var(--danger);
  border-color: #f3c9ca;
  background: #fdf1f1;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.card.full {
  margin: 0 28px 28px;
}

.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
}

.tree {
  max-height: 340px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0;
}

.tree ul {
  list-style: none;
  margin: 0;
  padding-left: 16px;
}

.tree > ul {
  padding-left: 0;
}

.tree li {
  margin: 4px 0;
}

.tree label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
}

.field-row {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin: 8px 0;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #46505c;
  cursor: pointer;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  outline: none;
  background: #fff;
}

input[type="checkbox"] {
  width: auto;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
}

.msg-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 10px 0;
}

.hidden {
  display: none;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.tabs button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  font: inherit;
  color: #46505c;
}

.tabs button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn {
  border-radius: 8px;
  padding: 9px 18px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font: inherit;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.actions .btn.ghost {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary);
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.preview,
.send-state {
  margin-top: 10px;
  font-size: 13px;
  color: #46505c;
  white-space: pre-wrap;
}

.advanced {
  margin: 10px 0;
  font-size: 12px;
}

.advanced summary {
  cursor: pointer;
  color: var(--muted);
}

.advanced textarea {
  margin: 8px 0;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

.status {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.status.success {
  background: #e7f6ee;
  color: var(--success);
}

.status.failed {
  background: #fdecec;
  color: var(--danger);
}

.status.partial {
  background: #fdf3e2;
  color: var(--warn);
}

.status.running,
.status.pending {
  background: var(--primary-soft);
  color: var(--primary);
}

@media (max-width: 980px) {
  .layout-inner {
    grid-template-columns: 1fr;
  }
}

/* ---------- 移动端适配 ---------- */
@media (max-width: 768px) {
  body {
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }

  .logo {
    width: 34px;
    height: 34px;
    font-size: 17px;
    border-radius: 9px;
  }

  .topbar h1 {
    font-size: 16px;
  }

  .topbar p {
    font-size: 11px;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .topbar-right .btn {
    padding: 6px 12px;
  }

  /* 页签横向滚动，不换行挤压 */
  .tabs-nav {
    padding: 8px 14px;
    gap: 8px;
    background: var(--bg);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tabs-nav::-webkit-scrollbar {
    display: none;
  }

  .tabs-nav button {
    flex: 0 0 auto;
    padding: 8px 14px;
    white-space: nowrap;
  }

  .tab-panel {
    padding: 12px 14px calc(24px + env(safe-area-inset-bottom));
  }

  .card {
    padding: 14px;
    margin-bottom: 12px;
  }

  .card.full {
    margin: 0 14px 14px;
  }

  .panel-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .panel-head h2,
  .card > h2 {
    margin: 0 0 10px;
    font-size: 15px;
  }

  /* 表单全部单列铺满 */
  .field-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 10px 0;
  }

  .inline-select,
  .inline-input {
    width: 100%;
    min-width: 0;
    flex: 1 1 100%;
  }

  .field-row > .btn {
    width: 100%;
  }

  /* 触控友好：输入框 16px 防 iOS 自动放大，按钮 44px 高 */
  input,
  textarea,
  select {
    font-size: 16px;
    padding: 10px 12px;
  }

  textarea {
    min-height: 96px;
  }

  .btn {
    min-height: 44px;
    padding: 10px 16px;
  }

  .topbar-right .btn {
    min-height: 32px;
  }

  .switch {
    min-height: 32px;
  }

  .actions {
    flex-direction: column-reverse;
    gap: 10px;
  }

  .actions .btn {
    width: 100%;
  }

  /* 站点卡片纵向排布 */
  .station-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }

  .station-ops {
    width: 100%;
  }

  .station-ops .btn {
    flex: 1 1 auto;
  }

  .ops {
    width: 100%;
  }

  .ops .btn {
    flex: 1 1 auto;
  }

  .route-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .layout-inner {
    grid-template-columns: 1fr;
  }

  .tree {
    max-height: 260px;
  }

  .tree ul {
    padding-left: 12px;
  }

  .tabs button {
    padding: 8px 12px;
  }

  /* 宽表在卡片内横向滚动，不撑破页面 */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px;
  }

  table {
    min-width: 560px;
    font-size: 13px;
  }

  th,
  td {
    padding: 8px 10px;
  }

  .login-box {
    width: calc(100vw - 40px);
    max-width: 360px;
    padding: 20px;
  }

  .preview,
  .send-state {
    font-size: 13px;
    word-break: break-word;
  }
}

@media (max-width: 400px) {
  .topbar {
    align-items: stretch;
  }

  .topbar-right {
    flex-wrap: wrap;
  }

  .station-index {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
}
