:root {
  color-scheme: light;
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --ink: #15202e;
  --muted: #66758a;
  --line: #d9e0e8;
  --accent: #0f766e;
  --accent-strong: #0a5c56;
  --success: #157347;
  --warm: #a45b13;
  --danger: #b42318;
  --shadow: 0 16px 38px rgba(29, 45, 68, 0.09);
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.1), transparent 34%),
    linear-gradient(315deg, rgba(164, 91, 19, 0.08), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: Avenir Next, Manrope, Verdana, sans-serif;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

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

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

button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

button.ghost {
  background: transparent;
}

button.danger {
  border-color: #f0c7c2;
  color: var(--danger);
}

input,
select {
  min-height: 38px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.topbar h1,
.detail h2,
.sidebar h2,
.detail h3 {
  margin: 0;
}

.topbar h1 {
  font-size: 23px;
  line-height: 1.1;
}

.topbar p,
.hint,
.eyebrow,
.upload-card p,
.test-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.session-box,
.login-box {
  display: grid;
  grid-template-columns: auto minmax(190px, 280px) auto;
  gap: 8px;
  align-items: center;
}

.session-box {
  grid-template-columns: auto auto auto;
}

.user-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.auth-view {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 42px 18px;
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(340px, 0.9fr);
  gap: 18px;
  align-items: stretch;
}

.auth-hero {
  position: relative;
  overflow: hidden;
  min-height: 620px;
  display: grid;
  align-content: space-between;
  gap: 28px;
  padding: 34px;
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(15, 118, 110, 0.94), rgba(13, 64, 67, 0.98)),
    #0f766e;
  color: #fff;
  box-shadow: var(--shadow);
}

.auth-hero::after {
  content: "";
  position: absolute;
  inset: auto -90px -120px auto;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
}

.auth-hero-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 24px;
  font-weight: 850;
}

.auth-hero h2 {
  max-width: 620px;
  margin: 10px 0 0;
  font-size: 42px;
  line-height: 1.04;
}

.auth-hero p {
  max-width: 590px;
  margin: 16px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 17px;
  line-height: 1.55;
}

.auth-hero .eyebrow {
  color: rgba(255, 255, 255, 0.72);
}

.auth-proof-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.auth-proof-grid div {
  min-height: 124px;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
}

.auth-proof-grid strong {
  font-size: 14px;
}

.auth-proof-grid span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  line-height: 1.35;
}

.auth-card {
  display: grid;
  gap: 18px;
  align-content: center;
  min-height: 620px;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.auth-card h2 {
  margin: 4px 0 0;
  font-size: 34px;
  line-height: 1.1;
}

.auth-card p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.auth-message {
  min-height: 42px;
  color: var(--muted);
}

.auth-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}

.oauth-block {
  display: grid;
  gap: 10px;
}

.divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.oauth-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.oauth-button {
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
  text-align: center;
}

.oauth-button.disabled {
  opacity: 0.52;
  pointer-events: none;
}

.telegram-auth {
  min-height: 40px;
  display: grid;
  align-items: center;
}

.auth-links a,
.link-button {
  border: 0;
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: none;
}

.link-button:hover,
.auth-links a:hover {
  text-decoration: underline;
  transform: none;
}

