:root {
  --bg: #f1f4f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #697586;
  --line: #e3e9f2;
  --nav: #101826;
  --blue: #2f64b8;
  --blue-soft: #eef5ff;
  --teal: #1f9b86;
  --green: #228653;
  --amber: #bf7417;
  --red: #c4423f;
  --soft: #f7f9fc;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  min-height: 36px;
  border-radius: 7px;
  padding: 0 12px;
  font-weight: 760;
  font-size: 13px;
  color: var(--ink);
  background: #e5ebf3;
  cursor: pointer;
}

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

input, select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--ink);
  padding: 8px 10px;
  outline: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.hidden { display: none !important; }

.login-error {
  margin: 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 750;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f6f9fe, #edf3f8);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 20px 50px rgba(20, 38, 60, .14);
  display: grid;
  gap: 20px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}

.brand-row strong, .brand-row span {
  display: block;
}

.brand-row strong {
  font-size: 18px;
  line-height: 1;
}

.brand-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.brand-row.compact strong {
  color: #fff;
  font-size: 17px;
}

.brand-row.compact span {
  color: #aeb9c6;
  font-size: 12px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}

.sidebar {
  background: var(--nav);
  color: #f8fafc;
  border-right: 1px solid #182536;
  padding: 22px 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav {
  display: grid;
  gap: 6px;
  align-content: start;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: transparent;
  color: #cbd5e1;
}

.nav-item.active {
  background: #2f68d8;
  color: #fff;
}

.sidebar-card {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  background: #17283a;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.sidebar-card span, .sidebar-card small {
  color: #b6c3d3;
  font-size: 12px;
  line-height: 1.35;
}

.sidebar-card strong {
  color: #fff;
  font-size: 32px;
}

.main {
  min-width: 0;
  padding: 22px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  background: rgba(255,255,255,.76);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filters-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 10px;
  box-shadow: 0 12px 28px rgba(20,38,60,.06);
}

.filter-main {
  display: grid;
  grid-template-columns: 1.1fr .55fr 1fr .8fr .9fr;
  gap: 10px;
}

.filter-secondary {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) .6fr 140px .7fr;
  gap: 10px;
  align-items: end;
}

.generate-queue {
  width: 100%;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 10px;
}

