* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #1f2937;
  background: #f5f6f8;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px;
  background: #111827; color: #fff;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 600; font-size: 16px; }
.auth a { color: #93c5fd; }
.auth { font-size: 13px; }

/* Hamburger button — hidden on desktop, shown on narrow screens. */
.icon-btn {
  display: none;
  background: transparent;
  border: 0;
  padding: 6px;
  cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 6px;
}
.icon-btn:hover { background: rgba(255,255,255,0.08); }
.hamburger,
.hamburger::before,
.hamburger::after {
  display: block;
  width: 20px; height: 2px;
  background: #fff;
  border-radius: 2px;
  position: relative;
  transition: transform 0.15s;
}
.hamburger::before { content: ''; position: absolute; top: -6px; left: 0; }
.hamburger::after  { content: ''; position: absolute; top:  6px; left: 0; }

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: calc(100vh - 56px);
  position: relative;
}
.sidebar {
  background: #fff;
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  overflow-y: auto;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.4);
  z-index: 19;
}
.sidebar section { margin-bottom: 28px; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sidebar h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; }
.tree { margin-top: 8px; }
.tree .brand-group { margin-bottom: 14px; }
.tree .brand-name {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: #9ca3af; padding: 4px 6px; font-weight: 600;
}
.tree .campaign-item {
  padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px;
  display: flex; justify-content: space-between; gap: 8px;
}
.tree .campaign-item:hover { background: #f3f4f6; }
.tree .campaign-item.active { background: #dbeafe; color: #1d4ed8; font-weight: 600; }
.tree .meta { font-size: 11px; color: #6b7280; }
button.small { padding: 4px 8px; font-size: 12px; }

.main { padding: 24px; overflow: auto; }
.main-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.main-header h2 { margin: 0; }
.stats { display: flex; gap: 18px; font-size: 13px; color: #4b5563; }
.stats span b { color: #111827; }

.card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 16px; margin-bottom: 16px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.card-header .actions { display: flex; gap: 8px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.row { display: flex; gap: 8px; margin-bottom: 8px; }
.row > * { flex: 1; }
input[type=text], input[type=email], input[type=url], select, textarea {
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px;
  font-family: inherit;
}
textarea { width: 100%; resize: vertical; box-sizing: border-box; }
td.editable { cursor: text; }
td.editable:hover { background: #f3f4f6; }
td.editable input { width: 100%; box-sizing: border-box; padding: 4px 6px; font: inherit; }
button {
  padding: 8px 14px; border: 0; background: #2563eb; color: #fff;
  border-radius: 6px; cursor: pointer; font-size: 14px;
}
button.ghost { background: transparent; color: #2563eb; border: 1px solid #2563eb; }
button.danger { background: #dc2626; }
/* Destructive outline button (e.g. Remove all creators). */
button.ghost.danger { background: transparent; color: #dc2626; border-color: #dc2626; }
button.ghost.danger:hover { background: #fef2f2; }
button.small { padding: 4px 8px; font-size: 12px; }
.hint { font-size: 12px; color: #6b7280; margin: 4px 0 0; }
#scrape-progress { display: flex; align-items: center; gap: 12px; }
#scrape-progress-text { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #e5e7eb; font-size: 13px; vertical-align: top; }
th { background: #f9fafb; font-weight: 600; color: #4b5563; }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  text-transform: uppercase;
}
.tag.pending_extraction { background: #fef3c7; color: #92400e; }
.tag.email_found { background: #dbeafe; color: #1d4ed8; }
.tag.no_email { background: #f3f4f6; color: #6b7280; }
.tag.outreach_sent { background: #e0e7ff; color: #4338ca; }
.tag.followup_sent { background: #ede9fe; color: #6d28d9; }
.tag.replied { background: #d1fae5; color: #065f46; }
.tag.failed { background: #fee2e2; color: #991b1b; }
.tag.invalid_email { background: #ffedd5; color: #9a3412; }

/* Sidebar nav link to Follow-up Rules page */
.sidebar-section { margin-top: 24px; }
.sidebar-nav-link {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: #374151;
  text-align: left;
}
.sidebar-nav-link:hover { background: #f3f4f6; }
.sidebar-nav-link .meta { color: #9ca3af; }

/* Email Templates page */
.template-block { margin: 10px 0; border: 1px solid #e5e7eb; border-radius: 6px; background: #fafafa; }
.template-block > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.template-block > summary::-webkit-details-marker { display: none; }
.template-block > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 6px;
  color: #6b7280;
  transition: transform 0.15s;
}
.template-block[open] > summary::before { transform: rotate(90deg); }
.template-block-title { font-weight: 600; font-size: 14px; color: #111827; flex: 1; }
.template-block-meta { display: flex; gap: 8px; align-items: center; }
.template-block-meta .badge.default {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #dbeafe;
  color: #1e40af;
  padding: 2px 8px;
  border-radius: 10px;
}
.template-block-body { padding: 14px; border-top: 1px solid #e5e7eb; }
.template-block-body h4 { margin: 0 0 6px; font-size: 13px; color: #374151; }
.template-block-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #4b5563; margin-top: 8px; }
.template-block-body label.checkbox-label { flex-direction: row; align-items: center; gap: 6px; }
.template-block-body input[type="text"],
.template-block-body input[type="number"],
.template-block-body textarea {
  padding: 6px 8px; font-size: 13px; border: 1px solid #d1d5db; border-radius: 4px; font-family: inherit;
}
.template-block-body textarea { resize: vertical; }

/* Follow-up rows inside a template */
.followups-list { display: flex; flex-direction: column; gap: 8px; }
.followup-row { border: 1px solid #e5e7eb; border-radius: 6px; background: #fff; }
.followup-row > summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.followup-row > summary::-webkit-details-marker { display: none; }
.followup-row > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 4px;
  color: #6b7280;
  transition: transform 0.15s;
}
.followup-row[open] > summary::before { transform: rotate(90deg); }
.followup-row-title { font-weight: 600; font-size: 13px; color: #374151; }
.followup-row-meta { flex: 1; }
.followup-row-body { padding: 0 12px 12px; }

/* Per-campaign template picker card */
#campaign-template-card .row { flex-wrap: wrap; }
#campaign-template-card select { padding: 6px 8px; font-size: 13px; border: 1px solid #d1d5db; border-radius: 4px; min-width: 280px; }

/* Horizontal scroll wrapper for the (wide) creator table. The table is given a
   comfortable min-width below so columns never get crushed together; this
   wrapper then provides a visible horizontal scrollbar to pan left/right. */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
  /* Firefox */
  scrollbar-width: thin;
  scrollbar-color: #9ca3af #eef0f3;
  /* Soft edge fade hints there's more to scroll horizontally. */
  background:
    linear-gradient(to right, #fff 30%, rgba(255, 255, 255, 0)) left center,
    linear-gradient(to left, #fff 30%, rgba(255, 255, 255, 0)) right center,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0)) left center,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0)) right center;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
/* WebKit/Blink scrollbar — make the "slider" obvious and easy to grab. */
.table-scroll::-webkit-scrollbar { height: 12px; }
.table-scroll::-webkit-scrollbar-track { background: #eef0f3; border-radius: 8px; }
.table-scroll::-webkit-scrollbar-thumb {
  background: #b6bcc6; border-radius: 8px; border: 2px solid #eef0f3;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: #9099a6; }

/* Give the creator table a comfortable width so its 9 columns (incl. the
   Views / Rate negotiation columns) stay readable instead of cramming into the
   viewport. The wrapper above scrolls when the screen is narrower. */
#creator-table { min-width: 1100px; }
#creator-table th, #creator-table td { vertical-align: top; }
/* Per-column breathing room. */
#creator-table th:nth-child(1), #creator-table td:nth-child(1) { min-width: 140px; } /* Instagram */
#creator-table th:nth-child(2), #creator-table td:nth-child(2) { min-width: 130px; } /* Name */
#creator-table th:nth-child(3), #creator-table td:nth-child(3) { min-width: 190px; } /* Email */
#creator-table th:nth-child(4), #creator-table td:nth-child(4) { min-width: 110px; white-space: nowrap; } /* Status */
#creator-table th:nth-child(5), #creator-table td:nth-child(5) { min-width: 72px; }  /* Opens */
#creator-table th:nth-child(6), #creator-table td:nth-child(6) { min-width: 130px; } /* Last activity */
#creator-table th:nth-child(7), #creator-table td:nth-child(7) { min-width: 118px; } /* Views */
#creator-table th:nth-child(8), #creator-table td:nth-child(8) { min-width: 210px; } /* Rate (value + timeline) */
#creator-table th:nth-child(9), #creator-table td:nth-child(9) { min-width: 96px; }  /* Actions */

/* --- Responsive: tablet and below ---------------------------------------- */
@media (max-width: 900px) {
  .main { padding: 16px; }
  .main-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .stats { flex-wrap: wrap; gap: 10px 16px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-header .actions { flex-wrap: wrap; }
}

/* --- Responsive: phones (sidebar becomes a slide-in drawer) ------------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .auth { font-size: 12px; max-width: 50vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: min(85vw, 320px);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { display: block; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .main { padding: 14px; }
  .card { padding: 12px; }
  .card-header h3 { font-size: 14px; }

  .row { flex-direction: column; }
  .row > * { width: 100%; }

  button { padding: 10px 14px; font-size: 14px; }

  /* Stretch buttons inside card headers so they're easy to tap */
  .card-header .actions { width: 100%; }
  .card-header .actions button { flex: 1 1 auto; min-width: 0; }

  /* Tables can't reflow; horizontal scroll wrapper handles overflow. */
  table { min-width: 720px; }

  /* Template page tweaks */
  .template-block-body { padding: 10px; }
  .template-block-meta { flex-wrap: wrap; justify-content: flex-end; }
  #campaign-template-card select { min-width: 0; width: 100%; }
}

/* --- Negotiation (Views / Rate / Offer columns + Max CPM) ---------------- */
.neg-cpm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}
.neg-cpm-label { font-size: 13px; font-weight: 600; color: #374151; white-space: nowrap; }
.neg-cpm-input { width: 110px; padding: 5px 8px; font-size: 13px; border: 1px solid #d1d5db; border-radius: 4px; }

.neg-offer { min-width: 230px; }
.neg-offer-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.neg-offer-head:empty { display: none; }
.neg-offer .neg-stage {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #4338ca;
  background: #e0e7ff;
  padding: 2px 6px;
  border-radius: 10px;
  margin-bottom: 0;
}
.neg-approved-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #92400e;
  background: #fef3c7;
  padding: 2px 6px;
  border-radius: 10px;
}
.neg-approved-badge.sent { color: #065f46; background: #d1fae5; }
.neg-offer-select { width: 100%; padding: 5px 8px; font-size: 12px; border: 1px solid #d1d5db; border-radius: 4px; margin-bottom: 6px; }
.neg-slider { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.neg-slider label { font-size: 11px; color: #6b7280; }
.neg-slider label b { color: #111827; }
.neg-offer input[type="range"] { width: 100%; accent-color: #2563eb; height: 18px; }
.neg-approve { width: 100%; background: #2563eb; }
.neg-approve:disabled { opacity: 0.6; cursor: default; }
.neg-offer-status { display: block; margin-top: 4px; }
/* Read-only view/video basis line under the offer dropdown. */
.neg-offer-basis { margin: 0 0 6px; }
/* The fee is now the computed read-out (admin sets CPM above). */
.neg-fee-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: #065f46;
  background: #d1fae5;
  padding: 3px 10px;
  border-radius: 10px;
  margin-bottom: 8px;
}

/* --- Rate column: editable value + delivery-tracking timeline ------------- */
.rate-value { font-weight: 600; }
.rate-value.editable { cursor: text; border-radius: 4px; padding: 1px 3px; margin: -1px -3px; }
.rate-value.editable:hover { background: #f3f4f6; }
.rate-value input { width: 100%; box-sizing: border-box; padding: 4px 6px; font: inherit; }

.rate-log { list-style: none; margin: 10px 0 0; padding: 0; }
.rate-log-item { position: relative; display: flex; gap: 8px; padding: 0 0 10px 2px; }
/* Vertical connector between the step dots. */
.rate-log-item::before {
  content: '';
  position: absolute;
  left: 5px; top: 12px; bottom: -2px;
  width: 2px; background: #e5e7eb;
}
.rate-log-item:last-child::before { display: none; }
.rate-log-dot {
  flex: 0 0 auto;
  width: 12px; height: 12px;
  margin-top: 2px;
  border-radius: 50%;
  background: #cbd5e1;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #cbd5e1;
  z-index: 1;
}
.rate-log-body { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.rate-log-text { font-size: 12px; color: #6b7280; word-break: break-word; }
.rate-log-when { font-size: 10px; color: #9ca3af; }
/* The newest entry is the current state — emphasize it. */
.rate-log-item.current .rate-log-text { color: #111827; font-weight: 600; }
/* Tone accents. */
.rate-log-item.tone-active .rate-log-dot { background: #6366f1; box-shadow: 0 0 0 1px #6366f1; }
.rate-log-item.tone-success .rate-log-dot { background: #10b981; box-shadow: 0 0 0 1px #10b981; }
.rate-log-item.tone-muted .rate-log-dot { background: #9ca3af; box-shadow: 0 0 0 1px #9ca3af; }
.rate-log-item.current.tone-active .rate-log-text { color: #4338ca; }
.rate-log-item.current.tone-success .rate-log-text { color: #065f46; }

/* --- Per-creator email thread dropdown ----------------------------------- */
.thread-toggle.active { background: #2563eb; color: #fff; border-color: #2563eb; }
tr.thread-row > td { background: #f9fafb; padding: 0; }
.thread-box {
  padding: 14px 16px;
  max-height: 440px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.thread-msg {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  max-width: 80%;
}
.thread-msg.out { align-self: flex-end; background: #eff6ff; border-color: #bfdbfe; }
.thread-msg.in  { align-self: flex-start; }
.thread-meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.thread-meta b { font-size: 13px; }
.thread-subj { font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; }
.thread-body { font-size: 13px; color: #1f2937; white-space: pre-wrap; word-break: break-word; }

/* Count badge on the Delegate button */
.count-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  margin-left: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  color: #fff;
  background: #dc2626;
  border-radius: 999px;
}

/* --- Delegate window ----------------------------------------------------- */
.delegate-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fff;
}
.delegate-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.delegate-head a { font-weight: 600; }
.delegate-reason {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  padding: 3px 8px;
  border-radius: 10px;
  max-width: 55%;
}
.delegate-question {
  margin-top: 10px;
  padding: 10px 12px;
  background: #f9fafb;
  border-left: 3px solid #cbd5e1;
  border-radius: 4px;
  font-size: 13px;
  color: #1f2937;
  white-space: pre-wrap;
  word-break: break-word;
}
.delegate-reply { width: 100%; box-sizing: border-box; }
/* "offer to approve" pill (when a card is here purely for an offer). */
.delegate-reason.offer { color: #4338ca; background: #e0e7ff; }
.delegate-subtitle { margin-top: 10px; }
/* The relocated offer controls inside a delegate card. */
.delegate-card .neg-offer { margin-top: 12px; max-width: 360px; }

/* Template "AI off" badge (mirrors .badge.default) */
.template-block-meta .badge.ai-off {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #fee2e2;
  color: #991b1b;
  padding: 2px 8px;
  border-radius: 10px;
}
