.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  background: var(--c-black);
  z-index: var(--z-modal);
  padding: 20px;
  -webkit-tap-highlight-color: transparent;
}
.modal-backdrop.active { display: flex; }
.modal-window {
  width: 780px;
  max-width: calc(100% - 40px);
  background: color-mix(in srgb, var(--c-panel-2) 84%, transparent);
  color: var(--c-white);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 4vh);
  border: 1px solid color-mix(in srgb, var(--c-white) 8%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transform: translateY(-8px);
  opacity: 0;
  transition: transform var(--transition-speed),
              opacity var(--transition-speed);
  margin-top: 2vh;
}
.modal-backdrop.active .modal-window {
  transform: translateY(0);
  opacity: 1;
}
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid color-mix(in srgb, var(--c-white) 03%, transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}
.modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--c-white);
  line-height: 1;
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--blueink);
  font-size: 18px;
  padding: 6px;
  cursor: pointer;
  border-radius: 8px;
}
.modal-close:hover {
  background: var(--c-panel-2);
  color: var(--c-white);
}
.modal-close:focus {
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring) color-mix(in srgb, var(--c-accent) 12%, transparent);
}
.modal-body {
  padding: 16px 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--c-white);
  font-size: 14px;
}
.modal-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: center;
}
.modal-row[data-position="left"]  { justify-content: flex-start; }
.modal-row[data-position="right"] { justify-content: flex-end; }
.modal-row .modal-element {
  flex: 1 1 auto;
  min-width: 110px;
}
.modal-label {
  display: block;
  font-size: 13px;
  color: var(--blueink);
}
.modal-message {
  color: var(--c-white);
  background: transparent;
  padding: 2px 0;
  font-size: 14px;
}
.modal-input,
.modal-select,
.modal-textarea,
.custom-dropdown-trigger {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--modalinput);
  color: var(--c-white);
  font-size: 14px;
  box-sizing: border-box;
  outline: none;
  font-family: "Source Code Pro", monospace;
  transition: box-shadow var(--transition-speed),
              transform var(--transition-speed),
              background var(--transition-speed);
  margin-top: 8px;
}
.modal-input::placeholder,
.modal-textarea::placeholder {
  color: var(--c-text-faint);
}
.modal-input:focus:not([type="checkbox"]):not([type="radio"]),
.modal-select:focus,
.modal-textarea:focus,
.custom-dropdown-trigger:focus {
  box-shadow: 0 0 0 var(--focus-ring) color-mix(in srgb, var(--c-accent) 08%, transparent);
  border-color: color-mix(in srgb, var(--c-accent) 18%, transparent);
  transform: translateY(-1px);
  background: var(--c-black);
}
.modal-textarea {
  min-height: 84px;
  resize: vertical;
}
.modal-btn,
.modal-inline-button,
.modal-action {
  padding: 8px 12px;
  border-radius: 56px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  transition: transform var(--transition-speed),
              box-shadow var(--transition-speed);
  background: var(--c-panel-3);
  color: var(--c-text-dim);
}
.modal-btn:focus {
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring) var(--c-text-faint);
}
.modal-btn:hover {
  transform: translateY(-1px);
}
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid color-mix(in srgb, var(--c-white) 03%, transparent);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.hidden { display: none !important; }
.small  { font-size: 13px; }
.center { text-align: center; }
.modal-btn.active {
  background: var(--accent2);
  color: var(--c-text-dim);
  outline: none;
  box-shadow: 0 0 0 var(--focus-ring) var(--c-text-faint);
}
.modal-input[type="checkbox"],
.modal-input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  position: relative;
  display: inline-block;
  vertical-align: middle;
  border: none;
  background: transparent;
  outline: none;
}
.modal-input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M 1 9 L 1 9 c 0 -5 3 -8 8 -8 L 9 1 C 14 1 17 5 17 9 L 17 9 c 0 4 -4 8 -8 8 L 9 17 C 5 17 1 14 1 9 L 1 9 Z" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="60" stroke-dashoffset="0"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  transition: all var(--transition-speed);
}
.modal-input[type="checkbox"]:checked::before {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M 1 9 L 1 9 c 0 -5 3 -8 8 -8 L 9 1 C 14 1 17 5 17 9 L 17 9 c 0 4 -4 8 -8 8 L 9 17 C 5 17 1 14 1 9 L 1 9 Z" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="60" stroke-dashoffset="60"/><polyline points="1 9 7 14 15 4" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="22" stroke-dashoffset="42"/></svg>');
  animation: checkboxCheck 0.5s ease forwards;
}
.modal-input[type="radio"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 18px;
  height: 18px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><circle cx="9" cy="9" r="8" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-dasharray="50.27" stroke-dashoffset="0"/></svg>');
  background-size: contain;
  background-repeat: no-repeat;
  transition: all var(--transition-speed);
}
.modal-input[type="radio"]:checked::before {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><circle cx="9" cy="9" r="8" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-dasharray="50.27" stroke-dashoffset="0"/><circle cx="9" cy="9" r="4" fill="%23c8ccd4"/></svg>');
  animation: radioCheck 0.3s ease forwards;
}
/* The SVG stroke above is a fixed hex color baked into a data-URI (can't
   reference theme vars there), so it's near-invisible on light backgrounds.
   Invert it in light theme instead of duplicating the SVGs. */
