* {
  box-sizing: border-box;
}

:root {
  --brand: #2f6fed;
  --brand-dark: #245ac4;
  --border: #dcdfe6;
  --text: #303133;
  --text-sub: #909399;
  --bg: #f2f4f8;
  --danger: #f56c6c;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.view {
  height: 100vh;
  height: 100dvh;
}

/* ===== 登录 ===== */
#loginView {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.login-box {
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 28px 28px 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .08);
}

.login-box h1 {
  margin: 0 0 22px;
  font-size: 20px;
  text-align: center;
  font-weight: 600;
}

.form-row {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
}

.form-row label {
  width: 56px;
  flex: none;
  color: var(--text-sub);
}

.form-row input {
  flex: 1;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  font-size: 14px;
  transition: border-color .15s;
}

.form-row input:focus {
  border-color: var(--brand);
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  color: var(--text-sub);
}

.check-row input {
  cursor: pointer;
}

#loginView .check-row {
  margin: 4px 0 18px;
}

.btn {
  height: 34px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: all .15s;
}

.btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn.primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}

.btn.primary:disabled {
  opacity: .6;
  cursor: not-allowed;
}

.btn.block {
  width: 100%;
}

.btn.icon {
  width: 28px;
  height: 28px;
  padding: 0;
  line-height: 1;
  font-size: 18px;
  border: none;
  background: transparent;
  color: var(--text-sub);
}

.btn.icon:hover {
  color: var(--danger);
  background: transparent;
}

.msg {
  min-height: 20px;
  margin-top: 10px;
  text-align: center;
  color: var(--danger);
  font-size: 13px;
}

/* ===== 主界面 ===== */
#mainView {
  display: flex;
  flex-direction: column;
  background: #fff;
}

.titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 44px;
  padding: 0 14px;
  flex: none;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.title {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  flex: none;
  font-size: 13px;
  color: var(--text-sub);
}

.status.online {
  color: #22a06b;
}

.status.connecting {
  color: #e6a23c;
}

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

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 42px;
  padding: 0 14px;
  flex: none;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.count-info {
  font-size: 13px;
  color: var(--text-sub);
}

#logoutBtn {
  height: 28px;
  margin-left: auto;
  padding: 0 12px;
  font-size: 13px;
}

.table-wrap {
  position: relative;
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
  touch-action: manipulation;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
  font-weight: 600;
  color: var(--text-sub);
  background: #f7f8fa;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid #f0f1f3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody tr:hover td {
  background: #f5f8ff;
}

tbody tr.highlight td {
  background: var(--danger);
  color: #fff;
}

.col-index {
  width: 46px;
  color: var(--text-sub);
}

tbody tr.highlight .col-index {
  color: #fff;
}

.empty-tip {
  display: none;
  padding: 40px;
  text-align: center;
  color: var(--text-sub);
}

/* ===== 详情弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .35);
}

.modal-box {
  width: 480px;
  max-width: calc(100vw - 40px);
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.modal-box textarea {
  display: block;
  width: 100%;
  height: 180px;
  padding: 12px 14px;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

/* ===== 小屏 / 手机端适配 ===== */
@media (max-width: 640px) {
  .login-box {
    padding: 22px 20px 16px;
  }

  .login-box h1 {
    font-size: 18px;
    margin-bottom: 18px;
  }

  /* 表单控件 >= 16px，避免 iOS 聚焦时自动放大页面 */
  .form-row input,
  .btn {
    font-size: 16px;
  }

  .form-row input,
  .btn {
    height: 40px;
  }

  #logoutBtn {
    height: 36px;
    margin-left: 0;
  }

  .titlebar {
    height: 40px;
    padding: 0 10px;
  }

  .title {
    font-size: 13px;
  }

  .status {
    font-size: 12px;
  }

  .toolbar {
    height: auto;
    min-height: 40px;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 8px 10px;
  }

  thead th {
    padding: 8px;
  }

  tbody td {
    padding: 7px 8px;
  }

  /* 详情弹窗：手机端全屏展示 */
  .modal {
    align-items: stretch;
  }

  .modal-box {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .modal-head {
    padding: 8px 8px 8px 14px;
  }

  /* 放大关闭按钮热区，便于手指点击 */
  .btn.icon {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }

  .modal-box textarea {
    flex: 1;
    height: auto;
    font-size: 16px;
  }

  .modal-foot {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  }
}
