:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #17202e;
  --ink-soft: #667085;
  --line: #e4e8ef;
  --red: #c4122f;
  --red-soft: #fdeef0;
  --blue: #14538f;
  --blue-soft: #eaf2fb;
  --green: #1f8a5b;
  --green-soft: #e8f6ef;
  --amber: #a9660a;
  --amber-soft: #fdf3e3;
  --gray-soft: #eef1f5;
  --shadow: 0 12px 40px rgba(16, 24, 40, .08);
  --radius: 16px;
  --sidebar: 236px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- login ---------- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 12% 8%, rgba(196, 18, 47, .22), transparent 60%),
    radial-gradient(800px 500px at 92% 92%, rgba(20, 83, 143, .24), transparent 60%),
    #0d1420;
}
.login-panel {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 24px;
  padding: 36px 34px 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 30px; }
.brand-dot {
  width: 14px; height: 14px; flex: none; border-radius: 4px;
  background: linear-gradient(135deg, var(--red), #7a0b1d);
  box-shadow: 0 0 0 5px rgba(196, 18, 47, .12);
}
.login-brand h1 { margin: 0; font-size: 21px; letter-spacing: .02em; }
.login-brand p { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-soft); letter-spacing: .08em; }
.login-form { display: grid; gap: 16px; }
.login-form .field > span { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 7px; }
.login-form input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 11px;
  background: #fbfcfe; outline: none; transition: border .15s, box-shadow .15s;
}
.login-form input:focus { border-color: rgba(196, 18, 47, .55); box-shadow: 0 0 0 3px rgba(196, 18, 47, .09); }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 12.5px; }
.login-foot { margin: 22px 0 0; text-align: center; font-size: 11.5px; color: #98a2b3; }

/* ---------- shell ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 30;
  background: #111a27; color: #dbe2ec; display: flex; flex-direction: column;
  padding: 24px 16px 18px;
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; }
.side-brand strong { display: block; font-size: 15.5px; color: #fff; letter-spacing: .03em; }
.side-brand small { display: block; margin-top: 3px; font-size: 11px; color: #8796aa; letter-spacing: .08em; }
.side-nav { display: grid; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 0; background: transparent; color: #9eacbe; cursor: pointer;
  padding: 11px 12px; border-radius: 10px; text-align: left; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; fill: currentColor; flex: none; opacity: .9; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-item.active { background: linear-gradient(135deg, rgba(196, 18, 47, .9), rgba(122, 11, 29, .85)); color: #fff; }
.side-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 0 6px 12px; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .12); color: #fff; font-weight: 700; font-size: 13px;
}
.side-user strong { display: block; font-size: 13px; color: #fff; }
.side-user small { font-size: 11px; color: #8796aa; }
.side-logout {
  width: 100%; border: 1px solid rgba(255, 255, 255, .12); background: transparent;
  color: #9eacbe; border-radius: 9px; padding: 9px; cursor: pointer; font-size: 12.5px;
}
.side-logout:hover { color: #fff; border-color: rgba(255, 255, 255, .3); }

.main { margin-left: var(--sidebar); min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  padding: 18px 32px; background: rgba(244, 246, 249, .9); backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(228, 232, 239, .8);
}
.topbar h2 { margin: 0; font-size: 19px; letter-spacing: .01em; }
.page-sub { margin: 4px 0 0; font-size: 12px; color: var(--ink-soft); }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.site-link {
  font-size: 12px; color: var(--ink-soft); text-decoration: none; padding: 7px 11px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff;
}
.site-link:hover { color: var(--ink); border-color: #cfd6e2; }
.mobile-menu { display: none; border: 0; background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 8px; cursor: pointer; }
.mobile-menu span { display: block; width: 16px; height: 2px; background: var(--ink); margin: 3px 0; border-radius: 2px; }
.view { padding: 26px 32px 48px; max-width: 1280px; }

/* ---------- common ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .03);
}
.card-pad { padding: 24px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 0 0 18px; }
.section-head h3 { margin: 0; font-size: 15.5px; }
.section-head p { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-soft); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 15px; border-radius: 9px; cursor: pointer; font-size: 13px;
  text-decoration: none; transition: border .15s, background .15s, color .15s;
}
.btn:hover { border-color: #c8d0dd; background: #fafbfc; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: #a90f29; border-color: #a90f29; }
.btn-blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-blue:hover { background: #0f4477; border-color: #0f4477; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--red); border-color: rgba(196, 18, 47, .25); background: var(--red-soft); }
.btn-danger:hover { background: #fbdde2; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.hint { color: var(--ink-soft); font-size: 12px; line-height: 1.7; }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.pill-new { background: var(--red-soft); color: var(--red); }
.pill-contacted { background: var(--amber-soft); color: var(--amber); }
.pill-done { background: var(--green-soft); color: var(--green); }
.pill-invalid { background: var(--gray-soft); color: #667085; }
.pill-jiesen { background: var(--red-soft); color: var(--red); }
.pill-siyuan { background: var(--blue-soft); color: var(--blue); }

/* ---------- overview ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 20px 22px; position: relative; overflow: hidden; }
.stat-card small { display: block; font-size: 12px; color: var(--ink-soft); }
.stat-card strong { display: block; margin-top: 8px; font-size: 30px; letter-spacing: -.02em; line-height: 1; }
.stat-card .stat-tag { position: absolute; right: 16px; top: 16px; font-size: 11px; color: var(--ink-soft); }
.stat-card::after {
  content: ""; position: absolute; right: -24px; bottom: -36px; width: 96px; height: 96px;
  border-radius: 50%; background: linear-gradient(135deg, rgba(196, 18, 47, .08), rgba(20, 83, 143, .08));
}
.overview-grid { display: grid; grid-template-columns: 1.35fr .65fr; gap: 18px; align-items: start; }
.recent-list { display: grid; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.recent-item:last-child { border-bottom: 0; }
.recent-item:hover .recent-name { color: var(--red); }
.recent-name { font-weight: 600; font-size: 13.5px; transition: color .15s; }
.recent-meta { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.recent-time { margin-left: auto; font-size: 11.5px; color: #98a2b3; white-space: nowrap; }
.mini-site { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.mini-site:last-child { border-bottom: 0; }
.mini-site strong { font-size: 13.5px; }
.mini-site small { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 11.5px; }

/* ---------- leads ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 12.5px; color: var(--ink-soft); }
.seg button.active { background: var(--ink); color: #fff; }
.toolbar input, .toolbar select {
  border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 8px 11px; font-size: 12.5px; outline: none;
}
.toolbar input:focus, .toolbar select:focus { border-color: #c2ccdb; }
.toolbar .spacer { flex: 1; }
.table-wrap { overflow-x: auto; }
table.leads { width: 100%; border-collapse: collapse; min-width: 860px; }
table.leads th {
  text-align: left; font-size: 11.5px; color: var(--ink-soft); font-weight: 600;
  padding: 12px 14px; background: #f8f9fc; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.leads td { padding: 13px 14px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13px; }
table.leads tr:last-child td { border-bottom: 0; }
table.leads tbody tr { cursor: pointer; transition: background .12s; }
table.leads tbody tr:hover { background: #fafbfe; }
.lead-name { font-weight: 600; }
.lead-sub { margin-top: 3px; font-size: 11.5px; color: var(--ink-soft); }
.lead-phone { font-variant-numeric: tabular-nums; white-space: nowrap; }
.lead-msg { max-width: 260px; color: var(--ink-soft); font-size: 12.5px; line-height: 1.6; }
.lead-actions { display: flex; gap: 6px; align-items: center; }
.status-select {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; font-size: 12px;
}
.empty { padding: 54px 20px; text-align: center; color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); margin-bottom: 6px; font-size: 14px; }

/* ---------- content editor ---------- */
.site-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.site-tab {
  display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); background: #fff;
  padding: 9px 15px; border-radius: 999px; cursor: pointer; font-size: 13px; color: var(--ink-soft);
}
.site-tab.active { border-color: transparent; background: var(--ink); color: #fff; }
.site-tab .tab-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.site-tab[data-site="siyuan"] .tab-dot { background: #2b7ac0; }
.form-sections { display: grid; gap: 18px; }
.form-section { padding: 22px 24px; }
.form-section > h3 { margin: 0 0 4px; font-size: 15px; }
.form-section > .hint { margin: 0 0 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 16px; }
.field-box { display: flex; flex-direction: column; gap: 6px; }
.field-box > span { font-size: 12px; color: var(--ink-soft); }
.field-box input, .field-box textarea, .field-box select {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #fbfcfe;
  padding: 9px 11px; outline: none; transition: border .15s, box-shadow .15s; font-size: 13px;
}
.field-box textarea { resize: vertical; min-height: 76px; line-height: 1.65; }
.field-box input:focus, .field-box textarea:focus { border-color: rgba(196, 18, 47, .5); box-shadow: 0 0 0 3px rgba(196, 18, 47, .07); background: #fff; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.repeat-list { display: grid; gap: 12px; }
.repeat-item { border: 1px solid var(--line); border-radius: 12px; background: #fcfcfe; overflow: hidden; }
.repeat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #f7f8fb; border-bottom: 1px solid var(--line); }
.repeat-head strong { font-size: 12.5px; }
.repeat-head .repeat-actions { margin-left: auto; display: flex; gap: 6px; }
.repeat-body { padding: 14px; }
.icon-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 7px; width: 28px; height: 28px;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--ink-soft); font-size: 13px;
}
.icon-btn:hover { color: var(--ink); border-color: #c8d0dd; }
.img-field { display: flex; gap: 10px; align-items: flex-start; }
.img-field .img-main { flex: 1; display: grid; gap: 8px; }
.img-field input { width: 100%; border: 1px solid var(--line); border-radius: 9px; background: #fbfcfe; padding: 9px 11px; font-size: 12.5px; outline: none; }
.img-field .img-preview {
  width: 76px; height: 58px; border-radius: 8px; border: 1px solid var(--line);
  background: #f3f5f8 center/cover no-repeat; flex: none;
}
.img-actions { display: flex; gap: 6px; }
.save-bar {
  position: sticky; bottom: 16px; z-index: 10; display: flex; align-items: center; gap: 14px;
  background: rgba(17, 26, 39, .94); color: #fff; padding: 13px 18px; border-radius: 14px;
  box-shadow: 0 16px 40px rgba(16, 24, 40, .22); backdrop-filter: blur(8px);
}
.save-bar .hint { color: #a7b3c4; margin: 0; }
.save-bar .btn { margin-left: auto; }
.unsaved-dot { width: 8px; height: 8px; border-radius: 50%; background: #f2b84b; display: inline-block; }

/* ---------- media ---------- */
.media-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.media-card { overflow: hidden; }
.media-thumb { aspect-ratio: 4 / 3; background: #eef1f5 center/cover no-repeat; }
.media-body { padding: 10px 12px 12px; }
.media-body strong { display: block; font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-body small { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 10.5px; }
.media-actions { display: flex; gap: 6px; margin-top: 9px; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.settings-grid .card-pad h3 { margin: 0 0 4px; font-size: 15px; }
.settings-form { display: grid; gap: 13px; margin-top: 16px; }
.settings-form .field-box input { background: #fff; }
.info-list { display: grid; gap: 12px; margin-top: 16px; }
.info-row { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.info-row:last-child { border-bottom: 0; }
.info-row span { color: var(--ink-soft); }

/* ---------- modal ---------- */
.modal-root:empty { display: none; }
.modal-mask {
  position: fixed; inset: 0; z-index: 80; background: rgba(8, 14, 24, .48);
  display: grid; place-items: center; padding: 20px; backdrop-filter: blur(2px);
}
.modal {
  width: min(560px, 100%); max-height: 88vh; overflow: auto; background: #fff;
  border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, .24);
}
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px 14px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-head p { margin: 4px 0 0; color: var(--ink-soft); font-size: 12px; }
.modal-close { margin-left: auto; border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--ink-soft); }
.modal-body { padding: 18px 22px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 22px 20px; }
.detail-grid { display: grid; grid-template-columns: 90px 1fr; gap: 10px 16px; font-size: 13px; }
.detail-grid dt { color: var(--ink-soft); font-size: 12px; }
.detail-grid dd { margin: 0; line-height: 1.65; word-break: break-word; }
.note-area { width: 100%; min-height: 80px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; resize: vertical; margin-top: 14px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 16px);
  background: #111a27; color: #fff; padding: 11px 18px; border-radius: 11px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .22);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #9f1230; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-grid { grid-template-columns: 1fr; }
  .media-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask { display: none; position: fixed; inset: 0; z-index: 25; background: rgba(8, 14, 24, .4); }
  .sidebar-mask.show { display: block; }
  .main { margin-left: 0; }
  .mobile-menu { display: inline-block; }
  .topbar { padding: 14px 18px; flex-wrap: wrap; }
  .topbar-actions { width: 100%; order: 3; }
  .view { padding: 18px 16px 40px; }
  .grid-2, .grid-3, .grid-4, .settings-grid { grid-template-columns: 1fr; }
  .span-2, .span-3, .span-4 { grid-column: auto; }
  .media-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 16px; }
  .stat-card strong { font-size: 24px; }
  .panel, .form-section, .card-pad { padding: 18px 16px; }
  .site-tabs { flex-wrap: wrap; }
}
