/* 客户短信系统 —— 自包含样式（无外部字体、无 CDN） */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f6ef7;
  --primary-dark: #3d5ae0;
  --danger: #e5484d;
  --success: #2ca42a;
  --warning: #f5a623;
  --text: #23272f;
  --text-2: #5c6470;
  --text-3: #9aa3af;
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e3e7ee;
  --radius: 10px;
  --sidebar-w: 220px;
  font-size: 15px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f6ef7 0%, #6a5af9 100%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px 36px;
  width: 360px; max-width: 92vw; box-shadow: 0 20px 60px rgba(20, 30, 80, .35);
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 16px;
  background: var(--primary); color: #fff; font-size: 26px; font-weight: 700;
  border-radius: 16px; display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-sub { color: var(--text-3); font-size: 13px; margin-bottom: 24px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 15px; margin-bottom: 14px; outline: none;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,.15); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: #20293a; color: #cdd5e3;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 20px 18px; font-size: 16px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08); white-space: nowrap;
}
.nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin: 2px 0; border-radius: 8px;
  color: #cdd5e3; text-decoration: none; font-size: 14.5px;
  transition: background .15s;
}
.nav a span { width: 20px; text-align: center; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page h2.page-title { font-size: 20px; margin-bottom: 4px; }
.page .page-desc { color: var(--text-2); font-size: 13.5px; margin-bottom: 20px; }

/* ---------- 通用组件 ---------- */
.btn {
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  padding: 9px 16px; font-size: 14px; font-family: inherit;
  background: #e9edf4; color: var(--text); transition: filter .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: #cdd5e3; border-color: rgba(255,255,255,.25); }
.btn-ghost:hover { background: rgba(255,255,255,.1); color: #fff; }
.btn-outline { background: #fff; border-color: var(--border); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
}
.card h3 { font-size: 15.5px; margin-bottom: 14px; }

input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  outline: none; background: #fff;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,.12);
}
textarea { resize: vertical; min-height: 84px; width: 100%; }

.form-item { margin-bottom: 14px; }
.form-item label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.form-item input, .form-item select { width: 100%; }
.form-row { display: flex; gap: 14px; }
.form-row .form-item { flex: 1; }
.form-hint { font-size: 12px; color: var(--text-3); margin-top: 5px; line-height: 1.5; }

/* 统计卡片 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card .stat-label { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; padding: 10px 12px; color: var(--text-2); font-size: 12.5px;
  border-bottom: 2px solid var(--border); white-space: nowrap; background: #fafbfd;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: #f8f9fc; }
.tbl .empty-row td { text-align: center; color: var(--text-3); padding: 36px 0; }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 500;
}
.tag-green { background: #e6f6e6; color: var(--success); }
.tag-red { background: #fdeaea; color: var(--danger); }
.tag-gray { background: #eef0f4; color: var(--text-2); }
.tag-blue { background: #e8edfe; color: var(--primary); }
.tag-orange { background: #fdf3e0; color: #b97b0a; }

/* 工具条 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; font-size: 13px; color: var(--text-2); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(18, 24, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; width: 560px; max-width: 96vw;
  max-height: 88vh; overflow-y: auto; padding: 24px;
  box-shadow: 0 24px 70px rgba(15, 22, 50, .3);
}
.modal.wide { width: 760px; }
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* 提示条 */
.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #fff; border-radius: 10px; padding: 12px 18px; font-size: 14px;
  box-shadow: 0 10px 34px rgba(15, 22, 50, .22); border-left: 4px solid var(--primary);
  max-width: 360px; animation: slidein .2s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 模板卡片 */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.tpl-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
}
.tpl-card .tpl-head { display: flex; align-items: center; gap: 8px; }
.tpl-card .tpl-name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-card .tpl-content { font-size: 13px; color: var(--text-2); line-height: 1.6; flex: 1; }
.tpl-card .tpl-foot { display: flex; align-items: center; justify-content: space-between; }

/* 发送相关 */
.target-box {
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 14px; max-height: 300px; overflow-y: auto; background: #fafbfd;
}
.target-item { display: flex; align-items: center; gap: 10px; padding: 7px 6px; font-size: 14px; border-bottom: 1px solid #eef1f6; }
.target-item:last-child { border-bottom: none; }
.target-item .t-name { flex: 1; }
.preview-box {
  background: #f6f8fc; border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-all;
}
.vars-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }

/* 空状态 */
.empty-state { text-align: center; color: var(--text-3); padding: 48px 0; font-size: 14px; }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }

