:root {
  --bg: #eef3f8;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --line: #dce5f1;
  --line-soft: #edf2f7;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --blue: #2563eb;
  --blue2: #0ea5e9;
  --navy: #0f172a;
  --green: #059669;
  --orange: #ea580c;
  --red: #dc2626;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 14px 44px rgba(15, 23, 42, 0.055);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -12%, rgba(37, 99, 235, 0.22), transparent 32%),
    radial-gradient(circle at 92% 4%, rgba(14, 165, 233, 0.16), transparent 26%),
    linear-gradient(180deg, #f7faff 0%, var(--bg) 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.crm-app {
  max-width: 1840px;
  margin: 0 auto;
  padding: 24px;
}

.crm-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 32px 36px;
  border-radius: 34px;
  background: linear-gradient(135deg, rgba(255,255,255,.92), rgba(239,246,255,.82));
  border: 1px solid rgba(219, 234, 254, .95);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .18em;
}

.crm-top h1 {
  margin: 10px 0 8px;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -0.07em;
}

.crm-top p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.top-actions,
.drawer-actions,
.pager,
.note-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 14px;
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-blue {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  box-shadow: 0 12px 28px rgba(37, 99, 235, .22);
}

.btn-dark {
  color: #fff;
  background: var(--navy);
}

.btn-light {
  color: #1d4ed8;
  background: #eff6ff;
}

.btn-cyan {
  color: #0369a1;
  background: #e0f2fe;
}

.btn-danger-soft {
  color: #b91c1c;
  background: #fee2e2;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin: 18px 0;
}

.metric-card {
  padding: 18px 20px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.metric-card strong {
  display: block;
  margin-top: 7px;
  font-size: 32px;
  letter-spacing: .02em;
}

.control-panel,
.workspace-card {
  border-radius: var(--radius-xl);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  backdrop-filter: blur(14px);
}

.control-panel {
  padding: 16px;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.quick-filter {
  border: 1px solid #dbeafe;
  background: rgba(248, 251, 255, .88);
  color: #1e3a8a;
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 850;
  cursor: pointer;
}

.quick-filter.active {
  color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue2));
  border-color: transparent;
  box-shadow: 0 12px 28px rgba(37, 99, 235, .22);
}

.filter-row {
  display: grid;
  grid-template-columns: 2fr repeat(7, minmax(118px, 1fr)) 86px 86px;
  gap: 10px;
  margin-top: 14px;
}

.filter-row input,
.filter-row select,
.owner-row select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  outline: none;
  color: var(--text);
  background: #fff;
}

.workspace-card {
  margin-top: 18px;
}

.workspace-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.workspace-head h2 {
  margin: 0;
  font-size: 18px;
}

