/* WHY: "Serious NAR tool" direction — USWDS credibility, Stripe-docs typographic
   polish, NAR brand palette. Tight and clean — no shadows, no ornamentation, no
   animation beyond tiny color transitions. Brand colors verified from nar.realtor:
   primary #006BB7, navy text #004282. */

:root {
  /* Brand */
  --nar-blue:       #006BB7;
  --nar-blue-hover: #005794;
  --nar-blue-dark:  #004282;
  --nar-blue-50:    #e6f1f8;
  --nar-blue-100:   #c9dfee;

  /* Grays */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Semantic */
  --text:          var(--gray-900);
  --text-muted:    var(--gray-500);
  --text-heading:  var(--nar-blue-dark);
  --bg:            #ffffff;
  --bg-alt:        var(--gray-50);
  --border:        var(--gray-200);
  --border-strong: var(--gray-300);
  --accent:        var(--nar-blue);
  --accent-hover:  var(--nar-blue-hover);
  --error:         #b91c1c;

  /* Status palette — USWDS-tinted: soft bg + darker text, not saturated fills */
  --status-gray-bg:  #e5e7eb; --status-gray-text:  #374151;
  --status-blue-bg:  #dbeafe; --status-blue-text:  #1e40af;
  --status-amber-bg: #fef3c7; --status-amber-text: #92400e;
  --status-green-bg: #d1fae5; --status-green-text: #065f46;
  --status-red-bg:   #fee2e2; --status-red-text:   #991b1b;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  /* Spacing (4px base) */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --radius:    6px;
  --radius-sm: 4px;

  --ring: 0 0 0 3px rgba(0, 107, 183, 0.2);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(ellipse 1200px 500px at 50% -200px, rgba(0, 66, 130, 0.10), transparent 70%),
    linear-gradient(180deg, #e7edf6 0%, #dce5f1 100%);
  min-height: 100vh;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6);
}

/* ---- Top bar ---- */
.topbar {
  background: linear-gradient(180deg, var(--nar-blue-dark) 0%, #003368 100%);
  border-bottom: 3px solid var(--nar-blue);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-6);
  gap: var(--space-4);
  flex-wrap: wrap;
}
.brand {
  font-size: var(--text-lg);
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: center;
}
.topbar nav {
  display: flex;
  gap: var(--space-5);
  align-items: center;
  flex-wrap: wrap;
}
.topbar nav a {
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--space-2) 0;
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s;
}
.topbar nav a:hover {
  color: #fff;
  border-bottom-color: var(--nar-blue);
  text-decoration: none;
}
.topbar .who {
  color: rgba(255, 255, 255, 0.6);
  font-size: var(--text-sm);
  padding-left: var(--space-4);
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}

/* ---- Typography ---- */
h1 {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-heading);
  margin: 0 0 var(--space-3);
  letter-spacing: -0.02em;
}
h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-heading);
  margin: var(--space-8) 0 var(--space-3);
}
h3 {
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: var(--space-6) 0 var(--space-2);
}
p, ul, ol { margin: 0 0 var(--space-4); }
p.muted, .muted { color: var(--text-muted); font-size: var(--text-sm); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ---- Form controls ---- */
input[type=text],
input[type=email],
input[type=password],
input[type=datetime-local],
select,
textarea {
  font: inherit;
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  line-height: 1.5;
  transition: border-color .1s, box-shadow .1s;
}
input[type=text]:focus,
input[type=email]:focus,
input[type=password]:focus,
input[type=datetime-local]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--nar-blue);
  box-shadow: var(--ring);
}
textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.65;
}
select { cursor: pointer; }

button, .btn {
  font: inherit;
  font-weight: 500;
  padding: var(--space-3) var(--space-5);
  background: var(--nar-blue);
  color: #fff;
  border: 1px solid var(--nar-blue);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}
.btn-ghost {
  background: #fff;
  color: var(--gray-700);
  border-color: var(--border-strong);
}
.btn-ghost:hover {
  background: var(--gray-50);
  border-color: var(--border-strong);
  color: var(--gray-900);
}

