/*
 * Formularies index (PD-29425) -- matches the design mockup's small, purple-accented
 * visual language rather than Bootstrap's defaults. Scoped under .formulary-index or
 * a dedicated `formulary-*` class; Bootstrap's `.badge`/`.btn`/`.card` are never
 * redefined globally. Colors are the mockup's literal hex, commented with its var name.
 */

/* The shared layout wraps every page in a white, padded .site-contents panel, which
 * would merge this page's own cards into that outer panel. Neutralize it and give
 * .main-content a grey ground instead, scoped via the bare controller-name body class
 * rather than `.formularies-index`, which would leave the show page in the panel. */
body.formularies .main-content,
body.sources .main-content,
body.runs .main-content {
  background-color: #f2f3f6; /* --bg */
}

/* `.main-content` is in the selector purely for specificity: application.css's
 * body > .main-content > .site-contents scores the same as a bare
 * `body.formularies .site-contents` and loads after this file, so the tie would
 * go to the white panel. Naming .main-content breaks the tie. */
body.formularies .main-content .site-contents,
body.sources .main-content .site-contents,
body.runs .main-content .site-contents {
  background-color: transparent;
  padding: 0;
  border-radius: 0;
  /* The table card owns horizontal scrolling; overflow:auto here doubled the scrollbar. */
  overflow-x: hidden;
}

.formulary-index select.formulary-select {
  appearance: none;
  font-size: 12px;
  font-weight: 600;
  color: #1c2130; /* --ink */
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7183' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  border: 1px solid #cfd3de;
  border-radius: 8px;
  padding: 6px 28px 6px 13px;
}

/* One rule for text + date inputs, matching the segmented buttons' weight.
 *
 * Date inputs share the text input's ink colour, which also colours their empty
 * mm/dd/yyyy hint -- accepted deliberately. That hint lives in the webkit shadow DOM
 * with no "is empty" selector, so the only alternative is muting the whole control,
 * which mutes a CHOSEN date identically and makes an applied filter read as unset.
 * Of the two, a hint that looks slightly too solid beats a real filter that looks
 * like a placeholder. Text inputs need no such tradeoff: ::placeholder below mutes
 * only the empty state. */
.formulary-index input[type="text"].form-control,
.formulary-index input[type="date"].form-control {
  font-size: 12px;
  font-weight: 600;
  color: #1c2130; /* --ink */
  border: 1px solid #cfd3de;
  border-radius: 8px;
  padding: 6px 13px;
}

.formulary-index input[type="text"].form-control::placeholder {
  font-size: 12px;
  font-weight: 600;
  color: #6b7183; /* --muted, matching "Active only" */
  opacity: 1; /* Firefox dims placeholders by default */
}

.formulary-index select.formulary-select--year {
  min-width: 110px;
}

.formulary-index select.formulary-select--state {
  min-width: 120px;
}

.formulary-index select.formulary-select--audit {
  min-width: 150px;
}

/* ---- Table: header + body typography ---- */
.formulary-index table {
  width: 100%;
  border-collapse: collapse;
}

.formulary-index th {
  font-size: 11px;
  font-weight: 700;
  color: #8b2fa8; /* --link */
  text-align: left;
  padding: 8px 9px;
  border-bottom: 2px solid #e3e5ec; /* --line */
  white-space: nowrap;
}

.formulary-index td {
  padding: 9px;
  border-bottom: 1px solid #e3e5ec; /* --line */
  vertical-align: middle;
  font-size: 12.3px;
}

/* ---- Page title (scoped -- do not restyle h1 globally) ---- */
.formulary-index h1 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}

/* :not(.btn) excludes the segmented-control toggle labels, restyled separately below. */
.formulary-index .form-label,
.formulary-index label:not(.btn) {
  font-size: 11px;
  font-weight: 700;
  color: #1c2130; /* --ink */
}

