/* Zeal Specialty Pharmacy - Secure Forms (styles shared with Grievance Reporting)
   Brand colours (Company Logos/_Color Codes.txt):
     purple #A083B7  yellow #FAF6AE  coral #F37B87  green #93D3BF
     orange #FBB47D  blue   #51ACE0  black  #000000  white #FFFFFF
   Brand purple is too light for text on white (2.9:1), so text, links and
   buttons use --purple-700, a darker shade of it (8.6:1). The pastel brand
   colours are used as badge/notice backgrounds with dark text on top. */

:root {
  --purple: #A083B7;
  --purple-700: #5B3F78;
  --purple-800: #47305F;
  --purple-50: #F6F2F9;
  --purple-100: #EAE1F1;
  --yellow: #FAF6AE;
  --coral: #F37B87;
  --green: #93D3BF;
  --orange: #FBB47D;
  --blue: #51ACE0;

  --ink: #241A30;
  --muted: #625873;
  --line: #E1D9E8;
  --card: #FFFFFF;
  --page: var(--purple-50);

  --ok-bg: #E4F4EE;     --ok-fg: #1D6650;
  --info-bg: #E2F1FA;   --info-fg: #1D5F86;
  --wait-bg: #FAF6AE;   --wait-fg: #5E5000;
  --bad-bg: #FDE7EA;    --bad-fg: #A12A3B;
  --note-bg: #FEF0E4;   --note-fg: #6E3C0C;
  --quiet-bg: #EEEAF2;  --quiet-fg: #5A5068;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(36, 26, 48, .06), 0 2px 8px rgba(36, 26, 48, .05);
  --stripes: linear-gradient(90deg,
      var(--purple) 0 16.66%, var(--yellow) 0 33.33%, var(--coral) 0 50%,
      var(--green) 0 66.66%, var(--orange) 0 83.33%, var(--blue) 0 100%);
}

* { box-sizing: border-box; }
/* The hidden attribute must always win over display rules below (inputs, buttons, textareas). */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--page);
}
a { color: var(--purple-700); text-underline-offset: 2px; }
a:hover { color: var(--purple-800); }
:focus-visible { outline: 3px solid var(--purple); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 6px; }
code { font: 13px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; font-weight: 400; }
.error { color: var(--bad-fg); }

