:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #fcfcfc;
  --ink: #1d1d1f;
  --muted: #86868b;
  --line: #e5e5ea;
  --accent: #0071e3;
  --accent-hover: #0058c7;
  --accent-2: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: -0.01em;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 18px 32px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
  font-weight: 650;
}

h2 {
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0;
}

.topbar p,
.results-toolbar p,
.status-line,
.muted {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 32px 36px;
}

.panel,
.drawer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.035);
}

.control-panel {
  padding: 18px;
  align-self: start;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.label-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
  flex: 0 0 auto;
}

.info-tip::after {
  content: attr(aria-label);
  position: absolute;
  left: 0;
  bottom: calc(100% + 9px);
  width: min(250px, calc(100vw - 32px));
  transform: translateY(4px);
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #17211d;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
  z-index: 20;
  text-transform: none;
  white-space: normal;
}

.info-tip::before {
  content: "";
  position: absolute;
  left: 8px;
  bottom: calc(100% + 4px);
  width: 8px;
  height: 8px;
  background: #17211d;
  transform: rotate(45deg);
  opacity: 0;
  transition: opacity 120ms ease;
  z-index: 19;
}

.info-tip:hover::after,
.info-tip:focus::after {
  opacity: 1;
  transform: translateY(0);
}

.info-tip:hover::before,
.info-tip:focus::before {
  opacity: 1;
}

.info-tip.align-center::after {
  left: 50%;
  transform: translateX(-50%) translateY(4px);
}

.info-tip.align-center:hover::after,
.info-tip.align-center:focus::after {
  transform: translateX(-50%) translateY(0);
}

.info-tip.align-center::before {
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
}

.info-tip.align-right::after {
  right: 0;
  left: auto;
}

.info-tip.align-right::before {
  right: 8px;
  left: auto;
}

@media (max-width: 900px) {
  .info-tip.align-center::after,
  .info-tip.align-right::after {
    right: auto;
    left: 0;
    transform: translateY(4px);
  }

  .info-tip.align-center:hover::after,
  .info-tip.align-center:focus::after,
  .info-tip.align-right:hover::after,
  .info-tip.align-right:focus::after {
    transform: translateY(0);
  }

  .info-tip.align-center::before,
  .info-tip.align-right::before {
    right: auto;
    left: 8px;
    transform: rotate(45deg);
  }
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
}

.controls-grid,
.name-grid,
.batch-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

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

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

.cost-estimate {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  padding: 10px 11px;
}

.toggles {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.toggles input,
th input {
  width: auto;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 113, 227, 0.22);
}

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

.full-width {
  width: 100%;
  margin-top: 10px;
}

.secondary-button {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.035);
}

.secondary-button:hover {
  background: var(--surface-2);
}

.danger-button {
  background: #fff;
  color: var(--accent-2);
  border-color: rgba(255, 59, 48, 0.25);
}

.danger-button:hover {
  background: rgba(255, 59, 48, 0.08);
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.icon-button {
  width: 38px;
  padding: 0;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  font-size: 20px;
}

.small-icon-button {
  width: 38px;
  min-height: 38px;
  flex: 0 0 38px;
  font-size: 17px;
}

.results-panel {
  min-width: 0;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

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

.selection-line {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.campaign-select-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(330px, 100%);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.campaign-select-label select {
  min-height: 38px;
  padding: 0 34px 0 11px;
  color: var(--ink);
  font-size: 13px;
}

.campaign-status {
  max-width: 210px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.table-wrap {
  overflow: auto;
}

.list-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--line);
}

.compact-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--surface-3);
  border-bottom: 1px solid var(--line);
}

.filters-bar {
  display: grid;
  grid-template-columns: minmax(140px, 1.25fr) minmax(140px, 1.25fr) minmax(120px, 1fr) repeat(4, minmax(120px, 0.85fr)) auto;
  align-items: end;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.filters-bar label {
  gap: 5px;
}

.filters-bar input,
.filters-bar select {
  min-height: 36px;
  padding: 8px 10px;
  font-size: 12px;
}

.tab-button {
  min-height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 0 18px;
  font-weight: 650;
}

.tab-button span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  margin-left: 7px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
}

.tab-button.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.lead-list-section[hidden] {
  display: none;
}

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

th,
td {
  text-align: left;
  padding: 11px 18px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--surface-3);
  font-weight: 650;
}

.sort-header {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  font: inherit;
  font-weight: 750;
  text-transform: inherit;
  letter-spacing: inherit;
}

.sort-header:hover,
.sort-header.active {
  color: var(--accent);
}

.sort-indicator {
  font-size: 12px;
  line-height: 1;
}

tr:hover td {
  background: rgba(245, 245, 247, 0.72);
}

tr:has(.row-check:checked) td {
  background: rgba(0, 113, 227, 0.07);
}

.empty-row td {
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.lead-button {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--accent);
  font-weight: 650;
  text-align: left;
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}

.pill.failed {
  color: var(--accent-2);
  background: rgba(255, 59, 48, 0.1);
}

.pill.ready {
  color: #1f8f3a;
  background: rgba(52, 199, 89, 0.12);
}

.pill.waiting {
  color: var(--warning);
  background: rgba(255, 149, 0, 0.12);
}

.inline-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.inline-link:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  padding: 18px;
  transform: translateX(105%);
  transition: transform 160ms ease;
  box-shadow: -18px 0 45px rgba(16, 31, 27, 0.14);
  overflow: auto;
  z-index: 30;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  position: sticky;
  top: -18px;
  z-index: 2;
  padding: 18px 0 10px;
  background: var(--surface);
}

#closeEditor {
  flex: 0 0 38px;
}

#editForm {
  display: grid;
  gap: 14px;
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

  .topbar {
    padding: 16px 14px;
  }

  .results-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions button {
    flex: 1 1 160px;
  }

  .toolbar-actions .small-icon-button {
    flex: 0 0 38px;
  }

  .filters-bar {
    grid-template-columns: 1fr 1fr;
  }

  .campaign-status {
    max-width: none;
    width: 100%;
  }

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