/* ---- Segmented control (Mapped / Active radio-as-button groups) ---- */
.formulary-index .btn-group[role="group"] {
  display: inline-flex;
  border: 1px solid #cfd3de;
  border-radius: 8px;
  overflow: hidden;
}

.formulary-index .btn-group[role="group"] .btn-outline-secondary {
  font-size: 12px;
  font-weight: 600;
  color: #6b7183; /* --muted */
  background: #fff;
  border: none;
  border-left: 1px solid #e3e5ec; /* --line */
  border-radius: 0;
  padding: 6px 13px;
}

.formulary-index .btn-group[role="group"] .btn-outline-secondary:first-of-type {
  border-left: none;
}

.formulary-index .btn-check:checked + .btn-outline-secondary {
  background: #7d219c; /* --purple */
  color: #fff;
  font-weight: 700;
}

/* ---- Search submit button ---- */
.formulary-index .btn-primary {
  font-size: 12.5px;
  font-weight: 700;
  background: #7d219c; /* --purple */
  border-color: #7d219c; /* --purple */
  border-radius: 7px;
  padding: 8px 16px;
}

.formulary-index .btn-primary:hover {
  background: #651b7e; /* --purple-dk */
  border-color: #651b7e; /* --purple-dk */
}

/* ---- Muted count text ("27 plans") ---- */
.formulary-mini {
  font-size: 10.5px;
  color: #6b7183; /* --muted */
}

/* See FormularyDecorator for which state maps to which modifier. */
.formulary-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  border-radius: 5px;
  padding: 2px 7px;
  letter-spacing: .02em;
  white-space: nowrap;
}

.formulary-badge--ok {
  background: #e2f4e8; /* --ok-bg */
  color: #1c7c40; /* --ok */
}

.formulary-badge--bad {
  background: #fbe3e6; /* --bad-bg */
  color: #a41e34; /* --bad */
}

.formulary-badge--muted {
  background: #eceef3; /* mockup literal, not a root var (.badge.no / .badge.audnone) */
  color: #6b7183;
}

.formulary-badge--direct {
  background: #f3e6fb; /* --direct-bg */
  color: #7d219c; /* --direct-ink */
}

.formulary-badge--cms {
  background: #e3edff; /* mockup .badge.cms */
  color: #2456c4;
}

.formulary-badge--mmit {
  background: #eef0f5; /* --mmit */
  color: #4a5164; /* --mmit-ink */
}

/* Inert until PD-29426 ships Formulary Detail. */
.formulary-btn {
  font-size: 12.5px;
  font-weight: 700;
  background: #7d219c; /* --purple */
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}

.formulary-btn:hover {
  background: #651b7e; /* --purple-dk */
}

.formulary-btn--sm {
  padding: 5px 11px;
  font-size: 11.5px;
}

.formulary-btn--ghost {
  background: #fff;
  color: #7d219c; /* --purple */
  border: 1.5px solid #7d219c; /* --purple */
}

.formulary-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Link-styled buttons and names: three classes outrank the layout's
 * `body .main-content .site-contents a` (purple, normal weight), which two would not. */
.main-content .formulary-index a.formulary-btn {
  color: #fff;
  text-decoration: none;
}

.main-content .formulary-index a.formulary-btn--ghost {
  color: #7d219c; /* --purple */
}