/* ---- Login card ---- */
.login-card {
  max-width: 380px;
  margin: var(--space-12) auto;
  padding: var(--space-8);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.login-card h1 {
  text-align: center;
  margin-bottom: var(--space-6);
  font-size: var(--text-2xl);
}
.login-card label { display: block; margin: var(--space-4) 0; }
.login-card label span {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--space-2);
}
.login-card button { width: 100%; margin-top: var(--space-4); }
.login-card .error {
  color: var(--status-red-text);
  background: var(--status-red-bg);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

/* ---- State cards (My States) ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-6);
}
.state-card {
  display: block;
  padding: var(--space-5);
  padding-left: calc(var(--space-5) + 4px);
  border: 1px solid var(--border);
  border-left: 5px solid var(--gray-300);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.state-card:hover {
  border-color: var(--nar-blue);
  box-shadow: 0 4px 12px rgba(0, 66, 130, 0.10);
  text-decoration: none;
  transform: translateY(-1px);
}
/* WHY: color the left border by status so the card grid reads like a visual dashboard */
.state-card.status-not_started        { border-left-color: var(--status-gray-text); }
.state-card.status-contact_identified { border-left-color: var(--status-blue-text); }
.state-card.status-scheduled          { border-left-color: var(--status-amber-text); }
.state-card.status-completed          { border-left-color: var(--status-green-text); }
.state-card.status-no_response        { border-left-color: var(--status-red-text); }
.state-card-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.state-name {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-heading);
  line-height: 1.3;
}
.assoc { color: var(--text-muted); font-size: var(--text-sm); line-height: 1.4; }
.contact-line, .progress-line, .updated {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-2);
}

/* ---- Status badges (tinted + ring) ---- */
.badge {
  display: inline-block;
  padding: 3px var(--space-3);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.5;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
}
.status-not_started        { background: var(--status-gray-bg);  color: var(--status-gray-text); }
.status-contact_identified { background: var(--status-blue-bg);  color: var(--status-blue-text); }
.status-scheduled          { background: var(--status-amber-bg); color: var(--status-amber-text); }
.status-completed          { background: var(--status-green-bg); color: var(--status-green-text); }
.status-no_response        { background: var(--status-red-bg);   color: var(--status-red-text); }

/* ---- State form ---- */
/* WHY: wrap the form in a white panel so it pops off the tinted body bg */
.state-form {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6) var(--space-8) var(--space-8);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  margin-top: var(--space-4);
}

/* ---- Mission summary box (top of state page) ---- */
.mission-box {
  background: linear-gradient(135deg, var(--nar-blue-dark) 0%, #003168 60%, #002448 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: var(--space-6) var(--space-6);
  margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) var(--space-6);
  border-left: 6px solid var(--nar-blue);
}
.mission-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
}
.mission-title h1 {
  color: #fff;
  margin: 0 0 var(--space-1);
  font-size: 2rem;
  letter-spacing: -0.02em;
}
.mission-title .assoc-name {
  color: rgba(255, 255, 255, 0.85);
  font-size: var(--text-base);
  font-weight: 500;
}
.mission-title .assoc-link {
  display: inline-block;
  color: #a8d0f0;
  font-size: var(--text-sm);
  margin-top: var(--space-1);
  text-decoration: none;
}
.mission-title .assoc-link:hover {
  color: #fff;
  text-decoration: underline;
}
.mission-meta .badge {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}
.mission-body {
  padding-top: var(--space-4);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}
.mission-kind {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #a8d0f0;
  margin-bottom: var(--space-2);
}
.mission-text {
  color: rgba(255, 255, 255, 0.92);
  font-size: var(--text-base);
  line-height: 1.65;
  margin: 0;
}
.mission-empty em { color: rgba(255, 255, 255, 0.6); }

/* Quick row (status selector, compact) */
.quick-row {
  display: flex;
  gap: var(--space-5);
  align-items: flex-end;
  padding: var(--space-4) var(--space-5);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.quick-cell { flex: 1 1 220px; }
.quick-cell .field-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-1);
}

.field-group { margin: var(--space-6) 0; }
.field-group > h2 { margin-top: 0; }
.field { display: block; margin: var(--space-3) 0; }
.field > span {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: var(--space-2);
}
.field.question .q-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--gray-900);
  margin-bottom: var(--space-2);
  line-height: 1.5;
}

