/* Import Raleway font */
@import url('https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,400;0,800;1,400;1,800&display=swap');

/* Root variables */
:root {
  --theme-color: var(--bs-primary, #2780E3);
  --body-background-color: #f2f6f9;
  --progressbar-position: top;
  --progress-bar-height: 10px;
  --progress-color: color-mix(in srgb, var(--theme-color) 80%, transparent);
  --footer-height: calc(0.5rem * 2 + 1.5em);
  --banner-height: calc(6px * 2 + 21px);
}

/* Styles for container and wrapper */
.sd-container {
    display: inline-block;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 0.5rem;
    background-color: #f9f9f9;
    margin: 0.5rem;
}

.sd-wrapper {
    text-align: center;
    margin: 0.5rem;
}

/* Layout */
body {
  background-color: var(--body-background-color);
}

.container-fluid .content {
  max-width: 800px;
  margin: 0 auto !important;
  padding: 0 0 5px !important;
}

.container-fluid {
  padding-bottom: 7rem;
}

/* Typography */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  margin-top: 0.5rem !important;
  margin-bottom: 0.5rem !important;
}

p, .form-group, .control-label {
  margin-bottom: 0.5rem;
}

.control-label, .radio label, .checkbox label {
  font-weight: normal;
  font-size: 1.1em;
}

/* Form elements */
.form-group {
  border: 1px solid #ddd;
  border-radius: 5px;
  padding: 1rem;
  background-color: #f9f9f9;
  margin-bottom: 1rem;
}

.form-group > label.control-label {
  margin-top: 0;
  margin-bottom: 0.3rem;
}

.form-control:focus {
  border-color: var(--theme-color);
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--theme-color) 25%, transparent);
}

.question-container {
  margin-left: auto;
  margin-right: auto;
  margin-bottom: auto;
  position: relative;
}

.shiny-input-container:not(.shiny-input-container-inline) {
  width: 100%;
}

/* Hidden Asterisk */
.hidden-asterisk {
  display: none;
  color: red;
  font-size: 1.5em;
  position: absolute;
  top: 0;
  right: 0.5em;
}

/* Radio and Checkbox styling */
.radio-inline,
.checkbox-inline,
.radio label,
.checkbox label {
  padding-bottom: 0.25rem;
}

.radio label span,
.checkbox label span {
  margin-left: 0.5rem;
}

.radio-group-buttons .btn-group-container-sw,
.checkbox-group-buttons .btn-group-container-sw {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  row-gap: 5px;
}

.checkbox-group-buttons .btn-group-container-sw {
  column-gap: 5px;
}

.radio-group-buttons .btn,
.checkbox-group-buttons .btn,
.btn-group-container-sw .btn {
  border: 1px solid var(--theme-color);
  background-color: color-mix(in srgb, var(--theme-color) 10%, white);
  color: var(--theme-color);
  transition: all 0.3s ease;
  white-space: normal;
  word-wrap: break-word;
}

.radio-group-buttons .btn:hover,
.checkbox-group-buttons .btn:hover,
.btn-group-container-sw .btn:hover {
  z-index: 1;
  background-color: color-mix(in srgb, var(--theme-color) 20%, white);
}

.radio-group-buttons .btn:first-child,
.checkbox-group-buttons .btn:first-child,
.btn-group-container-sw .btn:first-child {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.radio-group-buttons .btn:last-child,
.checkbox-group-buttons .btn:last-child,
.btn-group-container-sw .btn:last-child {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  margin-right: 0;
}

.radio-group-buttons .btn.active,
.checkbox-group-buttons .btn.active,
.btn-group-container-sw .btn.active {
  background-color: color-mix(in srgb, var(--theme-color) 80%, white);
  color: white;
  z-index: 2;
}

/* Date range styling */
.shiny-date-range-input .input-group-addon {
  background: none;
  border: none;
  padding: 0 10px 0 5px;
}

/* Progress bar */
#progressbar {
  position: fixed;
  left: 0;
  right: 0;
  height: var(--progress-bar-height);
  z-index: 1000;
  background-color: #ECE8DF;
}