/* Mockup `a.plink`: names and in-row actions, on an <a> or a <button>. */
.main-content .formulary-index .formulary-plink {
  color: #8b2fa8; /* --link */
  font-weight: 600;
  text-decoration: none;
  font-size: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.main-content .formulary-index .formulary-plink:hover {
  text-decoration: underline;
}

/* ---- Formulary detail: the design's literal values, annotated with its own var
 * names, exactly like the index palette above. ---- */

.formulary-index .sub {
  color: #6b7183; /* --muted */
  font-size: 12px;
  margin-bottom: 14px;
}

/* application.css sets a bare `h3 { font-size: 18px; font-weight: bold; }` --
 * this scoped selector is more specific (0,1,1 beats 0,0,1) so it wins regardless
 * of stylesheet load order, unlike the .main-content tie above. */
.formulary-index h3 {
  font-size: 13.5px;
  font-weight: 800;
  margin-bottom: 10px;
}

/* Card header row -- Plan mapping summary's badge and Drugs & coverage's panel
 * toggle both sit inline with their h3, not stacked below it. */
.formulary-index .cardhead {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.formulary-index .cardhead h3 {
  margin-bottom: 0;
}

/* ---- Metadata strip: seven fields, one wrapping row. ---- */
.formulary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 34px;
  font-size: 12.5px;
}

.formulary-meta-field {
  display: flex;
  flex-direction: column;
}

.formulary-meta-label {
  display: block;
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6b7183; /* --muted */
  margin-bottom: 3px;
}

.formulary-note {
  font-size: 12.5px;
  color: #6b7183; /* --muted */
  padding: 12px 0;
}

/* Plan-mapping table section head. The `+div` rule rounds the table wrapper's bottom
 * corners and clips its top ones so head and table read as one block -- which relies
 * on the view rendering `.table-responsive` as `.secthead`'s immediate next sibling. */
.formulary-index .secthead {
  background: #f7f2fa; /* mockup literal, no root var name given */
  border: 1px solid #e3e5ec; /* --line */
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 12px;
  font-weight: 800;
  font-size: 12px;
  color: #7d219c; /* --purple */
  margin-top: 14px;
}

.formulary-index .secthead + div {
  border: 1px solid #e3e5ec; /* --line */
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}

/* The Overrides panel's empty state is centred and padded, unlike the other panels'
 * left-aligned notes above. */
.formulary-empty-state {
  padding: 26px 10px;
  text-align: center;
  color: #6b7183; /* --muted */
  font-size: 12.5px;
}

.formulary-warning {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #a41e34; /* --bad, matches .formulary-badge--bad */
  background: #fbe3e6; /* --bad-bg */
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 12px;
}

/* Coverage Tier's Not Listed state -- see FormularyDrugDecorator::BADGE_WARN. */
.formulary-badge--warn {
  background: #fdf1d6; /* --warn-bg */
  color: #8a6d00; /* --warn */
}

/* The grey `source: {value}` annotation beside an overridden effective value. */
.formulary-source {
  display: inline-block;
  font-size: 10px;
  color: #9aa1b5;
  margin-left: 5px;
  white-space: nowrap;
}

/* med_id column -- tabular figures. */
.formulary-num {
  font-variant-numeric: tabular-nums;
}

/* The three boolean columns (4-6 of med_id, Drug, Coverage Tier, PA, ST, QL). */
.formulary-drug-table th:nth-child(n+4),
.formulary-drug-table td:nth-child(n+4) {
  text-align: center;
}

/* Bootstrap's .form-control is width:100%, which stretched this across the whole card
 * and pinned the Search button to the far right; flex:0 1 auto stops it re-growing. */
.formulary-index .formulary-search-input {
  width: auto;
  min-width: 260px;
  flex: 0 1 auto;
}

/* One <table> per section, so without a fixed layout each sizes its columns from its
 * OWN content and stacked sections fail to line up (all-em-dash Issuer ID / Plan Type
 * columns render narrower than ones carrying "70893" / "EPO"). Percentages sum to 100;
 * Carrier takes the slack, its values being the longest here. */
.formulary-index .formulary-plan-mapping-table {
  table-layout: fixed;
  width: 100%;
}

.formulary-index .formulary-plan-mapping-table th:nth-child(1),
.formulary-index .formulary-plan-mapping-table th:nth-child(2) {
  width: 8%;
}

.formulary-index .formulary-plan-mapping-table th:nth-child(3) {
  width: 28%;
}

.formulary-index .formulary-plan-mapping-table th:nth-child(4),
.formulary-index .formulary-plan-mapping-table th:nth-child(5),
.formulary-index .formulary-plan-mapping-table th:nth-child(6) {
  width: 13%;
}

.formulary-index .formulary-plan-mapping-table th:nth-child(7) {
  width: 17%;
}

/* ---- Sources index (PD-31323) ---- */

/* One baseline: every field is a label over a control, bottom-aligned; labels never wrap. */
.formulary-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}