.save-indicator {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-2);
  min-height: 1.1em;
}
.save-indicator.error { color: var(--error); }

.contact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-4);
}

/* ---- Contact rows ---- */
.contact-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-alt);
  margin-bottom: var(--space-3);
}
.contact-fields {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2) var(--space-3);
}
.contact-field { display: flex; flex-direction: column; }
.contact-field input { font-size: var(--text-sm); padding: var(--space-2); }
.contact-field .save-indicator { margin-top: var(--space-1); }
.contact-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  padding-top: var(--space-1);
}
.star-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.3rem; color: var(--gray-300); padding: 0; line-height: 1;
  transition: color .12s;
}
.star-btn:hover { color: var(--nar-blue); }
.star-btn.active { color: #d97706; }
.contact-delete-btn, .call-delete-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.2rem; color: var(--gray-400); padding: 0; line-height: 1;
}
.contact-delete-btn:hover, .call-delete-btn:hover { color: var(--error); }
.confirm-text { font-size: var(--text-xs); font-weight: 600; color: var(--error); }
.btn-link {
  background: none; border: none; cursor: pointer; font-size: var(--text-xs);
  font-weight: 600; padding: 0; text-decoration: underline;
}
.btn-link:first-of-type { color: var(--error); }
.btn-link:last-of-type { color: var(--text-muted); }

/* ---- Call log ---- */
.call-log-add {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.call-log-add select { flex: 0 0 200px; font-size: var(--text-sm); }
.call-log-add input { flex: 1 1 180px; font-size: var(--text-sm); }
.call-other-input { flex: 0 0 160px !important; }
.call-log-add .btn { flex: 0 0 auto; padding: var(--space-2) var(--space-4); font-size: var(--text-sm); }
.call-entry {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--nar-blue-100);
  background: var(--bg-alt);
  margin-bottom: var(--space-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--text-sm);
}
.call-main { flex: 1; display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline; }
.call-kind-badge {
  font-weight: 600; color: var(--nar-blue-dark);
  padding: 1px var(--space-2); background: var(--nar-blue-50);
  border-radius: 3px; font-size: var(--text-xs); white-space: nowrap;
}
.call-meta { color: var(--text-muted); font-size: var(--text-xs); }
.call-notes { color: var(--gray-700); flex-basis: 100%; }
.call-empty { color: var(--text-muted); font-size: var(--text-sm); font-style: italic; padding: var(--space-3) 0; }

/* ---- Dashboard ---- */
.filters {
  display: flex;
  gap: var(--space-4);
  align-items: end;
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: var(--space-5) 0 var(--space-6);
}
.filters label {
  display: flex;
  flex-direction: column;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  gap: var(--space-1);
}
.filters select { min-width: 180px; }
.filters .clear-link {
  font-size: var(--text-sm);
  color: var(--text-muted);
  padding-bottom: var(--space-3);
}

/* Page header row: h1 + action buttons on the right */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.page-header > div:first-child { flex: 1 1 auto; min-width: 240px; }
.page-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* Wrap dashboard tables in a white panel so they pop off the tinted body bg */
.panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-5) var(--space-4);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  margin-top: var(--space-5);
}
table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
table.grid thead th {
  background: var(--bg-alt);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
}
table.grid th a { color: var(--text-muted); text-decoration: none; }
table.grid th a:hover, table.grid th a.active { color: var(--nar-blue-dark); }
table.grid tbody td {
  padding: var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--gray-800);
}
table.grid tbody tr:hover { background: var(--bg-alt); }
table.grid tbody td a { color: var(--nar-blue-dark); font-weight: 500; }

/* ---- Mobile ---- */
@media (max-width: 768px) {
  .wrap { padding: var(--space-5) var(--space-4); }
  .topbar-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
  }
  .topbar nav { gap: var(--space-3); }
  .topbar .who { border-left: 0; padding-left: 0; }
  .contact-grid { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  h1 { font-size: var(--text-2xl); }
  table.grid { font-size: var(--text-xs); }
  table.grid thead th, table.grid tbody td { padding: var(--space-3) var(--space-2); }
}
