:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #5f6f7f;
  --line: #d8e0e8;
  --brand: #0f7b75;
  --brand-dark: #095e59;
  --accent: #c46a2c;
  --danger: #b42318;
  --ok: #127044;
  --shadow: 0 12px 32px rgba(18, 31, 46, 0.08);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  overflow-x: hidden;
}

body.login-page {
  display: grid;
  place-items: center;
  grid-template-columns: 1fr;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, rgba(15, 123, 117, 0.16), transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(196, 106, 44, 0.12), transparent 35%),
    var(--bg);
}

.login-card {
  width: min(100%, 400px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card .brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.login-card .brand img {
  width: 40px;
  height: 40px;
}

.login-card .brand strong,
.login-card .brand span {
  display: block;
}

.login-card .brand span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.login-card form {
  display: grid;
  gap: 14px;
}

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

.login-card input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.login-card button {
  background: var(--brand);
  color: #fff;
  margin-top: 4px;
}

.login-card button:hover {
  background: var(--brand-dark);
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

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

button,
a.download {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.sidebar hr.nav-divider {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin: 8px 0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

pre.tg-log {
  margin-top: 16px;
  max-height: 260px;
  overflow: auto;
  background: #0f1720;
  color: #dbe7f3;
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.wizard-steps {
  display: grid;
  gap: 14px;
  margin: 16px 0;
}

.wizard-card {
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}

.wizard-card strong {
  display: block;
  margin-bottom: 4px;
}

details.tg-advanced {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

details.tg-advanced summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--brand-dark);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-ok {
  background: #e5f7ee;
  color: var(--ok);
}

.badge-muted {
  background: #eef1f4;
  color: var(--muted);
}

.sidebar {
  min-height: 100vh;
  padding: 20px;
  background: #10212c;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 38px;
  height: 38px;
}

.brand strong,
.brand span,
.sidebar-note strong,
.sidebar-note span {
  display: block;
}

.brand span,
.sidebar-note,
nav button {
  color: rgba(248, 250, 252, 0.88);
}

nav button {
  background: transparent;
  text-align: left;
  font-weight: 600;
}

nav button.active,
nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
}

.sidebar-note {
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.45;
}

nav {
  display: grid;
  gap: 8px;
}

.sidebar-note span {
  color: rgba(248, 250, 252, 0.82);
}

.sidebar-note strong {
  color: #fff;
  margin-bottom: 4px;
}

main {
  min-width: 0;
  max-width: 100vw;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.topbar p,
.block-head span,
.result-head p,
.toggle-row p,
.muted {
  color: var(--muted);
  line-height: 1.5;
}

.primary {
  background: var(--brand);
  color: #fff;
}

.primary:hover {
  background: var(--brand-dark);
}

.ghost {
  color: var(--brand-dark);
  background: #e8f3f2;
}

.tab {
  display: none;
}

.tab.active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 18px;
  align-items: start;
}

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

.controls,
.result {
  padding: 18px;
}

.block + .block {
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.block-head,
.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.block-head h2,
.result-head h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.source-grid button {
  color: var(--muted);
  background: #edf2f5;
  min-height: 42px;
}

.source-grid button.active {
  color: #fff;
  background: var(--brand);
}

.avito-fields {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafb;
  margin-bottom: 14px;
}

.avito-fields > strong,
.avito-fields > p {
  display: block;
}

.avito-fields > p {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.segmented label {
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 40px;
  place-items: center;
  border-radius: 6px;
  background: #edf2f5;
  color: var(--muted);
  font-weight: 700;
}

.segmented input:checked + span {
  background: var(--brand);
  color: #fff;
}

.notice {
  border: 1px solid #c7e7df;
  border-radius: 8px;
  padding: 10px 12px;
  color: #065f56;
  background: #edf8f5;
  font-size: 14px;
}

.dropzone {
  min-height: 84px;
  border: 1px dashed #9eb2c2;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  background: #f8fafb;
  margin-bottom: 14px;
}

.dropzone.drag {
  border-color: var(--brand);
  background: #e9f6f5;
}

.dropzone strong,
.dropzone span {
  display: block;
}

.dropzone span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
  color: #334456;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  min-height: 40px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

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

.full {
  grid-column: 1 / -1;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 14px;
}

.preset-row button {
  min-height: 34px;
  color: #334456;
  background: #eef3f5;
}

.coord-helper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  color: var(--muted);
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.coord-helper p {
  line-height: 1.45;
}

.coord-helper button {
  flex: 0 0 auto;
}

.toggle-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 14px 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
}

.switch span {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #b9c6d2;
  display: block;
  position: relative;
}

.switch span::after {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.15s ease;
}

.switch input:checked + span {
  background: var(--brand);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.download {
  display: inline-flex;
  align-items: center;
  color: #fff;
  background: var(--accent);
  text-decoration: none;
}

.download.disabled {
  pointer-events: none;
  color: #718096;
  background: #e4e9ee;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metrics article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.metrics span,
.metrics strong {
  display: block;
}

.metrics span {
  color: var(--muted);
  font-size: 13px;
}

.metrics strong {
  margin-top: 6px;
  font-size: 18px;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) 100px repeat(6, auto);
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.check {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  white-space: nowrap;
}

.check input {
  width: 18px;
  min-height: 18px;
}

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

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

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

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

th {
  color: #46596b;
  background: #f7f9fb;
  font-size: 13px;
}

td {
  line-height: 1.4;
}

tr[data-row] {
  cursor: pointer;
}

tr[data-row]:hover,
tr[data-row].selected {
  background: #eef8f7;
}

.score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 28px;
  color: #fff;
  background: var(--brand);
  border-radius: 6px;
  font-weight: 800;
}

.lead-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
  position: sticky;
  top: 18px;
}

.lead-card h3 {
  font-size: 17px;
  margin-bottom: 8px;
}

.lead-card dl {
  display: grid;
  gap: 9px;
  margin: 12px 0;
}

.lead-card dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.lead-card dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.lead-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.lead-actions a,
.lead-actions button {
  min-height: 34px;
  color: var(--brand-dark);
  background: #e8f3f2;
  border-radius: 6px;
  padding: 8px 10px;
  text-decoration: none;
  border: 0;
  font-weight: 700;
}

.logs {
  margin-top: 18px;
}

pre {
  min-height: 170px;
  max-height: 280px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  color: #d8f3dc;
  background: #101820;
  border-radius: 8px;
  white-space: pre-wrap;
}

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

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

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

.settings-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.settings-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  color: #fff;
  background: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: var(--ok);
}

.badge.warn {
  background: var(--accent);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 14px 16px;
  color: #fff;
  background: #17212b;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 1180px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    position: static;
  }

  .workspace,
  .result-layout {
    grid-template-columns: 1fr;
  }

  .lead-card {
    position: static;
  }

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

@media (max-width: 720px) {
  main {
    padding: 16px;
  }

  .topbar,
  .block-head,
  .result-head,
  .history-item {
    display: grid;
  }

  .grid,
  .metrics,
  .dropzone,
  .settings-grid,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .source-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  table {
    min-width: 760px;
  }
}