/* 设置页提示条 */
.notice {
  background: #fff8e6; border: 1px solid #f3e0a8; color: #8a6d1a;
  border-radius: 8px; padding: 12px 16px; font-size: 13.5px; line-height: 1.7; margin-bottom: 16px;
}
.notice.blue { background: #e9f0fe; border-color: #b9cdfa; color: #2c4bb0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { word-break: break-all; }

/* 进度条 */
.progress { height: 8px; background: #e9edf4; border-radius: 6px; overflow: hidden; margin: 10px 0; }
.progress-bar { height: 100%; background: var(--primary); width: 0; transition: width .2s; }

/* ---------- 响应式 ---------- */
/* 平板：横向导航 */
@media (max-width: 1000px) and (min-width: 769px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { display: flex; overflow-x: auto; padding: 6px; }
  .nav a { white-space: nowrap; margin: 0 2px; padding: 8px 10px; font-size: 13px; }
  .brand { padding: 12px 16px; }
  .sidebar-footer { padding: 8px 14px 12px; }
  .main { padding: 16px 14px 40px; }
  .form-row { flex-direction: column; gap: 0; }
}

/* 手机（H5 / 微信）：底部标签栏 + 全宽控件 */
@media (max-width: 768px) {
  :root { font-size: 14px; }
  .app { flex-direction: column; }

  /* 侧边栏 → 固定底部标签栏（微信风格，适配 iPhone 底部安全区） */
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; height: auto; z-index: 100;
    background: #fff; color: var(--text);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 14px rgba(20, 30, 60, .08);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .brand, .sidebar-footer { display: none; }
  .nav {
    display: flex; flex-wrap: nowrap; overflow-x: auto;
    padding: 4px 2px 2px; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a {
    flex: 1 0 auto; flex-direction: column; gap: 2px; align-items: center;
    min-width: 48px; padding: 5px 2px 4px; margin: 0;
    font-size: 10px; white-space: nowrap; border-radius: 8px;
    color: var(--text-2);
  }
  .nav a span { width: auto; font-size: 18px; line-height: 1.2; }
  .nav a.active { background: transparent; color: var(--primary); font-weight: 600; }

  /* 主内容区留出底部栏高度 */
  .main { padding: 14px 12px calc(92px + env(safe-area-inset-bottom, 0)); }

  /* 工具栏竖排：搜索框全宽，按钮一行铺开 */
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .toolbar input, .toolbar select { width: 100% !important; grid-column: 1 / -1; }
  .toolbar .grow { display: none; }
  .toolbar .btn { min-height: 40px; }

  /* 表格：横向滑动 + 不压缩关键列 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tbl { min-width: 640px; }
  .tbl th, .tbl td { padding: 9px 10px; font-size: 13px; }
  .tbl .btn-sm { padding: 5px 10px; }

  /* 弹窗全宽、按钮加大便于触控 */
  .modal { width: calc(100vw - 24px); max-width: 100%; border-radius: 14px; padding: 18px 14px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1; min-height: 42px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }

  /* 表单行竖排 */
  .form-row { flex-direction: column; gap: 0; }
  input, select, textarea { font-size: 16px; } /* ≥16px 防止 iOS 聚焦自动放大 */

  /* 登录卡片适配 */
  .login-card { width: 100%; max-width: 100%; margin: 12px; border-radius: 14px; padding: 32px 22px; }

  /* toast 居顶全宽 */
  .toast-wrap { left: 12px; right: 12px; top: 12px; align-items: stretch; }
  .toast { text-align: center; }

  /* 统计卡片两列、模板/变量网格单列 */
  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .tpl-grid { grid-template-columns: 1fr !important; }
  .vars-grid { grid-template-columns: 1fr !important; }

  /* 分页按钮加大触控 */
  .pager .btn { min-width: 40px; min-height: 38px; }
}
