:root {
  --brand: #0077b6;
  --brand-light: #00b4d8;
  --ink: #10232e;
  --muted: #5b7180;
  --line: #dbe4ea;
  --bg: #f4f7f9;
  --card: #fff;
  --danger: #b42318;
  --ok: #067647;
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] loses to any class selector that sets display, and
   this file sets display on .login, .drawer and the table. Without this, every
   element JS hides with .hidden = true stays on screen -- the drawer worst of
   all, as a full-viewport overlay that eats every click. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button {
  font: inherit;
  cursor: pointer;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}
button:hover { background: var(--brand-light); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.link { background: none; color: var(--brand); padding: 6px 4px; font-weight: 500; }
button.link:hover { background: none; text-decoration: underline; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--brand-light);
  outline-offset: 2px;
}
label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }

/* ---- login ------------------------------------------------------------- */
.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login .card {
  width: min(420px, 100%);
  background: var(--card);
  padding: 32px;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgb(16 35 46 / 10%);
}
.login h1 { margin: 0 0 8px; font-size: 22px; }
.login p { margin: 0; color: var(--muted); }
.login button[type="submit"] { width: 100%; margin-top: 18px; }
.note { min-height: 20px; margin-top: 12px !important; font-size: 13px; }
.note.error { color: var(--danger); }
.note.ok { color: var(--ok); }

/* ---- shell ------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 14px 20px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 7px 14px;
  font-size: 13px;
}
.chips button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
#search-form { display: flex; gap: 8px; flex: 1; min-width: 260px; }

main { padding: 0 20px 40px; }

.leads { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; }
.leads th, .leads td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.leads th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.leads tbody tr { cursor: pointer; }
.leads tbody tr:hover { background: #eef5f9; }
.leads td.wrap { max-width: 260px; }

.tag { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.new { background: #e0f2fe; color: #075985; }
.tag.in_progress { background: #fef3c7; color: #92400e; }
.tag.won { background: #dcfce7; color: var(--ok); }
.tag.lost { background: #f1f5f9; color: #475569; }
.tag.spam { background: #fee2e2; color: var(--danger); }
.tag.sent { background: #dcfce7; color: var(--ok); }
.tag.pending { background: #f1f5f9; color: #475569; }
.tag.failed { background: #fee2e2; color: var(--danger); }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 20px; }
.pager span { color: var(--muted); font-size: 13px; }

/* ---- drawer ------------------------------------------------------------ */
.drawer { position: fixed; inset: 0; background: rgb(16 35 46 / 45%); display: flex; justify-content: flex-end; }
.drawer-inner {
  width: min(480px, 100%);
  background: var(--card);
  padding: 28px;
  overflow-y: auto;
  position: relative;
}
.drawer h2 { margin: 0 40px 4px 0; font-size: 20px; }
.close { position: absolute; top: 16px; right: 16px; background: none; color: var(--muted); font-size: 26px; line-height: 1; padding: 4px 10px; }
.close:hover { background: none; color: var(--ink); }
.drawer dl { margin: 20px 0; display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 14px; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; overflow-wrap: anywhere; }
#drawer-form button { width: 100%; margin-top: 14px; }
#drawer-retry { background: var(--card); color: var(--danger); border: 1px solid var(--danger); }
#drawer-retry:hover { background: #fee2e2; }

@media (width <= 780px) {
  .leads thead { display: none; }
  .leads tbody tr { display: grid; grid-template-columns: 1fr 1fr; padding: 8px 0; }
  .leads td { border: 0; padding: 4px 14px; }
  .leads tbody tr { border-bottom: 1px solid var(--line); }
}
