:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --line: #d8dee6;
  --text: #17202a;
  --muted: #657080;
  --accent: #246bfe;
  --open-bg: #e8f6ef;
  --open-text: #17623a;
  --closed-bg: #eef1f5;
  --closed-text: #4b5563;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 24px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.2;
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 20px clamp(12px, 3vw, 32px) 40px;
}

.company-link,
button,
select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.company-link,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  cursor: pointer;
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

select {
  min-width: 180px;
  padding: 0 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

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

.stats article {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats span {
  display: block;
  font-size: 28px;
  font-weight: 700;
}

.stats p {
  margin: 4px 0 0;
  color: var(--muted);
}

.status {
  min-height: 22px;
  margin: 0 0 14px;
  color: var(--muted);
}

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

.contacts-nav {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.contacts-nav h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.contacts-nav nav {
  display: grid;
  gap: 4px;
}

.contacts-nav a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.25;
}

.contacts-nav a:hover {
  background: #eef4ff;
  text-decoration: none;
}

.contacts-nav span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contacts-nav b {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.deals {
  display: grid;
  gap: 18px;
}

.deal-card,
.empty {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.deal-card {
  padding: 16px;
}

.contact-group {
  display: grid;
  gap: 10px;
  scroll-margin-top: 16px;
}

.contact-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 2px;
}

.contact-head h2 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.25;
}

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

.contact-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.contact-deals {
  display: grid;
  gap: 12px;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.deal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.deal-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
}

.meta,
.muted,
.activity-date {
  color: var(--muted);
}

.meta {
  margin-top: 5px;
  font-size: 13px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: start;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.open {
  background: var(--open-bg);
  color: var(--open-text);
}

.badge.closed {
  background: var(--closed-bg);
  color: var(--closed-text);
}

.deal-grid {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 18px;
  padding-top: 14px;
}

h2 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}

.contact-list {
  display: grid;
  gap: 8px;
}

.activity-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.activity-list li {
  min-width: 0;
}

.activity-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) max-content 120px;
  gap: 10px;
  align-items: baseline;
}

.activity-type {
  color: var(--muted);
  font-size: 13px;
}

.activity-date {
  justify-self: end;
  font-size: 13px;
  white-space: nowrap;
}

.activity-state {
  justify-self: end;
  padding: 3px 7px;
  border-radius: 999px;
  background: #fff4d6;
  color: #7a4b00;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.email-preview {
  margin: 8px 0 4px 96px;
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.email-preview summary {
  width: max-content;
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
}

.email-meta {
  display: grid;
  gap: 3px;
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.email-preview iframe {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.email-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.email-files a {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
}

@media (max-width: 760px) {
  .topbar,
  .deal-head,
  .contact-head {
    align-items: stretch;
    flex-direction: column;
  }

  .company-link {
    width: 100%;
  }

  .stats,
  .objects-layout,
  .deal-grid {
    grid-template-columns: 1fr;
  }

  .contacts-nav {
    position: static;
    max-height: none;
  }

  .contacts-nav nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .contacts-nav a {
    min-width: 180px;
  }

  .activity-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .activity-date,
  .activity-state {
    justify-self: start;
  }

  .email-preview {
    margin-left: 0;
  }
}
