/* Miami Design Co palette, applied to a dense work UI rather than a showcase.
   Readability first: this is a screen someone stares at all morning. */
:root {
  --canvas: #faf7f2;
  --surface: #ffffff;
  --plaster: #f1eae0;
  --sand: #e9dcc3;
  --ink: #17130e;
  --muted: #6b6257;
  --line: #e2d9cc;
  --coral: #e0492e;
  --coral-deep: #b4371f;
  --teal: #0f6b76;
  --palm: #14231f;
  --ok: #2f7d51;
  --warn: #b7791f;
  --radius: 3px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #14110e;
    --surface: #1c1815;
    --plaster: #262019;
    --sand: #3a3025;
    --ink: #f4efe7;
    --muted: #a39786;
    --line: #332c24;
    --coral: #f0674b;
    --ok: #55b07c;
    --warn: #d9a441;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--teal); }

.hidden { display: none !important; }

/* ---- login ---- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
}
.login h1 {
  font: 400 28px/1.1 var(--display);
  margin: 0 0 4px;
}
.login p { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.login input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login input:focus-visible { outline: 2px solid var(--coral); outline-offset: 1px; }

#googleBox { width: min(380px, 100%); margin: 0 auto; }
.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  font-size: 12px;
  color: var(--muted);
}
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.btn.google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  text-decoration: none;
}

/* ---- shell ---- */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.wordmark { font: 400 19px/1 var(--display); letter-spacing: -0.01em; }
.wordmark span { color: var(--coral); }
.tabs { display: flex; gap: 2px; margin-left: 12px; }
.tab {
  padding: 6px 12px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { background: var(--plaster); }
.tab[aria-selected="true"] { background: var(--plaster); color: var(--ink); font-weight: 600; }
.tab .count {
  font: 600 11px var(--mono);
  color: var(--coral);
  margin-left: 6px;
}
.topbar .spacer { flex: 1; }
.who {
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 4px 6px;
  border-radius: var(--radius);
  cursor: pointer;
}
.who:hover { background: var(--plaster); color: var(--ink); }

.btn {
  padding: 7px 13px;
  background: var(--ink);
  color: var(--canvas);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { background: var(--coral); border-color: var(--coral); }
.btn.ghost { background: none; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--plaster); color: var(--ink); border-color: var(--muted); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---- panes ---- */
.panes { display: flex; flex: 1; min-height: 0; }

.side {
  width: 216px;
  flex: 0 0 auto;
  border-right: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  background: var(--surface);
}
.side h3 {
  font: 600 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 8px;
}
.side h3:first-child { margin-top: 0; }
.side input[type="search"], .side select {
  width: 100%;
  padding: 7px 9px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.filter {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 5px 8px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}
.filter:hover { background: var(--plaster); }
.filter[aria-pressed="true"] { background: var(--plaster); color: var(--ink); font-weight: 600; }
.filter b { font: 600 11px var(--mono); color: var(--coral); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.stat b { display: block; font: 400 22px/1.1 var(--display); }
.stat span { font-size: 11px; color: var(--muted); }

.list { flex: 1 1 46%; min-width: 0; overflow-y: auto; border-right: 1px solid var(--line); }
.detail { flex: 1 1 54%; min-width: 0; overflow-y: auto; background: var(--surface); }

/* ---- rows ---- */
.row {
  display: block;
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  background: none;
  cursor: pointer;
  text-align: left;
}
.row:hover { background: var(--surface); }
.row[aria-current="true"] { background: var(--surface); border-left-color: var(--coral); }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: flex; gap: 8px; margin-top: 3px; font-size: 12px; color: var(--muted); }
.row-sub .find { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  font: 600 10px/1 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 2px;
  background: var(--plaster);
  color: var(--muted);
  white-space: nowrap;
}
.pill.new { background: var(--sand); color: var(--palm); }
.pill.queued { background: #d9e8ea; color: var(--teal); }
.pill.contacted { background: var(--plaster); color: var(--muted); }
.pill.replied, .pill.meeting { background: var(--coral); color: #fff; }
.pill.won { background: var(--ok); color: #fff; }
.pill.lost, .pill.suppressed { background: none; color: var(--muted); border: 1px solid var(--line); }
.pill.gap { background: none; border: 1px solid var(--line); color: var(--coral); }
.pill.due { background: var(--warn); color: #fff; }

.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---- detail ---- */
.detail-inner { padding: 22px 26px 60px; }
.detail h2 { font: 400 26px/1.15 var(--display); margin: 0 0 4px; }
.detail .meta { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.detail .meta a { word-break: break-all; }

.section { margin-top: 24px; }
.section > h4 {
  font: 600 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.scores { display: flex; gap: 8px; flex-wrap: wrap; }
.score {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 11px;
  min-width: 78px;
}
.score b { display: block; font: 400 19px/1.1 var(--display); }
.score span { font-size: 11px; color: var(--muted); }

.findings { margin: 0; padding-left: 18px; }
.findings li { margin-bottom: 5px; }

.statusbar { display: flex; gap: 5px; flex-wrap: wrap; }

.draft {
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.draft-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.draft-head strong { flex: 1; font-size: 13px; }
.draft textarea {
  width: 100%;
  min-height: 300px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 13px/1.6 var(--mono);
  resize: vertical;
}
.draft input.subject {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-weight: 600;
}

.field { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.field label { font-size: 12px; color: var(--muted); min-width: 92px; }
.field input, .field select, .field textarea {
  flex: 1;
  min-width: 140px;
  padding: 7px 9px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.field textarea { min-height: 64px; resize: vertical; font: inherit; }

.log { list-style: none; margin: 0; padding: 0; }
.log li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.log .when { font: 11px var(--mono); color: var(--muted); }
.log .actor { font-weight: 600; }

.warn-box {
  background: var(--plaster);
  border: 1px solid var(--sand);
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
.warn-box b {
  font: 600 10px/1 var(--mono);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--coral-deep);
  display: block;
  margin-bottom: 4px;
}
.warn-box.risk-high { background: #fbe9e4; border-color: var(--coral); }
.warn-box .law { font: 11px var(--mono); color: var(--muted); margin-top: 6px; }
.warn-box .ack-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--sand);
  font-size: 12px;
  color: var(--muted);
}
.warn-box .ack-done {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--sand);
  font-size: 12px;
  color: var(--ok);
}
.pill.risk-high { background: var(--coral); color: #fff; }
.pill.risk-medium { background: var(--sand); color: var(--palm); }

@media (prefers-color-scheme: dark) {
  .warn-box.risk-high { background: #3a201a; }
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--palm);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}

/* ---- dashboard ---- */
.board { max-width: 940px; margin: 0 auto; }

.big-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 20px 0 4px;
}
.big-stat {
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.big-stat b { display: block; font: 400 32px/1 var(--display); }
.big-label { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.big-hint { display: block; font: 11px var(--mono); color: var(--muted); opacity: .75; margin-top: 2px; }

.bars { display: flex; flex-direction: column; gap: 5px; }
.bar-row {
  display: grid;
  grid-template-columns: 140px 1fr 40px;
  align-items: center;
  gap: 10px;
  padding: 3px 4px;
  border-radius: var(--radius);
}
.bar-row.clickable { cursor: pointer; }
.bar-row.clickable:hover { background: var(--plaster); }
.bar-label { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 16px; background: var(--plaster); border-radius: 2px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--teal); min-width: 2px; }
.bar-fill.risky { background: var(--coral); }
.bar-fill.grey { background: var(--sand); }
.bar-value { font: 600 12px var(--mono); text-align: right; }

.note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* Height scales with the viewport so the map stays usable on a laptop and
   does not eat a phone screen whole. */
.map {
  height: clamp(260px, 46vh, 520px);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--plaster);
}
.map-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.leaflet-popup-content { font: 13px/1.5 var(--sans); }
.leaflet-popup-content .pop-addr { color: #666; font-size: 12px; }
/* The tile imagery is light; dim it rather than leave a glaring panel in a
   dark room. */
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: brightness(.72) saturate(.75); }
}

/* ---- discovery ---- */
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.board textarea {
  width: 100%;
  min-height: 92px;
  padding: 10px 12px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 13px/1.6 var(--mono);
  resize: vertical;
}
.jobs { display: flex; flex-direction: column; gap: 8px; }
.job {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--canvas);
}
.job-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.job-head strong { font-size: 13px; }
.job-head .note { margin: 0; margin-left: auto; }
.pill.job-running { background: var(--teal); color: #fff; }
.pill.job-queued { background: var(--sand); color: var(--palm); }
.pill.job-done { background: var(--ok); color: #fff; }
.pill.job-error { background: var(--coral); color: #fff; }
.job-log {
  margin: 10px 0 0;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font: 11px/1.6 var(--mono);
  white-space: pre-wrap;
}

table.plain { width: 100%; border-collapse: collapse; }
table.plain th, table.plain td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
table.plain th { font: 600 10px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

.row-hint {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--plaster);
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .side { display: none; }
  .panes { flex-direction: column; }
  .list, .detail { border-right: 0; min-height: 0; }
  .list { flex: 0 0 auto; max-height: 38vh; border-bottom: 1px solid var(--line); }
  .detail { flex: 1 1 auto; }
}

/* On a phone the header cannot hold the wordmark, five tabs and three buttons
   on one line. The tab strip scrolls on its own; the page never does. */
@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 14px;
  }
  .wordmark { font-size: 16px; }
  .tabs {
    order: 3;
    width: 100%;
    margin-left: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: 0 0 auto; }
  .topbar .spacer { display: none; }
  #addBtn { margin-left: auto; }
  .detail-inner { padding: 18px 16px 48px; }
  .bar-row { grid-template-columns: 96px 1fr 34px; gap: 8px; }
  .field label { min-width: 0; flex: 0 0 100%; }
}

@media (prefers-reduced-motion: reduce) {
  /* Leaflet is excluded: it drives tile opacity through a transition, so
     blanket-killing transitions there hides the map rather than calming it. */
  *:not(.leaflet-tile):not(.leaflet-pane):not(.leaflet-pane *) {
    animation: none !important;
    transition: none !important;
  }
}