#progressbar.top {
  top: 0;
}

#progressbar.bottom {
  bottom: 0; /* Default position at very bottom when no footer */
}

/* When the footer exists, adjust bottom progress bar position */
:has(.footer) #progressbar.bottom {
  bottom: var(--footer-height);
}

/* When a mode banner exists, raise the bottom progress bar above it */
:has(.sd-mode-banner) #progressbar.bottom {
  bottom: var(--banner-height);
}

/* When both footer and mode banner exist, stack above both */
:has(.footer):has(.sd-mode-banner) #progressbar.bottom {
  bottom: calc(var(--footer-height) + var(--banner-height));
}

#progressbar > div {
  width: 0%;
  height: 100%;
  background-color: var(--progress-color);
  transition: width 0.4s ease;
}

/* Buttons */
.btn-primary,
.btn-primary:hover,
.btn-primary:active,
.btn-primary:focus,
.action-button {
  background-color: var(--theme-color);
  border-color: var(--theme-color);
  color: #ffffff;
}

.action-button {
  background-color: color-mix(in srgb, var(--theme-color) 70%, transparent);
  transition: background-color 0.3s ease;
}

.action-button:hover,
.action-button:focus {
  background-color: var(--theme-color);
}

/* Links */
a:hover {
  color: color-mix(in srgb, var(--theme-color) 80%, black);
}

/* Media Queries */
@media screen and (max-width: 767px) {
  .radio-group-buttons .btn-group-container-sw,
  .checkbox-group-buttons .btn-group-container-sw {
    flex-direction: column;
  }
}

/* Footer styling */
.footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.5rem 1rem;
    height: var(--footer-height);
    background-color: color-mix(in srgb, var(--body-background-color) 90%, black);
    border-top: 1px solid #eee;
    color: #666;
    z-index: 999;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
    height: 100%;
}

.footer-content.center {
    justify-content: center;
}

.footer-left {
    text-align: left;
    margin-right: auto;
}

.footer-center {
    text-align: center;
    flex: 1;
}

.footer-right {
    text-align: right;
    margin-left: auto;
}

.footer a {
    color: var(--theme-color);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
    color: color-mix(in srgb, var(--theme-color) 80%, black);
}

/* Slider styling (ionRangeSlider, used by slider and slider_numeric) */
.irs--shiny .irs-line {
    height: 6px;
    border: none;
    border-radius: 3px;
    background: #e3e6ea;
    top: 27px;
}

.irs--shiny .irs-bar {
    height: 6px;
    border: none;
    background: var(--theme-color);
    top: 27px;
}

.irs--shiny .irs-handle {
    width: 22px;
    height: 22px;
    top: 19px;
    border: 2px solid var(--theme-color);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.irs--shiny .irs-handle.state_hover,
.irs--shiny .irs-handle:hover {
    background: color-mix(in srgb, var(--theme-color) 10%, white);
}

.irs--shiny .irs-single,
.irs--shiny .irs-from,
.irs--shiny .irs-to {
    background: var(--theme-color);
    border-radius: 4px;
    font-size: 12px;
}

.irs--shiny .irs-min,
.irs--shiny .irs-max {
    background: transparent;
    color: #8a8a8a;
    font-size: 11px;
}

/* Hide the small minor tick marks; keep only the labeled major ticks */
.irs--shiny .irs-grid-pol.small {
    display: none;
}

.irs--shiny .irs-grid-pol {
    width: 2px;
    background: #a8adb3;
}

.irs--shiny .irs-grid-text {
    color: #8a8a8a;
    font-size: 11px;
}

/* When a labeled grid is shown, the min/max labels above the track are
   redundant with the grid's end labels */
.irs--shiny:has(.irs-grid) .irs-min,
.irs--shiny:has(.irs-grid) .irs-max {
    display: none;
}

/* Image choice (mc_image / mc_multiple_image) */
.sd-image-choice .shiny-options-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 0.5rem;
}

.sd-image-choice .radio,
.sd-image-choice .checkbox {
    margin: 0;
}