.workspace-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#pageText {
  min-width: 54px;
  text-align: center;
  font-weight: 900;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.crm-table {
  width: 100%;
  min-width: 1480px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.crm-table th {
  text-align: left;
  background: rgba(248, 250, 252, .92);
  color: #475569;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.crm-table td {
  padding: 15px 14px;
  height: 86px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.crm-table tr:hover {
  background: rgba(248, 251, 255, .92);
}

.crm-table th:nth-child(1), .crm-table td:nth-child(1) { width: 72px; }
.crm-table th:nth-child(2), .crm-table td:nth-child(2) { width: 260px; }
.crm-table th:nth-child(3), .crm-table td:nth-child(3) { width: 260px; }
.crm-table th:nth-child(4), .crm-table td:nth-child(4) { width: 280px; }
.crm-table th:nth-child(5), .crm-table td:nth-child(5) { width: 250px; }
.crm-table th:nth-child(6), .crm-table td:nth-child(6) { width: 145px; }
.crm-table th:nth-child(7), .crm-table td:nth-child(7) { width: 170px; }
.crm-table th:nth-child(8), .crm-table td:nth-child(8) { width: 130px; }
.crm-table th:nth-child(9), .crm-table td:nth-child(9) { width: 150px; }

.cell-id {
  color: var(--muted);
  font-weight: 900;
}

.company-name {
  color: var(--text);
  font-size: 14px;
  font-weight: 950;
  cursor: pointer;
  line-height: 1.42;
}

.company-name:hover {
  color: var(--blue);
  text-decoration: underline;
}

.website-link {
  color: var(--blue);
  text-decoration: none;
  word-break: break-all;
}

.line-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted,
.sub-line {
  color: var(--faint);
}

.sub-line {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.4;
}

.contact-line {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  margin-bottom: 7px;
  line-height: 1.35;
}

.contact-line span {
  color: var(--faint);
  font-size: 12px;
  font-weight: 850;
}

.contact-line strong {
  color: var(--text);
  font-weight: 760;
  word-break: break-all;
}

.business-title {
  font-weight: 850;
  color: var(--text);
}

.badge,
.source-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}

.badge {
  padding: 5px 9px;
  color: #3730a3;
  background: #eef2ff;
}

.source-pill {
  padding: 5px 9px;
  color: #475569;
  background: #f1f5f9;
}

.status-pills {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-pill {
  justify-content: center;
  min-width: 94px;
  padding: 4px 9px;
  color: #475569;
  background: #f1f5f9;
}

.status-pill.good {
  color: #047857;
  background: #ecfdf5;
}

.status-pill.warn {
  color: #c2410c;
  background: #fff7ed;
}

.empty {
  padding: 44px !important;
  text-align: center;
  color: var(--faint);
}

/* Drawer */
.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, .38);
  backdrop-filter: blur(6px);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 90;
  width: min(780px, 96vw);
  height: 100vh;
  padding: 22px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 10% -8%, rgba(37, 99, 235, .16), transparent 32%),
    #f8fafc;
  box-shadow: -34px 0 100px rgba(15, 23, 42, .26);
}

.hidden {
  display: none !important;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border-radius: 26px;
  border: 1px solid #dbeafe;
  background: linear-gradient(135deg, #fff, #eff6ff);
}

.drawer-header h2 {
  margin: 8px 0;
  font-size: 26px;
  line-height: 1.25;
  letter-spacing: -0.04em;
}

.drawer-header p {
  margin: 0;
  color: var(--muted);
  word-break: break-all;
}

.drawer-close {
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--text);
  background: #e2e8f0;
  font-size: 28px;
}

.drawer-actions {
  flex-wrap: wrap;
  margin: 14px 0;
}

.drawer-section {
  margin-top: 14px;
  padding: 18px;
  border-radius: 24px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 10px 34px rgba(15, 23, 42, .045);
}

.ai-section {
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #fff, #eff6ff);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-head h3 {
  margin: 0;
  font-size: 16px;
}

.section-head span {
  color: var(--faint);
  font-size: 12px;
  font-weight: 800;
}

.rich-text {
  color: #334155;
  line-height: 1.78;
  font-size: 14px;
  white-space: pre-wrap;
}

.info-list {
  display: grid;
  gap: 10px;
}

.info-list div,
.contact-grid div {
  padding: 12px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid var(--line-soft);
}

.info-list label,
.contact-grid label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.info-list p,
.contact-grid strong {
  margin: 0;
  color: var(--text);
  word-break: break-word;
}

.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.note-section textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 13px;
  color: var(--text);
  line-height: 1.7;
  outline: none;
}

.note-actions {
  justify-content: flex-end;
  margin-top: 10px;
}

.owner-row {
  display: grid;
  grid-template-columns: 1fr 92px 92px;
  gap: 10px;
}

.drawer-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.timeline {
  display: grid;
  gap: 10px;
}

.timeline-item {
  padding: 12px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid var(--line-soft);
}

.timeline-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.timeline-item p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.timeline-empty {
  padding: 20px;
  text-align: center;
  color: var(--faint);
}

@media (max-width: 1420px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .crm-app {
    padding: 14px;
  }

  .crm-top,
  .workspace-head {
    flex-direction: column;
  }

  .metric-grid,
  .filter-row,
  .contact-grid,
  .owner-row {
    grid-template-columns: 1fr;
  }
}
