/* ============================================================
   BioDrive — Forms Companion Stylesheet
   Extends styles.css with form controls, using the same
   green/white token system. No new colors introduced.
   ============================================================ */

/* ----------------------------------------------------------
   1. Field primitives
   ---------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dark);
}

.field .req {
  color: var(--danger);
  font-weight: 700;
}

.field .hint {
  font-size: 12px;
  color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text-dark);
  background-color: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--g-500);
  box-shadow: 0 0 0 3px var(--g-50);
}

input[readonly] {
  background-color: var(--grey-50);
  color: var(--text-muted);
  cursor: not-allowed;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--g-600) 50%),
    linear-gradient(135deg, var(--g-600) 50%, transparent 50%);
  background-position: calc(100% - 22px) calc(50% - 3px), calc(100% - 16px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}

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

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

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

/* Email input paired with a "Send code" button — see register.html's
   email-verification step. The button keeps its natural width; the input
   takes whatever's left. */
.field-inline {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.field-inline input {
  flex: 1;
  min-width: 0;
}

.field-inline .btn {
  flex-shrink: 0;
  white-space: nowrap;
}

/* ----------------------------------------------------------
   2. Section dividers within a card body
   ---------------------------------------------------------- */
.form-section + .form-section {
  margin-top: 26px;
  padding-top: 26px;
  border-top: 1px solid var(--grey-200);
}

.form-section__label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--g-600);
  margin-bottom: 16px;
}

/* ----------------------------------------------------------
   3. Form footer (Cancel / Submit)
   ---------------------------------------------------------- */
.form-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 22px;
  border-top: 1px solid var(--grey-200);
  background-color: var(--grey-50);
}

/* ----------------------------------------------------------
   4. Checkbox / toggle row
   ---------------------------------------------------------- */
.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--g-600);
  cursor: pointer;
}

.checkbox-row__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-row__copy strong {
  font-size: 14px;
  color: var(--text-dark);
}

.checkbox-row__copy span {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Input with trailing unit (e.g. %, hrs) */
.input-unit {
  position: relative;
}

.input-unit input {
  padding-right: 44px;
}

.input-unit__suffix {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
}

/* ----------------------------------------------------------
   5. Prescription / batch row (repeatable, "dynamic-ready")
   ---------------------------------------------------------- */
.row-group {
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-sm);
  padding: 18px;
  background-color: var(--grey-50);
}

.row-group__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.row-group__title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.row-group__remove {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--danger);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
}

.add-row-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--g-700);
  background-color: var(--surface);
  border: 1px dashed var(--g-300);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  width: 100%;
  justify-content: center;
  cursor: pointer;
  margin-top: 14px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.add-row-btn:hover {
  background-color: var(--g-50);
  border-color: var(--g-500);
}

/* ----------------------------------------------------------
   6. Auth (login) page
   ---------------------------------------------------------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--grey-50);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background-color: var(--surface);
  border: 1px solid var(--grey-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px 32px;
}

/* Wider variant for the register form — more fields than sign-in, so a
   2-column field grid needs the extra room to avoid feeling cramped. */
.auth-card--wide {
  max-width: 560px;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  text-align: center;
}

.auth-brand__mark {
  width: 96px;
  height: auto;
  aspect-ratio: 513 / 238;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-brand__mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.auth-brand__name {
  font-size: 21px;
  font-weight: 700;
  color: var(--g-700);
}

.auth-brand__sub {
  font-size: 13px;
  color: var(--text-muted);
}

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

.role-toggle__btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  padding: 12px 10px;
  border: 1px solid var(--grey-200);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text-dark);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.role-toggle__btn:hover {
  border-color: var(--g-300);
  background-color: var(--g-50);
}

.role-toggle__btn.is-active {
  border-color: var(--g-600);
  background-color: var(--g-600);
  color: var(--white);
}

.auth-footer-note {
  margin-top: 20px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
}

.auth-footer-note a {
  color: var(--g-600);
  text-decoration: underline;
}

/* Error banner (mock state) */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 20px;
}

.error-banner__icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: var(--danger);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-banner__text strong {
  display: block;
  font-size: 13.5px;
  color: var(--danger);
}

.error-banner__text span {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* ----------------------------------------------------------
   7. Responsive
   ---------------------------------------------------------- */
@media (max-width: 760px) {
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }
  .field--span-2 {
    grid-column: span 1;
  }
  .form-footer {
    flex-direction: column-reverse;
  }
  .form-footer .btn {
    width: 100%;
  }
}

/* iOS Safari zooms the whole page in when a focused field's text is under
   16px, and the page is then left scrolled sideways with no way back — so
   every control gets 16px on a touch device.
   This lives in forms.css rather than with the other coarse-pointer rules in
   styles.css because forms.css is loaded second: the 14px rule above would
   otherwise win the cascade at equal specificity. */
@media (pointer: coarse) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* The auth card's generous desktop padding wastes a third of the usable
   width on a small phone, and the shell's 24px gutter compounds it. */
@media (max-width: 420px) {
  .auth-shell {
    padding: 16px 12px;
    /* Tall forms (register, activate) shouldn't be vertically centred on a
       short screen — that pushes the first field off the top. */
    align-items: flex-start;
  }
  .auth-card {
    padding: 26px 18px 22px;
  }
  .auth-brand__name {
    font-size: 19px;
  }
}

/* ----------------------------------------------------------
   8. Inline callout on the auth pages
   Used on register.html to explain why "Patient" isn't in the role picker
   and point at /activate.html instead — the one place the GP-controlled
   access rule has to be explained to someone who expected to sign up.
   ---------------------------------------------------------- */
.auth-note {
  margin: -4px 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--g-200);
  border-radius: var(--radius-sm);
  background-color: var(--g-50);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-dark);
}

.auth-note strong {
  display: block;
  margin-bottom: 2px;
  color: var(--g-700);
}

.auth-note a {
  color: var(--g-700);
  font-weight: 700;
  text-decoration: underline;
}