.sd-image-choice .radio label,
.sd-image-choice .checkbox label {
    cursor: pointer;
    padding: 0;
    font-weight: normal;
}

/* Hide the native control but keep it accessible (still keyboard/focusable) */
.sd-image-choice input[type="radio"],
.sd-image-choice input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.sd-image-card {
    border: 2px solid #ddd;
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sd-image-card-img {
    display: block;
    max-width: 160px;
    max-height: 160px;
    border-radius: 4px;
    margin: 0 auto;
}

.sd-image-card-caption {
    display: block;
    margin-top: 6px;
}

.sd-image-choice label:hover .sd-image-card {
    border-color: color-mix(in srgb, var(--theme-color) 50%, white);
}

/* Selected state: highlight the card whose input is checked */
.sd-image-choice label:has(input:checked) .sd-image-card {
    border-color: var(--theme-color);
    box-shadow: 0 0 0 1px var(--theme-color);
}

/* Keyboard focus visibility (the native control is visually hidden) */
.sd-image-choice label:has(input:focus-visible) .sd-image-card {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--theme-color) 35%, transparent);
}

/* Survey mode banner (preview mode / database not connected) */
.sd-mode-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: var(--banner-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    color: white;
    text-align: center;
    font-weight: bold;
    font-size: 14px;
    line-height: 21px;
    z-index: 9999;
}

#sd-preview-banner {
    background-color: #e6a817;
}

#sd-no-db-banner {
    background-color: #cc0000;
}

/* When a mode banner exists, raise the footer so it sits on top of the banner */
:has(.sd-mode-banner) .footer {
    bottom: var(--banner-height);
}

/* Matrix question styling */
.matrix-question-container {
    width: 100%;
    max-height: 70vh;
    overflow-x: auto;
    overflow-y: auto;
    margin-bottom: 2rem;
}

.matrix-question-container .form-group {
    margin-bottom: 0;
}

.matrix-question {
    width: 100%;
    border-collapse: collapse;
    font-size: 18px;
}

.matrix-question th, .matrix-question td {
    padding: 0;
    text-align: center;
    border: none;
    height: 10px;
    vertical-align: middle;
}

.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
  vertical-align: middle;
  padding: 4px;
}

.matrix-question th {
    background-color: #f9f9f9;
    font-weight: bold;
    font-size: 18px;
    position: sticky;
    top: 0;
    z-index: 1;
    box-shadow: 0 2px 3px rgba(0,0,0,0.1);
}

.table {
  --bs-table-striped-bg: #f9f9f9;
}

.matrix-question tr:nth-child(even) {
    background-color: #f9f9f9;
}

.matrix-question tr:nth-child(odd) {
    background-color: #f9f9f9;
}

.matrix-question .shiny-options-group {
    display: flex;
    justify-content: center; /* Center the radio buttons */
    width: 100%;
}

.matrix-question .shiny-options-group .radio,
.matrix-question .shiny-options-group .checkbox {
    margin: 0;
    flex: 1;
    text-align: center;
}

.matrix-question .shiny-options-group .radio label,
.matrix-question .shiny-options-group .checkbox label {
    padding-left: 0;
    display: inline-block;
}

.matrix-question .shiny-options-group .radio input,
.matrix-question .shiny-options-group .checkbox input {
    margin: 0;
    position: relative;
    top: 0.5rem; /* radio/checkbox position */
}

/* Hide radio/checkbox option labels (column headers show the options) */
.matrix-question .shiny-options-group .radio span,
.matrix-question .shiny-options-group .checkbox span {
    display: none;
}

/* Hide control-label in matrix question radio/checkbox groups (avoid duplicate labels when highlighted) */
.matrix-question .shiny-input-radiogroup > .control-label,
.matrix-question .shiny-input-checkboxgroup > .control-label {
    display: none;
}

/* Style for the sub-question labels */
.matrix-question td:first-child {
    text-align: left;
    font-weight: normal;
    padding-left: 15px; /* Add some left padding */
}

