/* ==========================================================================
   Enter Referral — public referral intake form styles
   --------------------------------------------------------------------------
   Styles the server-rendered markup emitted by scripts/app.ts (B.out) and the
   dynamic file-list rows rendered by static/utils.ts. Mirrors the innbetween /
   Soteria "Patient Enrollment" public-form look (light-blue card layout).
   Every selector the server markup and the client toggle uses is defined here:
   .wrap/#wrapper, .card, fieldset/legend, .grid, .field(.full), label,
   .required, inputs/select/textarea, .hint, .upload-actions, #addFileBtn,
   .file-list + per-file rows (.file-item/.file/.remove-file), .form-actions,
   .muted-note, #submit, #tMessage/.message, and the .hide/.show toggles that
   drive the 4 conditional reveals and the success swap.
   ========================================================================== */

:root {
  --bg: #f5fbff;            /* very light blue */
  --card: #ffffff;
  --muted: #6b7b8c;
  --accent: #4a90e2;        /* primary blue */
  --accent-strong: #0063a6; /* legend / button blue */
  --accent-soft: #e6f2ff;
  --radius: 12px;
  --shadow: 0 6px 18px rgba(74, 144, 226, 0.08);
  --input-border: #d9e9fb;
  --danger: #c90202;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
  margin: 0;
  padding: 28px 16px;
  background: linear-gradient(180deg, var(--bg), #f8fcff);
  color: #10303f;
  -webkit-font-smoothing: antialiased;
}

/* --- Page shell -------------------------------------------------------- */
.wrap {
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--input-border);
  box-shadow: var(--shadow);
}

header.card {
  background: linear-gradient(90deg, var(--accent-soft), #f1f8ff);
  padding: 18px 22px;
  margin-bottom: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

header.card div {
  display: flex;
  flex-direction: column;
}

header h1 {
  margin: 0;
  font-size: 20px;
  color: var(--accent);
  text-align: center;
}

header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* --- Form ------------------------------------------------------------- */
form.card {
  padding: 20px;
}

fieldset {
  border: 0;
  margin: 0 0 18px;
  padding: 0;
}

legend {
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--accent-strong);
  font-size: 15px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  align-items: start;
}

.field {
  min-width: 0; /* let grid cells shrink so long content doesn't overflow */
}

.field.full,
.full {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 13px;
  color: #10303f;
  margin-bottom: 6px;
}

.required {
  color: rgb(176, 11, 11);
}

input[type='text'],
input[type='email'],
input[type='tel'],
input[type='date'],
input[type='number'],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: #fbfdff;
  font-size: 14px;
  color: #06202a;
  box-sizing: border-box;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* --- Document upload --------------------------------------------------- */
/* Native file input is hidden; #addFileBtn triggers it via script.ts. */
#documentUpload {
  display: none;
}

.upload-actions {
  margin-top: 10px;
}

#addFileBtn {
  background: var(--accent-strong);
  color: #ffffff;
  border: none;
  outline: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease-in;
}

#addFileBtn:hover {
  background: #327fb3;
}

/* File rows rendered by utils.ts renderFileList():
   <div class="file-item"><span class="file">name</span>
     <button class="remove-file">Remove</button></div> */
.file-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--input-border);
  border-radius: 8px;
}

.file {
  font-size: 13px;
  color: #06202a;
  word-break: break-all;
}

.remove-file {
  background: var(--danger);
  color: #ffffff;
  border: none;
  outline: none;
  font-size: 11px;
  border-radius: 4px;
  padding: 4px 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease-in;
}

.remove-file:hover {
  background: #d51818;
}

/* --- Actions ---------------------------------------------------------- */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.muted-note {
  font-size: 12px;
  color: var(--muted);
  flex: 1;
  min-width: 220px;
}

#submit,
button[type='submit'] {
  background: var(--accent);
  color: #ffffff;
  border: 0;
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(74, 144, 226, 0.12);
  transition: filter 0.2s ease-in;
}

#submit:hover,
button[type='submit']:hover {
  filter: brightness(0.98);
}

/* --- Success panel (#tMessage; utils.ts swaps .hide -> .message) ------- */
#tMessage.message,
.message {
  display: flex;
  flex-direction: column;
  padding: 28px 20px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  justify-content: center;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#tMessage h1 {
  margin: 0 0 8px;
  font-size: 22px;
  color: var(--accent);
}

#tMessage p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* --- Searchable State combobox (script.ts setupStateCombo) ------------- */
.state-combo {
  position: relative;
}

.state-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.state-list li {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: #06202a;
}

.state-list li:hover,
.state-list li.active {
  background: var(--accent);
  color: #ffffff;
}

/* --- Visibility toggles (client-controlled) --------------------------- */
/* .hide hides the 4 conditional reveal wrappers AND #wrapper on success;
   .show reveals a conditional follow-up field. Keep both after the layout
   rules so they win on shared single-class specificity. */
.hide {
  display: none;
}

.show {
  display: block;
}

/* --- Responsive: collapse the grid to one column on narrow screens ----- */
@media (max-width: 720px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  #submit,
  button[type='submit'] {
    width: 100%;
  }
}
