:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #68758c;
  --line: #e3e8f1;
  --brand: #3157d5;
  --brand-dark: #2445b4;
  --brand-soft: #eef2ff;
  --accent: #0d9488;
  --success: #11875d;
  --warning: #b76508;
  --danger: #c43d4d;
  --shadow: 0 16px 40px rgba(43, 57, 84, .08);
  --shadow-sm: 0 7px 22px rgba(43, 57, 84, .07);
  --radius: 18px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(49, 87, 213, .08), transparent 28rem),
    var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", Inter, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
button, input, select, textarea { font: inherit; }
button, .btn { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid rgba(227, 232, 241, .88);
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(18px);
}

.header-inner {
  width: min(1460px, calc(100% - 36px));
  min-height: 70px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #4f6fe2, #294cc6);
  box-shadow: 0 9px 20px rgba(49, 87, 213, .25);
}

.main-nav { display: flex; align-items: center; gap: 5px; }
.main-nav a {
  padding: 9px 12px;
  border-radius: 9px;
  color: #4d5b71;
  font-weight: 650;
  white-space: nowrap;
}
.main-nav a:hover, .main-nav a.active { color: var(--brand); background: var(--brand-soft); }

.header-account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.avatar {
  width: 33px;
  height: 33px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line);
}

.page-shell { width: min(1460px, calc(100% - 36px)); margin: 0 auto; padding: 34px 0 60px; }
.page-shell.narrow { width: min(900px, calc(100% - 36px)); }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 24px;
}