/* Container Borders */
.question-container[data-question-id] input[type="text"],
.question-container[data-question-id] input[type="number"],
.question-container[data-question-id] textarea,
.question-container[data-question-id] select {
  border: 1px solid #ddd;
}

.question-container[data-question-id] input[type="radio"],
.question-container[data-question-id] input[type="checkbox"] {
  border-color: #ddd;
}

/* SweetAlert custom styling */
div:where(.swal2-container) .swal2-popup {
  font-size: 1rem !important;
}

div:where(.swal2-container) .swal2-html-container {
  padding: 0 2em;
}

/* Exit pop-up */
.modal {
  display: block !important;
  opacity: 1 !important;
}

.modal-backdrop {
  opacity: 0.5 !important;
}

.modal-dialog {
  z-index: 1050 !important;
}

.modal-body .shiny-input-container .control-label {
  text-align: center;
  width: 100%;
}

/* Required question highlighting */

.required-question-highlight .form-group,
.required-question-highlight.form-group {
  border-color: #dc3545 !important;
  background-color: rgba(220, 53, 69, 0.1) !important;
}

.required-question-highlight .form-control {
  border-color: #dc3545 !important;
}

.required-question-highlight .form-control:focus {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

/* Validation question highlighting (red, highest priority) */

.validation-question-highlight .form-group,
.validation-question-highlight.form-group {
  border-color: #dc3545 !important;
  background-color: rgba(220, 53, 69, 0.1) !important;
}

.validation-question-highlight .form-control {
  border-color: #dc3545 !important;
}

.validation-question-highlight .form-control:focus {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

/* Unanswered question highlighting (blue) */

.unanswered-question-highlight .form-group,
.unanswered-question-highlight.form-group {
  border-color: #007bff !important;
  background-color: rgba(0, 123, 255, 0.1) !important;
}

.unanswered-question-highlight .form-control {
  border-color: #007bff !important;
}

.unanswered-question-highlight .form-control:focus {
  border-color: #007bff !important;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25) !important;
}

/* Unanswered question highlighting (orange) */

.unanswered-question-highlight-orange .form-group,
.unanswered-question-highlight-orange.form-group {
  border-color: #fd7e14 !important;
  background-color: rgba(253, 126, 20, 0.1) !important;
}

.unanswered-question-highlight-orange .form-control {
  border-color: #fd7e14 !important;
}

.unanswered-question-highlight-orange .form-control:focus {
  border-color: #fd7e14 !important;
  box-shadow: 0 0 0 0.2rem rgba(253, 126, 20, 0.25) !important;
}

/* Unanswered question highlighting (green) */

.unanswered-question-highlight-green .form-group,
.unanswered-question-highlight-green.form-group {
  border-color: #28a745 !important;
  background-color: rgba(40, 167, 69, 0.1) !important;
}

.unanswered-question-highlight-green .form-control {
  border-color: #28a745 !important;
}

.unanswered-question-highlight-green .form-control:focus {
  border-color: #28a745 !important;
  box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}

/* Unanswered question highlighting (purple) */

.unanswered-question-highlight-purple .form-group,
.unanswered-question-highlight-purple.form-group {
  border-color: #6f42c1 !important;
  background-color: rgba(111, 66, 193, 0.1) !important;
}

.unanswered-question-highlight-purple .form-control {
  border-color: #6f42c1 !important;
}

.unanswered-question-highlight-purple .form-control:focus {
  border-color: #6f42c1 !important;
  box-shadow: 0 0 0 0.2rem rgba(111, 66, 193, 0.25) !important;
}

/* Unanswered question highlighting (gray) */

.unanswered-question-highlight-gray .form-group,
.unanswered-question-highlight-gray.form-group {
  border-color: #6c757d !important;
  background-color: rgba(108, 117, 125, 0.1) !important;
}

.unanswered-question-highlight-gray .form-control {
  border-color: #6c757d !important;
}

.unanswered-question-highlight-gray .form-control:focus {
  border-color: #6c757d !important;
  box-shadow: 0 0 0 0.2rem rgba(108, 117, 125, 0.25) !important;
}

/* Priority system: red highlighting overrides all unanswered colors */
.required-question-highlight.unanswered-question-highlight .form-group,
.required-question-highlight.unanswered-question-highlight.form-group,
.required-question-highlight.unanswered-question-highlight-orange .form-group,
.required-question-highlight.unanswered-question-highlight-orange.form-group,
.required-question-highlight.unanswered-question-highlight-green .form-group,
.required-question-highlight.unanswered-question-highlight-green.form-group,
.required-question-highlight.unanswered-question-highlight-purple .form-group,
.required-question-highlight.unanswered-question-highlight-purple.form-group,
.required-question-highlight.unanswered-question-highlight-gray .form-group,
.required-question-highlight.unanswered-question-highlight-gray.form-group {
  border-color: #dc3545 !important;
  background-color: rgba(220, 53, 69, 0.1) !important;
}

.required-question-highlight.unanswered-question-highlight .form-control,
.required-question-highlight.unanswered-question-highlight-orange .form-control,
.required-question-highlight.unanswered-question-highlight-green .form-control,
.required-question-highlight.unanswered-question-highlight-purple .form-control,
.required-question-highlight.unanswered-question-highlight-gray .form-control {
  border-color: #dc3545 !important;
}

.required-question-highlight.unanswered-question-highlight .form-control:focus,
.required-question-highlight.unanswered-question-highlight-orange .form-control:focus,
.required-question-highlight.unanswered-question-highlight-green .form-control:focus,
.required-question-highlight.unanswered-question-highlight-purple .form-control:focus,
.required-question-highlight.unanswered-question-highlight-gray .form-control:focus {
  border-color: #dc3545 !important;
  box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

/* Numeric input spinner styling */
.numeric-input-container {
  position: relative;
  display: inline-block;
  width: 100%;
}

.numeric-input-with-spinner {
  padding-right: 0 !important;
}

.numeric-input-with-spinner::-webkit-outer-spin-button,
.numeric-input-with-spinner::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.numeric-input-with-spinner[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.native-spinner {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: calc(100% - 4px);
  display: flex;
  flex-direction: column;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: linear-gradient(to bottom, #f9f9f9 0%, #f0f0f0 100%);
  overflow: hidden;
}

.native-spinner-button {
  flex: 1;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  font-size: 0;
  outline: none;
}

.native-spinner-button:hover {
  background: rgba(0,0,0,0.05);
}

.native-spinner-button:active {
  background: rgba(0,0,0,0.1);
}

.native-spinner-button::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
}

.spinner-up::before {
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 4px solid #666;
}

.spinner-down::before {
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 4px solid #666;
}

.native-spinner-button:not(:last-child) {
  border-bottom: 1px solid #ccc;
}

/* Navigation buttons styling */
.sd-nav-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  width: 100%;
  clear: both;
}

.sd-nav-button {
  min-width: 100px;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.sd-nav-prev {
  margin-right: auto;
}

.sd-nav-next {
  margin-left: auto;
}

/* Ensure navigation buttons work well on mobile */
@media screen and (max-width: 767px) {
  .sd-nav-button {
    min-width: 80px;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }
}

/* Option attribute popup */
.sd-has-attr {
  display: flex;
  align-items: center;
}

.sd-option-label {
  margin-left: 0 !important;
}

.sd-attr-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-bottom: 2px;
  margin-left: 0 !important;
}

.sd-attr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border-radius: 50%;
  border: 1.5px solid #888;
  background: transparent;
  color: #888;
  font-size: 0.7em;
  font-weight: bold;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.sd-attr-btn:hover,
.sd-attr-btn.sd-attr-active {
  background: #888;
  color: #fff;
}

.sd-attr-btn:active {
  background: #555;
  color: #fff;
  transform: scale(0.88);
}

.sd-attr-popup {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 0.82em;
  white-space: nowrap;
  z-index: 1001;
}

.sd-attr-wrap:hover .sd-attr-popup,
.sd-attr-popup.sd-attr-open {
  display: block;
}