.formulary-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* Mockup .tblhead controls: right-aligned in the title row, wrapping on narrow widths. */
.formulary-filters--inline {
  margin-left: auto;
  align-items: center;
  gap: 10px;
}

.formulary-filters--inline .formulary-select {
  width: auto;
}

.formulary-filters--inline .formulary-search-input,
.formulary-filters--inline .formulary-select {
  max-width: 100%;
}

.formulary-filters--inline .btn-group {
  flex-wrap: wrap;
}

/* Label-less, so align the link with the control centres, not their bottoms. */
.formulary-field--reset {
  padding-bottom: 6px;
}

.formulary-field .form-label,
.formulary-field label:not(.btn) {
  height: 14px;
  line-height: 14px;
  margin: 0;
  white-space: nowrap;
}

.formulary-badge--never {
  background: #eef0f5; /* mockup .badge.none */
  color: #8a8fa0;
}

/* Mockup table card: tighter padding than the filter card. */
.formulary-import-card.formulary-import-card--table {
  padding: 8px 10px;
}

/* New / Edit source form: mockup .card > h3, then bordered .fsec groups with an .fhead. */
.formulary-index .formulary-form-title {
  font-size: 13.5px;
  font-weight: 800;
  margin-bottom: 12px;
}

.formulary-form-section {
  border: 1px solid #e3e5ec; /* --line */
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.formulary-index .formulary-form-section-head {
  font-size: 10.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #6b7183; /* --muted */
  margin-bottom: 12px;
}

.formulary-form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

/* Mockup .tblhead: a table card's title row, with a muted .stat note beside the title. */
.formulary-table-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 12px 8px 10px;
}

.formulary-index .formulary-table-head .formulary-form-title {
  margin: 0;
}

.formulary-table-head .formulary-table-search {
  margin-left: auto;
  width: 220px;
  flex: 0 1 auto;
}

/* Mockup .pager: a right-aligned muted "1-N of N" line under a table. */
.formulary-pager {
  text-align: right;
  font-size: 12px;
  color: #6b7183; /* --muted */
  padding: 6px 8px;
}

.formulary-index h1 .formulary-badge {
  vertical-align: 5px;
}

.formulary-table-head .formulary-stat--end {
  margin-left: auto;
}

/* Fixed columns so the matched row's colspan note can't crowd the next column's heading. */
.formulary-recon {
  table-layout: fixed;
}

.formulary-recon__label {
  width: 20%;
}

.formulary-index .formulary-recon th,
.formulary-index .formulary-recon td {
  padding-right: 24px;
}

/* ---- Run header (mockup .h1sub, .scope, .ipill), shared by every run step ---- */
.formulary-index .formulary-h1sub {
  font-size: 12px;
  color: #6b7183; /* --muted */
  margin: 2px 0 10px;
}

.formulary-scope {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

.formulary-scope__k {
  color: #6b7183; /* --muted */
  font-weight: 600;
}

.formulary-scope__sep {
  color: #c2c6d2;
}

.formulary-ipill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid #d9dce6;
  border-radius: 6px;
  padding: 2px 7px;
  background: #fff;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.formulary-ipill__s {
  color: #6b7183; /* --muted */
  font-weight: 600;
}

/* ---- Run step rail (mockup .rail) ---- */
.formulary-rail {
  display: flex;
  list-style: none;
  padding: 0;
  background: #fff;
  border: 1px solid #e3e5ec; /* --line */
  border-radius: 10px;
  overflow: hidden;
  margin: 0 0 16px;
}

.formulary-rail__item {
  display: flex;
  flex: 1;
  min-width: 0;
  border-left: 1px solid #e3e5ec; /* --line */
}

.formulary-rail__item:first-child {
  border-left: none;
}

