
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: Arial, sans-serif;
  background: #f3f6fb;
  color: #1f2937;
}

/* ===== LOGIN ===== */

.login-screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(rgba(15, 23, 42, 0.82), rgba(15, 23, 42, 0.82)),
    #0f172a;
  z-index: 4000;
  padding: 20px;
}

.login-screen.active {
  display: flex;
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: #ffffff;
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
  border: 1px solid #dbe4f0;
}

.login-card h2 {
  margin: 0 0 10px 0;
  font-size: 28px;
  color: #0f172a;
}

.login-card p {
  margin: 0 0 18px 0;
  color: #64748b;
  line-height: 1.5;
}

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

.login-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  font-size: 15px;
  background: #fff;
}

.login-form button {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #2563eb;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.login-form button:hover {
  background: #1d4ed8;
}

.login-error {
  min-height: 20px;
  font-size: 13px;
  color: #dc2626;
}

/* ===== APP ===== */

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.app-shell.locked {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

.sidebar {
  background: #0f172a;
  color: #fff;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar h1 {
  margin: 0 0 12px 0;
  font-size: 24px;
}

.sidebar hr {
  width: 100%;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin: 10px 0;
}

.user-box {
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.5;
  padding: 8px 2px;
}

.nav-btn,
.sidebar button,
button {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: 0.2s ease;
}

.nav-btn:hover,
.sidebar button:hover,
button:hover {
  background: #eff6ff;
}

.nav-btn.active {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

.main {
  padding: 24px;
  overflow-x: auto;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.header-actions,
.small-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.filters input,
.filters select,
.dialog-form input,
.dialog-form select,
.dialog-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 14px;
  background: #fff;
  min-width: 0;
}

.filters input,
.filters select {
  min-width: 180px;
  max-width: 260px;
}

.cards {
  display: grid;
  gap: 14px;
}

.todo-card,
.template-card,
.region-card {
  background: #fff;
  border: 1px solid #dbe4f0;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.todo-card {
  cursor: pointer;
}

.todo-card:hover {
  border-color: #93c5fd;
  background: #f8fbff;
}

.muted {
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

/* ===== LEADS ===== */

.leads-grid {
  display: grid;
  gap: 16px;
}

.lead-card {
  background: #ffffff;
  border: 1px solid #dbe4f0;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.lead-card-top {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.lead-card-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lead-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lead-name {
  font-weight: 700;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.lead-address {
  font-size: 13px;
  color: #64748b;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.lead-meta-list {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.lead-meta-item {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.lead-meta-item strong {
  display: inline-block;
  min-width: 120px;
}

.lead-status-box,
.lead-actions-box {
  background: #f8fbff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px;
}

.lead-box-title {
  font-weight: 700;
  margin-bottom: 10px;
}

.status-cell {
  min-width: 260px;
}

.status-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.status-actions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  background: #fff;
}

.status-item-text {
  font-size: 13px;
  line-height: 1.35;
  color: #1e3a8a;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.status-item button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 10px;
  flex-shrink: 0;
}

.actions-cell {
  min-width: 180px;
}

.actions-cell .small-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.actions-cell .small-actions button {
  width: 100%;
}

.lead-card-bottom {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #e5edf6;
}

.description-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.description-title {
  font-weight: 700;
}

.description-text {
  white-space: pre-wrap;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.quick-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.quick-actions button {
  min-width: 110px;
}

.highlight-lead {
  outline: 3px solid #93c5fd;
  outline-offset: -3px;
  animation: highlightFade 2.5s ease;
}

@keyframes highlightFade {
  0% {
    background: #dbeafe;
  }
  100% {
    background: transparent;
  }
}

/* ===== REGION TILES ===== */

.region-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.region-tile {
  border: 1px solid #d7deea;
  border-radius: 16px;
  background: #fff;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: 0.2s ease;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

.region-tile:hover {
  transform: translateY(-2px);
  border-color: #93c5fd;
}

.region-tile.active {
  background: #eff6ff;
  border-color: #2563eb;
}

.region-tile-name {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

.region-tile-count {
  display: inline-block;
  min-width: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e5eefc;
  font-size: 13px;
  font-weight: 700;
}

.selected-region-title {
  margin: 8px 0 18px;
}

/* ===== DUPLICATES ===== */

.duplicate-flag-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 999px;
  background: #f59e0b;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.3);
}

.duplicate-flag-btn:hover {
  background: #d97706;
}

.duplicate-modal {
  max-width: 1100px;
}

.duplicate-pair-card {
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  background: #fff;
}

.duplicate-pair-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.duplicate-lead-box {
  border: 1px solid #dbe3f0;
  border-radius: 14px;
  padding: 14px;
  background: #f8fbff;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.duplicate-actions {
  margin-top: 14px;
}

.duplicate-keep-row {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

/* ===== DIALOGS ===== */

dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(1100px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  background: #fff;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-form {
  display: grid;
  gap: 12px;
  padding: 20px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
}

.dialog-form.wide {
  grid-template-columns: 1fr;
}

.dialog-form h3,
.dialog-form h4 {
  margin: 0 0 6px 0;
}

.dialog-form textarea {
  min-height: 110px;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* ===== LEAD DIALOG ===== */

#leadDialog {
  width: min(1200px, calc(100vw - 20px));
  max-width: calc(100vw - 20px);
  max-height: calc(100vh - 20px);
}

#leadDialog .dialog-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: start;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  overflow-x: hidden;
}

#leadDialog h3,
#leadDialog h4,
#leadDialog .dialog-actions,
#leadDialog #leadVersionsBox,
#leadDialog #leadGoogleInlineBox {
  grid-column: 1 / -1;
}

#leadDialog label {
  font-weight: 600;
  margin-bottom: 4px;
}

#leadDialog input,
#leadDialog select,
#leadDialog textarea {
  width: 100%;
  min-width: 0;
}

#leadDialog textarea {
  min-height: 110px;
}

#leadVersionsBox,
#leadGoogleInlineBox {
  display: grid;
  gap: 12px;
}