.token-form {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.workspace {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.phone-gate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.phone-gate h2 {
  margin: 4px 0 0;
}

.phone-gate p {
  margin: 6px 0 0;
  color: var(--muted);
}

.phone-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.sidebar,
.detail,
.admin-panel,
.upload-card,
.test-card,
.script-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar,
.detail,
.admin-panel {
  padding: 16px;
}

.panel-head,
.detail-head,
.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.campaign-list,
.lead-list {
  display: grid;
  gap: 9px;
}

.campaign-row {
  display: grid;
  width: 100%;
  gap: 8px;
  min-height: 92px;
  padding: 12px;
  text-align: left;
  background: var(--surface-soft);
}

.campaign-row.active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.row-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  font-weight: 750;
  line-height: 1.25;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: #edf1f5;
  color: #35465c;
  font-size: 12px;
  white-space: nowrap;
}

.badge.running {
  background: #dbf2ea;
  color: var(--success);
}

.badge.paused {
  background: #fff0d8;
  color: var(--warm);
}

.badge.finished {
  background: #e8edf5;
  color: #53657e;
}

.progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4eaf0;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.detail-head {
  align-items: center;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 800;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.metric-button {
  width: 100%;
  height: 100%;
  display: grid;
  align-content: start;
  text-align: left;
}

.metric-button:hover:not(:disabled) {
  background: #eef8f6;
}

.metric.accent {
  border-color: rgba(15, 118, 110, 0.35);
}

.metric.success {
  border-color: rgba(21, 115, 71, 0.32);
}

.metric.warm {
  border-color: rgba(164, 91, 19, 0.32);
}

.metric-value {
  font-size: 25px;
  font-weight: 800;
  line-height: 1;
}

.metric-label {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.metric-hint {
  margin-top: 7px;
  color: var(--accent);
  font-size: 11px;
}

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

.upload-card,
.test-card,
.script-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  box-shadow: none;
}

.script-card {
  margin-bottom: 18px;
}

.script-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.script-status {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 11px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.script-status.ready {
  border-color: rgba(22, 128, 114, .24);
  color: var(--primary);
  background: rgba(22, 128, 114, .08);
}

.script-status.admin {
  border-color: rgba(190, 125, 38, .28);
  color: #9a5d13;
  background: rgba(190, 125, 38, .08);
}

.script-guide {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.script-guide div {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--surface-soft);
}

.script-guide strong,
.script-fields span {
  display: block;
  color: var(--text);
  font-weight: 800;
  line-height: 1.25;
}

.script-guide span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.script-fields label {
  display: grid;
  gap: 7px;
}

.script-card textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px;
  font: inherit;
  line-height: 1.45;
}

.script-fields textarea {
  min-height: 132px;
}

.script-controls {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px auto;
  gap: 8px;
}

.upload-controls,
.test-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.test-controls {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.lead-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--surface-soft);
}

.results-title {
  margin-top: 18px;
}

.results-table {
  display: grid;
  gap: 9px;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) auto auto minmax(170px, auto);
  gap: 9px 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.result-name {
  font-weight: 750;
  line-height: 1.25;
}

.result-meta,
.result-summary {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.result-pill {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.result-summary {
  grid-column: 1 / -1;
}

.empty-state {
  border: 1px dashed #cbd4df;
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.admin-panel {
  margin-top: 16px;
}

.user-create-form {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(150px, 1fr) minmax(190px, 1fr) minmax(130px, 0.8fr) minmax(100px, 0.6fr) auto auto auto;
  gap: 8px;
  margin-bottom: 14px;
}

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

.user-row {
  display: grid;
  grid-template-columns: minmax(240px, 1.3fr) minmax(120px, 0.8fr) minmax(140px, 0.8fr) minmax(180px, 1fr) auto auto minmax(86px, 0.5fr) auto auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--surface-soft);
}

.badge.active {
  background: #dbf2ea;
  color: var(--success);
}

.badge.pending {
  background: #fff0d8;
  color: var(--warm);
}

.badge.disabled {
  background: #f7dedb;
  color: var(--danger);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(21, 32, 46, 0.42);
  backdrop-filter: blur(4px);
}

.modal-panel {
  position: relative;
  width: min(680px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(21, 32, 46, 0.24);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.modal-head h2 {
  margin: 0;
}

.modal-head p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.leads-modal-panel {
  display: grid;
  gap: 12px;
}

.lead-source-box {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.lead-source-box h3 {
  margin: 0;
}

.lead-source-box p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.lead-source-box textarea {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px;
  font: inherit;
  line-height: 1.45;
}

.billing-total {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  background: #eef8f6;
}

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

.billing-total strong {
  font-size: 24px;
}

.billing-list {
  min-height: 120px;
  overflow: auto;
  display: grid;
  gap: 9px;
  padding-right: 2px;
}

.billing-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.billing-row-title,
.billing-row-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.billing-row-title {
  font-weight: 750;
}

.billing-row-meta,
.billing-description {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.billing-amount {
  white-space: nowrap;
}

.billing-amount.positive {
  color: var(--success);
}

.billing-amount.negative {
  color: var(--danger);
}

@media (max-width: 980px) {
  .topbar,
  .main-grid,
  .work-row,
  .auth-view,
  .phone-gate,
  .phone-form,
  .oauth-grid,
  .script-controls,
  .script-guide,
  .script-fields,
  .user-create-form,
  .user-row {
    grid-template-columns: 1fr;
  }

  .auth-hero,
  .auth-card {
    min-height: auto;
  }

  .auth-proof-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .login-box,
  .session-box {
    grid-template-columns: 1fr;
  }

  .summary-strip,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .detail-head,
  .section-title {
    display: grid;
  }

  .actions {
    justify-content: stretch;
  }

  .actions button,
  .test-controls button,
  .upload-controls button {
    width: 100%;
  }

  .upload-controls,
  .test-controls {
    grid-template-columns: 1fr;
  }

  .result-row {
    grid-template-columns: 1fr;
  }

  .modal-head,
  .billing-total,
  .billing-row-title,
  .billing-row-meta {
    display: grid;
  }
}

@media (max-width: 560px) {
  .workspace,
  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .summary-strip,
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
