/* =========================================================
 * AI REFERRAL LETTER GENERATOR
 * ListenMD Clinical AI Tool
 * ========================================================= */


/* ---------------------------------------------------------
 * PAGE WRAPPER
 * --------------------------------------------------------- */

.ai-referral-letter {
  position: relative;
  box-sizing: border-box;
  width: min(100%, 1180px);
  margin-inline: auto;
  padding: 1rem 1rem 4rem;
}


/* ---------------------------------------------------------
 * HIDE DRUPAL DEFAULT TITLE / BREADCRUMB
 * --------------------------------------------------------- */

body:has(.ai-referral-letter) main {
  padding-top: 0 !important;
}

body:has(.ai-referral-letter) .block-page-title-block,
body:has(.ai-referral-letter) .block-system-breadcrumb-block,
body:has(.ai-referral-letter) .breadcrumb,
body:has(.ai-referral-letter) .region-breadcrumb,
body:has(.ai-referral-letter) .page-title {
  display: none !important;
}

body:has(.ai-referral-letter)
section > div[class*="container"]:not([class*="space-"]) {
  padding-top: 0;
  padding-bottom: 0;
}


/* ---------------------------------------------------------
 * HERO
 * --------------------------------------------------------- */

.ai-referral-letter__hero {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  margin: 0 auto 1.5rem;
  padding: 2.7rem 2rem 2.9rem;
  overflow: hidden;

  border: 1px solid #dce9f4;
  border-radius: 24px;

  background:
    radial-gradient(
      circle at top right,
      rgb(30 159 230 / 15%),
      transparent 37%
    ),
    radial-gradient(
      circle at bottom left,
      rgb(213 54 58 / 4%),
      transparent 30%
    ),
    linear-gradient(
      135deg,
      #f8fcff 0%,
      #ffffff 55%,
      #f3f9fd 100%
    );

  text-align: center;

  box-shadow:
    0 20px 50px rgb(19 58 92 / 7%),
    0 4px 12px rgb(19 58 92 / 4%);
}


/* Hero brand line */

.ai-referral-letter__hero::before {
  position: absolute;
  top: 0;
  left: 50%;

  width: 140px;
  height: 4px;

  border-radius: 0 0 4px 4px;

  background:
    linear-gradient(
      90deg,
      #173f6b,
      #1e9fe6,
      #d5363a
    );

  content: "";
  transform: translateX(-50%);
}


/* Hero badge */

.ai-referral-letter__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;

  margin-bottom: 1.15rem;
  padding: 0.5rem 0.95rem;

  border: 1px solid #bfdaed;
  border-radius: 999px;

  background: #eef8fe;

  color: #145f91;

  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ai-referral-letter__eyebrow-dot {
  width: 7px;
  height: 7px;

  border-radius: 50%;

  background: #1e9fe6;

  box-shadow:
    0 0 0 4px rgb(30 159 230 / 12%);
}


/* Hero icon */

.ai-referral-letter__hero-icon {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 54px;
  height: 54px;

  margin: 0 auto 1.15rem;

  border: 1px solid #c6e1f2;
  border-radius: 15px;

  background:
    linear-gradient(
      135deg,
      #eef9ff,
      #e1f3fc
    );

  color: #147db5;

  font-size: 1.7rem;
  font-weight: 700;

  box-shadow:
    0 8px 22px rgb(20 125 181 / 12%);
}


/* Hero heading */

