*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --parchment: #F6F1EB;
  --cream: #EDE6DC;
  --marble: #E3DDD5;
  --wood: #B8956A;
  --wood-dark: #9A7B56;
  --charcoal: #2A2520;
  --charcoal-light: #3D3630;
  --sage: #7E8E74;
  --sage-light: #A5B29B;
  --gold: #C4A76C;
  --text: #2A2520;
  --text-light: #5A5048;
  --white: #FDFCFA;
  --red: #C47E7E;
  --red-bg: #FDF0F0;
  --green: #4CAF50;
  --green-bg: #F0FDF0;
  --blue: #5B8AC4;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Jost', sans-serif;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--parchment);
  color: var(--text);
  min-height: 100vh;
}

/* --- Nav --- */
.nav {
  background: var(--charcoal);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-logo {
  font-family: var(--font-display);
  color: var(--white);
  font-size: 1.4rem;
  font-weight: 400;
  text-decoration: none;
}

.nav-links { display: flex; gap: 0.25rem; }

.nav-link {
  font-size: 0.82rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(253, 252, 250, 0.55);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 3px;
  transition: all 0.2s;
}

.nav-link:hover { color: var(--white); background: rgba(255,255,255,0.08); }
.nav-link.active { color: var(--gold); background: rgba(196, 167, 108, 0.12); }

/* --- Main --- */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* --- Page Header --- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.section-label {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--wood);
  margin-bottom: 0.35rem;
  display: block;
}

h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 300;
  color: var(--text);
}

.back-link {
  font-size: 0.82rem;
  color: var(--wood);
  text-decoration: none;
  display: inline-block;
  margin-bottom: 0.5rem;
}

.back-link:hover { color: var(--wood-dark); }

/* --- Filters --- */
.filters { display: flex; gap: 0.5rem; }

.filter-select {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text);
  background: var(--white);
  border: 1px solid var(--marble);
  border-radius: 3px;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 5 5-5' stroke='%235A5048' stroke-width='1.2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  cursor: pointer;
}

/* --- Table --- */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border: 1px solid var(--marble);
  border-radius: 4px;
  overflow: hidden;
}

.data-table th {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-light);
  background: var(--cream);
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--marble);
}

.data-table td {
  font-size: 0.88rem;
  font-weight: 300;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(227, 221, 213, 0.5);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: rgba(246, 241, 235, 0.5); }
.data-table tbody tr:last-child td { border-bottom: none; }

.td-date { font-size: 0.8rem; color: var(--text-light); white-space: nowrap; }
.td-email { font-size: 0.82rem; }
.td-phone { font-size: 0.82rem; white-space: nowrap; }
.td-actions { white-space: nowrap; }

.lead-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 400;
}

.lead-link:hover { color: var(--wood); }

/* --- Badges --- */
.status-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--white);
  padding: 0.25rem 0.65rem;
  border-radius: 3px;
}

.source-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-light);
  background: var(--cream);
  border: 1px solid var(--marble);
  padding: 0.2rem 0.55rem;
  border-radius: 3px;
}

/* --- Buttons --- */
.btn-sm {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  padding: 0.4rem 0.75rem;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-block;
}