.eyebrow { margin: 0 0 5px; color: var(--brand); font-weight: 750; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
h1, h2, h3 { margin-top: 0; line-height: 1.25; letter-spacing: -.025em; }
h1 { margin-bottom: 6px; font-size: clamp(27px, 3vw, 38px); }
h2 { font-size: 23px; }
h3 { font-size: 17px; }
.subtitle { margin: 0; color: var(--muted); }

.status-pill, .tag, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-ready, .badge-completed, .tag-成交 { color: #087a52; background: #e8f7f0; }
.status-pending, .badge-queued, .badge-ringing, .badge-initiated { color: #9a5a07; background: #fff3dc; }
.status-off, .badge-failed, .badge-busy, .badge-no-answer, .badge-canceled { color: #b52f42; background: #feecef; }
.badge-in-progress, .badge-answered, .tag-沟通 { color: #2855c5; background: #edf2ff; }
.tag-潜在 { color: #a35806; background: #fff4dc; }
.tag-陌生, .tag-default { color: #586579; background: #edf0f5; }

.flash-stack { display: grid; gap: 10px; margin-bottom: 20px; }
.flash {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 15px;
  border: 1px solid;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  background: #fff;
}
.flash-success { color: #0b7250; border-color: #afe1cd; background: #effbf6; }
.flash-error { color: #a52f41; border-color: #f1bcc5; background: #fff3f5; }
.flash-warning { color: #905207; border-color: #efd39a; background: #fff9eb; }
.flash-message { color: #3157a8; border-color: #c4d2fb; background: #f2f5ff; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card {
  position: relative;
  overflow: hidden;
  min-height: 124px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.stat-card::after {
  content: "";
  position: absolute;
  right: -24px;
  bottom: -38px;
  width: 105px;
  height: 105px;
  border-radius: 50%;
  background: var(--stat-color, var(--brand-soft));
}
.stat-label { color: var(--muted); font-weight: 650; }
.stat-value { display: block; margin-top: 8px; font-size: 31px; line-height: 1; font-weight: 850; letter-spacing: -.04em; }
.stat-note { display: block; margin-top: 9px; color: var(--muted); font-size: 12px; }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 20px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2, .panel-head h3 { margin: 0; }
.panel-body { padding: 22px; }
.panel-foot { padding: 16px 22px; border-top: 1px solid var(--line); background: var(--surface-soft); border-radius: 0 0 var(--radius) var(--radius); }

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.toolbar .search-field { min-width: 280px; flex: 1 1 340px; }
.toolbar select { min-width: 160px; }

.field, .field-group { display: grid; gap: 7px; }
.field label, .field-group > label { color: #455269; font-size: 13px; font-weight: 700; }
.required::after { content: " *"; color: var(--danger); }

input, select, textarea {
  width: 100%;
  color: var(--ink);
  border: 1px solid #cfd7e5;
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input, select { min-height: 42px; padding: 9px 11px; }
textarea { min-height: 120px; padding: 11px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #9aa5b6; }
input:focus, select:focus, textarea:focus { border-color: #8096ea; box-shadow: 0 0 0 4px rgba(49, 87, 213, .11); }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-prefix input { padding-left: 36px; }

.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; }
.span-3 { grid-column: span 3; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.field-hint { color: var(--muted); font-size: 12px; }

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  min-height: 39px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 720;
  line-height: 1.2;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { color: #fff; background: var(--brand); box-shadow: 0 7px 17px rgba(49, 87, 213, .2); }
.btn-primary:hover { color: #fff; background: var(--brand-dark); }
.btn-secondary { color: #405068; border-color: var(--line); background: #fff; }
.btn-secondary:hover { color: var(--brand); border-color: #bdc9ed; background: var(--brand-soft); }
.btn-success { color: #fff; background: var(--success); }
.btn-danger { color: var(--danger); border-color: #f2c4cb; background: #fff5f6; }
.btn-danger:hover { color: #fff; background: var(--danger); }
.btn-ai { color: #fff; background: linear-gradient(135deg, #6b46d9, #3157d5 65%, #078d84); box-shadow: 0 7px 17px rgba(76, 70, 190, .22); }
.btn-ai:hover { color: #fff; box-shadow: 0 10px 24px rgba(76, 70, 190, .3); }
.btn-ghost { color: var(--muted); background: transparent; }
.btn-small { min-height: 32px; padding: 6px 9px; border-radius: 8px; font-size: 12px; }
.btn-icon { width: 38px; padding: 7px; }
.btn[disabled], .btn.disabled { cursor: not-allowed; opacity: .48; transform: none; box-shadow: none; }
.inline-form { display: inline-flex; margin: 0; }

.quick-add summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
}
.quick-add summary::-webkit-details-marker { display: none; }
.quick-add[open] summary { margin-bottom: 18px; }
.quick-add-body { padding-top: 2px; }

.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  min-width: 1400px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}
.data-table .col-customer { width: 11%; }
.data-table .col-phone { width: 9%; }
.data-table .col-company { width: 16%; }
.data-table .col-stage { width: 8%; }
.data-table .col-remark { width: 11%; }
.data-table .col-track { width: 12%; }
.data-table .col-created { width: 9%; }
.data-table .col-actions { width: 24%; }
.data-table th {
  padding: 12px 13px;
  color: #667289;
  background: #f7f9fc;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  text-align: left;
  letter-spacing: .03em;
  white-space: nowrap;
}
.data-table td { padding: 14px 13px; border-bottom: 1px solid #edf0f5; vertical-align: middle; line-height: 1.45; }
.data-table tbody tr { transition: background .14s ease; }
.data-table tbody tr:hover { background: #fafbff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.customer-name { font-weight: 800; color: var(--ink); }
.customer-meta { overflow-wrap: anywhere; color: var(--muted); font-size: 12px; }
.phone-link { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 650; }
.remark-cell, .track-cell { min-width: 155px; max-width: 270px; }
.truncate { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.today-text { color: var(--danger); font-weight: 750; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; min-width: 0; }
.actions form { display: inline-flex; margin: 0; }
mark { color: #813904; background: #ffe9a6; border-radius: 4px; padding: 1px 3px; }

.empty-state { padding: 55px 20px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 14px; border-radius: 20px; color: var(--brand); background: var(--brand-soft); font-size: 26px; }
.empty-state h3 { margin-bottom: 5px; }
.empty-state p { margin: 0 0 18px; color: var(--muted); }

.pagination { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 22px; }
.pagination a, .pagination span { display: grid; place-items: center; min-width: 36px; height: 36px; padding: 0 9px; border: 1px solid var(--line); border-radius: 9px; color: #536177; background: #fff; }
.pagination .current { color: #fff; border-color: var(--brand); background: var(--brand); }
.pagination .disabled { opacity: .4; }

.info-banner {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 16px 18px;
  border: 1px solid #cad5fa;
  border-radius: 14px;
  color: #334e9f;
  background: #f1f4ff;
}
.info-banner.warning { color: #85500c; border-color: #ecd19a; background: #fff9e9; }
.info-banner.danger { color: #9c2f40; border-color: #efbdc5; background: #fff3f5; }
.info-banner p { margin: 3px 0 0; color: inherit; opacity: .84; }

.metric-row { display: flex; flex-wrap: wrap; gap: 10px; }
.metric-chip { padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); color: var(--muted); }
.metric-chip strong { color: var(--ink); }

.timeline { position: relative; display: grid; gap: 0; }
.timeline::before { content: ""; position: absolute; left: 17px; top: 10px; bottom: 10px; width: 2px; background: #dfe5ef; }
.timeline-item { position: relative; display: grid; grid-template-columns: 36px 1fr; gap: 14px; padding-bottom: 22px; }
.timeline-dot { z-index: 1; width: 12px; height: 12px; margin: 7px 0 0 12px; border: 3px solid #d7e0ff; border-radius: 50%; background: var(--brand); }
.timeline-content { padding: 15px 17px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.timeline-time { margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.timeline-content p { margin: 0; white-space: pre-wrap; }

.quick-phrases { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.quick-phrase { border: 1px solid #d7deeb; border-radius: 999px; padding: 5px 10px; color: #536177; background: #fff; cursor: pointer; font-size: 12px; }
.quick-phrase:hover { color: var(--brand); border-color: #aebeed; background: var(--brand-soft); }

.upload-zone { padding: 36px 22px; border: 2px dashed #cbd5e4; border-radius: 16px; text-align: center; background: #fafcff; }
.upload-zone input[type="file"] { max-width: 440px; border: 0; padding: 9px; background: #fff; }
.header-preview { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.header-preview code { padding: 5px 8px; border-radius: 7px; color: #485670; background: #edf1f7; }

.config-list { display: grid; gap: 9px; margin: 14px 0 0; }
.config-item { display: grid; grid-template-columns: 220px 1fr; gap: 14px; padding: 10px 12px; border-radius: 9px; background: #fff; }
.config-item code { color: #5b43bc; word-break: break-all; }

.conversation { display: grid; gap: 12px; }
.message { width: min(78%, 720px); padding: 12px 15px; border-radius: 15px; white-space: pre-wrap; }
.message-ai { justify-self: start; color: #35435a; border: 1px solid var(--line); border-bottom-left-radius: 4px; background: #fff; }
.message-customer { justify-self: end; color: #fff; border-bottom-right-radius: 4px; background: var(--brand); }
.message-role { display: block; margin-bottom: 4px; font-size: 11px; font-weight: 800; opacity: .72; }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.detail-item { padding: 14px; border-radius: 11px; background: var(--surface-soft); }
.detail-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.detail-value { font-weight: 720; word-break: break-word; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 46%) 1fr;
  background: #fff;
}
.auth-visual {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100vh;
  padding: clamp(38px, 6vw, 84px);
  color: #fff;
  background:
    linear-gradient(145deg, rgba(26, 42, 106, .84), rgba(49, 87, 213, .62)),
    url("/static/img/background.png") center / cover;
}
.auth-visual::after { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 75% 20%, rgba(255,255,255,.2), transparent 28%); }
.auth-copy { position: relative; z-index: 1; max-width: 570px; }
.auth-copy h1 { font-size: clamp(36px, 5vw, 60px); }
.auth-copy p { max-width: 480px; color: rgba(255,255,255,.78); font-size: 17px; }
.auth-card-wrap { display: grid; place-items: center; padding: 34px; background: #f8faff; }
.auth-card { width: min(420px, 100%); }
.auth-brand { margin-bottom: 34px; }
.auth-card h2 { margin-bottom: 6px; font-size: 29px; }
.auth-card .subtitle { margin-bottom: 25px; }
.auth-form { display: grid; gap: 16px; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 66px; }
.password-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border: 0; padding: 5px 7px; color: var(--brand); background: transparent; cursor: pointer; font-weight: 700; }
.auth-footer { margin-top: 22px; color: var(--muted); text-align: center; }
.auth-flashes { margin-bottom: 18px; }

code { font-family: "Cascadia Code", Consolas, monospace; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }

@media (max-width: 1080px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-inner { gap: 14px; }
  .main-nav { overflow-x: auto; }
  .user-chip span { display: none; }
  .span-3 { grid-column: span 6; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .header-inner { width: calc(100% - 22px); min-height: 62px; flex-wrap: wrap; padding: 9px 0; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-name { display: none; }
  .main-nav { order: 3; width: 100%; padding-bottom: 2px; }
  .main-nav a { padding: 7px 10px; font-size: 13px; }
  .header-account { margin-left: auto; }
  .page-shell, .page-shell.narrow { width: calc(100% - 22px); padding: 22px 0 44px; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 12px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat-card { min-height: 104px; padding: 15px; border-radius: 14px; }
  .stat-value { font-size: 26px; }
  .stat-note { display: none; }
  .panel { border-radius: 14px; }
  .panel-head, .panel-body { padding: 16px; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; }
  .toolbar .search-field, .toolbar select, .toolbar .btn { flex: 1 1 100%; width: 100%; min-width: 0; }
  .span-8, .span-6, .span-4, .span-3 { grid-column: span 12; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }

  .table-wrap { overflow: visible; }
  .data-table { min-width: 0; table-layout: auto; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tbody { display: grid; gap: 12px; }
  .data-table tr { padding: 7px 14px; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: var(--shadow-sm); }
  .data-table td { display: grid; grid-template-columns: 92px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed #e7ebf2; text-align: right; }
  .data-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; text-align: left; }
  .data-table td:last-child { border-bottom: 0; }
  .data-table .primary-cell { display: block; text-align: left; padding: 12px 0; }
  .data-table .primary-cell::before { display: none; }
  .data-table .actions-cell { display: block; }
  .data-table .actions-cell::before { display: none; }
  .actions { min-width: 0; }
  .actions .btn, .actions form { flex: 1 1 auto; }
  .actions form .btn { width: 100%; }
  .remark-cell, .track-cell { min-width: 0; max-width: none; }

  .auth-shell { display: block; background: #f8faff; }
  .auth-visual { min-height: 210px; padding: 34px 24px; justify-content: center; }
  .auth-copy h1 { margin-bottom: 8px; font-size: 32px; }
  .auth-copy p { margin-bottom: 0; font-size: 14px; }
  .auth-card-wrap { place-items: start center; padding: 28px 22px 50px; }
  .auth-brand { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .config-item { grid-template-columns: 1fr; gap: 3px; }
  .message { width: 91%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
