:root {
  --black: #111;
  --white: #fff;
  --off-white: #f7f5f2;
  --line: #e5ded6;
  --muted: #706b67;
  --accent: #b89a52;
  --danger: #a53030;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "DM Sans", sans-serif;
  background: var(--off-white);
  color: var(--black);
}

.hidden { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--black);
}

.auth-card {
  width: min(460px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  padding: 36px;
}

.brand,
.eyebrow,
label,
.sidebar-brand,
.nav-item,
button {
  letter-spacing: 3px;
  text-transform: uppercase;
}

.brand,
.eyebrow {
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
}

h1,
h2 {
  margin: 14px 0 18px;
  line-height: 1.1;
}

p {
  color: var(--muted);
  line-height: 1.6;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 24px 0;
  border: 1px solid var(--line);
}

.tabs button {
  border: 0;
  background: var(--white);
  padding: 14px;
  cursor: pointer;
}

.tabs button.active {
  background: var(--black);
  color: var(--white);
}

.auth-form,
.panel {
  display: grid;
  gap: 14px;
}

label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--black);
  font: inherit;
  padding: 14px;
}

textarea { resize: vertical; }

button {
  border: 1px solid var(--black);
  background: var(--black);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  padding: 14px 18px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.link-button,
.secondary-button,
.ghost-button {
  background: transparent;
  color: var(--black);
}

.full-button {
  width: 100%;
  margin-bottom: 14px;
}

.ghost-button {
  color: var(--white);
  border-color: rgba(255,255,255,0.35);
}

.danger-button {
  background: var(--danger);
  border-color: var(--danger);
}

.message,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.message.is-error { color: var(--danger); }

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

.sidebar {
  background: var(--black);
  color: var(--white);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar-brand {
  color: var(--white);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--white);
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
  color: rgba(255,255,255,0.7);
  font-size: 12px;
}

.main {
  padding: 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.section { display: none; }
.active-section { display: block; }

.panel {
  background: var(--white);
  border: 1px solid var(--line);
  padding: 24px;
}

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

.span-2 { grid-column: span 2; }

.field-help {
  margin: 6px 0 12px;
  font-size: 13px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}

.checkbox-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--off-white);
  padding: 12px;
  color: var(--black);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.checkbox-option input {
  width: auto;
  flex: 0 0 auto;
}

.checkbox-option span {
  line-height: 1.35;
}

.intake-fieldset {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.optional-label {
  letter-spacing: 0;
  text-transform: none;
  font-weight: 400;
}

.request-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  align-items: start;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.request-list {
  display: grid;
  gap: 10px;
}

.request-item {
  border: 1px solid var(--line);
  background: var(--off-white);
  padding: 14px;
  cursor: pointer;
}

.request-item.active {
  border-color: var(--black);
}

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

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.status {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--white);
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.payment-summary {
  border: 1px solid var(--line);
  background: var(--off-white);
  padding: 16px;
}

.payment-summary h3 {
  margin: 0;
  font-size: 16px;
}

.payment-facts {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}

.payment-facts strong {
  color: var(--black);
}

.payment-list {
  display: grid;
  gap: 10px;
}

.engagement-progress {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
  margin: 14px 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.engagement-progress span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.engagement-progress strong {
  display: block;
}

.next-step-note {
  grid-column: 1 / -1;
  background: var(--white);
  border: 1px solid var(--line);
  padding: 12px;
}

.next-step-note p {
  margin: 5px 0 0;
}

.payment-card {
  border: 1px solid var(--line);
  background: var(--white);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.matching-grid,
.matching-group,
.candidate-card-grid {
  display: grid;
  gap: 14px;
}

.matching-group {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.matching-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.matching-group-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}

.matching-group h3 {
  margin: 0 0 4px;
}

.candidate-card-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.candidate-card {
  border: 1px solid var(--line);
  background: var(--off-white);
}

.candidate-photo {
  aspect-ratio: 3 / 4;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.candidate-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.candidate-photo.loaded-photo img {
  display: block;
}

.candidate-photo.loaded-photo span {
  display: none;
}

.candidate-photo.missing-photo img {
  display: none;
}

.candidate-body {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.candidate-body span {
  color: var(--muted);
  font-size: 13px;
}

.payment-title {
  font-weight: 700;
  text-transform: capitalize;
}

.paid-badge {
  border: 1px solid var(--line);
  padding: 5px 9px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

.client-chat-widget {
  position: fixed;
  right: 24px;
  bottom: 20px;
  z-index: 1000;
  width: min(430px, calc(100vw - 32px));
  display: grid;
  justify-items: end;
  gap: 10px;
}

.client-chat-tab {
  border: 1px solid var(--black);
  background: var(--black);
  color: var(--white);
  padding: 14px 16px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  max-width: 100%;
}

.client-chat-tab strong {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--danger);
  color: var(--white);
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  letter-spacing: 0;
}

.client-chat-panel {
  display: none;
  width: 100%;
  max-height: min(640px, calc(100vh - 120px));
  border: 1px solid var(--line);
  background: var(--white);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.18);
  padding: 18px;
  overflow: hidden;
}

.client-chat-panel.open {
  display: grid;
  gap: 12px;
}

.client-chat-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.client-chat-head h2 {
  margin: 0 0 4px;
  font-size: 22px;
}

.client-chat-head p,
.chat-status {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.chat-icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--black);
  font-size: 22px;
  line-height: 1;
}

.chat-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.chat-thread-select {
  width: 100%;
}

.chat-messages {
  min-height: 220px;
  max-height: 310px;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: var(--off-white);
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.chat-empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.chat-message {
  display: grid;
  gap: 4px;
  max-width: 84%;
}

.chat-message.client {
  justify-self: end;
}

.chat-message-body {
  border: 1px solid var(--line);
  background: var(--white);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-message.client .chat-message-body {
  background: var(--black);
  color: var(--white);
  border-color: var(--black);
}

.chat-message.unsent .chat-message-body,
.chat-message.client.unsent .chat-message-body {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  border-style: dashed;
  font-style: italic;
}

.chat-message-meta {
  color: var(--muted);
  font-size: 11px;
}

.chat-composer {
  display: grid;
  gap: 10px;
}

.chat-composer textarea {
  resize: vertical;
}

.chat-composer button {
  width: 100%;
}

.chat-status.is-error {
  color: var(--danger);
}

@media (max-width: 900px) {
  .app-shell,
  .request-layout,
  .form-grid,
  .checkbox-grid,
  .engagement-progress,
  .candidate-card-grid {
    grid-template-columns: 1fr;
  }

  .span-2 { grid-column: span 1; }

  .sidebar {
    min-height: auto;
  }

  .client-chat-widget {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }
}
