/* ========== 基础 ========== */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f6f8;
  color: #222;
  font-size: 14px;
  line-height: 1.55;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  cursor: pointer;
  border: 0;
  background: #2563eb;
  color: #fff;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 14px;
}
button:hover { background: #1d4ed8; }

.muted { color: #888; font-size: 13px; }
.mono { font-family: "SFMono-Regular", Consolas, "Courier New", monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ========== 顶部导航 ========== */
.topnav {
  display: flex;
  align-items: center;
  background: #1e293b;
  color: #fff;
  padding: 0 20px;
  height: 50px;
}
.topnav .brand { font-weight: 600; font-size: 16px; margin-right: 30px; }
.topnav .links { flex: 1; display: flex; gap: 4px; }
.topnav .links a {
  color: #cbd5e1;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.topnav .links a:hover { background: #334155; text-decoration: none; color: #fff; }
.topnav .links a.active { background: #2563eb; color: #fff; }
.topnav .logout button {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
  padding: 4px 12px;
  font-size: 13px;
}
.topnav .logout button:hover { background: #334155; }

/* v1.7 顶部"手动获取"按钮 */
.btn-refresh {
  background: #10b981;
  border: 0;
  color: #fff;
  padding: 4px 12px;
  margin-right: 10px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-refresh:hover { background: #059669; }
.btn-refresh:disabled { background: #6b7280; cursor: wait; }

/* ========== 主区域 ========== */
.container {
  max-width: min(1800px, 96vw);   /* v1.6: 大屏更宽,小屏自适应 */
  margin: 0 auto;
  padding: 20px;
}
h1 {
  font-size: 20px;
  margin: 0 0 16px 0;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
h1 .total { font-size: 13px; color: #888; font-weight: normal; }

/* ========== 过滤表单 ========== */
.filter {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.filter input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding: 7px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
}
.filter select {
  padding: 7px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
}
.btn-ghost {
  padding: 7px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #475569;
  font-size: 14px;
}
.btn-ghost:hover { background: #fff; text-decoration: none; }

/* ========== 消息表格 ========== */
.msg-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.msg-table th {
  background: #f8fafc;
  text-align: left;
  padding: 10px 14px;
  font-weight: 500;
  color: #64748b;
  font-size: 13px;
  border-bottom: 1px solid #e2e8f0;
}
.msg-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.msg-table tr:last-child td { border-bottom: 0; }
.msg-table tr:hover { background: #f8fafc; }
.msg-table tr.stale { background: #fef2f2; }
.msg-table tr.stale:hover { background: #fee2e2; }
.msg-table .empty { text-align: center; padding: 40px; color: #94a3b8; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.badge-sms       { background: #dbeafe; color: #1e40af; }
.badge-email     { background: #fef3c7; color: #92400e; }
.badge-ios       { background: #ede9fe; color: #5b21b6; }
.badge-android   { background: #d1fae5; color: #065f46; }
.badge-unknown   { background: #e2e8f0; color: #475569; }
.badge-status-ok      { background: #d1fae5; color: #065f46; }
.badge-status-error   { background: #fecaca; color: #991b1b; }
.badge-status-unknown { background: #e2e8f0; color: #475569; }

/* ========== 验证码胶囊 ========== */
.code-pill {
  display: inline-block;
  background: #2563eb;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  user-select: all;
  letter-spacing: 1px;
}
.code-pill:hover { background: #1d4ed8; }

.subject { font-weight: 500; margin-bottom: 4px; color: #334155; }
.body { color: #64748b; font-size: 13px; line-height: 1.5; }

.error-msg { color: #991b1b; font-size: 12px; max-width: 300px; word-break: break-all; }

/* ========== 分页 ========== */
.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  color: #64748b;
}
.pager a {
  padding: 6px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #475569;
}
.pager a:hover { background: #fff; text-decoration: none; }

/* ========== 登录页 ========== */
.login-bg {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  margin: 0;
}
.login-card {
  background: #fff;
  padding: 36px 40px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  width: 360px;
}
.login-card h1 {
  text-align: center;
  margin: 0 0 6px 0;
  font-size: 22px;
  display: block;
}
.login-card .muted { text-align: center; margin-bottom: 24px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #475569; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 15px;
}
.login-card input:focus { outline: none; border-color: #2563eb; }
.login-card button {
  margin-top: 10px;
  padding: 10px;
  font-size: 15px;
  font-weight: 500;
}
.login-card .error {
  background: #fee2e2;
  color: #991b1b;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ========== v1.3 新增:CRUD 表单 + Flash + 移动端 ========== */

.btn-primary {
  background: #2563eb;
  color: #fff;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 14px;
  border: 0;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-h1 { font-size: 13px; padding: 4px 12px; margin-left: 10px; vertical-align: middle; }

.btn-small {
  background: #f1f5f9;
  color: #475569;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
  margin-right: 4px;
}
.btn-small:hover { background: #e2e8f0; }
.btn-danger { color: #991b1b; border-color: #fecaca; background: #fef2f2; }
.btn-danger:hover { background: #fee2e2; }

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 13px;
}
.flash-ok  { background: #d1fae5; color: #065f46; }
.flash-err { background: #fee2e2; color: #991b1b; }

.actions { white-space: nowrap; }
.required { color: #dc2626; font-weight: 600; }

.badge-group { background: #ede9fe; color: #5b21b6; }
.filter-label { color: #64748b; font-size: 13px; margin-right: 4px; }

/* 编辑行展开 */
.edit-row td { background: #f8fafc !important; }
.edit-row:hover td { background: #f8fafc !important; }
.edit-form, .add-form { padding: 12px 8px; max-width: 600px; }
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 13px; color: #475569; font-weight: 500; }
.form-row input[type="text"], .form-row input[type="password"],
.form-row input[type="email"], .form-row input[type="number"] {
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}
.form-row.two-col { flex-direction: row; gap: 12px; }
.form-row.two-col > div { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.form-row-check label { flex-direction: row; align-items: center; display: flex; gap: 6px; }
.form-row-check input { margin: 0; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }

/* 模态对话框 */
dialog.modal {
  border: 0;
  border-radius: 10px;
  padding: 0;
  max-width: 540px;
  width: 90vw;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
dialog.modal::backdrop { background: rgba(0,0,0,0.4); }
dialog.modal h2 { margin: 0 0 16px 0; font-size: 18px; padding: 16px 20px 0; }
dialog.modal .add-form { padding: 0 20px 20px; }

/* ========== v1.4 设备表格(12 列宽布局 + tooltip) ========== */

.table-wrap {
  overflow-x: auto;     /* 桌面小屏自动横向滚动,不强压列宽 */
  -webkit-overflow-scrolling: touch;
}

.dev-table {
  table-layout: fixed;
  min-width: 1620px;    /* v1.6 微调,所有列舒展不挤压 */
}
/* v2.2 col-id + col-label 必须完整展示(原各 140/130px 固定截断)
 * 因为 .dev-table 是 table-layout:fixed,要给固定 width 才生效,不能 auto;
 * 又因为 .msg-table td 设了 nowrap,要在更具体 selector 加 normal override */
.dev-table .col-id {
  width: 260px;
  white-space: normal !important;
  word-break: break-all;
}
.dev-table .col-label {
  width: 220px;
  white-space: normal !important;
  word-break: break-all;
}

/* v2.2 徽章/标签 不换行(避免"短信"被截成"短\n信") */
.badge { white-space: nowrap; }

/* v2.2 messages 表表头 + 单元格 都不换行;只有"内容"列允许换行 */
.msg-table th,
.msg-table td { white-space: nowrap; }
.msg-table td[data-label="内容"],
.msg-table td.col-body,
.msg-table th[data-col="body"] { white-space: normal; word-break: break-word; }

/* v2.2 点击复制号码 */
.copyable {
  cursor: pointer;
  border-bottom: 1px dashed #888;
  transition: background .15s, border-color .15s;
  padding: 1px 2px;
}
.copyable:hover {
  background: rgba(91,141,239,.12);
  border-bottom-color: #5b8def;
}

/* 右下角 toast */
.copy-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: #2c3e50;
  color: #fff;
  padding: 10px 18px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  z-index: 9999;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.copy-toast.show { opacity: 1; transform: translateY(0); }

/* 双击就地编辑单元格 */
.editable { cursor: text; position: relative; }
.editable:hover { background: rgba(91,141,239,.06); }
.inline-edit-input {
  width: 95%;
  padding: 4px 6px;
  border: 1px solid #5b8def;
  border-radius: 3px;
  font-family: inherit;
  font-size: inherit;
  background: #fff;
}
textarea.inline-edit-input { min-height: 56px; resize: vertical; }

/* col-label 已在上方 v2.2 区域定义为 220px,这里不再覆盖 */
.dev-table .col-emp   { width: 90px;  }
.dev-table .col-plat  { width: 70px;  }
.dev-table .col-phone { width: 130px; }
.dev-table .col-note  { width: 200px; }
.dev-table .col-time  { width: 120px; }
.dev-table .col-act   { width: 130px; }

/* v1.6 邮箱表列宽控制(避免错误详情列吃掉所有空间) */
.mbox-table {
  table-layout: fixed;
}
.mbox-table .col-addr  { width: 220px; }
.mbox-table .col-label { width: 180px; }
.mbox-table .col-group { width: 100px; }
.mbox-table .col-stat  { width: 100px; }
.mbox-table .col-time  { width: 150px; }
.mbox-table .col-err   { width: 260px; }
.mbox-table .col-act   { width: 130px; }
.mbox-table .err-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: help;
}
.mbox-table .err-cell:hover { background: #fef2f2; }

/* v1.6 状态徽章更醒目 */
.badge-status-ok      { background: #d1fae5; color: #065f46; font-weight: 600; }
.badge-status-error   { background: #fecaca; color: #991b1b; font-weight: 600; }
.badge-status-paused  { background: #e2e8f0; color: #475569; }
.badge-status-unknown { background: #fef3c7; color: #92400e; }

/* 备注列:超过宽度时截断 + ... + 鼠标悬停看完整(title 原生 tooltip) */
.note-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  cursor: help;
}
.note-cell:hover { background: #f0f9ff; }

/* v1.9 列内容超出宽度时自动截断 + ... (设备 ID / 显示名 / 员工 / 邮箱地址 / 邮箱标签 / 主副卡号) */
/* table-layout:fixed 让列宽固定,加 overflow:hidden + text-overflow:ellipsis 触发省略 */
.dev-table td.col-id,
.dev-table td.col-label,
.dev-table td.col-emp,
.dev-table td.col-phone,
.mbox-table td.col-addr,
.mbox-table td.col-label,
.mbox-table td.col-group {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: help;
}
.dev-table td.col-id:hover,
.dev-table td.col-label:hover,
.dev-table td.col-emp:hover,
.dev-table td.col-phone:hover,
.mbox-table td.col-addr:hover,
.mbox-table td.col-label:hover,
.mbox-table td.col-group:hover { background: #f0f9ff; }

/* 表单 textarea */
.edit-form textarea, .add-form textarea {
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
  resize: vertical;
}
.edit-form-wide { max-width: 100%; }

/* 顶部搜索框 */
.filter input[type="text"]:focus { outline: none; border-color: #2563eb; }

/* ========== 移动端响应式(<=768px) ========== */
@media (max-width: 768px) {
  .container { padding: 10px; }
  h1 { font-size: 18px; flex-wrap: wrap; }
  .topnav { height: auto; padding: 8px; flex-wrap: wrap; }
  .topnav .brand { font-size: 14px; margin-right: 12px; }
  .topnav .links a { padding: 4px 8px; font-size: 13px; }

  /* 表格转卡片布局 */
  .msg-table { box-shadow: none; background: transparent; }
  .msg-table thead { display: none; }
  .msg-table tbody tr {
    display: block;
    background: #fff;
    margin-bottom: 12px;
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }
  .msg-table tbody tr.stale { background: #fef2f2; }
  .msg-table td {
    display: block;
    padding: 4px 0;
    border: 0;
    font-size: 13px;
  }
  .msg-table td::before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: #64748b;
    margin-right: 6px;
    display: inline-block;
    min-width: 70px;
  }
  .msg-table td.actions { padding-top: 8px; border-top: 1px solid #f1f5f9; margin-top: 6px; }
  .msg-table td.actions::before { display: none; }

  /* 表单两列变单列 */
  .form-row.two-col { flex-direction: column; }

  /* 验证码胶囊在手机上加大 */
  .code-pill { padding: 6px 14px; font-size: 16px; }

  /* v1.4 设备表移动端:取消固定宽度,note 不再截断,改成自然换行 */
  .table-wrap { overflow-x: visible; }
  .dev-table, .mbox-table { table-layout: auto; min-width: 0; }
  /* 用 .msg-table 前缀提升特异性,胜过桌面的 .mbox-table .err-cell 规则 */
  .msg-table .note-cell, .msg-table .err-cell {
    white-space: normal !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  /* 模态框 */
  dialog.modal { width: 95vw; }

  /* 过滤栏堆叠 */
  .filter { flex-direction: column; align-items: stretch; }
  .filter input, .filter select { width: 100%; }
}

/* 超窄屏(<=480px,大多数手机竖屏) */
@media (max-width: 480px) {
  .topnav .brand { display: none; }
  .topnav .logout button { padding: 2px 8px; font-size: 12px; }
  h1 .total { display: block; font-size: 12px; margin-top: 2px; }
  .btn-h1 { display: block; margin-top: 6px; margin-left: 0; }
}

/* v1.7 移动端隐藏导入导出和大表格相关功能 */
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
}

/* ========== v2.2.0 整体布局(左 sidebar + 右 main) ========== */
.app-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: #1e293b;
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 16px 0 12px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  padding: 0 18px 16px;
  font-weight: 600;
  font-size: 16px;
  border-bottom: 1px solid #334155;
  margin-bottom: 8px;
}
.sidebar .side-links {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}
.sidebar .side-links a {
  color: #cbd5e1;
  padding: 10px 18px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 3px solid transparent;
}
.sidebar .side-links a:hover {
  background: #334155;
  color: #fff;
  text-decoration: none;
}
.sidebar .side-links a.active {
  background: #0f172a;
  color: #fff;
  border-left-color: #2563eb;
}
.sidebar .side-links .icon { font-size: 16px; width: 18px; text-align: center; }
.sidebar .side-bottom {
  border-top: 1px solid #334155;
  padding: 12px 14px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar .btn-refresh {
  width: 100%;
  background: #10b981;
  color: #fff;
  border: 0;
  padding: 8px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.sidebar .btn-refresh:hover { background: #059669; }
.sidebar .btn-refresh:disabled { background: #6b7280; cursor: wait; }
.sidebar .logout button {
  width: 100%;
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
  padding: 7px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}
.sidebar .logout button:hover { background: #334155; color: #fff; }

.main-content {
  flex: 1;
  background: #f5f6f8;
  padding: 24px;
  overflow-x: auto;
  min-width: 0;
}

/* 移动端折叠为顶部水平条 */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 10px;
    gap: 8px;
    align-items: center;
  }
  .sidebar .brand { padding: 0; margin: 0; border: 0; }
  .sidebar .side-links { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .sidebar .side-links a { padding: 6px 10px; border-left: 0; border-bottom: 2px solid transparent; }
  .sidebar .side-links a.active { border-bottom-color: #2563eb; border-left: 0; }
  .sidebar .side-bottom { flex-direction: row; border: 0; padding: 0; margin-left: auto; }
  .sidebar .btn-refresh, .sidebar .logout button { width: auto; padding: 6px 12px; }
  .main-content { padding: 16px; }
}

/* ========== v2.2.0 二级 Tab(余额资费子页面) ========== */
.sub-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #e2e8f0;
  margin: -4px 0 16px 0;
  flex-wrap: wrap;
}
.sub-tabs a {
  padding: 8px 16px;
  color: #64748b;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: 14px;
}
.sub-tabs a:hover {
  color: #2563eb;
  background: #f1f5f9;
  text-decoration: none;
}
.sub-tabs a.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
  font-weight: 600;
}

/* ========== v2.2.0 余额资费表格细节 ========== */
.bal-table { table-layout: auto; }
.bal-table .col-narrow { width: 70px; }
.bal-table tr.row-failed { background: #f8fafc; color: #94a3b8; }
.bal-table td.balance-neg { color: #c0392b; font-weight: 700; }
.bal-table tr.card-secondary td:first-child { padding-left: 28px; color: #94a3b8; }
.bal-table tr.card-secondary { font-size: 13px; }

/* 顶部统计卡片(支出账单页用) */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-card .stat-label { font-size: 12px; color: #94a3b8; }
.stat-card .stat-value { font-size: 22px; font-weight: 600; color: #1e293b; margin-top: 4px; }

/* P0 stub 提示框 */
.stub-notice {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 14px 18px;
  border-radius: 8px;
  margin: 20px 0;
}
.stub-notice h2 { margin: 0 0 8px 0; font-size: 16px; color: #92400e; }

.row-querying {
  opacity: 0.5;
}