html[data-theme="light"] .modal-input[type="checkbox"]::before,
html[data-theme="light"] .modal-input[type="radio"]::before {
  filter: invert(1);
}
@keyframes checkboxCheck {
  0%   { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M 1 9 L 1 9 c 0 -5 3 -8 8 -8 L 9 1 C 14 1 17 5 17 9 L 17 9 c 0 4 -4 8 -8 8 L 9 17 C 5 17 1 14 1 9 L 1 9 Z" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="60" stroke-dashoffset="0"/><polyline points="1 9 7 14 15 4" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="22" stroke-dashoffset="66"/></svg>'); }
  100% { background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"><path d="M 1 9 L 1 9 c 0 -5 3 -8 8 -8 L 9 1 C 14 1 17 5 17 9 L 17 9 c 0 4 -4 8 -8 8 L 9 17 C 5 17 1 14 1 9 L 1 9 Z" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="60" stroke-dashoffset="60"/><polyline points="1 9 7 14 15 4" fill="none" stroke="%23c8ccd4" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="22" stroke-dashoffset="42"/></svg>'); }
}
@keyframes radioCheck {
  0%   { transform: scale(0.8);  opacity: 0.8; }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1);    opacity: 1; }
}
@media (max-width: 560px) {
  .modal-window { width: 100%; max-width: 100%; border-radius: 8px; padding: 0; }
  .modal-body   { padding: 12px; }
  .modal-header { padding: 10px 12px; }
  .modal-footer { padding: 10px; }
}

.custom-dropdown {
  position: relative;
  width: 100%;
}
.custom-dropdown-trigger {
  position: relative;
  padding-right: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.custom-dropdown-trigger::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--blueink);
  border-bottom: 2px solid var(--blueink);
  transform: translateY(-75%) rotate(45deg);
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.custom-dropdown-trigger[aria-expanded="true"]::after {
  transform: translateY(-25%) rotate(225deg);
}
.custom-dropdown-portal-menu {
  position: fixed;
  background: color-mix(in srgb, var(--c-panel) 78%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-white) 8%, transparent);
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px color-mix(in srgb, var(--c-black) 50%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow: hidden;
  z-index: 100001;
  opacity: 0;
  transform: scale(0.96) translateY(-10px);
  transition: all 0.23s cubic-bezier(0.4, 0, 0.2, 1);
  visibility: hidden;
  display: flex;
  flex-direction: column;
}
.custom-dropdown-portal-menu.active {
  opacity: 1;
  transform: scale(1) translateY(0);
  visibility: visible;
}
.dropdown-search {
  padding: 10px;
  background: var(--c-panel);
  border-bottom: 1px solid color-mix(in srgb, var(--c-white) 03%, transparent);
}
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px 8px 38px;
  background: var(--c-panel-3);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--c-white);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.search-input:focus {
  border-color: color-mix(in srgb, var(--c-accent) 50%, transparent);
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--blueink);
  pointer-events: none;
}
.options-list {
  padding: 6px;
  overflow-y: auto;
  max-height: calc(38px * 6);
}
.options-list::-webkit-scrollbar { width: 4px; }
.options-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}
.custom-dropdown-option {
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px;
  margin: 1px 0;
  transition: background 0.2s ease;
  color: var(--c-white);
}
.custom-dropdown-option:hover {
  background: color-mix(in srgb, var(--c-white) 05%, transparent);
}
.custom-dropdown-option[aria-selected="true"] {
  background: color-mix(in srgb, var(--c-accent) 10%, transparent);
  color: var(--c-white);
}
.no-results {
  padding: 20px;
  text-align: center;
  color: var(--blueink);
  font-size: 13px;
}
.modal-element {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.modal-label {
  display: inline;
  font-size: 13px;
  color: var(--blueink);
  margin-bottom: 0;
  font-weight: 500;
  order: 2;
}
