:root {
  --ink: #172033;
  --muted: #667085;
  --line: #dfe7ef;
  --soft-line: #edf1f7;
  --blue: #0b6bcb;
  --blue-dark: #084f99;
  --green: #12a36d;
  --gold: #b9821d;
  --red: #b42318;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --side: #0b1220;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }

.admin-shell { display: block; }
.admin-side {
  position: fixed;
  inset: 0 auto 0 0;
  width: 312px;
  padding: 24px 18px;
  color: #fff;
  background: var(--side);
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}
.admin-brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 14px;
  min-width: 0;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.admin-brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #ffffff;
  color: var(--side);
  font-weight: 900;
}
.admin-brand strong { display: block; font-size: 19px; line-height: 1.25; }
.admin-brand em, .admin-nav em {
  display: block;
  margin-top: 3px;
  color: #9aa8bd;
  font-size: 12px;
  font-style: normal;
}
.admin-nav { display: grid; gap: 8px; }
.admin-nav a {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 12px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #dce5f3;
  transition: background .18s ease, border-color .18s ease, color .18s ease;
}
.admin-nav a:hover {
  background: rgba(255,255,255,.07);
  border-color: rgba(255,255,255,.1);
  color: #fff;
}
.admin-nav a.is-active {
  background: #ffffff;
  color: var(--side);
  border-color: #ffffff;
}
.admin-nav a.is-active em { color: #58677d; }
.admin-nav-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255,255,255,.1);
  font-weight: 900;
}
.admin-nav b,
.admin-nav em {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-nav a.is-active .admin-nav-icon {
  background: #eaf3ff;
  color: var(--blue);
}
.admin-side-foot {
  margin-top: auto;
  padding: 14px 8px 4px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: grid;
  gap: 10px;
  color: #cbd5e1;
  font-size: 14px;
}
.admin-side-foot a:hover { color: #fff; }

.admin-main {
  min-height: 100vh;
  margin-left: 312px;
  outline: none;
  min-width: 0;
}
.admin-main.is-loading .admin-content { opacity: .52; }
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(245,247,251,.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.admin-topbar span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}
.admin-topbar strong { display: block; margin-top: 2px; font-size: 22px; }
.admin-top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}
.admin-top-actions a, .admin-primary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}
.admin-content {
  width: min(1320px, 100%);
  padding: 30px 32px 42px;
}
.admin-page-hero {
  margin-bottom: 22px;
  padding: 24px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.admin-page-hero h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
}
.admin-page-hero p {
  max-width: 780px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.75;
}
.admin-eyebrow {
  margin: 0 0 8px !important;
  color: var(--blue) !important;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
}

.panel, .stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 36px rgba(16,24,40,.06);
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stats div { padding: 22px; }
.stats b {
  display: block;
  margin-bottom: 8px;
  color: var(--blue);
  font-size: 34px;
  line-height: 1;
}
.stats span {
  display: block;
  color: var(--ink);
  font-weight: 900;
}
.stats em {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  line-height: 1.5;
}
.panel { padding: 24px; }
.panel h2 { margin: 0 0 12px; font-size: 22px; }
.panel p { margin: 0; color: var(--muted); line-height: 1.8; }
.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
  gap: 18px;
}
.admin-checklist {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.85;
}

.form {
  display: grid;
  gap: 18px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
label {
  display: grid;
  gap: 8px;
  color: #344054;
  font-size: 14px;
  font-weight: 800;
}
input, textarea, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--ink);
  font: inherit;
  background: #fff;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(11,107,203,.12);
}
textarea { min-height: 132px; resize: vertical; }
button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--blue);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}
button:hover, .admin-top-actions a:hover, .admin-primary-link:hover { background: var(--blue-dark); }
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.form-actions span {
  color: var(--muted);
  font-size: 13px;
}
.json-toolbar {
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}
.json-toolbar span { color: var(--ink); font-weight: 900; }
.json-toolbar b { font-weight: 700; }
.json-form textarea {
  min-height: 58vh;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.55;
  white-space: pre;
}

.notice, .error {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
}
.notice.success {
  background: #ecfdf3;
  color: #067647;
  border: 1px solid #abefc6;
}
.error {
  background: #fff1f0;
  color: var(--red);
  border: 1px solid #fecdca;
}
.lead-total {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  background: #ecfdf3;
  color: #067647;
  font-weight: 900;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
.lead-table {
  min-width: 0;
  table-layout: fixed;
}
.lead-table th:nth-child(1) { width: 18%; }
.lead-table th:nth-child(2) { width: 8%; }
.lead-table th:nth-child(3) { width: 14%; }
.lead-table th:nth-child(4) { width: 14%; }
.lead-table th:nth-child(5) { width: 9%; }
.lead-table th:nth-child(6) { width: 13%; }
.lead-table th:nth-child(7) { width: 24%; }
th, td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--soft-line);
  text-align: left;
  vertical-align: top;
}
th {
  position: sticky;
  top: 0;
  color: #475467;
  background: #f8fafc;
  font-size: 13px;
  white-space: nowrap;
}
tbody tr:hover { background: #fbfdff; }
.nowrap { white-space: nowrap; }
.lead-time {
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: normal;
  white-space: normal;
}
.lead-phone {
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.message-cell { line-height: 1.65; overflow-wrap: anywhere; }
.source-cell {
  color: var(--muted);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.source-cell a:hover {
  color: var(--blue);
  text-decoration: underline;
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  background: #eef7ff;
  color: #07559f;
  font-weight: 800;
  white-space: nowrap;
}
.empty-state {
  padding: 42px 20px;
  text-align: center;
}
.empty-state h2 { margin: 0 0 10px; }
.empty-state p { margin: 0 auto; max-width: 520px; color: var(--muted); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(11,107,203,.12), rgba(18,163,109,.1)),
    #f4f7fb;
}
.login-box {
  width: min(420px, 92vw);
  padding: 34px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(16,24,40,.14);
  display: grid;
  gap: 14px;
}
.login-box h1 { margin: 0; font-size: 30px; }
.login-box p { margin: 0; color: var(--muted); line-height: 1.7; }

@media (max-width: 1100px) {
  .admin-side {
    position: static;
    width: auto;
    max-height: none;
  }
  .admin-main { margin-left: 0; }
  .admin-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .admin-side-foot { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .admin-side { padding: 16px 12px; }
  .admin-nav { grid-template-columns: 1fr; }
  .admin-topbar {
    align-items: flex-start;
    padding: 16px 18px;
    flex-direction: column;
  }
  .admin-content { padding: 20px 18px 30px; }
  .admin-page-hero {
    align-items: flex-start;
    flex-direction: column;
    padding: 20px;
  }
  .stats, .form-grid { grid-template-columns: 1fr; }
  .admin-page-hero h1 { font-size: 26px; }
  .json-toolbar { flex-direction: column; }
  .lead-table { min-width: 760px; }
}