.btn-sms { background: var(--sage); color: var(--white); }
.btn-sms:hover { background: #6B7D62; }
.btn-email { background: var(--blue); color: var(--white); }
.btn-email:hover { background: #4A76AE; }
.btn-update { background: var(--wood); color: var(--white); }
.btn-update:hover { background: var(--wood-dark); }
.btn-copy { background: var(--charcoal); color: var(--white); margin-top: 0.75rem; }
.btn-copy:hover { background: var(--charcoal-light); }

/* --- Detail Grid --- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.detail-card {
  background: var(--white);
  border: 1px solid var(--marble);
  border-radius: 4px;
  padding: 1.5rem;
}

.detail-card.full-width { grid-column: 1 / -1; }

.detail-card h3 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 400;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--marble);
}

.detail-list { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; }
.detail-list dt { font-size: 0.78rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-light); }
.detail-list dd { font-size: 0.88rem; font-weight: 300; }
.detail-list a { color: var(--wood); text-decoration: none; }
.detail-list a:hover { color: var(--wood-dark); }

.message-text {
  font-size: 0.88rem;
  font-weight: 300;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Forms in detail --- */
.status-form, .notes-form, .sms-form {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notes-input, .sms-input {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 300;
  width: 100%;
  border: 1px solid var(--marble);
  border-radius: 3px;
  padding: 0.6rem;
  resize: vertical;
  background: var(--parchment);
}

.notes-input:focus, .sms-input:focus {
  outline: none;
  border-color: var(--wood);
  box-shadow: 0 0 0 3px rgba(184, 149, 106, 0.12);
}

.notes-actions, .sms-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.notes-saved {
  font-size: 0.78rem;
  color: var(--sage);
  font-weight: 400;
}

/* --- Email Preview --- */
.email-buttons { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.email-preview {
  margin-top: 1rem;
  background: var(--parchment);
  border: 1px solid var(--marble);
  border-radius: 3px;
  padding: 1rem;
}

.email-field {
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

.email-body {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 300;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--marble);
}

/* --- Pre-Apps --- */
.preapp-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.preapp-card {
  background: var(--white);
  border: 1px solid var(--marble);
  border-radius: 4px;
  padding: 1.75rem;
}

.preapp-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.preapp-name {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 400;
}

.preapp-date {
  font-size: 0.78rem;
  color: var(--text-light);
}

.preapp-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--marble);
}

.flag {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  padding: 0.3rem 0.65rem;
  border-radius: 3px;
}

.flag-green { background: var(--green-bg); color: #2E7D32; border: 1px solid #C8E6C9; }
.flag-red { background: var(--red-bg); color: #C62828; border: 1px solid #FFCDD2; }

.preapp-details {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.preapp-section h4 {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--wood);
  margin-bottom: 0.5rem;
}

.preapp-section dl { font-size: 0.85rem; }
.preapp-section dt { font-weight: 500; font-size: 0.78rem; color: var(--text-light); margin-top: 0.3rem; }
.preapp-section dd { font-weight: 300; margin-left: 0; }
.preapp-section.full-width { grid-column: 1 / -1; }
.preapp-section p { font-size: 0.88rem; font-weight: 300; line-height: 1.6; }

.preapp-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--marble);
}

/* --- SMS Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 37, 32, 0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--white);
  border-radius: 6px;
  padding: 2rem;
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 400;
  margin-bottom: 1rem;
}

.modal textarea {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 300;
  width: 100%;
  border: 1px solid var(--marble);
  border-radius: 3px;
  padding: 0.6rem;
  resize: vertical;
  min-height: 100px;
  margin-bottom: 0.75rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-cancel {
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--cream);
  color: var(--text);
  border: 1px solid var(--marble);
  padding: 0.4rem 0.75rem;
  border-radius: 3px;
  cursor: pointer;
}

/* --- Toast --- */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
}

.toast {
  font-size: 0.85rem;
  font-weight: 400;
  padding: 0.75rem 1.25rem;
  border-radius: 4px;
  margin-top: 0.5rem;
  animation: fadeIn 0.3s ease;
}

.toast-success { background: var(--green-bg); color: #2E7D32; border: 1px solid #C8E6C9; }
.toast-error { background: var(--red-bg); color: #C62828; border: 1px solid #FFCDD2; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--white);
  border: 1px solid var(--marble);
  border-radius: 4px;
}

.empty-state p {
  font-size: 0.95rem;
  font-weight: 300;
  color: var(--text-light);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .main { padding: 1rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .detail-grid { grid-template-columns: 1fr; }
  .preapp-details { grid-template-columns: 1fr 1fr; }
  .data-table { font-size: 0.82rem; }
}

@media (max-width: 480px) {
  .preapp-details { grid-template-columns: 1fr; }
  .filters { flex-direction: column; }
}