/* ---- header ---------------------------------------------------------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 24px;
  padding: 10px 24px; background: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand img { height: 46px; width: auto; display: block; }
.brand .app-name {
  padding-left: 12px; border-left: 1px solid var(--line);
  font-size: 15px; font-weight: 600; color: var(--purple-700); white-space: nowrap;
}
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; margin-right: auto; }
.topbar nav a {
  padding: 6px 12px; border-radius: 999px; text-decoration: none;
  color: var(--ink); font-size: 15px; font-weight: 500;
}
.topbar nav a:hover { background: var(--purple-50); }
.topbar nav a[aria-current="page"] { background: var(--purple-100); color: var(--purple-800); }
.who { color: var(--muted); font-size: 14px; white-space: nowrap; margin-left: auto; }
.stripes { height: 5px; background: var(--stripes); }

/* ---- page title band -------------------------------------------------- */
.hero {
  background:
    linear-gradient(rgba(52, 34, 74, .55), rgba(52, 34, 74, .55)),
    url("/static/brand/background.jpg") center / cover;
  color: #fff;
}
.hero-inner { max-width: 1100px; margin: 0 auto; padding: 28px 24px 30px; }
.hero h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.01em; }
.hero p { margin: 6px 0 0; color: rgba(255, 255, 255, .88); }
.hero a { color: #fff; }
.hero code { color: #fff; }
.back { display: inline-block; margin-bottom: 8px; font-size: 14px; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 24px 56px; }
main.narrow, .hero-inner.narrow { max-width: 820px; }
.hint { display: block; margin-top: 2px; font-size: 13px; font-weight: 400; color: var(--muted); }

/* ---- cards ----------------------------------------------------------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin: 0 0 16px;
}
.panel > h2:first-child { margin-top: 0; }
.panel-head { display: flex; align-items: baseline; gap: 10px; }
.panel-head h2 { margin: 0 0 12px; }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }
.narrative { white-space: pre-wrap; margin: 0; }
dl.facts + .narrative, dl.facts + .notice { margin-top: 12px; }
details summary { cursor: pointer; color: var(--purple-700); margin: 12px 0 6px; font-weight: 500; }

/* ---- notices --------------------------------------------------------- */
.notice, .error-summary {
  border-radius: 8px; padding: 10px 14px; margin: 0 0 16px; border: 1px solid;
}
.notice { background: var(--note-bg); border-color: var(--orange); color: var(--note-fg); }
.error-summary { background: var(--bad-bg); border-color: var(--coral); color: var(--bad-fg); }
.error-summary p { margin: 0 0 4px; font-weight: 600; }
.error-summary ul { margin: 0; padding-left: 20px; }

/* ---- forms ----------------------------------------------------------- */
form label { display: block; margin: 0 0 16px; font-weight: 600; }
input[type=text], input[type=date], input[type=search], input[type=tel], input[type=email], textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 9px 12px;
  font: inherit; font-weight: 400; color: var(--ink);
  background: #fff; border: 1px solid #CFC4DA; border-radius: 8px;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--purple-700); box-shadow: 0 0 0 3px rgba(160, 131, 183, .35);
}
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
label.radio { display: inline-flex; align-items: center; gap: 8px; margin: 0 20px 6px 0; font-weight: 400; }
label.radio.block { display: flex; margin: 6px 0; }
input[type=radio] { accent-color: var(--purple-700); width: 18px; height: 18px; margin: 0; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }
.inline { display: flex; gap: 8px; margin-top: 6px; }
.inline input { margin-top: 0; }
.choice { margin: 0 0 16px; padding: 4px 16px 2px; background: var(--purple-50); border-radius: 8px; }
.choice h3 { margin: 10px 0 10px; }
p.hint { margin: 8px 0 0; }
/* A hint right under a form field tucks up against it (the field's label has a 16px bottom margin). */
label + p.hint { margin: -8px 0 16px; }

button, .button {
  display: inline-block; padding: 10px 20px; font: inherit; font-weight: 600;
  color: #fff; background: var(--purple-700); border: 1px solid var(--purple-700);
  border-radius: 8px; cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { background: var(--purple-800); border-color: var(--purple-800); color: #fff; }
button.secondary { background: #fff; color: var(--purple-700); }
button.secondary:hover { background: var(--purple-50); color: var(--purple-800); }

/* ---- tables ---------------------------------------------------------- */
table.queue { width: 100%; border-collapse: collapse; font-size: 14px; }
table.queue th, table.queue td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.queue th { color: var(--muted); font-weight: 600; font-size: 13px; }
table.queue tbody tr:last-child td { border-bottom: 0; }
table.queue tbody tr:hover { background: var(--purple-50); }
.empty { color: var(--muted); margin: 0; }
.count {
  display: inline-block; min-width: 24px; padding: 1px 8px; border-radius: 999px;
  background: var(--purple-100); color: var(--purple-800); font-size: 13px; font-weight: 600; text-align: center;
}
.reason { margin: 6px 0 0; font-size: 13px; }

/* ---- status badges --------------------------------------------------- */
.status {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--quiet-bg); color: var(--quiet-fg);
}
.status-compliance_review { background: var(--wait-bg); color: var(--wait-fg); }
.status-supervisor_review { background: var(--info-bg); color: var(--info-fg); }
.status-closed_resolved   { background: var(--ok-bg); color: var(--ok-fg); }
.status-closed_not_grievance { background: var(--quiet-bg); color: var(--quiet-fg); }
.ai-evaluated   { background: var(--ok-bg); color: var(--ok-fg); }
.ai-failed, .ai-scrub_failed { background: var(--bad-bg); color: var(--bad-fg); }

/* ---- timeline -------------------------------------------------------- */
ol.timeline { list-style: none; padding: 0; margin: 0; }
ol.timeline li {
  position: relative; display: flex; flex-wrap: wrap; gap: 2px 12px;
  padding: 8px 0 8px 22px; font-size: 14px;
}
ol.timeline li::before {
  content: ""; position: absolute; left: 4px; top: 15px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--purple);
}
ol.timeline li:not(:last-child)::after {
  content: ""; position: absolute; left: 8px; top: 26px; bottom: -8px; width: 1px; background: var(--line);
}
ol.timeline .when { color: var(--muted); min-width: 170px; }

/* ---- welcome / sign-in ----------------------------------------------- */
body.welcome {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    linear-gradient(rgba(52, 34, 74, .35), rgba(52, 34, 74, .35)),
    url("/static/brand/background.jpg") center / cover fixed;
}
.welcome-card {
  width: 100%; max-width: 440px; background: #fff; border-radius: 16px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(36, 26, 48, .25); text-align: center;
}
.welcome-card .body { padding: 32px 32px 28px; }
.welcome-card img { width: 260px; max-width: 100%; height: auto; }
.welcome-card h1 { font-size: 22px; margin: 18px 0 6px; }
.welcome-card p { color: var(--muted); margin: 0 0 22px; }
.welcome-card .button { width: 100%; padding: 12px 20px; }
.welcome-card .fine { font-size: 12px; margin: 16px 0 0; }

/* ---- small screens --------------------------------------------------- */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .brand img { height: 34px; }
  .brand .app-name { display: none; }
  .topbar nav { order: 3; width: 100%; margin: 0 -10px; gap: 2px; }
  .topbar nav a { padding: 6px 10px; font-size: 14px; }
  .hero-inner { padding: 20px 16px 22px; }
  .hero h1 { font-size: 22px; }
  main { padding: 16px 16px 40px; }
  .panel { padding: 16px; }
  table.queue thead { display: none; }
  table.queue tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
  table.queue tbody tr:last-child { border-bottom: 0; }
  table.queue td { display: block; border: 0; padding: 2px 0; }
  ol.timeline .when { min-width: 0; width: 100%; }
}

/* label + input + button on one row (reporter name) */
label + .field { margin: -10px 0 16px; }
.field input { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
@media (max-width: 520px) {
  .field { flex-wrap: wrap; }
  .field input { flex-basis: 100%; }
}
.field-error { display: block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--bad-fg); }
.field-error:empty { display: none; }
input[aria-invalid="true"] { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(243, 123, 135, .25); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions + .hint, .actions + p { margin-top: 12px; }
a.button.secondary { background: #fff; color: var(--purple-700); }
a.button.secondary:hover { background: var(--purple-50); color: var(--purple-800); }
.kb-text { white-space: pre-wrap; font: 13px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace; margin: 0; max-height: 70vh; overflow: auto; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 14px; }
.inline-form .hint { margin: 0; }
input[type=file] { display: block; margin-top: 6px; font: inherit; font-weight: 400; }

/* Determination form: show only the section for the chosen answer (none until one is chosen).
   Browsers without :has() skip this block and show both, and the server ignores the other one. */
@supports selector(:has(*)) {
  form:has(input[name="final_is_grievance"]) .choice-yes,
  form:has(input[name="final_is_grievance"]) .choice-no { display: none; }
  form:has(input[name="final_is_grievance"][value="yes"]:checked) .choice-yes,
  form:has(input[name="final_is_grievance"][value="no"]:checked) .choice-no { display: block; }
}
.people-filter { margin-bottom: 6px; }
.people-count:empty { display: none; }

/* ---- admin -------------------------------------------------------------- */
.gear { display: inline-flex; vertical-align: middle; margin-right: 8px; padding: 4px; border-radius: 8px; color: var(--purple-700); }
.gear:hover, .gear[aria-current="page"] { background: var(--purple-100); color: var(--purple-800); }
.tabs { display: flex; gap: 6px; margin: 12px 0 0; }
.tabs a { padding: 5px 14px; border-radius: 999px; text-decoration: none; color: #fff; background: rgba(255, 255, 255, .14); }
.tabs a:hover { background: rgba(255, 255, 255, .24); }
.tabs a[aria-current="page"] { background: #fff; color: var(--purple-800); }
.notice.ok { background: var(--ok-bg); border-color: var(--green); color: var(--ok-fg); }
.report-notice { white-space: pre-wrap; }
input[type=checkbox] { accent-color: var(--purple-700); width: 18px; height: 18px; margin: 0; flex: none; }
.inline .unit { align-self: center; color: var(--muted); font-weight: 400; }
input[name$="_due_days"] { max-width: 90px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---- due dates ---------------------------------------------------------- */
.status.due { background: var(--quiet-bg); color: var(--quiet-fg); }
.status.due-today { background: var(--wait-bg); color: var(--wait-fg); }
.status.due-overdue { background: var(--bad-bg); color: var(--bad-fg); }
input[name="digest_window_days"] { max-width: 70px; }

/* ---- home ------------------------------------------------------------- */
.home-report { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.home-report h2 { margin: 0 0 4px; }
.home-report p { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
a.tile { display: block; color: var(--ink); text-decoration: none; transition: border-color .15s, box-shadow .15s; }
a.tile:hover { border-color: var(--purple); color: var(--ink); }
.tile h2 { margin: 0 0 10px; color: var(--purple-800); }
.tile-count { margin: 0 0 4px; }
.tile-count strong { font-size: 22px; }
.tile-flags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.tile p.muted { margin: 4px 0 0; }
.attention { margin: 0; padding-left: 18px; color: var(--note-fg); }
.more { margin: 10px 0 0; font-size: 14px; }

/* ==== Secure Forms additions ============================================ */
.badge-open   { background: var(--ok-bg); color: var(--ok-fg); }
.badge-closed { background: var(--quiet-bg); color: var(--quiet-fg); }
.badge-draft  { background: var(--wait-bg); color: var(--wait-fg); }
.copy-link { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.copy-link code { padding: 6px 10px; background: var(--purple-50); border-radius: 6px; word-break: break-all; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.page-actions .spacer { margin-left: auto; }
button.small, .button.small { padding: 6px 14px; font-size: 14px; }

/* Form editor page: JSON on the left, live preview on the right (stacked on small screens). */
body.designer main { max-width: none; padding: 0; }
.designer-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line);
}
.designer-bar h1 { font-size: 18px; margin: 0; }
.designer-bar .spacer { margin-left: auto; }
.designer-bar .save-state { color: var(--muted); font-size: 14px; }
.json-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 16px 24px 32px; }
.json-pane, .preview-pane { display: flex; flex-direction: column; min-width: 0; }
.pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pane-head h2 { margin: 0 0 8px; }
#definition {
  flex: 1; min-height: 70vh; margin: 0; resize: vertical; tab-size: 2; white-space: pre;
  font: 13px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.preview-pane .survey-wrap { max-height: 78vh; overflow: auto; padding: 24px 28px; }
label.file-pick { margin: 0 0 8px; font-weight: 500; font-size: 14px; color: var(--purple-700); cursor: pointer; }
label.file-pick input { display: none; }
label.file-pick:hover { text-decoration: underline; }
@media (max-width: 1000px) {
  .json-editor { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  #definition { min-height: 45vh; }
}
.problems { margin: 0; padding: 10px 24px 10px 44px; background: var(--bad-bg); color: var(--bad-fg); }
.problems:empty { display: none; }

/* Reports */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 16px; align-items: end; }
.filters label { margin-bottom: 12px; }
.bar-cell { width: 45%; }
.bar { height: 10px; border-radius: 5px; background: var(--purple); min-width: 2px; }
.total { font-size: 28px; font-weight: 700; color: var(--purple-800); margin: 0; }
.export-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.export-form select { width: auto; margin: 0; }

/* ---- public forms ------------------------------------------------------ */
body.public { background: var(--page); }
.public-header { background: #fff; }
.public-header .inner { max-width: 820px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.public-header img { height: 42px; width: auto; }
.public-main { max-width: 820px; margin: 0 auto; padding: 16px 16px 48px; }
.public-main h1 { font-size: 24px; margin: 8px 0 12px; }
.survey-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.submit-area { margin: 16px 0 0; }
.submit-area .cf-turnstile { margin: 0 0 12px; min-height: 65px; }
.submit-status { margin: 12px 0 0; }
.privacy { font-size: 13px; color: var(--muted); margin-top: 24px; }
.thanks { text-align: center; padding: 32px 16px; }
.thanks .ref { font: 600 20px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--purple-800); }
@media (max-width: 760px) {
  .public-header img { height: 34px; }
  .public-main h1 { font-size: 20px; }
  .designer-bar { padding: 10px 16px; }
}

/* Destructive actions */
button.danger, .button.danger { background: #A12A3B; border-color: #A12A3B; color: #fff; }
button.danger:hover, .button.danger:hover { background: #86202F; border-color: #86202F; }
.button.danger-outline { background: #fff; border-color: #E8A3AD; color: #A12A3B; }
.button.danger-outline:hover { background: var(--bad-bg); border-color: #A12A3B; color: #86202F; }
.staging-banner { padding: 6px 24px; background: var(--wait-bg); color: var(--wait-fg); font-size: 13px; font-weight: 600; }

/* Submissions list and detail */
.filters .search-field { grid-column: span 2; }
table.submissions td { vertical-align: middle; }
.status.sub-sent { background: var(--ok-bg); color: var(--ok-fg); }
.status.sub-pending { background: var(--wait-bg); color: var(--wait-fg); }
.status.sub-failed { background: var(--bad-bg); color: var(--bad-fg); }
.pager { display: flex; justify-content: space-between; margin-top: 12px; }
.pager a:only-child:last-child { margin-left: auto; }
dl.facts.answers dd { white-space: pre-wrap; overflow-wrap: anywhere; }
.file-list { margin: 0; padding-left: 18px; }
.file-list li { margin: 4px 0; }
@media (max-width: 760px) { .filters .search-field { grid-column: auto; } }