#leadVersionsBox .generator-modal-box,
#leadGoogleInlineBox .generator-modal-box {
  background: #f8fbff;
  border: 1px solid #dbe4f0;
  border-radius: 14px;
  padding: 14px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#leadVersionsBox .generator-modal-box div,
#leadGoogleInlineBox .generator-modal-box div {
  margin-bottom: 6px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#leadDialog .dialog-actions {
  position: sticky;
  bottom: 0;
  background: #fff;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
  z-index: 2;
}

/* ===== GENERATOR ===== */

.generator-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.generator-checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fbff;
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.generator-summary {
  display: grid;
  gap: 12px;
}

.generator-summary-box {
  background: #f8fbff;
  border: 1px solid #dbe4f0;
  border-radius: 12px;
  padding: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.generator-summary-title {
  font-weight: 700;
  margin-bottom: 8px;
}

.generator-tag-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.generator-tag {
  background: #e0ecff;
  color: #1e3a8a;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
}

.generator-result-card {
  background: #fff;
  border: 1px solid #dbe4f0;
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.generator-result-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.generator-result-name {
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.generator-result-meta {
  font-size: 13px;
  color: #64748b;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.generator-result-checkbox {
  margin-top: 4px;
}

.generator-badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.generator-badge {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
}

.generator-badge.new {
  background: #dcfce7;
  color: #166534;
}

.generator-badge.similar {
  background: #fef3c7;
  color: #92400e;
}

.generator-badge.duplicate {
  background: #fee2e2;
  color: #991b1b;
}

.generator-match-box {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px;
  background: #f8fbff;
  margin-top: 8px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.generator-match-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.generator-match-item {
  border-top: 1px solid #e5edf6;
  padding-top: 8px;
  margin-top: 8px;
}

.generator-verification-summary-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.generator-results-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.generator-results-column {
  background: #f8fbff;
  border: 1px solid #dbe4f0;
  border-radius: 14px;
  padding: 12px;
  min-height: 180px;
}

.generator-results-column h4 {
  margin: 0 0 12px 0;
  font-size: 16px;
}

.generator-check-panel {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.generator-check-panel button {
  font-size: 12px;
}

.generator-result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.generator-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.generator-modal-backdrop.open {
  display: flex;
}

.generator-modal {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  border: 1px solid #dbe4f0;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
}

.generator-modal h3 {
  margin-top: 0;
}

.generator-modal-grid {
  display: grid;
  gap: 12px;
}

.generator-modal-box {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  background: #f8fbff;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .main {
    padding: 16px;
  }

  .generator-results-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .lead-card-top {
    grid-template-columns: 1fr;
  }

  .duplicate-pair-grid {
    grid-template-columns: 1fr;
  }

  #leadDialog .dialog-form {
    grid-template-columns: 1fr;
  }

  .status-cell,
  .actions-cell {
    min-width: 0;
  }
}

@media (max-width: 700px) {
  .header-row,
  .filters,
  .dialog-actions,
  .quick-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .filters input,
  .filters select {
    min-width: 100%;
    max-width: 100%;
  }

  .todo-card,
  .template-card,
  .region-card,
  .lead-card {
    padding: 12px;
  }

  .region-tiles {
    grid-template-columns: 1fr 1fr;
  }

  .login-card {
    padding: 22px 18px;
  }
}

@media (max-width: 520px) {
  .region-tiles {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 12px;
  }

  .sidebar {
    padding: 16px 12px;
  }

  dialog {
    width: calc(100vw - 12px);
    max-width: calc(100vw - 12px);
    max-height: calc(100vh - 12px);
  }

  #leadDialog {
    width: calc(100vw - 12px);
    max-width: calc(100vw - 12px);
    max-height: calc(100vh - 12px);
  }

  .dialog-form,
  #leadDialog .dialog-form {
    padding: 14px;
    gap: 10px;
  }

  .generator-modal {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .quick-actions button,
  .small-actions button,
  .dialog-actions button {
    width: 100%;
  }
}
