:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #dbeafe;
  --success:       #16a34a;
  --danger:        #dc2626;
  --warning:       #d97706;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --radius:        8px;
  --shadow:        0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:     0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
               'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: var(--primary);
  color: #fff;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: .75rem;
}
.header-title { font-size: 1.05rem; font-weight: 700; white-space: nowrap; }
.header-sub   { font-size: .8rem; opacity: .75; margin-top: 1px; }
.header-nav   { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }
.user-chip     {
  font-size: .8rem; color: rgba(255,255,255,.85);
  background: rgba(255,255,255,.15);
  border-radius: 20px; padding: .2rem .7rem;
  white-space: nowrap;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem .9rem;
  border-radius: var(--radius); border: none; cursor: pointer;
  font-size: .85rem; font-weight: 500; text-decoration: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap; font-family: inherit;
}
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover  { background: #b91c1c; }
.btn-outline  { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.5); }
.btn-outline:hover { background: rgba(255,255,255,.15); }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm   { padding: .25rem .6rem; font-size: .78rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ── Container ── */
.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem; }

/* ── Card ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.25rem;
}
.card-header {
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.card-title { font-size: .95rem; font-weight: 600; }
.card-body  { padding: 1.25rem; }

/* ── Form ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .875rem;
}
.form-group        { display: flex; flex-direction: column; gap: .3rem; }
.form-group.full   { grid-column: 1 / -1; }
.form-label        { font-size: .85rem; font-weight: 500; }
.form-label .req   { color: var(--danger); margin-left: 2px; }
.form-control {
  padding: .575rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem; color: var(--text);
  background: #fff; width: 100%; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control[readonly] { background: #f8fafc; color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  background: #f8fafc;
  padding: .7rem 1rem;
  text-align: left; font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.cell-wrap {
  max-width: 200px; word-break: break-all;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1;
  overflow: hidden;
}
tr.data-row { cursor: pointer; }
.td-actions { white-space: nowrap; vertical-align: middle; }
tr.data-row.expanded td,
tr.data-row.expanded:hover td { background: #eff6ff; }
tr.data-row.expanded .cell-wrap { display: block; overflow: visible; }
/* 有复查记录时：数据行底部线去掉，和复查行合为一体 */
tr.data-row:has(+ tr.review-row.loaded) td { border-bottom: none; }
/* 数据行展开时复查行也变蓝色背景 */
tr.data-row.expanded + tr.review-row td { background: #eff6ff !important; }
/* 数据行hover时复查行也跟着高亮 */
tr.data-row:hover + tr.review-row.loaded td { background: #f8fafc !important; }
.nowrap { white-space: nowrap; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-icon  { font-size: 2.5rem; margin-bottom: .75rem; }

/* ── Alert ── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); font-size: .875rem; margin-bottom: 1rem; }
.alert-danger  { background: #fef2f2; color: var(--danger);  border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

/* ── Badge ── */
.badge { display: inline-block; padding: .15rem .55rem; border-radius: 20px; font-size: .75rem; font-weight: 500; }
.badge-blue   { background: var(--primary-light); color: var(--primary); }
.badge-green  { background: #dcfce7; color: var(--success); }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: #fff; border-radius: 12px;
  width: 100%; max-width: 620px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  transform: translateY(-16px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title  { font-size: 1rem; font-weight: 600; }
.modal-close  {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: var(--text-muted); line-height: 1; padding: .2rem;
}
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex; gap: .75rem; justify-content: flex-end;
}

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  padding: 1rem;
}
.login-card {
  background: #fff; border-radius: 14px;
  padding: 2.5rem 2rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo       { text-align: center; margin-bottom: 1.75rem; }
.login-logo h1    { font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.login-logo p     { color: var(--text-muted); font-size: .875rem; margin-top: .25rem; }
.login-logo .icon { font-size: 2.5rem; margin-bottom: .5rem; }

/* ── Filters bar ── */
.filters {
  display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end;
  padding: .875rem 1.25rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.filters .form-group { min-width: 140px; flex: 1 1 140px; }
.filters .form-label { font-size: .8rem; }
.filters .btn { align-self: flex-end; }

/* ── Stat chips ── */
.stat-row { display: flex; gap: .75rem; flex-wrap: wrap; padding: .75rem 1.25rem; background: var(--primary-light); }
.stat-chip { font-size: .8rem; color: var(--primary); font-weight: 500; }
.stat-chip strong { font-size: 1.1rem; }

/* ── Date separator ── */
.date-sep {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem 1rem;
  font-size: .8rem; font-weight: 600; color: var(--text-muted);
  background: #f8fafc; border-bottom: 1px solid var(--border);
}
.date-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Responsive table → cards on mobile ── */
@media (max-width: 720px) {
  .hide-sm { display: none !important; }

  table, thead, tbody, th, td, tr { display: block; }
  thead tr { position: absolute; top: -9999px; left: -9999px; }

  tr.data-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: .75rem;
    padding: .75rem 1rem;
  }
  tr.data-row:hover { background: #f8fafc; }
  tr.data-row td { border: none; padding: .3rem 0; display: flex; gap: .5rem; }
  tr.data-row td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--text-muted);
    font-size: .8rem; min-width: 72px; flex-shrink: 0;
  }
  tr.data-row td.td-actions { justify-content: flex-start; padding-top: .5rem; border-top: 1px solid var(--border); margin-top: .25rem; }
  tr.data-row td.td-actions::before { display: none; }
  .cell-wrap { max-width: none; }
  .table-wrap table { overflow: visible; }
}

/* ── Mobile-only utility ── */
.show-sm { display: none; }

@media (max-width: 720px) {
  /* Show-sm: visible only on mobile */
  .show-sm { display: inline !important; }
  /* Expanded row reveals hide-sm columns */
  tr.data-row.expanded td.hide-sm { display: flex !important; }
  /* Admin: #/日期/团队/姓名/代理线 on one line */
  .tbl-admin tr.data-row td:nth-child(-n+5) {
    display: inline-flex !important; align-items: center;
    padding: .15rem 0; border: none;
  }
  .tbl-admin tr.data-row td:nth-child(1)::before { content: ''; min-width: 0; }
  .tbl-admin tr.data-row td:nth-child(2)::before,
  .tbl-admin tr.data-row td:nth-child(3)::before,
  .tbl-admin tr.data-row td:nth-child(4)::before {
    content: ' · '; min-width: 0; font-weight: normal;
  }
  .tbl-admin tr.data-row td:nth-child(5)::before {
    content: ' · 代理线 '; min-width: 0; font-weight: normal; color: var(--text-muted);
  }
  /* History table: # · 日期 · 团队 · 姓名 · 代理线 值 */
  .tbl-history tr.data-row td:nth-child(-n+5) {
    display: inline-flex !important; align-items: center;
    padding: .15rem 0; border: none;
  }
  .tbl-history tr.data-row td:nth-child(1)::before { content: ''; min-width: 0; }
  .tbl-history tr.data-row td:nth-child(2)::before,
  .tbl-history tr.data-row td:nth-child(3)::before,
  .tbl-history tr.data-row td:nth-child(4)::before { content: ' · '; min-width: 0; font-weight: normal; }
  .tbl-history tr.data-row td:nth-child(5)::before {
    content: ' · 代理线 '; min-width: 0; font-weight: normal; color: var(--text-muted);
  }
  /* Dashboard table: # · 日期 · 团队 · 姓名 · 代理线 值 */
  .tbl-dash tr.data-row td:nth-child(-n+5) {
    display: inline-flex !important; align-items: center;
    padding: .15rem 0; border: none;
  }
  .tbl-dash tr.data-row td:nth-child(1)::before { content: ''; min-width: 0; }
  .tbl-dash tr.data-row td:nth-child(2)::before,
  .tbl-dash tr.data-row td:nth-child(3)::before,
  .tbl-dash tr.data-row td:nth-child(4)::before { content: ' · '; min-width: 0; font-weight: normal; }
  .tbl-dash tr.data-row td:nth-child(5)::before {
    content: ' · 代理线 '; min-width: 0; font-weight: normal; color: var(--text-muted);
  }
}

@media (max-width: 480px) {
  .header-title { font-size: .95rem; }
  .btn { padding: .4rem .7rem; font-size: .82rem; }
  .card-body { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .modal-body, .modal-footer { padding: 1rem; }
}

/* ── Review rows ── */
.review-row          { display: none; }
.review-row.loaded   { display: table-row; }
.review-cell {
  padding: .1rem 1rem .5rem 2.5rem !important;
  background: #fff !important;
  border-bottom: 1px solid var(--border) !important;
  max-width: 0 !important;
  overflow: hidden !important;
}
.review-list { display: flex; flex-direction: column; gap: .3rem; padding: .15rem 0; }
.review-item {
  display: flex !important;
  align-items: flex-start;
  overflow: hidden;
  gap: .75rem;
  padding: .25rem .5rem .25rem .6rem;
  border-left: 3px solid var(--primary);
  background: #fff;
  border-radius: 0 4px 4px 0;
  font-size: .82rem;
  line-height: 1.55;
}
.review-date {
  font-size: .78rem; font-weight: 700; color: var(--primary);
  white-space: nowrap; flex-shrink: 0; min-width: 58px; padding-top: .05rem;
}
.review-content {
  color: var(--text); flex: 1; min-width: 0;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
/* <br> 默认隐藏，折叠时只显示一行 */
.review-content br { display: none; }
/* 点击数据行展开时，复查内容也完整显示 */
tr.data-row.expanded + tr.review-row .review-content {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
}
tr.data-row.expanded + tr.review-row .review-content br { display: inline; }
.review-actions { display: flex; gap: .2rem; flex-shrink: 0; opacity: 0; transition: opacity .15s; }
.review-item:hover .review-actions { opacity: 1; }
.btn-xs { padding: .1rem .35rem !important; font-size: .72rem !important; line-height: 1.5 !important; }
.review-empty { font-size: .8rem; color: var(--text-muted); }

@media (max-width: 720px) {
  .review-row.loaded { display: block; }
  .review-row td {
    display: block !important;
    padding: 0 !important;
    border: none !important;
  }
  .review-cell { padding: .3rem .75rem .4rem 1rem !important; max-width: none !important; overflow: visible !important; }
  .review-item { display: flex !important; }
  .review-actions { opacity: 1; }
}
