:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #172033;
  --muted: #64748b;
  --line: #d9e2ec;
  --nav: #172033;
  --nav-soft: #202b3d;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #e0f2f1;
  --warn: #b45309;
  --bad: #b42318;
  --good: #15803d;
  --shadow: 0 18px 45px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, .08), transparent 34rem),
    linear-gradient(180deg, #f8fafc 0, var(--bg) 24rem);
}
a { color: var(--accent-dark); }
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px 1fr;
}
.sidebar {
  background: linear-gradient(180deg, var(--nav) 0%, #101827 100%);
  color: #d9e2ef;
  padding: 24px 18px;
  box-shadow: 8px 0 30px rgba(15, 23, 42, .18);
}
.brand {
  display: block;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 20px;
  line-height: 1.15;
  margin-bottom: 22px;
}
.nav {
  display: grid;
  gap: 6px;
}
.nav a, .logout {
  width: 100%;
  display: block;
  color: #d9e2ef;
  text-align: left;
  text-decoration: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 8px;
  padding: 11px 12px;
  font: inherit;
  cursor: pointer;
}
.nav a:hover, .logout:hover {
  background: var(--nav-soft);
  border-color: rgba(255,255,255,.25);
  color: #fff;
}
.main { min-width: 0; }
.topbar {
  height: 68px;
  background: rgba(255,255,255,.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.content { padding: 28px; max-width: 1500px; min-width: 0; }
h1 { font-size: 28px; margin: 0 0 18px; letter-spacing: 0; }
h2 { font-size: 19px; margin: 0 0 14px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.grid { display: grid; gap: 16px; min-width: 0; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric strong { display: block; font-size: 26px; margin-top: 4px; }
.metric {
  background: linear-gradient(180deg, #fff, var(--panel-soft));
}
.span-all {
  grid-column: 1 / -1;
}
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 14px;
}
.section-head h2 {
  margin-bottom: 0;
}
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.status-card {
  display: grid;
  gap: 8px;
  min-height: 118px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, #f8fafc);
  color: var(--ink);
  text-decoration: none;
}
.status-card:hover {
  border-color: rgba(15, 118, 110, .35);
  box-shadow: 0 8px 22px rgba(15, 23, 42, .08);
  transform: translateY(-1px);
}
.status-card strong {
  font-size: 28px;
  line-height: 1;
}
.funnel {
  display: grid;
  gap: 10px;
}
.funnel-row {
  display: grid;
  grid-template-columns: minmax(120px, 170px) minmax(0, 1fr) 70px;
  gap: 12px;
  align-items: center;
  min-width: 0;
}
.funnel-label {
  font-weight: 700;
}
.funnel-track {
  height: 12px;
  border-radius: 999px;
  background: #e7edf5;
  overflow: hidden;
  min-width: 0;
}
.funnel-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.muted { color: var(--muted); }
.flash {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}
.flash.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}
.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  align-items: end;
}
.bulkbar {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(160px, 220px) minmax(160px, 260px) auto;
  gap: 10px;
  align-items: end;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.check-col { width: 42px; text-align: center; }
.check-col input { width: auto; }
.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed #b8c4d4;
  border-radius: 8px;
  background: var(--panel-soft);
}
.empty-state strong {
  color: var(--ink);
  font-size: 18px;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.span-2 { grid-column: span 2; }
.form-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  z-index: 4;
}
.compact-form {
  gap: 10px;
  margin-bottom: 10px;
}
.table-form {
  display: grid;
  gap: 6px;
  min-width: 220px;
}
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}
.checkbox-line input { width: auto; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 11px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(15, 118, 110, .15);
  border-color: var(--accent);
}
textarea { min-height: 110px; resize: vertical; }
.btn, button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.primary, button.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 20px rgba(15, 118, 110, .22);
}
.btn.primary:hover, button.primary:hover { background: var(--accent-dark); }
.btn.secondary, button.secondary {
  background: #e8eef5;
  color: var(--ink);
  border: 1px solid #d1dae7;
}
.btn.secondary:hover, button.secondary:hover { background: #dde6f1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
}
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}
th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--panel-soft);
}
.sort-link {
  color: inherit;
  text-decoration: none;
}
.sort-link:hover {
  color: var(--accent);
}
tr:hover td { background: #fbfdff; }
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}
.badge.status-new { background: #e0f2fe; color: #0369a1; }
.badge.status-sql, .badge.status-won { background: #dcfce7; color: var(--good); }
.badge.status-lost, .badge.status-bad_fit { background: #fee2e2; color: var(--bad); }
.badge.status-interested, .badge.status-meeting_scheduled, .badge.status-proposal_sent { background: #fef3c7; color: var(--warn); }
.badge.good { background: #dcfce7; color: var(--good); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.bad { background: #fee2e2; color: var(--bad); }
.lead-title { font-weight: 800; color: var(--ink); text-decoration: none; }
.detail-list {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 10px 14px;
  overflow-wrap: anywhere;
}
.activity {
  border-left: 3px solid var(--accent);
  padding: 10px 0 10px 12px;
  margin-bottom: 10px;
}
.status-note {
  border: 1px solid #facc15;
  background: #fffbeb;
  color: #713f12;
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
  overflow-wrap: anywhere;
}
.error-box {
  white-space: pre-wrap;
  overflow: auto;
  border: 1px solid #fecaca;
  background: #fff7f7;
  color: #7f1d1d;
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
}
.pagination { display: flex; gap: 8px; margin-top: 14px; }
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth .panel { width: min(460px, 100%); }
.auth > .flash {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, calc(100% - 32px));
}
hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .topbar {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
  }
  .filters, .bulkbar, .grid.cols-4, .grid.cols-2 { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .content { padding: 16px; }
  .panel { width: 100%; }
  .section-head {
    display: grid;
    gap: 4px;
  }
  table { font-size: 14px; }
  .table-scroll table { min-width: 980px; }
  .detail-list { grid-template-columns: 1fr; }
}

/* Practical CRM refinements */
body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: linear-gradient(180deg, #f6f8fb 0, #eef2f6 280px, #eef2f6 100%);
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  min-height: 100vh;
}

.nav a.active {
  background: #fff;
  border-color: #fff;
  color: var(--nav);
  font-weight: 800;
}

.topbar {
  height: 60px;
}

.content {
  padding: 24px;
}

.content > .actions:first-child {
  background: transparent;
  align-items: flex-start;
}

.content > .actions:first-child h1 {
  line-height: 1.1;
  max-width: min(820px, 100%);
}

.panel {
  box-shadow: 0 8px 24px rgba(15, 23, 42, .06);
}

.filters {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.filters > .filter-search {
  grid-column: span 2;
}

.advanced-filters {
  grid-column: 1 / -1;
}

.advanced-filters summary {
  cursor: pointer;
  width: fit-content;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #d1dae7;
  border-radius: 8px;
  padding: 8px 12px;
  background: #eef4f8;
  color: var(--ink);
  font-weight: 800;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.filter-grid label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 41px;
  padding: 9px 10px;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.filter-grid input[type="checkbox"] {
  width: auto;
}

.table-scroll {
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-scroll table {
  margin: 0;
}

.table-scroll th {
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  line-height: 1.35;
}

tr:hover td {
  background: #f7fbff;
}

.contact-stack {
  display: grid;
  gap: 5px;
  max-width: 260px;
}

.contact-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-summary {
  display: grid;
  grid-template-columns: minmax(120px, .7fr) minmax(90px, .45fr) minmax(140px, .7fr) minmax(220px, 1.4fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
}

.lead-summary > div:not(.quick-actions) {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.lead-summary strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.quick-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-list {
  gap: 0;
  border-top: 1px solid var(--line);
}

.detail-list > span,
.detail-list > strong {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.activity {
  background: #fbfdff;
  border: 1px solid #e2e8f0;
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
}

.btn, button {
  min-height: 40px;
  white-space: nowrap;
}

.bulkbar {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

@media (max-width: 960px) {
  .app {
    display: block;
  }

  .sidebar {
    min-height: 0;
    padding: 12px;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .18);
  }

  .brand {
    margin-bottom: 10px;
    font-size: 18px;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a,
  .logout {
    flex: 0 0 auto;
    width: auto;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
  }

  .topbar {
    display: none;
  }

  .content {
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }

  .panel {
    padding: 14px;
    margin-bottom: 12px;
  }

  .filters {
    gap: 9px;
  }

  .filters > .filter-search {
    grid-column: span 1;
  }

  .content > .actions:first-child {
    gap: 10px;
  }

  .content > .actions:first-child .actions {
    width: 100%;
  }

  .content > .actions:first-child .btn {
    flex: 1 1 140px;
  }

  .lead-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .lead-summary .quick-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .lead-summary .quick-actions .btn {
    flex: 1 1 96px;
  }

  .detail-list > span,
  .detail-list > strong {
    padding: 7px 0;
  }
}
