/* CRM Lite 响应式样式：浅色主题、桌面侧边栏 + 表格、手机卡片列表 + 底部导航 */

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #e3e8f0;
  --text: #1c2536;
  --muted: #6b7688;
  --primary: #2f6bff;
  --primary-dark: #2255d6;
  --primary-soft: #eaf0ff;
  --success: #14875a;
  --success-soft: #e6f6ee;
  --warn: #b26a00;
  --warn-soft: #fff3e0;
  --info: #3a6ea5;
  --info-soft: #eaf2fb;
  --danger: #c0392b;
  --danger-soft: #fdeceb;
  --shadow: 0 2px 12px rgba(28, 37, 54, 0.06);
  --radius: 12px;
  --sidebar-width: 224px;
}

* { box-sizing: border-box; }

/* 必须置于所有布局规则之前：作者样式中的 display:flex 会覆盖 UA 的 [hidden] */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; margin-bottom: 12px; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: 12.5px; background: var(--surface-soft); padding: 2px 6px; border-radius: 5px; }
strong { font-weight: 650; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.icon { vertical-align: -3px; flex: 0 0 auto; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { border-color: #c9d3e4; background: var(--surface-soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: var(--surface); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); border-color: #f0c9c5; background: var(--surface); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.tiny { padding: 5px 9px; font-size: 12.5px; border-radius: 7px; }
.btn.block { width: 100%; }
.icon-btn { border: none; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.icon-btn:hover { color: var(--text); }

/* ---------------- 登录 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 48px;
  background: linear-gradient(160deg, #eef3ff 0%, #f5f7fb 55%, #f8fafc 100%);
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(47, 107, 255, .10);
  padding: 30px 28px 26px;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff;
}
.brand-login { margin-bottom: 22px; }
.login-title { font-size: 22px; }
.login-sub { font-size: 13px; margin-top: 6px; margin-bottom: 24px; }
.login-form { display: flex; flex-direction: column; gap: 4px; }

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 13px; color: #414c60; font-weight: 550; }
.form-row label em { color: var(--danger); font-style: normal; margin-left: 2px; }
.form-row input, .form-row select, .form-row textarea, .search-box input, .inline-label input, .inline-label select, .select-inline {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  min-height: 38px;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus,
.search-box input:focus, .inline-label input:focus, .inline-label select:focus, .select-inline:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 107, 255, .10);
}
.form-row textarea { resize: vertical; }
.field-hint { color: var(--muted); font-size: 12px; }
.static-value { border: 1px dashed var(--border); border-radius: 9px; padding: 9px 11px; background: var(--surface-soft); }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin: 2px 0 6px; }
.preview-line { color: var(--primary-dark); background: var(--primary-soft); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 2px 0 0; }

.demo-accounts {
  margin-top: 24px;
  border-top: 1px dashed var(--border);
  padding-top: 18px;
}
.demo-accounts h2 { font-size: 13.5px; margin-bottom: 10px; }
.demo-accounts-list { display: flex; flex-direction: column; gap: 7px; }
.demo-account {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  background: var(--surface-soft); border: 1px solid var(--border);
  border-radius: 9px; padding: 7px 9px; font-size: 12.5px;
}
.demo-account-label { color: var(--muted); min-width: 132px; }
.demo-sep { color: var(--muted); }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
}
.sidebar .brand { padding: 0 8px 22px; }
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; border: none; background: transparent;
  padding: 10px 12px; border-radius: 9px;
  color: #4c586c; font-size: 14px; font-family: inherit;
  cursor: pointer; text-align: left;
}
.nav-item:hover { background: var(--surface-soft); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 14px; }
.user-badge { font-size: 12.5px; color: var(--muted); margin-bottom: 10px; word-break: break-all; }

.content { flex: 1; min-width: 0; margin-left: var(--sidebar-width); padding: 22px 26px 48px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.topbar-text p { font-size: 12.5px; margin-top: 4px; }
.topbar-extra { flex: 0 0 auto; }
.view-root { display: flex; flex-direction: column; gap: 16px; }
.bottom-nav { display: none; }

/* ---------------- 卡片 / 指标 ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.note-card { background: linear-gradient(180deg, #f7faff 0%, #ffffff 100%); }
.note-card p { font-size: 13px; color: #45516a; margin-top: 6px; }
.warn-card { background: linear-gradient(180deg, #fffaf2 0%, #ffffff 100%); border-color: #f2dfc0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.metric-label { font-size: 12.5px; color: var(--muted); }
.metric-value { font-size: 20px; font-weight: 680; margin-top: 4px; letter-spacing: -.3px; word-break: break-all; }
.metric-hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* ---------------- 工具栏 ---------------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 0 11px; min-width: 240px; flex: 1 1 240px; color: var(--muted); }
.search-box input { border: none; box-shadow: none !important; padding-left: 0; min-height: 36px; }
.search-box input:focus { outline: none; }
.inline-label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.inline-label input, .inline-label select { min-width: 140px; }
.select-inline { width: auto; min-width: 160px; }
.filter-bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.segmented { display: inline-flex; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 3px; }
.seg { border: none; background: transparent; border-radius: 7px; padding: 6px 16px; font-size: 13.5px; font-family: inherit; color: var(--muted); cursor: pointer; }
.seg.active { background: var(--primary); color: #fff; font-weight: 600; }

/* ---------------- 表格（桌面） ---------------- */
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 12.5px; background: var(--surface-soft); white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #fafbfe; }
.data-table td { word-break: break-word; }
.row-ops { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { padding: 34px 12px; text-align: center; color: var(--muted); font-size: 13.5px; }
.loading { padding: 48px 12px; text-align: center; color: var(--muted); }
.error-box { padding: 18px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); border: 1px solid #f0c9c5; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; white-space: normal; }
.tag.ok { background: var(--success-soft); color: var(--success); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.info { background: var(--info-soft); color: var(--info); }

/* ---------------- 纯 CSS 条形图 ---------------- */
.bar-chart { display: flex; flex-direction: column; gap: 11px; margin-top: 8px; }
.bar-row { display: grid; grid-template-columns: 92px minmax(0, 1fr) 148px; align-items: center; gap: 10px; }
.bar-label { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-stack { display: flex; flex-direction: column; gap: 4px; }
.bar-track { height: 9px; background: #eef1f7; border-radius: 20px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 20px; transition: width .3s ease; }
.bar-fill.primary { background: var(--primary); }
.bar-fill.secondary { background: #8fb0ff; }
.bar-value { font-size: 12px; color: #4c586c; text-align: right; white-space: nowrap; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot.primary { background: var(--primary); }
.dot.secondary { background: #8fb0ff; }

/* ---------------- 弹窗 / 提示 ---------------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(21, 30, 48, .42);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh - 36px);
  overflow-y: auto; background: var(--surface);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(20, 30, 50, .24);
}
.modal-small { max-width: 400px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-form { padding: 16px 20px 4px; }
.modal-body { padding: 18px 20px 4px; }
.confirm-text { font-size: 14px; color: #3d495e; line-height: 1.7; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px 18px; }
.stack-form { margin-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 200; max-width: min(90vw, 480px);
  padding: 11px 18px; border-radius: 10px;
  background: #22304a; color: #fff; font-size: 13.5px;
  box-shadow: 0 8px 26px rgba(20, 30, 50, .28);
  text-align: center;
}
.toast.error { background: var(--danger); }
.toast.success { background: #1d7a54; }

/* ---------------- 手机端：卡片列表 + 底部导航 ---------------- */
@media (max-width: 768px) {
  body { font-size: 14px; }
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 16px 12px 92px; }
  .topbar { margin-bottom: 14px; }
  h1 { font-size: 18px; }
  .topbar-text p { font-size: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-value { font-size: 17px; }
  .card { padding: 14px; border-radius: 11px; }
  .view-root { gap: 12px; }
  .toolbar { gap: 8px; }
  .search-box { flex: 1 1 100%; min-width: 0; }
  .toolbar .btn { flex: 1 1 auto; }
  .select-inline { flex: 1 1 100%; width: 100%; }
  .filter-bar .inline-label { flex: 1 1 calc(50% - 5px); }
  .filter-bar .inline-label input, .filter-bar .inline-label select { min-width: 0; width: 100%; }

  /* 表格转卡片：用 data-label 伪元素显示列名 */
  .table-wrap { overflow: visible; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    margin-bottom: 10px;
    padding: 8px 12px;
  }
  .data-table tbody tr:last-child { margin-bottom: 0; }
  .data-table td {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 14px; padding: 6px 0; border: none;
    text-align: right; font-size: 13.5px;
  }
  .data-table td::before {
    content: attr(data-label);
    flex: 0 0 auto; color: var(--muted);
    font-size: 12.5px; font-weight: 550; text-align: left;
  }
  .data-table td:last-child { border-top: 1px dashed var(--border); margin-top: 4px; padding-top: 10px; }
  .row-ops { justify-content: flex-end; }
  .bar-row { grid-template-columns: 68px minmax(0, 1fr) 96px; gap: 7px; }
  .bar-value { font-size: 11px; }

  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -3px 16px rgba(28, 37, 54, .06);
  }
  .bottom-item {
    flex: 1 1 0; min-width: 0; border: none; background: transparent;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 5px 2px; color: var(--muted); font-size: 11px;
    font-family: inherit; cursor: pointer; white-space: nowrap;
  }
  .bottom-item span { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bottom-item.active { color: var(--primary); font-weight: 600; }
  .toast { bottom: 84px; }
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal { max-width: 100%; border-radius: 16px 16px 0 0; max-height: 88vh; }
  .login-wrap { align-items: flex-start; padding-top: 40px; }
  .login-card { padding: 24px 20px; border-radius: 14px; }
  .demo-account-label { min-width: 100%; }
}

@media (max-width: 380px) {
  .metrics { grid-template-columns: 1fr; }
  .bottom-item { font-size: 10px; }
}
