/* Stimulation calendar, design A′: one Monday–Sunday week of lanes × days.
   Cell content sits directly in the grid; the cell itself carries the state fill. */
.stim-calendar { --stim-cal-label: 220px; --stim-cal-trigger-wash: #fffbf2; --stim-cal-inset: #f5f3ee; --stim-cal-today: #edeffc; --stim-cal-today-line: #d3d8f3; margin-top: 40px; font-family: var(--font-sans); color: var(--ink); }
.stim-calendar-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.stim-calendar-heading h2 { margin: 0; font: 700 1.0625rem/1.5 var(--font-sans); }
.stim-calendar .cycle-switcher { margin-bottom: 16px; }

.stim-calendar-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 24px; margin-bottom: 12px; }
.stim-calendar-nav { display: flex; align-items: center; gap: 8px; }
.stim-calendar-step { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); }
.stim-calendar-step svg { width: 18px; height: 18px; }
.stim-calendar-step:hover { border-color: #56619a; color: #56619a; }
.stim-calendar-step.is-disabled { color: #b7b0a4; background: transparent; }
.stim-calendar-range { min-width: 150px; margin: 0; text-align: center; font-size: 1rem; font-weight: 700; white-space: nowrap; }
.stim-calendar-today { display: inline-flex; align-items: center; min-height: 44px; margin-left: 8px; padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: .875rem; font-weight: 700; text-decoration: none; }
.stim-calendar-today:hover { border-color: #56619a; }
.stim-calendar-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 0; padding: 0; list-style: none; font-size: .75rem; color: var(--muted); }
.stim-calendar-legend li { display: inline-flex; align-items: center; gap: 6px; }
.stim-calendar-swatch { display: inline-grid; place-items: center; width: 18px; height: 14px; border-radius: 4px; border: 1px solid transparent; }
.stim-calendar-swatch svg { width: 11px; height: 11px; }
.stim-calendar-swatch.is-recorded { background: var(--success-soft); border-color: #cfe3da; color: var(--success); }
.stim-calendar-swatch.is-trigger { background: var(--warning-soft); border-color: var(--warning-border); }
.stim-calendar-swatch.is-today { background: var(--stim-cal-today); border-color: var(--stim-cal-today-line); }

.stim-calendar-scroll { overflow-x: auto; overscroll-behavior-x: contain; }
.stim-calendar-week { width: 100%; min-width: 820px; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: .8125rem; }
.stim-calendar-week th, .stim-calendar-week td { padding: 0; vertical-align: top; border-bottom: 1px solid var(--line); text-align: left; }
.stim-calendar-week td + td, .stim-calendar-week th + td, .stim-calendar-week td + th, .stim-calendar-week th + th { border-left: 1px solid var(--line); }
.stim-calendar-week thead th, .stim-calendar-corner { padding: 12px 8px 10px; border-bottom: 1px solid var(--line-strong); font-weight: 400; }
.stim-calendar-corner { width: var(--stim-cal-label); }
.stim-calendar-week thead time { display: grid; gap: 1px; }
.stim-calendar-weekday { font-size: .75rem; color: var(--muted); }
.stim-calendar-week thead strong { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stim-calendar-week thead strong small { font-size: .75rem; font-weight: 600; }
.stim-calendar-week thead th.is-today { box-shadow: inset 0 3px 0 #56619a; }
.stim-calendar-today-pill { justify-self: start; display: inline-block; padding: 4px 6px; border-radius: 999px; background: #56619a; color: #fff; font-size: .625rem; font-weight: 700; line-height: 1; text-transform: uppercase; text-box: trim-both cap alphabetic; }
.stim-calendar-week .is-today { background: var(--stim-cal-today); }
.stim-calendar-week td.is-today, .stim-calendar-week th.is-today, .stim-calendar-week .is-today + td { border-left-color: var(--stim-cal-today-line); }

.stim-calendar-week tbody th { width: var(--stim-cal-label); padding: 12px 12px 12px 8px; font-weight: 400; }
.stim-calendar-week tbody th { display: table-cell; }
.stim-calendar-week tbody th > * { vertical-align: top; }
.stim-calendar-lane th, .stim-calendar-group th { white-space: normal; }
.stim-calendar-lane th .fertility-illustration, .stim-calendar-group th .fertility-illustration { float: left; width: 24px; height: 24px; margin: 0 10px 0 0; }
.stim-calendar-lane-text { display: grid; gap: 2px; overflow: hidden; }
.stim-calendar-lane-text strong { font-size: .875rem; font-weight: 700; }
.stim-calendar-lane-text small { font-size: .75rem; color: var(--muted); }
.stim-calendar-lane.is-medication th { padding-left: 42px; }
.stim-calendar-group th { padding: 10px 8px; font-weight: 700; font-size: .875rem; }
.stim-calendar-group th span { line-height: 24px; }
.stim-calendar-tag { display: inline-block; margin-left: 4px; padding: 3px 7px; border: 1px solid var(--warning-border); border-radius: 999px; background: var(--warning-soft); color: var(--warning-ink); font-size: .6875rem; font-weight: 700; line-height: 1; vertical-align: 1px; text-box: trim-both cap alphabetic; }
.stim-calendar-lane.is-trigger > th, .stim-calendar-lane.is-trigger > td:not(.is-today) { background: var(--stim-cal-trigger-wash); }
.stim-calendar-lane.is-trigger > th, .stim-calendar-lane.is-trigger > td { border-top: 1px solid var(--line-strong); border-bottom-color: var(--line-strong); }

/* The cell carries the state; scheduled and "Sin registro" stay unfilled so the
   today column shows through them. */
.stim-calendar-week td.is-recorded { background: var(--success-soft); }
.stim-calendar-week td.is-pending { background: var(--stim-cal-inset); }
.stim-calendar-week .stim-calendar-lane td.is-trigger { background: var(--warning-soft); }
.stim-calendar-week tbody td { padding: 8px; vertical-align: middle; text-align: center; }

.stim-calendar-entry { display: grid; justify-items: center; align-content: center; gap: 1px; width: 100%; min-height: 44px; padding: 2px 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: center; text-decoration: none; line-height: 1.3; }
.stim-calendar-entry + .stim-calendar-entry { margin-top: 6px; }
.stim-calendar-entry small { font-size: .75rem; color: var(--muted); }
.stim-calendar-entry-title { display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-weight: 700; }
.stim-calendar-entry svg { width: 13px; height: 13px; flex: none; }
a.stim-calendar-entry:hover .stim-calendar-entry-title, button.stim-calendar-entry:hover .stim-calendar-trigger-time, a.stim-calendar-entry-title:hover { text-decoration: underline; text-underline-offset: 3px; }
.stim-calendar-dose.is-recorded { color: #2f5f4e; }
.stim-calendar-dose.is-recorded small { color: #2f5f4e; }
.stim-calendar-dose.is-unrecorded .stim-calendar-entry-title { font-weight: 600; color: #5e6478; }
.stim-calendar-week td.is-recorded .stim-calendar-entry small { color: #2f5f4e; }
.stim-calendar-trigger { color: var(--warning-ink); cursor: pointer; }
span.stim-calendar-trigger { cursor: default; }
.stim-calendar-trigger-time { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stim-calendar-trigger .stim-calendar-entry-title { font-size: .75rem; font-weight: 600; }
.stim-calendar-trigger-state { justify-content: center; display: inline-flex; align-items: center; gap: 2px; color: #7a5513; font-size: .75rem; font-weight: 700; }
.stim-calendar-state { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600; color: #2f5f4e; text-decoration: none; }
.stim-calendar-state:hover { text-decoration: underline; text-underline-offset: 3px; }
.stim-calendar-entry form { margin: 2px 0 0; }
.stim-calendar-action { display: inline-flex; align-items: center; gap: 2px; min-height: 32px; padding: 0; border: 0; background: transparent; color: #56619a; font: 700 .75rem/1.3 var(--font-sans); text-align: center; cursor: pointer; }
.stim-calendar-action:hover { text-decoration: underline; text-underline-offset: 3px; }

.stim-calendar-hidden { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 24px; padding: 12px 12px; border-bottom: 1px solid var(--line); font-size: .8125rem; color: var(--muted); }
.stim-calendar-hidden ul { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0; padding: 0; list-style: none; }
.stim-calendar-hidden a { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; color: var(--muted); text-decoration: none; }
.stim-calendar-hidden a strong { color: var(--ink); }
.stim-calendar-hidden a:hover { text-decoration: underline; text-underline-offset: 3px; }
.stim-calendar-hidden svg { width: 14px; height: 14px; color: #56619a; }
.stim-calendar-empty { margin: 12px 0; color: var(--muted); }

@media (max-width: 1100px) { .stim-calendar { --stim-cal-label: 180px; } }

/* Edit mode: editable courses, doses and the trigger open one anchored editor. */
.stim-calendar-edit-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.stim-calendar-edit-actions form { margin: 0; }
.stim-calendar-full-editor { margin-right: 6px; color: #56619a; font-size: .8125rem; font-weight: 700; text-underline-offset: 3px; }
button.stim-calendar-lane-text { width: 100%; padding: 4px 6px; margin: -4px -6px; border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.stim-calendar-edit-hint { color: #56619a; font-size: .75rem; font-weight: 700; }
button.stim-calendar-lane-text:hover, button.stim-calendar-lane-text[aria-expanded="true"],
button.stim-calendar-dose[aria-expanded="true"], button.stim-calendar-trigger[aria-expanded="true"] { background: var(--lilac-soft, #edeffc); }
button.stim-calendar-dose { cursor: pointer; border-radius: 6px; padding: 2px 4px; margin: 0 -4px; width: calc(100% + 8px); }
button.stim-calendar-dose:hover .stim-calendar-entry-title { text-decoration: underline; text-underline-offset: 3px; }

.stim-editor { position: fixed; inset: 0; margin: auto; width: min(440px, calc(100vw - 32px)); height: fit-content; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 22px 24px 18px; border: 1px solid var(--line-strong); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 54px rgba(30, 36, 66, .10); }
.stim-editor::backdrop { background: rgb(30 36 66 / .35); }
.stim-editor[open] { animation: stim-editor-in 200ms cubic-bezier(.16, 1, .3, 1); }
@keyframes stim-editor-in { from { opacity: 0; transform: translateY(4px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .stim-editor[open] { animation: none; } }
.stim-editor-form { display: grid; gap: 14px; }
.stim-editor header h3 { margin: 0; font: 700 1rem/1.4 var(--font-sans); }
.stim-editor header p { margin: 2px 0 0; color: var(--muted); font-size: .8125rem; }
.stim-editor .field { display: grid; gap: 4px; margin: 0; min-width: 0; }
.stim-editor .field input { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; }
.stim-editor .field-error { min-height: 1.2em; font-size: .75rem; }
.stim-editor-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.stim-editor-pair[hidden] { display: none; }
.stim-editor-pair-error, .stim-editor-note { grid-column: 1 / -1; }
.stim-editor-note { margin: 0; color: var(--muted); font-size: .75rem; }
.stim-editor footer { display: flex; justify-content: flex-end; gap: 10px; }

/* Add and remove from the popover. */
#stim-add-item { display: inline-flex; align-items: center; gap: 6px; }
#stim-add-item svg { width: 16px; height: 16px; }
.stim-editor [hidden] { display: none !important; }
.stim-editor .field select { width: 100%; min-width: 0; }
.stim-editor footer { flex-wrap: wrap; }
.stim-editor-remove { margin-right: auto; }
#stim-editor-error-base:empty { display: none; }

/* Cell add buttons: every row a doctor can add to, on today and later days. */
.stim-calendar-lane.is-new_medication th { padding-left: 42px; }
.stim-calendar-lane.is-new_medication .stim-calendar-lane-text strong { color: var(--muted); font-weight: 600; }
.stim-calendar-lane th > svg { float: left; width: 22px; height: 22px; margin: 1px 11px 0 1px; color: #56619a; }
.stim-calendar-add { display: grid; place-items: center; width: 100%; min-height: 44px; padding: 0; border: 1px dashed transparent; border-radius: 8px; background: transparent; color: #b7b0a4; cursor: pointer; transition: border-color 160ms ease-out, color 160ms ease-out, background-color 160ms ease-out; }
.stim-calendar-add svg { width: 16px; height: 16px; }
.stim-calendar-week td:hover > .stim-calendar-add, .stim-calendar-add:focus-visible, .stim-calendar-add[aria-expanded="true"] { border-color: #56619a; color: #56619a; background: rgb(255 255 255 / .6); }
.stim-calendar-add.is-compact { min-height: 32px; margin-top: 4px; }
@media (prefers-reduced-motion: reduce) { .stim-calendar-add { transition: none; } }
.stim-calendar-quick-add { margin: 0; }
/* A day with a planned ultrasound suggests booking its appointment. */
.stim-calendar-add.is-suggested { display: inline-flex; gap: 4px; border-color: #c3c9ec; background: var(--lilac-soft, #edeffc); color: #56619a; font: 700 .75rem/1 var(--font-sans); }
.stim-calendar-add.is-suggested:hover, .stim-calendar-add.is-suggested:focus-visible { border-color: #56619a; background: #e1e5f8; }
/* Medication row actions in edit mode: edit the course, or remove what remains. */
.stim-calendar-lane-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; margin-top: 4px; }
.stim-calendar-lane-action { min-height: 32px; padding: 0; border: 0; background: transparent; color: #56619a; font: 700 .75rem/1.3 var(--font-sans); text-align: left; cursor: pointer; }
.stim-calendar-lane-action:hover { text-decoration: underline; text-underline-offset: 3px; }
.stim-calendar-lane-action[aria-expanded="true"] { text-decoration: underline; }
.stim-calendar-lane-action.is-danger { color: var(--danger-ink, #9a3434); }

/* Dialog type and rhythm: one control size, one label size, one gap between fields. */
.stim-editor-form { gap: 16px; }
.stim-editor .stim-editor-medication { display: grid; gap: 16px; }
.stim-editor .stim-editor-medication[hidden] { display: none; }
.stim-editor .stim-editor-pair { gap: 16px 12px; }
.stim-editor .field { gap: 6px; }
.stim-editor .field > label { font: 700 .8125rem/1.3 var(--font-sans); color: var(--ink); }
.stim-editor .field :is(input, select) { min-height: 44px; padding: 0 .75rem; border-radius: 10px; font: 400 .9375rem/1.4 var(--font-sans); }
.stim-editor .field-error { min-height: 0; margin: 0; font-size: .75rem; line-height: 1.35; }
/* An empty message keeps its live region but takes no row. */
.stim-editor .field-error:empty { position: absolute; }
.stim-editor footer { margin-top: 4px; }
.stim-editor footer .button { min-height: 44px; padding: 0 1rem; font: 700 .9375rem/1 var(--font-sans); }
/* Catalog choice: the package reads as a caption, manual entry as a quiet link. */
.stim-editor .medication-search-details:not(:empty) { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.stim-editor .medication-package-name { color: var(--muted); font: 400 .8125rem/1.4 var(--font-sans); }
.stim-editor .medication-search-details .button { min-height: 32px; padding: 0; border: 0; background: transparent; color: #56619a; font: 700 .8125rem/1.3 var(--font-sans); }
.stim-editor .medication-search-details .button:hover { text-decoration: underline; text-underline-offset: 3px; }
.stim-editor .medication-search-details label { display: grid; gap: 6px; width: 100%; font: 700 .8125rem/1.3 var(--font-sans); }
.stim-editor .medication-search-status { font-size: .8125rem; }
.stim-editor .medication-search-anchor:has(.medication-search-clear:not([hidden])) > input { padding-inline-end: 2.75rem; text-overflow: ellipsis; }
/* A planned visit waiting for its booking reads like the booking suggestion. */
.stim-calendar-entry.is-suggested { border: 1px dashed #c3c9ec; border-radius: 8px; background: var(--lilac-soft, #edeffc); }
.stim-calendar-entry.is-suggested small { color: #56619a; font-weight: 700; }

/* Entry chips (design C): every entry is a rounded chip tinted by its row's
   kind. Cells stay unfilled so the today column shows through; green and a
   check appear only on recorded evidence. */
.stim-calendar {
  --chip-med: #edeffc; --chip-med-ink: #394777;
  --chip-lab: #fdede6; --chip-lab-ink: #8a3a1d;
  --chip-us: #e6ecf7; --chip-us-ink: #394777;
  --chip-visit: #f5f3ee; --chip-visit-ink: #4a4f63;
  --chip-icon-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.3 5 8.6l4.6-5' fill='none' stroke='%2339745F' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
/* Chips need about 104px per day; narrower frames scroll the week sideways. */
.stim-calendar-week { min-width: calc(var(--stim-cal-label) + 7 * 104px); }
.stim-calendar-week tbody td { padding: 4px; text-align: left; }
.stim-calendar-week td.is-recorded:not(.is-today), .stim-calendar-week td.is-pending:not(.is-today),
.stim-calendar-week .stim-calendar-lane td.is-trigger:not(.is-today), .stim-calendar-lane.is-trigger > td:not(.is-today) { background: transparent; }

/* The icon leads the chip's first line like a word, so narrow day columns wrap
   naturally; times and doses never split, and only an over-long word breaks. */
.stim-calendar-week .stim-calendar-entry { display: block; width: 100%; min-height: 40px; margin: 0; padding: 6px; border: 0; border-radius: 10px;
  background: var(--chip-bg, var(--chip-visit)); color: var(--chip-ink, var(--chip-visit-ink)); text-align: left; line-height: 1.3; hyphens: auto; overflow-wrap: anywhere; }
.stim-calendar-week .stim-calendar-entry > :is(span, small, a, form) { display: block; }
/* Only recorded evidence carries a mark: the check leads the chip's first line. */
:is(.stim-calendar-week td.is-recorded .stim-calendar-entry, .stim-calendar-week .stim-calendar-dose.is-recorded) > :first-child::before { content: ""; display: inline-block; width: 16px; height: 16px; margin-right: 5px; border-radius: 5px; vertical-align: -3px;
  background: rgb(255 255 255 / .8) var(--chip-icon-check) center / 12px no-repeat; }
.stim-calendar-week :is(.stim-calendar-dose .stim-calendar-entry-title, .stim-calendar-trigger-time, .stim-calendar-entry > a:first-child) { white-space: nowrap; }
.stim-calendar-week .stim-calendar-entry + .stim-calendar-entry { margin-top: 4px; }
.stim-calendar-week .stim-calendar-entry-title { font-size: .8125rem; }
.stim-calendar-week .stim-calendar-entry-title > svg { display: none; }
.stim-calendar-week .stim-calendar-entry small { color: inherit; opacity: .85; font-size: .6875rem; line-height: 1.25; }
.stim-calendar-week .stim-calendar-entry > .stim-calendar-trigger-state { display: flex; justify-content: flex-start; font-size: .6875rem; white-space: nowrap; overflow-wrap: normal; }
.stim-calendar-week .stim-calendar-trigger .stim-calendar-entry-title { font-size: .75rem; font-weight: 600; }

.stim-calendar-lane.is-medication { --chip-bg: var(--chip-med); --chip-ink: var(--chip-med-ink); }
.stim-calendar-lane.is-trigger { --chip-bg: var(--warning-soft); --chip-ink: #4d3817; }
.stim-calendar-lane.is-trigger .stim-calendar-entry { box-shadow: inset 0 0 0 1px var(--warning-border); }
.stim-calendar-lane[data-lane="studies"] { --chip-bg: var(--chip-lab); --chip-ink: var(--chip-lab-ink); }
.stim-calendar-lane[data-lane="ultrasounds"] { --chip-bg: var(--chip-us); --chip-ink: var(--chip-us-ink); }

/* Recorded evidence is green; a past dose without a check-off is outlined, not filled. */
.stim-calendar-week td.is-recorded .stim-calendar-entry, .stim-calendar-week .stim-calendar-dose.is-recorded { background: var(--success-soft); color: #2f5f4e; box-shadow: none; }
.stim-calendar-week .stim-calendar-dose.is-unrecorded { background: var(--surface, #fff); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line-strong, #ddd8cf); }
.stim-calendar-week .stim-calendar-entry.is-suggested { background: var(--lilac-soft, #edeffc); color: #56619a; box-shadow: inset 0 0 0 1px #c3c9ec; }

.stim-calendar-week button.stim-calendar-entry { cursor: pointer; font: inherit; }
.stim-calendar-week button.stim-calendar-entry:hover { box-shadow: inset 0 0 0 1px rgb(30 36 66 / .28); }
.stim-calendar-week button.stim-calendar-entry[aria-expanded="true"] { box-shadow: inset 0 0 0 2px #56619a; }
.stim-calendar-week button.stim-calendar-entry:hover .stim-calendar-entry-title { text-decoration: none; }
.stim-editor .stim-editor-hint { color: var(--muted); font-size: .75rem; line-height: 1.35; }
