:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #eef4fa;
  --text: #16202a;
  --muted: #647382;
  --line: #d9e2ea;
  --blue: #1d6fd6;
  --green: #12805c;
  --red: #c23a3a;
  --amber: #a76612;
  --shadow: 0 16px 40px rgba(36, 54, 74, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter,
    "Segoe UI",
    Arial,
    sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 42px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

.topbar-actions,
.period-group,
.panel-heading,
.tabs,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.role-field {
  min-width: 170px;
}

.client-mode .specialist-only {
  display: none !important;
}

.client-mode .workspace-grid {
  grid-template-columns: 1fr;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-heading {
  display: grid;
  gap: 4px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-mode-login #register-form,
.auth-mode-register #login-form {
  display: none !important;
}

.auth-message {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

.auth-message.is-info {
  color: var(--blue);
}

.link-button {
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 900;
  text-align: left;
  padding: 0;
}

.user-info {
  min-width: min(320px, 100%);
}

.user-info div {
  display: grid;
  gap: 3px;
  text-align: right;
}

.user-info span {
  color: var(--text);
  font-weight: 900;
}

.user-info strong {
  color: var(--muted);
  font-size: 13px;
}

.tabs {
  margin-bottom: 14px;
  overflow-x: auto;
}

.tab-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--muted);
  padding: 0 16px;
  font-weight: 900;
  white-space: nowrap;
}

.tab-button.is-active {
  border-color: var(--blue);
  background: #eaf3ff;
  color: var(--blue);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.control-panel,
.panel,
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  margin-bottom: 14px;
}

.period-group {
  flex-wrap: wrap;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 111, 214, 0.16);
}

.data-freshness {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid #f0d8ae;
  border-radius: 7px;
  background: #fff8ed;
  color: var(--amber);
  font-size: 13px;
  font-weight: 800;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--amber);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 108px;
  padding: 16px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metric-card strong {
  align-self: end;
  font-size: 25px;
  line-height: 1;
  white-space: nowrap;
}

.metric-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.metric-placeholder strong {
  color: var(--muted);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  padding: 16px;
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

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

.form-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  margin-top: 14px;
}

.sync-state {
  display: grid;
  gap: 10px;
}

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

.settings-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  color: var(--text);
}

.settings-grid input {
  width: 16px;
  min-height: 16px;
}

.sync-state div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.sync-state span,
.muted-copy {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.sync-state strong {
  text-align: right;
}

.placeholder-box {
  display: grid;
  gap: 8px;
  min-height: 120px;
  align-content: center;
  padding: 16px;
  border: 1px dashed #bfd2e6;
  border-radius: 8px;
  background: #f8fbff;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
  font-weight: 700;
}

.placeholder-box strong {
  color: var(--text);
  font-size: 16px;
}

.placeholder-box p {
  margin: 0;
}

.client-form {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.client-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.yandex-account-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.client-main,
.client-project,
.yandex-account-item div {
  display: grid;
  gap: 4px;
}

.client-item span,
.yandex-account-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.client-item strong,
.yandex-account-item strong {
  color: var(--text);
  font-size: 14px;
}

.client-webhook {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.client-webhook code {
  min-width: 0;
  overflow: hidden;
  padding: 5px 7px;
  border: 1px solid #cfe1f7;
  border-radius: 6px;
  background: #eef6ff;
  color: var(--blue);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-webhook {
  min-height: 30px;
  border: 1px solid #cfe1f7;
  border-radius: 7px;
  background: #ffffff;
  color: var(--blue);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

.specialist-client-line {
  color: var(--text);
  font-weight: 800;
}

button:disabled,
button.is-loading {
  cursor: wait;
  opacity: 0.68;
}

.primary-button,
.danger-button,
.ghost-button,
.icon-button {
  min-height: 42px;
  border-radius: 7px;
  border: 1px solid transparent;
  font-weight: 900;
}

.primary-button {
  width: 100%;
  background: var(--blue);
  color: #ffffff;
}

.danger-button {
  background: #fff1f1;
  border-color: #ffd0d0;
  color: var(--red);
  padding: 0 12px;
}

.ghost-button,
.icon-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
  padding: 0 12px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  padding: 0;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

[hidden],
.is-hidden {
  display: none !important;
}

.table-panel {
  margin-bottom: 14px;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
  font-weight: 700;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

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

.lead-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.lead-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-weight: 900;
}

.lead-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.touchpoints-panel {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #cfe1f7;
  border-radius: 8px;
  background: #f3f8ff;
}

.touchpoint-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.touchpoint-icon {
  display: inline-grid;
  place-items: center;
  width: 28px;
  min-height: 28px;
  border-radius: 7px;
  background: var(--surface-strong);
  font-size: 15px;
}

.touchpoint-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.touchpoint-copy strong {
  color: var(--text);
  font-size: 13px;
}

.touchpoint-copy span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

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

.badge.neutral {
  background: var(--surface-strong);
  color: var(--muted);
}

.badge.good {
  background: #e8f6f0;
  color: var(--green);
}

.badge.warn {
  background: #fff8ed;
  color: var(--amber);
}

.badge.danger {
  background: #fff1f1;
  color: var(--red);
}

.delete-lead,
.edit-lead,
.touchpoints-toggle {
  min-height: 30px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 900;
}

.delete-lead {
  border: 1px solid #ffd0d0;
  background: #fff7f7;
  color: var(--red);
}

.edit-lead {
  border: 1px solid #cfe1f7;
  background: #eef6ff;
  color: var(--blue);
}

.touchpoints-toggle {
  border: 1px solid #d6dfeb;
  background: var(--surface);
  color: var(--text);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(360px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #16202a;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 12px;
  }

  .topbar,
  .control-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .period-group,
  .form-grid,
  .settings-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 94px;
  }

  .metric-card strong {
    font-size: 22px;
  }

  .lead-item {
    grid-template-columns: 1fr;
  }

  .client-item,
  .yandex-account-item {
    grid-template-columns: 1fr;
  }

  .client-webhook {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .copy-webhook {
    justify-self: start;
  }

  .badge-row {
    justify-content: flex-start;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 30px;
  }
}
