/* widgets.css — form controls styled to match Streamlit / BaseWeb. */

/* ---- Field wrapper + label ---- */
.field {
  margin-bottom: 1rem;
}
.field-label {
  display: block;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 0.35rem;
  line-height: 1.4;
}
.field-label .help {
  cursor: help;
  color: var(--text-muted);
  font-size: 1rem;
  margin-left: 0.25rem;
}
.small-label {
  font-size: max(1rem, 0.85em);
  margin-bottom: 0;
}

/* ---- Selectbox (native <select> dressed as BaseWeb) ---- */
.sb {
  position: relative;
}
.sb select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  font-family: var(--font);
  font-size: max(1rem, 0.85em);
  color: var(--text);
  /* Streamlit/BaseWeb selectbox: light-grey fill, no visible border at rest */
  background: var(--secondary-bg);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.4rem 2rem 0.4rem 0.75rem;
  min-height: 2.5rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.sb select:hover {
  border-color: var(--border-strong);
}
.sb select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}
.sb::after {
  content: "";
  position: absolute;
  right: 0.85rem;
  top: 50%;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

/* ---- Form card (matches st.form: subtle bordered container wrapping the fields) ---- */
.form-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: calc(1rem - 1px) 1.25rem;
  margin-bottom: 0.5rem;
}
.form-card .cols {
  margin-bottom: 0;
}

/* ---- Radio (horizontal, BaseWeb-like) ---- */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.radio-group.vertical {
  flex-direction: column;
  gap: 0.4rem;
}
.radio-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 1rem;
  white-space: nowrap;
}
/* Vertical groups (e.g. the long FR occupation labels) wrap instead of overflowing,
   which prevents a horizontal scrollbar on the page without clipping the text. */
.radio-group.vertical .radio-option {
  white-space: normal;
  align-items: flex-start;
}
.radio-group.vertical .radio-dot {
  margin-top: 0.15rem;
}
.radio-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.radio-dot {
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--bg);
  display: inline-block;
  position: relative;
  flex: 0 0 auto;
  transition: border-color 0.15s ease;
}
.radio-option input:checked + .radio-dot {
  border-color: var(--primary);
}
.radio-option input:checked + .radio-dot::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--primary);
}
.radio-option input:focus-visible + .radio-dot {
  box-shadow: var(--shadow-focus);
}

/* ---- Slider (custom div, matches Streamlit/BaseWeb): real thumb with the value
   label as its child → always centred on the circle, fixed small gap above. ---- */
.slider {
  width: 100%;
  padding: 1.6rem 0 0.4rem; /* top room for the value label above the thumb */
}
.slider-track {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--slider-track);
  cursor: pointer;
  touch-action: none;
}
/* thumb centre travels thumbRadius(9px) .. width-9px, keeping the circle in bounds */
.slider-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--primary);
  width: calc(9px + var(--pn, 1) * (100% - 18px));
  pointer-events: none;
}
.slider-thumb {
  position: absolute;
  top: 50%;
  left: calc(9px + var(--pn, 1) * (100% - 18px));
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  transform: translate(-50%, -50%);
  cursor: grab;
}
.slider-thumb:active {
  cursor: grabbing;
}
.slider-thumb:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(238, 45, 78, 0.25);
}
/* value label: child of the thumb → perfectly centred, fixed 6px gap above the circle */
.slider-bubble {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  color: var(--primary);
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  pointer-events: none;
}
.slider-bubble.hidden {
  display: none;
}

/* ---- Buttons ---- */
.btn {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.1;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  width: 100%;
  white-space: normal;
}
.btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}
.btn-inline {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

/* ---- Checkbox ---- */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}
.checkbox input {
  width: 1.3rem;
  height: 1.3rem;
  accent-color: var(--primary);
  cursor: pointer;
}
.checkbox .checkbox-label {
  font-size: 1rem;
}

/* ---- Tabs ---- */
.tabs {
  display: block; /* wrapper: tablist on top, panels below */
}
/* the actual tab bar — spaced tabs, horizontally scrollable when too wide (Streamlit) */
.tablist {
  display: flex;
  gap: 1.75rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 0.55rem 0.15rem;
  margin-bottom: -1px;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover {
  color: var(--text);
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tabpanel {
  padding-top: 1rem;
}

/* ---- Expander (native details/summary) ---- */
.expander {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0.75rem 0;
  overflow: hidden;
}
.expander > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.6rem 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  user-select: none;
}
.expander > summary::-webkit-details-marker {
  display: none;
}
.expander > summary::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.expander[open] > summary::before {
  transform: rotate(45deg);
}
.expander .expander-body {
  padding: 0.5rem 1rem 1rem;
  border-top: 1px solid var(--border);
}

/* ---- Multiselect (red chips + dropdown list, matching Streamlit) ---- */
.multiselect {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 2rem 0.3rem 0.4rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.6rem;
}
.multiselect.open {
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}
.ms-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}
.ms-placeholder {
  color: var(--text-muted);
  font-size: 1rem;
}
/* selected chips: Streamlit primary red */
.ms-chip {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.2rem 0.15rem 0.55rem;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.ms-chip-x {
  border: none;
  background: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.2rem;
}
.ms-chip-x:hover {
  color: #fff;
}
.ms-toggle {
  position: absolute;
  right: 0.5rem;
  top: 0.55rem;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
}
.ms-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  z-index: 60;
  max-height: 16rem;
  overflow-y: auto;
  padding: 0.25rem 0;
}
.ms-option {
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  font-size: 1rem;
}
.ms-option:hover,
.ms-option:focus-visible {
  background: var(--secondary-bg);
  outline: none;
}
.ms-empty {
  padding: 0.5rem 0.9rem;
  color: var(--text-muted);
}

/* ---- Phosphor inline icons — swapped in for the leading emoji in buttons and
       info boxes (see js/components/icons.js). Icons use fill:currentColor, so
       they inherit the surrounding text colour and size with the font. ---- */
.wp-ico-wrap {
  display: inline-flex;
  align-items: center;
  flex: none;
}
.wp-ico {
  width: 1.15em;
  height: 1.15em;
  display: block;
}
.btn-has-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}
.info-box-icon {
  display: flex;
  align-items: flex-start;
  gap: 0.55em;
}
.info-box-icon .wp-ico {
  width: 1.2em;
  height: 1.2em;
  margin-top: 0.1em;
}
/* status icons carry a semantic colour; all other icons inherit the text colour */
.wp-ico-warn {
  color: #c47d12;
}
.wp-ico-err {
  color: #e62846;
}
/* caption + subhead icon rows */
.field-caption-icon {
  display: flex;
  align-items: flex-start;
  gap: 0.4em;
}
.field-caption-icon .wp-ico {
  width: 1.05em;
  height: 1.05em;
  margin-top: 0.14em;
}
.subhead-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}
/* central el() emoji->icon swap: a leading icon that flows inline before its text */
.wp-ico-inline {
  display: inline-flex;
  vertical-align: -0.15em;
  margin-right: 0.35em;
}

/* ---- Help popover (click / tap / hover) — replaces the native title tooltip ---- */
.help-tip-wrap {
  position: relative;
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.25rem;
}
.help-tip {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  line-height: 0;
  border-radius: 999px;
}
.help-tip:hover,
.help-tip[aria-expanded="true"] {
  color: var(--blue);
}
.help-tip:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.help-tip .wp-ico {
  width: 1rem;
  height: 1rem;
}
.help-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  transform: translateY(-4px);
  z-index: 200;
  width: max-content;
  max-width: 260px;
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 20px rgba(38, 39, 48, 0.16);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}
.help-tip-wrap.open .help-pop {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}
