:root {
  color-scheme: dark;
  --bg: #080808;
  --bg-deep: #020202;
  --surface: #0f0f0f;
  --elev: #171717;
  --hover: #262626;
  --line: #1c1c1c;
  --line-strong: #242424;
  --text: #f0f0f0;
  --muted: #939393;
  --gray: #cccccc;
  --green: #7aff78;
  --red: #ff4758;
  --orange: #fdac53;
  --blue: #6ccdfb;
  --radius: 30px;
  --radius-sm: 16px;
  --pad: 28px;
  --gap: 18px;
  --content: 1328px;
  --sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23939393' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { background: var(--bg-deep); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 450;
  line-height: 1.45;
  font-feature-settings: "ss01", "ss02", "ss06";
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 2px solid var(--line);
  box-shadow: 0 4px 60px #000000bf;
}

.topbar-inner {
  width: min(var(--content), calc(100% - 32px));
  margin: 0 auto;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: 22px;
  font-weight: 520;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.records {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 10px 0;
  padding: 6px 14px;
  background: var(--elev);
  border: 2px solid var(--line);
  border-radius: 999px;
}

.records strong {
  font-size: 18px;
  font-weight: 520;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.records span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

main {
  width: min(var(--content), calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 72px;
}

.stack { display: grid; gap: var(--gap); }

.panel {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  padding: 22px var(--pad);
  background: var(--elev);
  border-bottom: 2px solid var(--line);
}

.lead-search {
  flex: 0 1 300px;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
}

.lead-search::placeholder { color: var(--muted); }

.empty-row td { color: var(--muted); }

.panel-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 520;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.add-lead { margin: 0; }

.add-lead > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-sizing: border-box;
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  margin: 0;
  padding: 0 14px;
  list-style: none;
  background: var(--elev);
  cursor: pointer;
}

.add-lead > summary::-webkit-details-marker { display: none; }

.add-lead > summary h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 520;
  letter-spacing: -0.02em;
  line-height: 1;
}

.add-lead > summary::after {
  content: "+";
  flex: 0 0 auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 500;
  line-height: 1;
}

.add-lead[open] > summary {
  border-bottom: 2px solid var(--line);
}

.add-lead[open] > summary::after { content: "\2212"; }

.add-lead > summary:focus { outline: none; }

.add-lead > summary:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: -4px;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14.5px;
}

col.name { width: 216px; }
col.email { width: 15%; }
col.phone { width: 164px; }
col.geo { width: 168px; }
col.call { width: 216px; }