.ai-referral-letter__hero h1 {
  max-width: 820px;
  margin: 0 auto 1rem;

  color: #173a5e;

  font-size:
    clamp(
      2.25rem,
      5vw,
      3.6rem
    );

  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.ai-referral-letter__hero h1 span {
  display: block;
  color: #1685c0;
}


/* Hero description */

.ai-referral-letter__hero p {
  max-width: 720px;
  margin: 0 auto;

  color: #607387;

  font-size:
    clamp(
      1rem,
      2vw,
      1.1rem
    );

  line-height: 1.75;
}


/* ---------------------------------------------------------
 * MAIN FORM CARD
 * --------------------------------------------------------- */

.ai-referral-letter__card {
  position: relative;

  padding:
    clamp(
      1.4rem,
      3vw,
      2.2rem
    );

  overflow: hidden;

  border: 1px solid #d7e5ef;
  border-radius: 20px;

  background: #fff;

  box-shadow:
    0 20px 55px rgb(20 56 88 / 9%),
    0 4px 12px rgb(20 56 88 / 4%);
}


/* Brand accent line */

.ai-referral-letter__card::before {
  position: absolute;
  top: 0;
  left: 0;

  width: 100%;
  height: 3px;

  background:
    linear-gradient(
      90deg,
      #173f6b,
      #1e9fe6,
      #d5363a
    );

  content: "";
}


/* ---------------------------------------------------------
 * FORM SECTIONS
 * --------------------------------------------------------- */

.ai-referral-letter__section {
  margin: 0 0 1.5rem;
  padding: 1.6rem;

  border: 1px solid #dce5ed;
  border-radius: 16px;

  background: #fbfdff;
}

.ai-referral-letter__section > legend {
  width: auto;
  padding: 0 0.4rem;

  color: #173a5e;

  font-size: 1.2rem;
  font-weight: 800;
}


/* ---------------------------------------------------------
 * LABELS
 * --------------------------------------------------------- */

.ai-referral-letter label {
  display: block;
  margin-bottom: 0.45rem;

  color: #334e68;

  font-size: 0.9rem;
  font-weight: 700;
}


/* ---------------------------------------------------------
 * INPUTS
 * --------------------------------------------------------- */

.ai-referral-letter input[type="text"],
.ai-referral-letter input[type="number"],
.ai-referral-letter select,
.ai-referral-letter textarea {
  box-sizing: border-box;
  width: 100%;

  padding: 0.8rem 0.9rem;

  border: 1px solid #c8d7e2;
  border-radius: 11px;

  background: #fff;

  color: #263746;

  font: inherit;
  font-size: 0.95rem;

  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.ai-referral-letter textarea {
  min-height: 125px;
  line-height: 1.65;
  resize: vertical;
}

.ai-referral-letter input:hover,
.ai-referral-letter select:hover,
.ai-referral-letter textarea:hover {
  border-color: #9fbcd1;
}

.ai-referral-letter input:focus,
.ai-referral-letter select:focus,
.ai-referral-letter textarea:focus {
  border-color: #1976ad;
  outline: none;

  background: #fff;

  box-shadow:
    0 0 0 4px rgb(25 118 173 / 12%);
}


/* ---------------------------------------------------------
 * FIELD SPACING
 * --------------------------------------------------------- */

.ai-referral-letter .form-item {
  margin-top: 0;
  margin-bottom: 1.25rem;
}

.ai-referral-letter .description {
  margin-top: 0.4rem;

  color: #738595;

  font-size: 0.82rem;
  line-height: 1.5;
}


/* ---------------------------------------------------------
 * INVALID FIELD STATE
 * --------------------------------------------------------- */

.ai-referral-letter
.form-item--error
input[type="text"],
.ai-referral-letter
.form-item--error
input[type="number"],
.ai-referral-letter
.form-item--error
select,
.ai-referral-letter
.form-item--error
textarea {
  border-color: #d64545 !important;

  background: #fffafa;

  box-shadow:
    0 0 0 3px rgb(214 69 69 / 8%);
}

.ai-referral-letter .form-item--error-message {
  margin-top: 0.4rem;

  color: #b42318;

  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
}


/* ---------------------------------------------------------
 * PATIENT GRID
 * --------------------------------------------------------- */

.ai-referral-letter__patient-section
.fieldset-wrapper {
  display: grid;

  grid-template-columns:
    repeat(
      2,
      minmax(0, 1fr)
    );

  gap: 0 1rem;
}

.ai-referral-letter__patient-section
.form-item-patient-name {
  grid-column: 1 / -1;
}


/* ---------------------------------------------------------
 * SAFETY NOTICE
 * --------------------------------------------------------- */

.ai-referral-letter__notice {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;

  margin: 0.4rem 0 1.5rem;
  padding: 1rem 1.1rem;

  border: 1px solid #efcf8b;
  border-left: 4px solid #df8d00;
  border-radius: 12px;

  background: #fffaf0;

  color: #5d4500;

  font-size: 0.9rem;
  line-height: 1.55;
}

.ai-referral-letter__notice-icon {
  display: flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 auto;

  width: 28px;
  height: 28px;

  border-radius: 50%;

  background: #fff0bf;

  color: #805600;

  font-weight: 900;
}

.ai-referral-letter__notice strong {
  display: block;
  margin-bottom: 0.15rem;

  color: #7a3e00;

  font-weight: 800;
}

.ai-referral-letter__notice p {
  margin: 0;
}


/* ---------------------------------------------------------
 * LOCAL VALIDATION ERRORS
 * --------------------------------------------------------- */

.ai-referral-letter__validation-errors {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;

  margin: 0 0 1.2rem;
  padding: 1rem 1.15rem;

  border: 1px solid #efb5b5;
  border-left: 4px solid #c62828;
  border-radius: 12px;

  background: #fff5f5;

  color: #7f1d1d;

  font-size: 0.9rem;
  line-height: 1.55;

  scroll-margin-top: 120px;

  box-shadow:
    0 8px 22px rgb(198 40 40 / 7%);
}

.ai-referral-letter__validation-error-icon {
  display: flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 auto;

  width: 30px;
  height: 30px;

  border-radius: 50%;

  background: #fee2e2;

  color: #b91c1c;

  font-size: 0.95rem;
  font-weight: 900;
  line-height: 1;
}

.ai-referral-letter__validation-error-content {
  flex: 1 1 auto;
  min-width: 0;
}

.ai-referral-letter__validation-error-content strong {
  display: block;

  margin-bottom: 0.35rem;

  color: #991b1b;

  font-size: 0.95rem;
  font-weight: 800;
}

.ai-referral-letter__validation-error-content ul {
  margin: 0;
  padding-left: 1.15rem;
}

.ai-referral-letter__validation-error-content li {
  margin: 0.25rem 0;

  color: #7f1d1d;

  font-size: 0.9rem;
  line-height: 1.5;
}

.ai-referral-letter__validation-error-content li::marker {
  color: #c62828;
}


/*
 * Hide Drupal's duplicate global error banner when
 * local validation errors are already displayed.
 */
body:has(.ai-referral-letter__validation-errors)
.messages--error,
body:has(.ai-referral-letter__validation-errors)
.messages.messages--error,
body:has(.ai-referral-letter__validation-errors)
.alert-danger,
body:has(.ai-referral-letter__validation-errors)
.alert-error {
  display: none !important;
}


/* ---------------------------------------------------------
 * GENERATE BUTTON
 * --------------------------------------------------------- */

.ai-referral-letter__actions {
  margin-top: 1.25rem;
  margin-bottom: 0;
}

.ai-referral-letter
input.ai-referral-letter__generate,
.ai-referral-letter
button.ai-referral-letter__generate {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 100%;
  min-height: 52px;

  margin: 0;
  padding: 0.9rem 1.5rem;

  border: 0 !important;
  border-radius: 10px !important;

  background:
    linear-gradient(
      135deg,
      #123f6d 0%,
      #147db5 100%
    ) !important;

  color: #fff !important;
  -webkit-text-fill-color: #fff !important;

  font-size: 1rem;
  font-weight: 800;

  cursor: pointer;

  box-shadow:
    0 12px 28px rgb(20 125 181 / 25%);

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.ai-referral-letter
input.ai-referral-letter__generate:hover,
.ai-referral-letter
button.ai-referral-letter__generate:hover {
  transform: translateY(-2px);

  box-shadow:
    0 15px 32px rgb(20 125 181 / 32%);
}


/* ---------------------------------------------------------
 * AJAX LOADER
 * --------------------------------------------------------- */

.ai-referral-letter .ajax-progress {
  display: flex;
  align-items: center;
  justify-content: center;

  gap: 0.65rem;

  width: 100%;
  margin-top: 0.75rem;
}

.ai-referral-letter
.ajax-progress-throbber
.throbber {
  display: inline-block;

  box-sizing: border-box;

  width: 20px;
  height: 20px;

  padding: 0;

  border:
    3px solid
    rgb(20 125 181 / 20%);

  border-top-color: #147db5;
  border-radius: 50%;

  background: transparent;

  animation:
    referral-letter-spin
    0.7s linear infinite;
}

.ai-referral-letter .ajax-progress .message,
.ai-referral-letter .ajax-progress__message {
  padding: 0;

  color: #52697d;

  font-size: 0.9rem;
  font-weight: 600;
}

@keyframes referral-letter-spin {
  to {
    transform: rotate(360deg);
  }
}


/* ---------------------------------------------------------
 * RESULT WRAPPER
 * --------------------------------------------------------- */

.ai-referral-letter__result {
  margin-top: 1.5rem;
  scroll-margin-top: 120px;
}

.ai-referral-letter__result:empty {
  display: none;
}


/* ---------------------------------------------------------
 * RESULT HEADER
 * --------------------------------------------------------- */

.ai-referral-letter__result-header {
  position: relative;

  padding: 1.4rem 1.5rem;
  overflow: hidden;

  border: 1px solid #cfe4d8;
  border-radius: 16px 16px 0 0;

  background:
    linear-gradient(
      135deg,
      #f4fbf7,
      #f9fdfb
    );
}

.ai-referral-letter__result-header > div {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.ai-referral-letter__result-header h3 {
  margin: 0;

  color: #173a5e;

  font-size: 1.2rem;
  font-weight: 800;
}

.ai-referral-letter__success-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 auto;

  width: 30px;
  height: 30px;

  border-radius: 50%;

  background: #dff5e5;

  color: #176b32;

  font-weight: 900;
}

.ai-referral-letter__result-header p {
  margin: 0.5rem 0 0;

  color: #637789;

  font-size: 0.88rem;
}


/* ---------------------------------------------------------
 * GENERATED LETTER CARD
 * --------------------------------------------------------- */

.ai-referral-letter__letter-card {
  overflow: hidden;

  border: 1px solid #dce5ed;
  border-top: 0;

  border-radius: 0 0 16px 16px;

  background: #fff;

  box-shadow:
    0 14px 40px rgb(20 45 70 / 8%);
}

.ai-referral-letter__letter-label {
  padding: 0.8rem 1.4rem;

  border-bottom: 1px solid #e4eaf0;

  background: #f7fafc;

  color: #52697d;

  font-size: 0.75rem;
  font-weight: 800;

  letter-spacing: 0.06em;
  text-transform: uppercase;
}


/* ---------------------------------------------------------
 * EDITABLE GENERATED LETTER
 * --------------------------------------------------------- */

.ai-referral-letter__generated-letter {
  display: block;

  box-sizing: border-box;

  width: 100%;
  min-height: 420px;

  margin: 0 !important;
  padding: 1.5rem !important;

  border: 0 !important;
  border-radius: 0 !important;

  background: #fff !important;

  color: #263746;

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  font-size: 0.97rem !important;
  line-height: 1.8 !important;

  resize: vertical;
}

.ai-referral-letter__generated-letter:hover {
  border: 0 !important;
}

.ai-referral-letter__generated-letter:focus {
  outline: none;

  background: #fbfdff !important;

  box-shadow:
    inset 0 0 0 2px rgb(20 125 181 / 18%);
}


/* ---------------------------------------------------------
 * RESULT ACTION BUTTONS
 * --------------------------------------------------------- */

.ai-referral-letter__result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;

  gap: 0.75rem;

  margin-top: 1rem;
}

.ai-referral-letter__result-actions > * {
  flex: 0 0 auto !important;
  width: auto !important;
}


/* Copy Referral Letter */

.ai-referral-letter
.ai-referral-letter__copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  flex: 0 0 auto !important;

  width: auto !important;
  min-width: 190px;
  min-height: 46px;

  margin: 0 !important;
  padding: 0.75rem 1.25rem !important;

  border: 1px solid #147db5 !important;
  border-radius: 9px !important;

  background: #fff !important;

  color: #147db5 !important;
  -webkit-text-fill-color: #147db5 !important;

  font-size: 0.95rem !important;
  font-weight: 800 !important;
  line-height: 1.2;

  cursor: pointer;

  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.ai-referral-letter
.ai-referral-letter__copy:hover,
.ai-referral-letter
.ai-referral-letter__copy:focus {
  background: #eef8fe !important;

  color: #126fa4 !important;
  -webkit-text-fill-color: #126fa4 !important;

  transform: translateY(-1px);

  box-shadow:
    0 6px 16px rgb(20 125 181 / 10%);
}


/* Download PDF */

.ai-referral-letter
.ai-referral-letter__download-pdf {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;

  flex: 0 0 auto !important;

  width: auto !important;
  min-width: 190px;
  min-height: 46px;

  margin: 0 !important;
  padding: 0.75rem 1.25rem !important;

  border: 0 !important;
  border-radius: 9px !important;

  background:
    linear-gradient(
      135deg,
      #123f6d 0%,
      #147db5 100%
    ) !important;

  color: #fff !important;
  -webkit-text-fill-color: #fff !important;

  font-size: 0.95rem !important;
  font-weight: 800 !important;
  line-height: 1.2;

  cursor: pointer;

  box-shadow:
    0 8px 20px rgb(20 125 181 / 18%);

  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.ai-referral-letter
.ai-referral-letter__download-pdf:hover,
.ai-referral-letter
.ai-referral-letter__download-pdf:focus {
  color: #fff !important;
  -webkit-text-fill-color: #fff !important;

  transform: translateY(-1px);

  box-shadow:
    0 10px 24px rgb(20 125 181 / 25%);
}


/* ---------------------------------------------------------
 * GENERATION ERROR
 * --------------------------------------------------------- */

.ai-referral-letter__error {
  padding: 1rem 1.15rem;

  border: 1px solid #dc8c8c;
  border-left: 5px solid #b42318;
  border-radius: 12px;

  background: #fff2f1;

  color: #7a271a;

  font-size: 0.95rem;
  line-height: 1.55;

  scroll-margin-top: 120px;
}

.ai-referral-letter__error strong {
  display: block;
  margin-bottom: 0.25rem;

  color: #912018;

  font-weight: 800;
}

.ai-referral-letter__error p {
  margin: 0;
}


/* ---------------------------------------------------------
 * MOBILE
 * --------------------------------------------------------- */

@media (max-width: 760px) {

  .ai-referral-letter {
    padding: 1rem 0.75rem 3rem;
  }


  /* Hero */

  .ai-referral-letter__hero {
    padding: 2rem 1.1rem;

    border-radius: 18px;
  }

  .ai-referral-letter__hero h1 {
    font-size:
      clamp(
        2rem,
        10vw,
        2.7rem
      );
  }

  .ai-referral-letter__hero p {
    font-size: 0.95rem;
  }


  /* Main card */

  .ai-referral-letter__card {
    padding: 1rem;

    border-radius: 16px;
  }


  /* Form sections */

  .ai-referral-letter__section {
    padding: 1.1rem;

    border-radius: 12px;
  }


  /* Patient grid */

  .ai-referral-letter__patient-section
  .fieldset-wrapper {
    grid-template-columns: 1fr;
  }

  .ai-referral-letter__patient-section
  .form-item-patient-name {
    grid-column: auto;
  }


  /* Validation */

  .ai-referral-letter__validation-errors {
    gap: 0.7rem;

    padding: 0.9rem 1rem;

    border-radius: 10px;
  }

  .ai-referral-letter__validation-error-icon {
    width: 28px;
    height: 28px;
  }

  .ai-referral-letter__validation-error-content strong {
    font-size: 0.9rem;
  }

  .ai-referral-letter__validation-error-content li {
    font-size: 0.85rem;
  }


  /* Generated letter */

  .ai-referral-letter__generated-letter {
    min-height: 360px;

    padding: 1.4rem 1.2rem !important;
  }


  /* Result header */

  .ai-referral-letter__result-header {
    padding: 1.2rem;
  }


  /* Buttons */

  .ai-referral-letter__result-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .ai-referral-letter__result-actions > * {
    width: 100% !important;
  }

  .ai-referral-letter
  .ai-referral-letter__copy,
  .ai-referral-letter
  .ai-referral-letter__download-pdf {
    width: 100% !important;
    min-width: 0;
  }
}