* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: #f4f5f7;
  color: #1a1a1a;
}
label { display: block; font-size: 13px; color: #555; margin: 10px 0 4px; }
input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d0d2d6;
  border-radius: 6px;
  background: #fff;
}
textarea { resize: vertical; }
button {
  cursor: pointer;
  border-radius: 6px;
  padding: 9px 16px;
  border: 1px solid #d0d2d6;
  background: #fff;
}
button:hover { background: #f0f1f3; }
button.primary {
  background: #1f4e78;
  color: #fff;
  border-color: #1f4e78;
}
button.primary:hover { background: #163a5a; }
button.ghost { background: transparent; }
.muted { color: #777; font-size: 13px; }
.error { color: #b3261e; font-size: 13px; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-wrap[hidden] { display: none; }
.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 2rem;
  width: 320px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.login-card h1 { font-size: 18px; margin: 0 0 1rem; }
.login-card button { width: 100%; margin-top: 14px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #1f4e78;
  color: #fff;
}
.topbar .brand { font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-left: 24px; }
.tab-btn {
  background: transparent;
  border: none;
  color: #cfe0ee;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 14px;
}
.tab-btn:hover { background: rgba(255,255,255,0.1); }
.tab-btn.active { background: rgba(255,255,255,0.18); color: #fff; font-weight: 500; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: 1100px; }
.table-scroll td, .table-scroll th { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .muted { color: #d8e3ec; }
.topbar button.ghost { color: #fff; border-color: rgba(255,255,255,0.4); }
.topbar button.ghost:hover { background: rgba(255,255,255,0.1); }

.content { max-width: 1100px; margin: 0 auto; padding: 20px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 14px 16px;
}
.stat-label { font-size: 13px; color: #666; margin: 0 0 4px; }
.stat-value { font-size: 26px; font-weight: 600; margin: 0; }
.stat-value.danger { color: #b3261e; }

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar input[type=text] { flex: 1; }
.toolbar select { width: 160px; }

.table-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}
.table-card.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  padding: 10px 12px;
  color: #666;
  font-weight: 500;
  border-bottom: 1px solid #eaeaea;
  background: #fafafa;
}
th.row-num, td.row-num { width: 36px; text-align: center; color: #999; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #f0f1f3; }
th.sortable::after { content: ""; display: inline-block; width: 10px; margin-left: 4px; opacity: 0.35; }
th.sortable.sort-asc::after { content: "\25B2"; opacity: 1; }
th.sortable.sort-desc::after { content: "\25BC"; opacity: 1; }
td { padding: 10px 12px; border-bottom: 1px solid #f0f0f0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f9fb; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 4px; background: #eef0f3; }
.badge-Converted { background: #e2f3e5; color: #1e6b30; }
.badge-Lost { background: #fbe4e4; color: #9c2b2b; }
.badge-Pending { background: #eee; color: #555; }
.overdue { color: #b3261e; font-weight: 600; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  width: 520px;
  max-height: 90vh;
  display: flex;
  gap: 16px;
}
.modal-body { flex: 1; min-width: 0; overflow-y: auto; max-height: calc(90vh - 3rem); padding-right: 4px; }
.modal-side {
  width: 130px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 1px solid #eee;
  padding-left: 16px;
  padding-top: 4px;
}
.modal-side button { width: 100%; }
.modal h2 { margin: 0 0 4px; font-size: 16px; }
.modal-divider { border: none; border-top: 1px solid #eee; margin: 14px 0; }
.history-item { font-size: 13px; padding: 6px 0; border-bottom: 1px solid #f0f0f0; }
.confirm-modal { width: 360px; z-index: 20; }
.confirm-modal .modal-side { border-left: none; padding-left: 0; padding-top: 0; }
.wide-modal { width: 720px; max-width: 90vw; }
.temp-password {
  font-family: "Courier New", monospace;
  font-size: 20px; font-weight: 600;
  background: #f4f5f7; border: 1px dashed #c8cbd1;
  border-radius: 6px; padding: 10px 14px;
  text-align: center; letter-spacing: 0.5px;
}
.dup-badge { display: inline-block; font-size: 12px; padding: 2px 6px; border-radius: 4px; background: #fdf1d8; color: #8a5b0c; }
.history-item:last-child { border-bottom: none; }
.duplicate-warning {
  background: #fdf1d8;
  border: 1px solid #f0c96b;
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: -6px;
  font-size: 13px;
  color: #7a5a0c;
}
.duplicate-warning .dup-row { padding: 3px 0; }
.duplicate-warning .dup-row:not(:last-child) { border-bottom: 1px solid rgba(0,0,0,0.08); }

.call-icon {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; font-size: 14px;
}
.call-link { color: #1f4e78; text-decoration: none; }
.call-link:hover { text-decoration: underline; }
.wa-icon { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; font-size: 14px; }
.phone-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.phone-row input { flex: 1; min-width: 120px; }
.call-btn, .wa-btn {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 4px;
  color: #fff;
  padding: 8px 12px; border-radius: 6px;
  text-decoration: none; font-size: 13px; white-space: nowrap;
}
.call-btn { background: #1f8a4c; }
.call-btn:hover { background: #176b3a; }
.wa-btn { background: #25d366; }
.wa-btn:hover { background: #1da851; }
.call-btn[hidden], .wa-btn[hidden] { display: none; }
.field-highlight {
  outline: 2px solid #1f8a4c;
  outline-offset: 2px;
  transition: outline-color 1.4s ease;
}

/* Responsive: tablet and mobile */
@media (max-width: 720px) {
  .content { padding: 12px; max-width: 100%; }

  .topbar { flex-wrap: wrap; padding: 10px 14px; row-gap: 8px; }
  .topbar .tabs { order: 3; width: 100%; margin-left: 0; }
  .topbar .spacer { display: none; }
  .topbar .muted { font-size: 12px; }

  .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stats-row .stat-card:nth-child(3) { grid-column: span 2; }
  .stat-value { font-size: 22px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar select { width: 100%; }
  .toolbar button { width: 100%; }

  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-card table { min-width: 760px; }
  th, td { padding: 9px 10px; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100%;
    max-height: 94vh;
    border-radius: 14px 14px 0 0;
    flex-direction: column;
    padding: 1.25rem 1rem;
  }
  .modal-body { max-height: calc(94vh - 8rem); }
  .modal-side {
    width: 100%; flex-direction: row;
    border-left: none; border-top: 1px solid #eee;
    padding-left: 0; padding-top: 12px; margin-top: 4px;
  }
  .modal-side button { flex: 1; }
  .confirm-modal { width: 100%; }
  .confirm-modal .modal-side { flex-direction: row; }

  .login-card { width: 90vw; max-width: 340px; }
}
