.custom-select,
.custom-datetime {
  position: relative;
  width: 100%;
}

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 24, .4);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 16px 16px;
  z-index: 30;
  overflow-y: auto;
}

.modal {
  width: min(560px, 96vw);
  max-height: 84vh;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line, #d7e4df);
  box-shadow: 0 20px 36px rgba(0, 0, 0, .16);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal.modal-sm {
  width: min(480px, 96vw);
}

.modal.modal-md {
  width: min(560px, 96vw);
}

.modal.modal-lg {
  width: min(720px, 96vw);
}

.modal.modal-xl {
  width: min(1040px, 96vw);
}

.modal .panel-head {
  min-height: 56px;
  padding: 0 16px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;
}

.modal .panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.modal .panel-title {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.4;
}

.modal-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  width: auto;
}

.modal .panel-head .btn.secondary[data-close] {
  min-width: 88px;
  height: 40px;
  min-height: 40px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.modal-footer .btn {
  height: 40px;
  min-height: 40px;
  min-width: 88px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: 10px;
}

.custom-select-btn,
.custom-datetime-btn {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line, #d7e4df);
  border-radius: 10px;
  background: #fff;
  color: var(--text, #1e2a2b);
  padding: 9px 38px 9px 10px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-btn::after,
.custom-datetime-btn::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted, #607175);
  border-bottom: 2px solid var(--muted, #607175);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.custom-select.is-open .custom-select-btn::after,
.custom-datetime.is-open .custom-datetime-btn::after {
  transform: translateY(-35%) rotate(-135deg);
}

.custom-select-panel,
.custom-datetime-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 40;
  display: none;
  width: 100%;
  border: 1px solid var(--line, #d7e4df);
  border-radius: 16px;
  background: var(--surface, #fff);
  box-shadow: 0 16px 36px rgba(27, 60, 58, .12);
  padding: 6px;
}

.custom-select-panel.open,
.custom-datetime-panel.open {
  display: block;
}

.custom-select-grid {
  display: grid;
  gap: 4px;
}

.custom-select-grid.cols-1 {
  grid-template-columns: minmax(0, 1fr);
}

.custom-select-grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.custom-select-grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.custom-select-grid.cols-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.custom-select-grid.cols-8 {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.custom-select-option {
  width: 100%;
  border: 1px solid var(--line, #d7e4df);
  border-radius: 10px;
  background: #fff;
  color: var(--text, #1e2a2b);
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 400;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}

.custom-select-option:hover {
  background: var(--surface-soft, #f8fbfa);
}

.custom-select-option.active {
  border-color: rgba(44, 122, 115, .28);
  background: rgba(44, 122, 115, .12);
  color: var(--primary-strong, #235f59);
}

.custom-datetime-panel {
  max-width: 360px;
  padding: 8px 8px 10px;
}

.custom-datetime-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.custom-datetime-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary-strong, #235f59);
}

.custom-datetime-nav {
  border: 1px solid var(--line, #d7e4df);
  background: #fff;
  color: var(--primary-strong, #235f59);
  width: 28px;
  height: 28px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.custom-datetime-weekdays,
.custom-datetime-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.custom-datetime-weekdays {
  margin-bottom: 4px;
}

.custom-datetime-weekday {
  font-size: 11px;
  color: var(--muted, #607175);
  text-align: center;
  padding: 2px 0;
}

.custom-datetime-day {
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 34px;
  background: #fff;
  color: var(--text, #1e2a2b);
  font-size: 12px;
  cursor: pointer;
}

.custom-datetime-day:hover {
  border-color: var(--line, #d7e4df);
  background: var(--surface-soft, #f8fbfa);
}

.custom-datetime-day.muted {
  color: rgba(96, 113, 117, .45);
}

.custom-datetime-day.active {
  background: rgba(44, 122, 115, .12);
  border-color: rgba(44, 122, 115, .28);
  color: var(--primary-strong, #235f59);
  font-weight: 700;
}

.custom-datetime-time {
  display: grid;
  grid-template-columns: minmax(0, .7fr) minmax(0, .7fr) auto;
  gap: 4px;
  margin-top: 6px;
  padding: 0 8px;
  align-items: end;
}

.custom-datetime-time .time-field {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.custom-datetime-time label {
  font-size: 10px;
  color: var(--muted, #607175);
  font-weight: 600;
}

.time-control {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr 24px;
  align-items: stretch;
  width: 100%;
  border: 1px solid var(--line, #d7e4df);
  border-radius: 8px;
  background: #fff;
  overflow: visible;
}

.time-arrow,
.time-value,
.time-confirm-btn {
  border: 0;
  background: transparent;
  color: var(--text, #1e2a2b);
  font-family: inherit;
  cursor: pointer;
}

.time-arrow {
  min-height: 30px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted, #607175);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.time-value {
  min-height: 30px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.time-confirm-btn {
  min-height: 30px;
  border-radius: 8px;
  background: var(--primary, #2c7a73);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  width: auto;
  min-width: 70px;
  padding: 0 14px;
  white-space: nowrap;
}

.time-confirm-field label {
  visibility: hidden;
}

.time-popup {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 6;
  display: none;
  padding: 0;
  bottom: calc(100% + 4px);
}

.time-popup.open {
  display: block;
}

.time-popup-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  background: #fff;
  border: 1px solid var(--line, #d7e4df);
  border-radius: 10px;
  box-shadow: 0 10px 22px rgba(27, 60, 58, .12);
  overflow: hidden;
}

.time-popup-item {
  border: 0;
  background: #fff;
  color: var(--text, #1e2a2b);
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  padding: 5px 0;
  text-align: center;
  cursor: pointer;
}

.time-popup-item.active {
  color: var(--primary-strong, #235f59);
  font-weight: 700;
}

.time-popup-item:hover {
  background: rgba(44, 122, 115, .08);
}

@media (max-width: 640px) {
  .custom-datetime-panel {
    max-width: none;
    width: min(360px, calc(100vw - 32px));
  }

  .custom-select-grid.cols-6,
  .custom-select-grid.cols-8 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .custom-datetime-time {
    gap: 6px;
    padding: 0 8px;
  }
}
