/* ===== 自托管 CRM v1.3 —— 全新视觉体系（零外部资源） ===== */
:root {
  --primary: #4f6ef7;
  --primary-2: #6a83ff;
  --primary-dark: #3b56d9;
  --primary-soft: #eef1fe;
  --danger: #ef5350;
  --danger-soft: #fdeceb;
  --warn: #f5a623;
  --warn-soft: #fef4e3;
  --ok: #10b48a;
  --ok-soft: #e6f7f1;
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #232a3d;
  --muted: #7b8394;
  --border: #e6e9f2;
  --sidebar-1: #1c2337;
  --sidebar-2: #273052;
  --sidebar-text: #a7b0c7;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(28, 35, 55, .04), 0 6px 20px rgba(28, 35, 55, .07);
  --shadow-lg: 0 12px 40px rgba(28, 35, 55, .16);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h3 { font-size: 15px; font-weight: 600; }
::selection { background: rgba(79,110,247,.2); }

/* ---- 登录 ---- */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1c2337 0%, #2c3a6e 45%, #4f6ef7 130%); position: relative; overflow: hidden; }
.login-page::before { content: ""; position: absolute; width: 560px; height: 560px; border-radius: 50%; background: radial-gradient(circle, rgba(106,131,255,.25), transparent 65%); top: -180px; right: -140px; }
.login-page::after { content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(16,180,138,.14), transparent 65%); bottom: -140px; left: -110px; }
.login-card { position: relative; z-index: 1; background: rgba(255,255,255,.97); backdrop-filter: blur(10px); padding: 44px 38px 36px; border-radius: 20px; width: 380px; max-width: calc(100vw - 32px); box-shadow: 0 24px 70px rgba(10, 16, 38, .45); text-align: center; }
.login-logo { font-size: 46px; filter: drop-shadow(0 6px 14px rgba(79,110,247,.35)); }
.login-card h1 { font-size: 21px; margin: 10px 0 4px; letter-spacing: .5px; }
.login-sub { color: var(--muted); margin-bottom: 26px; font-size: 13px; }
.login-card input { width: 100%; margin-bottom: 12px; padding: 11px 12px; }
.login-card .btn { padding: 11px; font-size: 15px; letter-spacing: 6px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

/* ---- 布局 ---- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 208px; background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2)); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { font-size: 17px; font-weight: 700; color: #fff; padding: 22px 20px 16px; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.sidebar-brand::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, rgba(255,255,255,.16), transparent); margin-left: 8px; }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 8px 12px; }
.sidebar-nav a { color: var(--sidebar-text); padding: 10px 13px; border-radius: 10px; font-size: 14px; display: flex; align-items: center; transition: all .15s; }
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; transform: translateX(2px); }
.sidebar-nav a.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 6px 16px rgba(79,110,247,.35); }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.whoami { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1; padding: 26px 30px 40px; max-width: 1200px; min-width: 0; }

/* ---- 通用 ---- */
h2.page-title { font-size: 21px; margin-bottom: 4px; font-weight: 700; letter-spacing: .3px; }
.page-sub { color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; border: 1px solid rgba(230,233,242,.6); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.mt { margin-top: 14px; }
.muted { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

input, select, textarea {
  font: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 11px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,.14); }
textarea { width: 100%; resize: vertical; }

.btn { font: inherit; border: none; border-radius: var(--radius-sm); padding: 8px 16px; cursor: pointer; background: #edf0f7; color: var(--text); transition: all .15s; white-space: nowrap; font-weight: 500; }
.btn:hover { filter: brightness(.95); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 4px 12px rgba(79,110,247,.3); }
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); filter: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ok { background: linear-gradient(135deg, #10b48a, #26c79d); color: #fff; }
.btn-ghost { background: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(128,140,170,.15); filter: none; }
.btn-sm { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---- 表格（桌面） ---- */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 10px; background: #f7f8fc; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th:first-child { border-radius: 8px 0 0 8px; }
.tbl th:last-child { border-radius: 0 8px 8px 0; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: #f8f9fe; }

/* ---- 标签 ---- */
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 10px; border-radius: 20px; color: #fff; margin: 2px 4px 2px 0; font-weight: 500; }
.tag .x { cursor: pointer; opacity: .75; font-style: normal; }
.tag .x:hover { opacity: 1; }
.tag-add { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 10px; border-radius: 20px; border: 1px dashed #b9c2d6; color: var(--muted); cursor: pointer; margin: 2px 0; background: #fff; transition: all .15s; }
.tag-add:hover { border-color: var(--primary); color: var(--primary); }

/* ---- 仪表盘 ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 13px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; border: 1px solid rgba(230,233,242,.6); position: relative; overflow: hidden; transition: transform .15s; }
.stat:hover { transform: translateY(-2px); }
.stat::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 3px; background: linear-gradient(90deg, var(--primary), var(--primary-2)); opacity: 0; transition: opacity .15s; }
.stat:hover::after { opacity: 1; }
.stat .num { font-size: 27px; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; }
.stat .num.red { color: var(--danger); }
.stat .num.blue { color: var(--primary); }
.stat .num.green { color: var(--ok); }
.stat .num.orange { color: var(--warn); }
.reminder-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 6px; border-bottom: 1px solid var(--border); }
.reminder-item:last-child { border-bottom: none; }
.reminder-item .r-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.badge { font-size: 11px; padding: 2px 9px; border-radius: 10px; white-space: nowrap; font-weight: 500; }
.badge.urgent { background: var(--danger-soft); color: var(--danger); }
.badge.normal { background: var(--warn-soft); color: #c07d10; }
.badge.done { background: var(--ok-soft); color: var(--ok); }

/* ---- 图表 ---- */
.chart-wrap { display: flex; justify-content: space-between; align-items: flex-end; gap: 6px; padding: 10px 4px 0; min-height: 130px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-bars { display: flex; align-items: flex-end; gap: 5px; height: 96px; }
.bar { width: 16px; border-radius: 5px 5px 2px 2px; min-height: 4px; transition: height .4s ease; }
.bar-blue { background: linear-gradient(180deg, #7b93ff, var(--primary)); }
.bar-green { background: linear-gradient(180deg, #4fd8b8, var(--ok)); }
.chart-label { font-size: 11px; color: var(--muted); }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-right: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-blue { background: var(--primary); }
.dot-green { background: var(--ok); }
input[type=color] { border: 1px solid var(--border); background: #fff; border-radius: 8px; cursor: pointer; padding: 2px; }

/* ---- 智能录入 ---- */
.drop-zone { border: 2px dashed #c3cbdd; border-radius: var(--radius); padding: 46px 20px; text-align: center; cursor: pointer; background: linear-gradient(180deg, #fafbfe, #f6f8fd); transition: .15s; }
.drop-zone:hover, .drop-zone.drag { border-color: var(--primary); background: var(--primary-soft); }
.drop-zone .dz-icon { font-size: 42px; }
.drop-zone p { color: var(--muted); margin-top: 8px; }
.ocr-progress { margin-top: 14px; }
.progress-bar { height: 8px; background: #e8ecf5; border-radius: 6px; overflow: hidden; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); width: 0; transition: width .2s; border-radius: 6px; }
.preview-img { max-width: 300px; max-height: 190px; border-radius: 12px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-top: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.field { min-width: 0; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field input, .field select { width: 100%; }
.raw-text { background: #f6f8fc; border-radius: 10px; padding: 10px 12px; font-size: 12px; max-height: 130px; overflow: auto; white-space: pre-wrap; color: var(--muted); }

/* ---- 弹窗 ---- */
.modal-mask { position: fixed; inset: 0; background: rgba(23, 29, 48, .5); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 18px; width: 580px; max-width: 100%; max-height: 90vh; overflow: auto; padding: 26px; box-shadow: var(--shadow-lg); animation: modalin .18s ease; }
@keyframes modalin { from { transform: translateY(14px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { margin-bottom: 16px; font-size: 17px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---- Toast ---- */
.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: rgba(28, 35, 55, .92); backdrop-filter: blur(6px); color: #fff; padding: 11px 18px; border-radius: 11px; box-shadow: var(--shadow-lg); animation: slidein .22s ease; font-size: 13px; max-width: min(340px, calc(100vw - 36px)); }
.toast.err { background: rgba(229, 83, 80, .94); }
.toast.ok { background: rgba(16, 180, 138, .94); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.empty { text-align: center; color: var(--muted); padding: 38px 0; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
code.k { background: var(--primary-soft); color: var(--primary-dark); padding: 3px 8px; border-radius: 6px; font-size: 12px; user-select: all; word-break: break-all; }
.search-input { min-width: 200px; flex: 1; max-width: 320px; }

/* ================= 移动端适配 ================= */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 50; flex-direction: row; align-items: center; box-shadow: var(--shadow); }
  .sidebar-brand { padding: 14px 16px; font-size: 16px; }
  .sidebar-brand::after { display: none; }
  .sidebar-nav { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 6px 10px; gap: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .sidebar-nav a { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .sidebar-nav a:hover { transform: none; }
  .sidebar-footer { border-top: none; padding: 10px 14px; }
  .main { padding: 16px 14px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat .num { font-size: 22px; }
  .card { padding: 16px 14px; border-radius: 12px; }
  .row { gap: 8px; }
  .search-input { min-width: 0; width: 100%; }
  .preview-img { max-width: 100%; }

  /* 表格 → 卡片式布局 */
  .tbl-wrap { overflow: visible; }
  .tbl thead { display: none; }
  .tbl, .tbl tbody { display: block; width: 100%; }
  .tbl tr { display: block; background: #fff; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; padding: 6px 14px; box-shadow: 0 1px 3px rgba(28,35,55,.05); }
  .tbl tbody tr:hover { background: #fff; }
  .tbl td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-bottom: 1px dashed var(--border); padding: 8px 0; text-align: right; }
  .tbl td:last-child { border-bottom: none; }
  .tbl td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 500; flex-shrink: 0; text-align: left; }
  .tbl td[data-label=""]::before, .tbl td.no-label::before { content: none; }
  .tbl td:last-child { flex-wrap: wrap; justify-content: flex-end; }
  .tbl td a { word-break: break-all; }

  .reminder-item { flex-wrap: wrap; }
  .reminder-item .r-title { flex-basis: 100%; order: 3; }
  .chart-bars { height: 70px; }
  .bar { width: 11px; }
  .modal { padding: 18px 16px; border-radius: 14px; }
  .modal .modal-actions .btn { flex: 1; }
  h2.page-title { font-size: 19px; }
}