/* Three classes beat the global `body .main-content .site-contents a` rule on the done-step links. */
.main-content .formulary-rail .formulary-rail__step {
  flex: 1;
  display: block;
  position: relative;
  min-width: 0;
  padding: 11px 15px;
  color: #1c2130; /* --ink */
  text-decoration: none;
}

.formulary-rail__n {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6b7183; /* --muted */
  margin-bottom: 3px;
}

.formulary-rail__t {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-content .formulary-rail .formulary-rail__step--done {
  background: #f7fbf8;
}

/* The global `a:hover` outranks the rule above; keep the title ink on hover. */
.main-content .formulary-rail a.formulary-rail__step--done:hover {
  color: #1c2130; /* --ink */
  background: #eef7f1;
}

.formulary-rail__step--done .formulary-rail__n {
  color: #1c7c40; /* --ok */
}

.formulary-rail__step--cur {
  background: #f7f2fa;
}

.formulary-rail__step--cur .formulary-rail__n {
  color: #7d219c; /* --purple */
}

.formulary-rail__step--cur::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: #7d219c; /* --purple */
}

.formulary-rail__step--todo {
  opacity: 0.5;
}

@media (max-width: 1050px) {
  .formulary-rail {
    flex-wrap: wrap;
  }

  .formulary-rail__item {
    min-width: 33%;
  }
}

.formulary-isum {
  white-space: nowrap;
  font-size: 12px;
}

.formulary-isum b {
  font-variant-numeric: tabular-nums;
}

.formulary-stat {
  font-size: 12px;
  color: #6b7183; /* --muted */
}

.formulary-count {
  font-weight: 600;
  color: #6b7183; /* --muted */
  margin-left: 6px;
}

.formulary-index select.formulary-issuer-select {
  max-width: 420px;
}

/* Step 3: tier mapping table. Colors are the step-2 literals. */
.formulary-tier-select {
  min-width: 120px;
}

/* One line per cell: .form-select is width 100%, which pushed the Split form onto a second line. */
.formulary-tier-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.formulary-tier-cell .formulary-tier-select {
  width: auto;
}

.formulary-tier-values {
  font-size: 10.5px;
  color: #6b7183; /* --muted */
}

.formulary-tier-subrow > td:first-child {
  padding-left: 28px;
}

.formulary-tier-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.formulary-tier-notice {
  font-size: 12.5px;
  padding: 8px 12px;
  margin: 8px 0;
  border-radius: 7px;
  background: #e2f4e8; /* --ok-bg */
  color: #1c7c40; /* --ok */
}

.formulary-tier-notice--alert {
  background: #fbe3e6; /* --bad-bg */
  color: #a41e34; /* --bad */
}

/* Step 3: formulary recognition notes. Colors follow the existing formulary palette (ADR 0011). */
.formulary-note-row {
  font-size: 12.5px;
  color: #6b7183; /* --muted */
}

.formulary-compare {
  font-size: 12.5px;
  padding: 6px 4px;
}

.formulary-compare h4 {
  font-size: 12.5px;
  font-weight: 800;
  margin: 8px 0 2px;
}

.formulary-compare ul {
  margin: 0;
  padding-left: 18px;
}

/* Stale warning on the source card: runs listed inline, one size. */
.formulary-reresolve-stale {
  margin: 0;
  font-size: 12.5px;
}

.formulary-reresolve-behind {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  font-size: 12.5px;
}

body .main-content .formulary-reresolve-stale .formulary-reresolve-behind a {
  font-size: inherit;
}

/* Step 3 formulary cards (PD-32088) */
.formulary-card {
  margin-top: 16px;
}

.formulary-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
}

.formulary-card-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin: 8px 0;
}

.formulary-card-facts dt {
  font-size: 11px;
  text-transform: uppercase;
}

.formulary-card-facts dd {
  margin: 0;
}

.formulary-card-form {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.formulary-plan-list ul {
  margin: 8px 0 0;
  padding-left: 20px;
}