.metric {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 11px;
  display: grid;
  align-content: center;
  gap: 4px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  font-size: 18px;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.lead-map-panel {
  min-height: 440px;
  display: grid;
  grid-template-rows: auto minmax(390px, 46vh);
}

.lead-map {
  min-height: 390px;
  height: 100%;
  border-top: 1px solid var(--line);
  background: #eaf3f8;
  overflow: hidden;
}

.brazil-map-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.brazil-map-bg {
  fill: #dff0f6;
}

.brazil-state {
  fill: #f8fbf7;
  stroke: #7fa7b7;
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.brazil-state.active {
  fill: #dcecff;
  stroke: #2563eb;
  stroke-width: 2;
}

.brazil-state.solo {
  fill: #eef6ff;
}

.map-point {
  cursor: pointer;
  outline: none;
}

.map-point circle {
  stroke: #ffffff;
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
}

.map-point.active circle,
.map-point:focus circle {
  stroke: #0f172a;
  stroke-width: 3.5;
}

.command-grid {
  display: none;
  grid-template-columns: minmax(520px, 1fr) minmax(360px, .55fr);
  gap: 12px;
}

.city-panel,
.queue-panel {
  min-height: 320px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.city-list,
.queue-list {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

.city-list {
  display: grid;
  gap: 8px;
}

.city-row {
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 86px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-align: left;
}

.city-row:hover {
  border-color: #b9cdf0;
  background: #f7fbff;
}

.rank {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--blue-soft);
  color: var(--blue);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.city-row strong,
.city-row small {
  display: block;
}

.city-row strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.city-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.city-row b {
  justify-self: end;
  font-size: 17px;
}

.queue-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.queue-column {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcff;
  padding: 8px;
  display: grid;
  align-content: start;
  gap: 7px;
}

.queue-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}

.queue-title span {
  min-width: 24px;
  height: 24px;
  border-radius: 7px;
  background: #e7edf7;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
}

.queue-card {
  min-height: 74px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
  padding: 9px;
  display: grid;
  gap: 3px;
}

.queue-card strong,
.queue-card span,
.queue-card small {
  display: block;
  overflow-wrap: anywhere;
}

.queue-card strong {
  font-size: 12px;
}

.queue-card span,
.queue-card small,
.queue-empty {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.queue-empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(580px, 1fr) minmax(390px, .52fr);
  gap: 12px;
}

.panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(20,38,60,.05);
}

.panel-head {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.panel-head strong {
  font-size: 14px;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 740;
}

.list-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.lead-list {
  min-height: 0;
  height: 100%;
  overflow: auto;
}

.lead-list.is-loading {
  opacity: 0.72;
  pointer-events: none;
}

.load-more {
  width: calc(100% - 24px);
  margin: 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
  min-height: 42px;
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}

.load-more:hover {
  background: #eef3fb;
}

.lead-row {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 12px 14px;
  text-align: left;
  display: grid;
  grid-template-columns: 44px minmax(230px, 1fr) 126px 76px minmax(118px, 144px);
  gap: 10px;
  align-items: center;
  border-radius: 0;
  min-height: 74px;
}

.lead-rank {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #2f68d8;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 900;
}

.lead-row:hover, .lead-row.active {
  background: #f4f8ff;
}

.lead-row.active {
  box-shadow: inset 4px 0 0 var(--blue);
}

.lead-title strong, .lead-title span {
  display: block;
}

.lead-title strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.lead-title span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.cell-label {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 800;
  margin-bottom: 3px;
}

.cell-value {
  display: block;
  font-size: 14px;
  font-weight: 820;
  overflow-wrap: anywhere;
}

.tag {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.tag-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag.hot { color: #8a2c25; background: #fdeceb; }
.tag.good { color: #145b36; background: #eaf7f0; }
.tag.warn { color: #744608; background: #fff2d4; }
.tag.neutral { color: #435263; background: #edf2f7; }

.detail-stack {
  min-height: 0;
  display: grid;
  gap: 12px;
  grid-template-rows: auto;
}

.script-panel {
  display: none;
}

.detail-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.detail-body {
  padding: 12px 14px;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

.lead-dossier {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  align-items: start;
}

.photo-box {
  min-height: 170px;
  height: 170px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(135deg, #f0f5f8, #dde7ee);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 780;
  text-align: center;
}

.photo-box img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  object-position: left center;
  display: block;
}

.photo-open {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
  display: block;
}

.photo-open span {
  position: absolute;
  right: 10px;
  bottom: 10px;
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 820;
}

.photo-open:hover img,
.photo-open:focus-visible img {
  filter: saturate(1.06) contrast(1.03);
}

.photo-open:focus-visible {
  outline: 3px solid rgba(48, 104, 211, 0.45);
  outline-offset: -3px;
}

.photo-empty {
  width: 100%;
  min-height: 170px;
  height: 170px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #eef2f6, #f8fafc);
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.detail-title {
  display: grid;
  gap: 4px;
}

h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.detail-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.reason-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  padding: 10px;
  display: grid;
  gap: 5px;
}

.reason-card strong {
  font-size: 13px;
}

.reason-card p {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 700;
}

.facts-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  align-content: start;
}

.facts-list div {
  min-height: 0;
  border-bottom: 1px solid var(--line);
  padding: 0 0 7px;
  display: grid;
  gap: 2px;
}

.facts-list div:first-child {
  grid-column: auto;
}

.facts-list span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.facts-list strong {
  font-size: 12px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.detail-actions a, .detail-actions button {
  min-height: 36px;
  border-radius: 7px;
  padding: 8px 10px;
  text-align: center;
  text-decoration: none;
  font-size: 13px;
  font-weight: 780;
  color: var(--ink);
  background: #e5ebf3;
}

.detail-actions a.primary-link {
  background: var(--blue);
  color: #fff;
}

.map-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.compact-head {
  min-height: 42px;
  padding: 9px 10px;
}

.compact-head span {
  border-radius: 999px;
  background: #e7f7f1;
  color: #1a775b;
  padding: 4px 8px;
}

.map-sketch {
  height: 118px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(#e7edf5 1px, transparent 1px),
    linear-gradient(90deg, #e7edf5 1px, transparent 1px),
    #f8fbff;
  background-size: 52px 52px;
}

.map-sketch::before {
  content: "";
  position: absolute;
  left: 28px;
  right: 28px;
  top: 64px;
  height: 6px;
  border-radius: 999px;
  background: #cfd9e7;
  transform: rotate(-10deg);
}

.map-sketch span {
  position: absolute;
  right: 30%;
  top: 48px;
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  background: #d64545;
  transform: rotate(-45deg);
  box-shadow: 0 4px 12px rgba(214,69,69,.28);
}

.map-sketch span::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: #fff;
}

.script-inline {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  padding: 9px;
  display: grid;
  gap: 6px;
}

.script-inline > div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.script-inline strong {
  font-size: 13px;
}

.script-inline span,
.script-inline small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 740;
}

.script-inline p {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.32;
  font-weight: 720;
}

.script-body {
  padding: 14px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.38;
  overflow: auto;
}

.script-body strong {
  color: var(--ink);
  font-size: 14px;
}

.status-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-buttons button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.photo-viewer.hidden {
  display: none;
}

.photo-viewer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.72);
}

.photo-viewer-card {
  position: relative;
  z-index: 1;
  width: min(1040px, 96vw);
  max-height: 92vh;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.28);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.photo-viewer-head {
  min-height: 52px;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.photo-viewer-head strong {
  font-size: 15px;
  overflow-wrap: anywhere;
}

.photo-viewer-head button {
  min-height: 32px;
  padding: 0 11px;
  border-radius: 7px;
}

.photo-viewer-card img {
  width: 100%;
  max-height: calc(92vh - 52px);
  object-fit: contain;
  background: #0f172a;
  display: block;
}

body.photo-viewer-open {
  overflow: hidden;
}

@media (max-width: 1180px) {
  .app { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .main { overflow: visible; }
  .sidebar { display: none; }
  .workspace, .command-grid { grid-template-columns: 1fr; }
  .lead-list { max-height: 520px; }
}

@media (max-width: 760px) {
  .main { padding: 12px; }
  .topbar, .top-actions { display: grid; }
  .filter-main, .filter-secondary, .metrics, .workspace, .lead-dossier, .detail-actions, .command-grid, .queue-list {
    grid-template-columns: 1fr;
  }
  .detail-stack {
    grid-template-rows: auto auto;
  }
  .visual-stack {
    grid-template-rows: minmax(220px, auto) auto;
  }
  .lead-map-panel {
    min-height: 330px;
    grid-template-rows: auto 280px;
  }
  .lead-row {
    grid-template-columns: 38px repeat(2, minmax(0, 1fr));
    gap: 8px;
    min-height: 0;
    padding: 10px 12px;
  }
  .lead-title, .tag-stack {
    grid-column: 1 / -1;
  }
  .cell-label {
    font-size: 9px;
    margin-bottom: 2px;
  }
  .cell-value {
    font-size: 13px;
  }
}