th, td {
  padding: 14px 16px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

tbody tr:last-child td { border-bottom: 0; }
@media (hover: hover) {
  tbody tr:hover td { background: var(--hover); }
}
tr.is-new td { background: rgba(122, 255, 120, 0.1); }

td.num {
  font-family: var(--mono);
  font-size: 13px;
}

.call-status {
  position: relative;
  min-width: 0;
}

.call-icon {
  position: absolute;
  top: 50%;
  left: 10px;
  display: inline-flex;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.call-status[data-status="pending"] .call-icon { color: var(--orange); }
.call-status[data-status="assisting"] .call-icon { color: var(--blue); }
.call-status[data-status="success"] .call-icon { color: var(--green); }
.call-status[data-status="failed"] .call-icon { color: var(--red); }

.call-select, .customer-select, .geo-select {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 34px;
  padding: 0 26px 0 10px;
  color: var(--text);
  background-color: var(--elev);
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px 6px;
  border: 2px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.call-select { padding-left: 30px; }
.customer-select, .geo-select { height: 30px; }

.call-select option, .customer-select option, .geo-select option, form select option {
  color: var(--text);
  background-color: var(--elev);
}

.call-select option:checked, .customer-select option:checked, .geo-select option:checked, form select option:checked {
  background-color: var(--hover);
}

@media (hover: hover) {
  .call-select:hover, .customer-select:hover, .geo-select:hover, form select:hover { border-color: #333333; }
}

.name-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.lead-name {
  max-width: 100%;
  font-weight: 600;
}

.issue-context {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.issue-body {
  line-height: 1.4;
}

.customer-type {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  width: 100%;
  min-width: 0;
  margin: 0;
}

.customer-type-label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 550;
  letter-spacing: 0.06em;
  line-height: 1.2;
  text-transform: uppercase;
}

form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 18px;
  padding: var(--pad);
}

.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }

label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

form input, form select, form textarea {
  width: 100%;
  color: var(--text);
  background: var(--elev);
  border: 2px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 15px;
}

form input, form select { height: 46px; padding: 0 18px; }
form select {
  padding-right: 44px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 18px center;
  background-size: 10px 6px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

form textarea {
  min-height: 120px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  resize: vertical;
  line-height: 1.45;
}

form input::placeholder, form textarea::placeholder { color: var(--muted); }

form input:focus, form select:focus, form textarea:focus, .call-select:focus, .customer-select:focus, .geo-select:focus, .lead-search:focus {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-color: #333333;
}

.actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 18px;
}

button {
  height: 50px;
  padding: 0 22px;
  color: #000000;
  background: var(--gray);
  border: 1.5px solid transparent;
  border-radius: 57px;
  font: inherit;
  font-size: 17px;
  font-weight: 470;
  letter-spacing: 0.025em;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.15s;
}

button:hover { background: #ffffff; }
button:active { transform: scale(0.98); }
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.status { margin: 0; color: var(--muted); font-size: 14.5px; }
.status.is-ok { color: var(--green); }
.status.is-error { color: var(--red); }

@media (max-width: 1100px) {
  .panel { border-radius: 20px; }
  .panel-head { padding: 16px 20px; }
  .lead-search { height: 44px; font-size: 16px; }

  table, tbody { display: block; }
  colgroup { display: none; }
  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  tbody {
    display: grid;
    gap: 10px;
    padding: 12px;
  }

  tbody:empty { padding: 0; }

  tbody tr {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-areas:
      "person person person call call call"
      "email email phone phone geo geo"
      "issue issue issue issue issue issue";
    gap: 16px;
    min-width: 0;
    padding: 18px;
    background: var(--elev);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
  }

  tbody tr.is-new { border-color: var(--green); }

  tbody td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
  }

  tbody td, tbody tr.is-new td, tbody tr:hover td { background: transparent; }

  .lead-person { grid-area: person; }
  .lead-email { grid-area: email; }
  .num { grid-area: phone; }
  .lead-geo { grid-area: geo; }
  .lead-issue { grid-area: issue; }
  .call { grid-area: call; align-self: end; }

  tbody td.num { font-size: 14px; }

  tbody .lead-issue {
    padding-top: 14px;
    border-top: 1px solid var(--line-strong);
  }

  .lead-email::before { content: "Email" / ""; }
  .num::before { content: "Phone" / ""; }
  .lead-geo::before { content: "Geo" / ""; }
  .lead-issue::before { content: "Issue description" / ""; }
  .call::before { content: "Call status" / ""; }

  .lead-email::before, .num::before, .lead-geo::before, .lead-issue::before, .call::before {
    display: block;
    margin-bottom: 5px;
  }

  .lead-email::before, .num::before, .lead-geo::before, .lead-issue::before, .call::before, .customer-type-label {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 550;
    letter-spacing: 0.06em;
    line-height: 1.2;
    text-transform: uppercase;
  }

  .lead-name { font-size: 17px; line-height: 1.3; }
  .name-stack { gap: 12px; }
  .customer-type { gap: 5px; max-width: 300px; }
  .call-status { max-width: 300px; }
  .call-select, .customer-select, .geo-select {
    height: 44px;
    padding: 0 34px 0 14px;
    background-color: var(--surface);
    background-position: right 14px center;
    border-color: var(--line-strong);
    font-size: 16px;
  }
  .call-select { padding-left: 36px; }
  .call-icon { left: 14px; }

  .add-lead > summary {
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    padding: 0 20px;
  }

  tbody .empty-row { display: block; }
}

@media (max-width: 620px) {
  .topbar-inner {
    width: calc(100% - 24px);
    gap: 10px;
    min-height: 56px;
  }
  h1 { font-size: 17px; }
  .records { flex-shrink: 0; gap: 5px; padding: 6px 9px; }
  .records strong { font-size: 16px; }
  .records span { font-size: 9px; }
  main { width: calc(100% - 24px); padding-top: 16px; }
  .stack { gap: 12px; }
  .panel-head { gap: 12px; padding: 12px 12px 12px 16px; }
  .panel-head h2 { font-size: 20px; }
  .lead-search { flex: 1 1 0; }
  tbody { gap: 8px; padding: 8px; }
  tbody tr {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "person person"
      "call call"
      "email email"
      "phone geo"
      "issue issue";
    gap: 14px 12px;
    padding: 16px;
    border-radius: 14px;
  }
  .call { align-self: auto; }
  tbody .lead-email {
    padding-top: 14px;
    border-top: 1px solid var(--line-strong);
  }
  .customer-type, .call-status { max-width: none; }
  .add-lead > summary { padding: 0 16px; }
  form { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  form input, form select, form textarea { font-size: 16px; }
}

@media (max-width: 440px) {
  tbody tr {
    grid-template-areas:
      "person person"
      "call call"
      "email email"
      "phone phone"
      "geo geo"
      "issue issue";
  }
}

@supports (appearance: base-select) {
  .call-select, .customer-select, .geo-select, form select {
    display: flex;
    align-items: center;
    appearance: base-select;
  }

  .call-select::picker-icon, .customer-select::picker-icon, .geo-select::picker-icon, form select::picker-icon { display: none; }

  .call-select::picker(select), .customer-select::picker(select), .geo-select::picker(select), form select::picker(select) {
    appearance: base-select;
    min-width: anchor-size(width);
    margin: 6px 0;
    padding: 6px;
    color: var(--text);
    background: var(--elev);
    border: 2px solid var(--line-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 16px 48px #000000cc;
  }

  .call-select::picker(select), .customer-select::picker(select), .geo-select::picker(select) { font-size: 13px; }

  .call-select option, .customer-select option, .geo-select option, form select option {
    gap: 8px;
    min-height: 36px;
    padding: 8px 14px 8px 10px;
    color: var(--muted);
    background: transparent;
    border-radius: 10px;
    white-space: nowrap;
    cursor: pointer;
  }

  .call-select option:checked, .customer-select option:checked, .geo-select option:checked, form select option:checked {
    color: var(--text);
    background: var(--line-strong);
    font-weight: 600;
  }

  .call-select option:hover, .customer-select option:hover, .geo-select option:hover, form select option:hover,
  .call-select option:focus-visible, .customer-select option:focus-visible, .geo-select option:focus-visible, form select option:focus-visible {
    color: var(--text);
    background: var(--hover);
    outline: none;
  }

  .call-select option::checkmark, .customer-select option::checkmark, .geo-select option::checkmark, form select option::checkmark { color: var(--green); }

  .call-select:open, .customer-select:open, .geo-select:open, form select:open { border-color: #333333; }

  @media (max-width: 1100px), (pointer: coarse) {
    .call-select::picker(select), .customer-select::picker(select), .geo-select::picker(select) { font-size: 16px; }
    .call-select option, .customer-select option, .geo-select option, form select option { min-height: 44px; }
  }
}
