:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #17201c;
  --muted: #68746f;
  --line: #dfe6e3;
  --accent: #16735f;
  --accent-strong: #0d5b4a;
  --amber: #bc7b18;
  --danger: #b42318;
  --radius: 8px;
  --shadow: 0 14px 40px rgba(23, 32, 28, 0.07);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111915;
  color: #f7fbf9;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
  font-size: 17px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--accent);
  border-radius: 7px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item, .export-link {
  width: 100%;
  border: 0;
  color: #d7e2de;
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  border-radius: 7px;
  cursor: pointer;
  text-decoration: none;
}

.nav-item.active, .nav-item:hover, .export-link:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.export-link {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.workspace {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

h1, h2, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.15; letter-spacing: 0; }
h2 { font-size: 16px; }
.topbar p { color: var(--muted); margin-top: 7px; }

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 9px 10px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 115, 95, 0.12);
}

button.primary {
  border: 0;
  border-radius: 7px;
  min-height: 38px;
  padding: 9px 14px;
  color: white;
  background: var(--accent);
  cursor: pointer;
  font-weight: 650;
}

button.primary:hover { background: var(--accent-strong); }
button.primary:disabled {
  cursor: wait;
  opacity: 0.68;
}

button.small {
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}

button.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

button.ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.action-row {
  display: flex;
  gap: 6px;
  align-items: center;
  white-space: nowrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  font-size: 25px;
  line-height: 1.1;
  margin-top: 7px;
}

.view { display: none; }
.view.active { display: block; }

.grid-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.table-panel { min-width: 0; }
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fbfcfc;
}

tr.customer-row { cursor: pointer; }
tr.customer-row:hover { background: #f7fbfa; }
tr.customer-row.selected { background: #edf7f4; }

.company-name {
  font-weight: 700;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.muted { color: var(--muted); }
.score {
  color: var(--amber);
  font-weight: 760;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #eef4f2;
  color: #31534a;
  font-size: 12px;
  font-weight: 650;
}

.detail-panel {
  min-height: 560px;
  position: sticky;
  top: 18px;
}

.empty {
  color: var(--muted);
  padding: 22px;
}

.hidden { display: none; }

.detail {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.detail-title h2 {
  font-size: 19px;
  line-height: 1.2;
}

.detail-meta {
  color: var(--muted);
  margin-top: 5px;
}

.detail-section {
  display: grid;
  gap: 8px;
}

.detail-section h3 {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
}

.contact-line, .source-line, .activity-line {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px;
  overflow-wrap: anywhere;
}

.status-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.note-form {
  display: grid;
  gap: 8px;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.form-panel {
  max-width: 940px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.search-panel {
  max-width: none;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(180px, 1fr) minmax(150px, 1fr) 92px auto auto;
  gap: 10px;
  padding: 14px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.checkbox.inline {
  grid-column: auto;
  white-space: nowrap;
}

.search-status {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: var(--muted);
}

.form-grid textarea, .checkbox {
  grid-column: 1 / -1;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.checkbox input {
  min-height: auto;
}

.task-list {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
}

.task-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.import-box {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px;
}

.schema {
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding: 12px 14px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #111915;
  color: white;
  padding: 11px 13px;
  border-radius: 7px;
  box-shadow: var(--shadow);
}

@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    align-items: center;
    overflow: auto;
  }
  .nav { display: flex; }
  .nav-item, .export-link { white-space: nowrap; width: auto; }
  .grid-layout { grid-template-columns: 1fr; }
  .detail-panel { position: static; }
  .topbar { flex-direction: column; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-form .primary, .checkbox.inline { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  html, body { overflow-x: hidden; }
  .workspace { padding: 14px; }
  .search-row, .import-box { flex-direction: column; align-items: stretch; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .search-form { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
}
